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

Package repository permissions endpoint #5604

Merged
merged 16 commits into from Nov 17, 2022
Merged

Conversation

castelblanque
Copy link
Collaborator

Description of the change

Adds a new procedure GetPackageRepositoryPermissions in the repositories API that allows to get the permissions for the current user with regards to package repositories.

Returned structure of data is (per plugin):

  • Global permissions (no namespace). Verbs allowed (get, list, etc.)
  • Same as above but specific for a namespace, if specified

Benefits

This endpoint will allow to:

  • Perform in a single call what is being done now with multiple canI requests from frontend.
  • Abstract away the frontend from knowing about the CRDs used by plugins. See here.

Possible drawbacks

N/A

Applicable issues

Rafa Castelblanque added 6 commits October 28, 2022 17:56
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
@netlify
Copy link

netlify bot commented Nov 3, 2022

Deploy Preview for kubeapps-dev ready!

Name Link
🔨 Latest commit 150a143
🔍 Latest deploy log https://app.netlify.com/sites/kubeapps-dev/deploys/637577149578b600088aff5d
😎 Deploy Preview https://deploy-preview-5604--kubeapps-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
@castelblanque castelblanque changed the title permissions endpoint Package repository permissions endpoint Nov 3, 2022
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
// Each access review is requested in a go routine
for _, v := range AccessVerbs {
wg.Add(1)
go func(verb string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Each SelfSubjectAccessReview is created on a go routine.

Copy link
Contributor

@antgamdia antgamdia left a comment

Choose a reason for hiding this comment

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

Neat! It's great we can finally free the UI up from performing the low-level canI for the repo auth.

@@ -720,6 +720,48 @@
]
}
},
"/core/packages/v1alpha1/repositories/c/{context.cluster}/permissions": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FTR, we should also update the openapi.yaml file when upgrading the API.
See #5610

Comment on lines 515 to 519
kubeappsapis.core.plugins.v1alpha1.Plugin plugin = 1;

map<string, bool> global = 2;

map<string, bool> namespace = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add a short sentence above each param for the autogenerated docs

Copy link
Collaborator

@beni0888 beni0888 left a comment

Choose a reason for hiding this comment

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

LGTM! Great job @castelblanque! 👏🏻

@dlaloue-vmware
Copy link
Collaborator

From the code, it seems that "global" is considered equivalent to not providing a namespace when doing the checks, which i assume is doing a check cluster wide (similar to the --all-namespace option?)

This is technically not accurate, and aside from cluster admins, this may not always return the correct results.

In the case of Carvel and Helm plugins, being able to create/update/delete global repositories is equivalent to having the permission on the corresponding global namespace - which is different than having permissions at the cluster level.
For example, i may be a user with privileges to create global repos and yet not be a cluster admin. I would not be able to manage global repositories via the UI.

For a user scoped to a namespace, "list" and "get" will return false for the global checks, even though the user can list and view global repositories.

Flux does not really have a notion of global repositories, I think the checks should always be false for the global map (i.e. we can skip the checks).

Rafa Castelblanque added 7 commits November 7, 2022 08:43
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Merge

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
@castelblanque
Copy link
Collaborator Author

Thanks all for the review!

@dlaloue-vmware I agree, switched now to the global namespace (in Helm and Kapp). For Flux, no global info is returned.

@dlaloue-vmware dlaloue-vmware merged commit 28ae5f5 into main Nov 17, 2022
@dlaloue-vmware dlaloue-vmware deleted the 5521-permissions-endpoint branch November 17, 2022 00:49
dlaloue-vmware added a commit that referenced this pull request Nov 17, 2022
)

### Description of the change

This PR sits on top of PR #5604 and adapts UI to use the API endpoint
introduced to return allowed permissions for package repositories.
It also fixes #5542, opened for Flux.
Areas affected are:
- `Add package repository` button is enabled only if the user has
`create` permission at current namespace or cluster level.
- `Edit/Delete` buttons on each repo are enabled if user has `update`
permission in repository type.
- `Show repositories in all namespaces` switch is enabled if user has
`list` permissions cluster-wide.

### Benefits

Real permissions granted to the current user are checked to adapt the UI
when managing package repositories.

### Possible drawbacks

Some more fine-tuning of the UI is needed to take advantage of the new
permissions API endpoint.

### Applicable issues

- fixes #5542

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
Co-authored-by: Dimitri Laloue <74025858+dlaloue-vmware@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New package repository API endpoint to provide repositories permissions
5 participants