-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auth: Add more tests for entity enrichment with entitlements #14973
auth: Add more tests for entity enrichment with entitlements #14973
Conversation
adf22a4
to
62c1c61
Compare
351ce70
to
42954b9
Compare
57bb795
to
25c7335
Compare
8026848
to
dfc1e69
Compare
dfc1e69
to
ed4ab9e
Compare
12eaf11
to
077ebe8
Compare
3a2a3f1
to
0c270f7
Compare
f3f4a03
to
812d005
Compare
…uld not be enriched with entitlements Signed-off-by: Gabriel Mougard <[email protected]>
…p>, volume<snapshot|backup> entities Signed-off-by: Gabriel Mougard <[email protected]>
…lice of pointers Signed-off-by: Gabriel Mougard <[email protected]>
812d005
to
af7d62a
Compare
test/suites/auth.sh
Outdated
echo "Second check failed (or pool not found)!" >&2 | ||
false | ||
fi | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storage pools aren't project specific. This should work without the project=default
key value pair when adding the permissions, and without the project query parameter.
Also, why did you list all storage pools, rather than just querying for the one that permissions have been granted against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, removing this query param. As for the tests, I need to test both endpoints to see if entitlements are attached in both cases: the storage-pools/{name}
one and the storage-pools/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the pattern you've created in the tests by listing all and using jq
to make assertions. For me it's quite clear what's going on, but more comments on the test wouldn't hurt.
Additionally, the with-access-entitlements
tests are getting quite long. Could you please move them into another bash function and call that?
@markylaing thanks for the review! |
af7d62a
to
000f97a
Compare
…ceOnly.` Signed-off-by: Gabriel Mougard <[email protected]>
Signed-off-by: Gabriel Mougard <[email protected]>
000f97a
to
7fa1d7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more thing - can you please move the with-access-entitlements
tests to another bash function and call that? Thanks.
4f90416
to
e851b13
Compare
Signed-off-by: Gabriel Mougard <[email protected]>
e851b13
to
b0a63b9
Compare
@markylaing @gabrielmougard is this ready for final review now? |
yes (I addressed @markylaing latest comment regarding moving the tests in their own function) |
lxc auth group permission add test-group server admin | ||
lxc auth group permission add test-group server viewer | ||
lxc auth group permission add test-group server project_manager | ||
[ "$(lxc_remote query "oidc:/1.0?with-access-entitlements=admin,viewer,project_manager" | jq -r '.access_entitlements | sort | @csv')" = '"admin","project_manager","viewer"' ] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at the end of the file.
lxc auth identity group add oidc/[email protected] test-group | ||
# Create a new test project, add some entitlements on it and check that these are reflected in the 'access_entitlements' field returned from the API. | ||
lxc project create test-project | ||
lxc auth group permission add test-group project test-project can_view | ||
lxc auth group permission add test-group project test-project can_edit | ||
lxc auth group permission add test-group project test-project can_delete | ||
|
||
# Check the created project entitlements given a list of candidate entitlements (some are wrong: `can_create_instances` and `can_create_networks`. These should not be returned). | ||
[ "$(lxc_remote query "oidc:/1.0/projects/test-project?recursion=1&with-access-entitlements=can_view,can_edit,can_delete,can_create_instances,can_create_networks" | jq -r '.access_entitlements | sort | @csv')" = '"can_delete","can_edit","can_view"' ] | ||
lxc project delete test-project | ||
|
||
# Repeat the same test for other entity types. | ||
# Instance | ||
ensure_import_testimage | ||
lxc init testimage test-foo | ||
lxc auth group permission add test-group instance test-foo can_view project=default | ||
lxc auth group permission add test-group instance test-foo can_edit project=default | ||
lxc auth group permission add test-group instance test-foo can_delete project=default | ||
[ "$(lxc_remote query "oidc:/1.0/instances/test-foo?project=default&recursion=1&with-access-entitlements=can_view,can_edit,can_delete,can_exec" | jq -r '.access_entitlements | sort | @csv')" = '"can_delete","can_edit","can_view"' ] | ||
lxc delete test-foo -f | ||
|
||
# Storage volume | ||
# Storage volume entitlements test | ||
pool_name="$(lxc storage list -f csv | cut -d, -f1)" | ||
lxc storage volume create "${pool_name}" test-volume | ||
lxc auth group permission add test-group storage_volume test-volume can_view project=default pool="${pool_name}" type=custom | ||
lxc auth group permission add test-group storage_volume test-volume can_edit project=default pool="${pool_name}" type=custom | ||
lxc auth group permission add test-group storage_volume test-volume can_delete project=default pool="${pool_name}" type=custom | ||
[ "$(lxc_remote query "oidc:/1.0/storage-pools/${pool_name}/volumes/custom/test-volume?project=default&recursion=1&with-access-entitlements=can_view,can_edit,can_delete,can_manage_backups,can_manage_snapshots" | jq -r '.access_entitlements | sort | @csv')" = '"can_delete","can_edit","can_view"' ] | ||
lxc storage volume delete "${pool_name}" test-volume | ||
entities_enrichment_with_entitlements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this to just below line 220 and then you won't need to re-add the OIDC user to the test group on line 290.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of nits that can be cleaned up in a follow up.
Permissions for auth groups and certificates were not being deleted properly by the triggers. This caused dangling permissions to be logged when new tests were added by @gabrielmougard in #14973. More details on the trigger changes can be found in the commit messages. I've also added a regex to `deps/panic-checker` to check for this log line and fail any future tests if it is found again. I've run the tests with this addition to the test suite before and after adding the fix to ensure it works and catches the log message. Note that these dangling permissions are *not* a security issue because they reference entities by their ID. If they are dangling, it means they are no longer referencing anything and therefore not granting access. They also can never reference another new entity, since all of our database IDs are set to auto-increment.
This adds tests for the enrichment of the remaining LXD entities that are eligible. This also remove support for entitlement enrichment for instance<snapshot|backup> and volume<snapshot|backup>. These are managed by the parent instance/volume
can_mange_<snapshots|backups>