Skip to content
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 project query parameter to URLs in authorizer #13317

Merged
merged 9 commits into from
Jul 26, 2024

Conversation

markylaing
Copy link
Contributor

@markylaing markylaing commented Apr 11, 2024

In our implementation of (github.com/openfga/openfga/pkg/storage).OpenFGADatastore, entity URLs are expected to include the project query parameter even if it is the default project. However, LXD typically displays URLs without the project query parameter when a resource is in the default project (with the exception of permissions, where we have been explicit).

This PR ensures that the project query parameter is added to URLs inside the Authorizer so that this doesn't need to be done elsewhere in the codebase (such as in project.FilterUsedBy which has now been simplified).

Closes #13072

@markylaing markylaing requested a review from tomponline as a code owner April 11, 2024 15:55
@markylaing markylaing self-assigned this Apr 11, 2024
@markylaing markylaing marked this pull request as draft April 11, 2024 15:56
@markylaing markylaing force-pushed the authorizer-add-project branch from ad1d4e6 to a4fa4d3 Compare April 24, 2024 12:29
@markylaing markylaing force-pushed the authorizer-add-project branch from a4fa4d3 to eb099b5 Compare July 5, 2024 15:15
@markylaing markylaing marked this pull request as ready for review July 5, 2024 15:16
@markylaing
Copy link
Contributor Author

@tomponline This is ready for review when you have time. Thanks.

@markylaing markylaing changed the title Auth: Add project query parameter to URLs in authorizer. Auth: Add project query parameter to URLs in authorizer Jul 5, 2024
@markylaing markylaing force-pushed the authorizer-add-project branch from 685eb8f to e030027 Compare July 9, 2024 09:21
lxd/auth/drivers/tls.go Outdated Show resolved Hide resolved
Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question on tests and a few nits around "err" in logging.

Previously this was just returned in the path arguments.

Signed-off-by: Mark Laing <[email protected]>
So that `URL` is the inverse of `ParseURL`, we should explicitly
ignore the `projectName` argument when creating the URL of a
project.

Signed-off-by: Mark Laing <[email protected]>
We now expect the project name to be returned from ParseURL.
Additionally, we now test that the normalised URL is what we expect.

Signed-off-by: Mark Laing <[email protected]>
…ents.

We can now use the value of `projectName` returned from ParseURL.

Signed-off-by: Mark Laing <[email protected]>
…uments.

We can now use the value of `projectName` returned from ParseURL.

Signed-off-by: Mark Laing <[email protected]>
This commit regenerates the entity URLs that are passed into
`CheckPermission` and the `PermissionChecker` returned by
`GetPermissionChecker` to enforce that the project parameter
is added to the URL even if it is "default". This is expected
by the underlying `storage.OpenFGADatastore` implementation.

Signed-off-by: Mark Laing <[email protected]>
The entity URLs returned by `projectUsedBy` included the project
query parameter even when the project was "default".

Signed-off-by: Mark Laing <[email protected]>
We no longer need to enforce that the project query parameter
is set in the URLs that are passed into Authorizer methods, nor
do we need to strip the project query parameter from the URL.

Signed-off-by: Mark Laing <[email protected]>
All LXD entity URLs are parsed into a project, a location, and a slice
of path arguments. Previously when parsing a project URL, the project
name was empty because it is present in the path arguments. Now that the
project name is being returned, we need our entity SQL queries to match.

Signed-off-by: Mark Laing <[email protected]>
@markylaing markylaing force-pushed the authorizer-add-project branch from e030027 to 2443da2 Compare July 25, 2024 13:08
@markylaing markylaing requested a review from tomponline July 25, 2024 13:11
Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tomponline tomponline merged commit b7b1ee2 into canonical:main Jul 26, 2024
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth: authorizer should add project=default where necessary
2 participants