Skip to content

Commit

Permalink
fix: fix data access policies condition logic (#8976)
Browse files Browse the repository at this point in the history
Data access policies conditions should be joined via AND operator,
but the initial implementation used OR by mistake

Also ensured that rbac smoke tests are ran as part of the CI
  • Loading branch information
bsod90 authored Nov 21, 2024
1 parent e948856 commit 47e7897
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 504 deletions.
6 changes: 5 additions & 1 deletion .github/actions/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ echo "::endgroup::"

echo "::group::MongoBI"
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mongobi
echo "::endgroup::"
echo "::endgroup::"

echo "::group::RBAC"
yarn lerna run --concurrency 1 --stream --no-prefix smoke:rbac
echo "::endgroup::"
2 changes: 1 addition & 1 deletion packages/cubejs-server-core/src/core/CompilerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class CompilerApi {
if (typeof b !== 'boolean') {
throw new Error(`Access policy condition must return boolean, got ${JSON.stringify(b)}`);
}
return a || b;
return a && b;
});
}
return true;
Expand Down
21 changes: 21 additions & 0 deletions packages/cubejs-testing/birdbox-fixtures/rbac/cube.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ module.exports = {
},
};
}
if (user === 'manager') {
if (password && password !== 'manager_password') {
throw new Error(`Password doesn't match for ${user}`);
}
return {
password,
superuser: false,
securityContext: {
auth: {
username: 'manager',
userAttributes: {
region: 'CA',
city: 'Fresno',
canHaveAdmin: false,
minDefaultId: 10000,
},
roles: ['manager'],
},
},
};
}
throw new Error(`User "${user}" doesn't exist`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,23 @@ cube('line_items', {
excludes: ['created_at'],
},
},
{
role: 'manager',
conditions: [
{
if: security_context.auth?.userAttributes?.region === 'CA',
},
{
// This condition should not match the one defined in the "manager" mock context
if: security_context.auth?.userAttributes?.region === 'San Francisco',
},
],
rowLevel: {
allowAll: true,
},
memberLevel: {
excludes: ['created_at'],
},
},
],
});
2 changes: 1 addition & 1 deletion packages/cubejs-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"smoke:postgres": "jest --verbose -i dist/test/smoke-postgres.test.js",
"smoke:redshift": "jest --verbose -i dist/test/smoke-redshift.test.js",
"smoke:redshift:snapshot": "jest --verbose --updateSnapshot -i dist/test/smoke-redshift.test.js",
"smoke:rbac": "TZ=UTC jest --verbose --forceExit -i dist/test/smoke-rbac.test.js",
"smoke:rbac": "TZ=UTC jest --verbose -i dist/test/smoke-rbac.test.js",
"smoke:cubesql": "TZ=UTC jest --verbose --forceExit -i dist/test/smoke-cubesql.test.js",
"smoke:cubesql:snapshot": "TZ=UTC jest --verbose --forceExit --updateSnapshot -i dist/test/smoke-cubesql.test.js",
"smoke:prestodb": "jest --verbose -i dist/test/smoke-prestodb.test.js",
Expand Down
Loading

0 comments on commit 47e7897

Please sign in to comment.