grafana/pkg/services/accesscontrol
Tom Ratcliffe fc51ec70ba
Alerting: Add manage permissions UI logic for Contact Points (#92885)
* Add showPolicies prop

* Add manage permissions component for easier reuse within alerting

* Add method for checking whether to show access control within alerting

* Remove accidental console.log from main

* Tweak styling for contact point width and add manage permissions drawer

* Improve typing for access control type response

* Add basic test for manage permissions on contact points list

* Only show manage permissions if grafana AM and alertingApiServer is enabled

* Update i18n

* Add test utils for turning features on and back off

* Add access control handlers

* Update tests with new util

* Pass AM in and add tests

* Receiver OSS resource permissions

There is a complication that is not fully addressed: Viewer defaults to read:*
and Editor defaults to read+write+delete:*

This is different to other resource permissions where non-admin are not granted
any global permissions and instead access is handled solely by resource-specific
permissions that are populated on create and removed on delete.

This allows them to easily remove permission to view or edit a single resource
from basic roles.

The reason this is tricky here is that we have multiple APIs that can
create/delete receivers: config api, provisioning api, and k8s receivers api.
Config api in particular is not well-equipped to determine when creates/deletes
are happening and thus ensuring that the proper resource-specific permissions
are created/deleted is finicky.

We would also have to create a migration to populate resource-specific
permissions for all current receivers. This migration would need to be reset so
it can run again if the flag is disabled.

* Add access control permissions

* Pass in contact point ID to receivers form

* Temporarily remove access control check for contact points

* Include access control metadata in k8s receiver List & Get

GET: Always included.
LIST: Included by adding a label selector with value `grafana.com/accessControl`

* Include new permissions for contact points navbar

* Fix receiver creator fixed role to not give global read

* Include in-use metadata in k8s receiver List & Get

GET: Always included.
LIST: Included by adding a label selector with value `grafana.com/inUse`

* Add receiver creator permission to receiver writer

* Add receiver creator permission to navbar

* Always allow listing receivers, don't return 403

* Remove receiver read precondition from receiver create

Otherwise, Creator role will not be able to create their first receiver

* Update routes permissions

* Add further support for RBAC in contact points

* Update routes permissions

* Update contact points header logic

* Back out test feature toggle refactor

Not working atm, not sure why

* Tidy up imports

* Update mock permissions

* Revert more test changes

* Update i18n

* Sync inuse metadata pr

* Add back canAdmin permissions after main merge

* Split out check for policies navtree item

* Tidy up utils and imports and fix rules in use

* Fix contact point tests and act warnings

* Add missing ReceiverPermissionAdmin after merge conflict

* Move contact points permissions

* Only show contact points filter when permissions are correct

* Move to constants

* Fallback to empty array and remove labelSelectors (not needed)

* Allow `toAbility` to take multiple actions

* Show builtin alertmanager if contact points permission

* Add empty state and hide templates if missing permissions

* Translations

* Tidy up mock data

* Fix tests and templates permission

* Update message for unused contact points

* Don't return 403 when user lists receivers and has access to none

* Fix receiver create not adding empty uid permissions

* Move SetDefaultPermissions to ReceiverPermissionService

* Have SetDefaultPermissions use uid from string

Fixes circular dependency

* Add FakeReceiverPermissionsService and fix test wiring

* Implement resource permission handling in provisioning API and renames

Create: Sets to default permissions
Delete: Removes permissions
Update: If receiver name is modified and the new name doesn't exist, it copies
the permissions from the old receiver to the newly created one. If old receiver
is now empty, it removes the old permissions as well.

* Split contact point permissions checks for read/modify

* Generalise getting annotation values from k8s entities

* Proxy RouteDeleteAlertingConfig through MultiOrgAlertmanager

* Cleanup permissions on config api reset and restore

* Cleanup permissions on config api POST

note this is still not available with feature flag enabled

* Gate the permission manager behind FF until initial migration is added

* Sync changes from config api PR

* Switch to named export

* Revert unnecessary changes

* Revert Filter auth change and implement in k8s api only

* Don't allow new scoped permissions to give access without FF

Prevents complications around mixed support for the scoped permissions causing
oddities in the UI.

* Fix integration tests to account for list permission change

* Move to `permissions` file

* Add additional tests for contact points

* Fix redirect for viewer on edit page

* Combine alerting test utils and move to new file location

* Allow new permissions to access provisioning export paths with FF

* Always allow exporting if its grafana flavoured

* Fix logic for showing auto generated policies

* Fix delete logic for contact point only referenced by a rule

* Suppress warning message when renaming a contact point

* Clear team and role perm cache on receiver rename

Prevents temporarily broken UI permissions after rename when a user's source of
elevated permissions comes from a cached team or basic role permission.

* Debug log failed cache clear on CopyPermissions

---------

Co-authored-by: Matt Jacobson <matthew.jacobson@grafana.com>
2024-09-27 19:56:32 +01:00
..
acimpl ManagedServiceAccounts: Add a config option to disable the feature on-prem (#93571) 2024-09-27 09:11:59 +02:00
actest RBAC: Add required component to perform access control checks for user api when running single tenant (#93104) 2024-09-23 11:26:44 +02:00
api Instrument tracing across dashboards (#91937) 2024-08-29 22:26:15 -08:00
database Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
migrator Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
mock RBAC: Add required component to perform access control checks for user api when running single tenant (#93104) 2024-09-23 11:26:44 +02:00
ossaccesscontrol Alerting: Add manage permissions UI logic for Contact Points (#92885) 2024-09-27 19:56:32 +01:00
permreg RBAC: FIX Allow specifying several valid scopes for a kind (#93176) 2024-09-10 17:22:40 +01:00
pluginutils Actionsets: Add ability for plugins to add actions for core actionsets (i.e. folders:edit) (#88776) 2024-07-19 16:16:23 +01:00
resourcepermissions Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
ssoutils Auth: Improve /admin/authentication permission checks and include new SSO pages (#81183) 2024-01-25 11:13:24 +01:00
accesscontrol_test.go Add auth spans and remove deduplication code for scopes (#89804) 2024-07-02 22:08:57 -08:00
accesscontrol.go Alerting: Managed receiver resource permission in receiver_svc (#93556) 2024-09-23 21:12:25 +03:00
authorize_in_org_test.go RBAC: Fix an issue with server admins not being able to manage users in orgs that they don't belong to (#92024) 2024-08-22 10:04:06 +01:00
authorizer_test.go RBAC: Add legacy authorization checks to service accounts (#93753) 2024-09-27 15:53:11 +02:00
authorizer.go RBAC: Add legacy authorization checks to service accounts (#93753) 2024-09-27 15:53:11 +02:00
cacheutils_test.go RBAC: Optimize permissions caching (#92673) 2024-09-03 15:46:56 +02:00
cacheutils.go RBAC: Optimize permissions caching (#92673) 2024-09-03 15:46:56 +02:00
checker_test.go Chore: Fix goimports grouping (#62426) 2023-01-30 09:34:18 +01:00
checker.go RBAC: Add required component to perform access control checks for user api when running single tenant (#93104) 2024-09-23 11:26:44 +02:00
errors.go Actionsets: Add ability for plugins to add actions for core actionsets (i.e. folders:edit) (#88776) 2024-07-19 16:16:23 +01:00
evaluator_test.go RBAC: handle partially resolved scopes (#85323) 2024-03-28 10:08:07 +01:00
evaluator.go Instrument tracing across accesscontrol (#91864) 2024-08-16 14:08:19 -08:00
filter_bench_test.go Chore: Remove Result field from datasources (#63048) 2023-02-09 15:49:44 +01:00
filter_test.go Chore: Update test database initialization (#81673) 2024-02-09 09:35:39 -05:00
filter.go Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
metadata_bench_test.go Chore: Fix error handling in postDashboard, remove UserDisplayDTO, fix live redis client initialization (#87206) 2024-05-06 14:17:34 -04:00
metadata_test.go RBAC: Add function to generate wildcards from prefix (#54275) 2022-08-26 17:10:35 +02:00
metadata.go Instrument tracing across accesscontrol (#91864) 2024-08-16 14:08:19 -08:00
middleware_test.go Zanzana: Evaluate permissions alongside with RBAC engine (#90064) 2024-07-05 11:31:23 +02:00
middleware.go Auth: Use sessionStorage instead of cookie for automatic redirection (#92759) 2024-09-24 18:38:09 +02:00
models_test.go ExtSvcAuth: Assign roles locally (#78669) 2023-11-29 12:12:30 +01:00
models.go Alerting: Notifications Templates API (#91349) 2024-09-25 09:31:57 -04:00
resolvers_test.go Chore: Fix goimports grouping (#62426) 2023-01-30 09:34:18 +01:00
resolvers.go Instrument tracing across accesscontrol (#91864) 2024-08-16 14:08:19 -08:00
roles_test.go AccessControl: Remove package lists for roles and grants (#47141) 2022-04-06 09:31:14 +02:00
roles.go Auth: Add LDAP scope to Grafana Admin (#92990) 2024-09-05 17:15:47 +01:00
scope_test.go RBAC: Add function to generate wildcards from prefix (#54275) 2022-08-26 17:10:35 +02:00
scope.go Zanzana: Evaluate permissions alongside with RBAC engine (#90064) 2024-07-05 11:31:23 +02:00