File tree Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Expand file tree Collapse file tree 5 files changed +60
-3
lines changed Original file line number Diff line number Diff line change @@ -1195,7 +1195,12 @@ class ApiGateway {
11951195 currentQuery = this . parseMemberExpressionsInQuery ( currentQuery ) ;
11961196 }
11971197
1198- const normalizedQuery = normalizeQuery ( currentQuery , persistent ) ;
1198+ let normalizedQuery = normalizeQuery ( currentQuery , persistent ) ;
1199+
1200+ if ( hasExpressionsInQuery ) {
1201+ normalizedQuery = this . evalMemberExpressionsInQuery ( normalizedQuery ) ;
1202+ }
1203+
11991204 // First apply cube/view level security policies
12001205 const queryWithRlsFilters = await compilerApi . applyRowLevelSecurity (
12011206 normalizedQuery ,
@@ -1207,8 +1212,8 @@ class ApiGateway {
12071212 context ,
12081213 ) ;
12091214
1210- if ( hasExpressionsInQuery ) {
1211- rewrittenQuery = this . evalMemberExpressionsInQuery ( rewrittenQuery ) ;
1215+ if ( this . hasExpressionsInQuery ( rewrittenQuery ) ) {
1216+ rewrittenQuery = this . parseMemberExpressionsInQuery ( rewrittenQuery ) ;
12121217 }
12131218
12141219 return normalizeQuery (
Original file line number Diff line number Diff line change @@ -43,6 +43,27 @@ module.exports = {
4343 } ,
4444 } ;
4545 }
46+ if ( user === 'default' ) {
47+ if ( password && password !== 'default_password' ) {
48+ throw new Error ( `Password doesn't match for ${ user } ` ) ;
49+ }
50+ return {
51+ password,
52+ superuser : false ,
53+ securityContext : {
54+ auth : {
55+ username : 'default' ,
56+ userAttributes : {
57+ region : 'CA' ,
58+ city : 'San Francisco' ,
59+ canHaveAdmin : false ,
60+ minDefaultId : 20000 ,
61+ } ,
62+ roles : [ ] ,
63+ } ,
64+ } ,
65+ } ;
66+ }
4667 throw new Error ( `User "${ user } " doesn't exist` ) ;
4768 }
4869} ;
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ cubes:
1919
2020 access_policy :
2121 - role : " *"
22+ row_level :
23+ filters :
24+ - member : " {CUBE}.city"
25+ operator : equals
26+ values : ["{ security_context.auth.userAttributes.city }"]
2227 - role : admin
2328 conditions :
2429 # This thing will fail if there's no auth info in the context
Original file line number Diff line number Diff line change @@ -587,4 +587,12 @@ Array [
587587]
588588` ;
589589
590+ exports [` Cube RBAC Engine RBAC via SQL API default policy SELECT with member expressions: users_member_expression 1` ] = `
591+ Array [
592+ Object {
593+ " count" : " 149" ,
594+ } ,
595+ ]
596+ ` ;
597+
590598exports [` Cube RBAC Engine RBAC via SQL API manager SELECT * from line_items: line_items_manager 1` ] = ` Array []` ;
Original file line number Diff line number Diff line change @@ -165,6 +165,24 @@ describe('Cube RBAC Engine', () => {
165165 } ) ;
166166 } ) ;
167167
168+ describe ( 'RBAC via SQL API default policy' , ( ) => {
169+ let connection : PgClient ;
170+
171+ beforeAll ( async ( ) => {
172+ connection = await createPostgresClient ( 'default' , 'default_password' ) ;
173+ } ) ;
174+
175+ afterAll ( async ( ) => {
176+ await connection . end ( ) ;
177+ } , JEST_AFTER_ALL_DEFAULT_TIMEOUT ) ;
178+
179+ test ( 'SELECT with member expressions' , async ( ) => {
180+ const res = await connection . query ( 'SELECT COUNT(city) as count from "users" HAVING (COUNT(1) > 0)' ) ;
181+ // Pushed SQL queries should not fail
182+ expect ( res . rows ) . toMatchSnapshot ( 'users_member_expression' ) ;
183+ } ) ;
184+ } ) ;
185+
168186 describe ( 'RBAC via REST API' , ( ) => {
169187 let client : CubeApi ;
170188 let defaultClient : CubeApi ;
You can’t perform that action at this time.
0 commit comments