-
Notifications
You must be signed in to change notification settings - Fork 931
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: Handle dangling permissions #12992
Conversation
4702572
to
6812751
Compare
6812751
to
ea72ac3
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.
My main question with this PR is can we remove the permissions when the entity is deleted? Its great we are detecting any dangling ones and handling them to avoid access control issues - but leaving orphaned entries in the DB by design seems rather unfortunate - and something we would have considered to be a bug previously.
Also, are there any risks of a dangling permission being re-used for a new entity of the same type and name & project? |
No, when the new entity is added its ID will be different. The embedded driver wont be able to get a URL for the permission with the ID of the deleted entity because it will not be able to query for it's name/project etc. by ID. Also, when adding a permission to a group the URL is parsed to get an entity ID, as the old entity has been deleted, the new permission can only reference the new entity.
There are a few approaches here and non are perfect:
I realised this morning that there is another case where permissions can be dangling. If a permission is added to a group, the permission is created and an association is made between the group and the permission. If the group is subsequently deleted, the association between the group and permission is also deleted but the permission itself is not deleted. Overall, my feeling is that the best approach will be a combination of 2 and 3. 2 ensures that dangling permissions are never used for authorization, nor are they ever shown via the API. 3 can additionally delete permissions that don't belong to any groups and will ensure clean up happens regularly enough that the permissions table doesn't grow too much. I kind of think of this like a garbage collector that optimistically cleans up when something goes out of scope, but also does a stop-the-world periodically. |
Moved to draft as approach has changed after discussion |
f139229
to
e97686d
Compare
e97686d
to
6287941
Compare
@tomponline I've implemented the changes we discussed:
|
1 similar comment
@tomponline I've implemented the changes we discussed:
|
I've just now remembered that we can get rid of a lot of warning deletion logic so I'll keep as draft until I've done that. |
Do we need this really? |
We can go back to cleaning up opportunistically if you like. My thinking was to remove any logic from the API endpoints that aren't specifically required. I suppose I can write a clean up function and defer call to it in the API handlers? |
That's what the triggers were to prevent right? |
Yes. Basically I added the task so that LXD complains fairly loudly if the triggers aren't working as expected. |
I don't think we need a task if the triggers are there. We could log a warning if the access checker detects them when its ignoring them perhaps? |
Sure happy to do that :) |
@tomponline this PR is causing some of the clustering tests to fail. Sometimes when setting up another cluster member it fails to start up. I think it's to do with the logic for when to apply the triggers in this commit: 6b2a611 On startup I'm calling |
a15cb04
to
4e5c01b
Compare
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Updates the method to return a slice of valid permissions, a slice of dangling permissions, and a map of entity type to map of entity ID to URL. Additionally, improves performance by ensuring queries are not executed more than once for permissions that reference the same entity. Signed-off-by: Mark Laing <mark.laing@canonical.com>
Additionally, log a warning if dangling permissions are encountered. Signed-off-by: Mark Laing <mark.laing@canonical.com>
This function was previously quite complicated as we had to check if a permission already existed before creating it and return a slice of permission IDs to the caller. Now permissions are directly related to groups via foreign key we can convert the URLs, delete any existing permissions for the group, and create the new ones. Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
b8acb6b
to
e3fdb6b
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.
There doesn't appear to be any error wrapping in that last commit despite what the commit message says
e3fdb6b
to
9792ab9
Compare
I've reworded the commits to separate it out properly. This was an oversight while rebasing. |
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Additionally, wrap errors returned from `EnsureSchema` and `applyTriggers`. Signed-off-by: Mark Laing <mark.laing@canonical.com>
9792ab9
to
7eed28f
Compare
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
7eed28f
to
1741b7c
Compare
Additionally, capitalise error messages. Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
1741b7c
to
fcde91b
Compare
The
permissions
table hasentity_id
,entity_type
, andentitlement
columns. When a permission is created, we validate that the entity exists and get its ID. However, if the entity is deleted the permission is left dangling.Dangling permissions could never have been displayed or used because we can't construct a URL for them for use in the API responses. However, not handling them led to some strange behaviour in the OpenFGA datastore (see #12976 (comment)) and of course we don't want the permissions table to grow indefinitely.
This PR adds logic to lazily delete dangling permissions as they are encountered.