grafana/pkg/services
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
..
accesscontrol Alerting: Add manage permissions UI logic for Contact Points (#92885) 2024-09-27 19:56:32 +01:00
annotations Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
anonymous Identity: Remove typed id (#91801) 2024-08-13 10:18:28 +02:00
apikey Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
apiserver K8s: Move standalone apiserver CLI to enterprise (#93799) 2024-09-27 09:04:35 +03:00
auth [authn] use authlib client+interceptors for in-proc mode (#93124) 2024-09-24 09:03:48 +03:00
authn Auth: Use sessionStorage instead of cookie for automatic redirection (#92759) 2024-09-24 18:38:09 +02:00
authz K8s: namespace mapper should use authlib's util (#92332) 2024-08-27 15:01:42 -07:00
caching Fixing typos (#70487) 2023-06-22 09:43:38 +01:00
cleanup Dashboards: Add feature restore dashboards backend (#83131) 2024-05-16 14:36:26 -03:00
cloudmigration Cloud migrations: disable flaky test (#93921) 2024-09-27 16:36:08 +01:00
contexthandler Auth: Use sessionStorage instead of cookie for automatic redirection (#92759) 2024-09-24 18:38:09 +02:00
correlations Correlations: Allow correlations to target URLs (#92442) 2024-09-24 09:38:17 -05:00
dashboardimport Identity: remove GetTypedID (#91745) 2024-08-09 18:20:24 +03:00
dashboards Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
dashboardsnapshots Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
dashboardversion Chore: removing (more) redundant transactions (#89373) 2024-06-25 09:19:49 -04:00
datasourceproxy Plugins: Preserve trailing slash in plugin proxy (#86859) 2024-06-05 13:36:14 +02:00
datasources Remove the need for plugins to implement AdmissionHandler for v0alpha1 (#93272) 2024-09-13 09:08:26 +02:00
encryption Tracing: Various improvements (#88308) 2024-05-27 14:21:40 +02:00
extsvcauth ManagedServiceAccounts: Add a config option to disable the feature on-prem (#93571) 2024-09-27 09:11:59 +02:00
featuremgmt Alerting: Prometheus primary mode for the alert list page (#92975) 2024-09-27 14:27:16 +02:00
folder Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
gcom Cloud migrations: create route to delete token (#88297) 2024-05-31 10:03:43 -03:00
grpcserver Unified Storage: Propagate traces from the apiserver grpc client (#91226) 2024-08-06 09:52:11 -06:00
guardian Identity: remove GetTypedID (#91745) 2024-08-09 18:20:24 +03:00
hooks Hooks: Remove AddLoginHook and RunLogin hooks (#73227) 2023-08-17 09:51:45 +02:00
kmsproviders Secrets: Make the Migrator extensible (#67307) 2023-06-19 23:44:01 +02:00
ldap LDAP: SSO Configuration page (#91875) 2024-08-20 17:31:13 +02:00
libraryelements LibraryElements: add fake service implementation and replace its usage in Dashboard API (#93783) 2024-09-27 14:22:29 +02:00
librarypanels Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
licensing Navigation: Remove ApplyAdminIA logic (#89113) 2024-06-12 16:45:13 +01:00
live Live: Clean up redis after test run (#93806) 2024-09-26 08:41:47 -04:00
login Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
loginattempt Chore: Add login protection when user is trying different uppercase letters (#87588) 2024-05-10 13:49:59 +02:00
navtree Alerting: Add manage permissions UI logic for Contact Points (#92885) 2024-09-27 19:56:32 +01:00
ngalert Alerting: Add manage permissions UI logic for Contact Points (#92885) 2024-09-27 19:56:32 +01:00
notifications Notifications: Add Message-ID header to outgoing emails (#83752) 2024-09-12 03:58:06 +00:00
oauthtoken Auth: Update oauthtoken service to use remote cache and server lock (#90572) 2024-08-19 18:57:37 +02:00
org Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
playlist Playlists: limit the total number of playlists (#92132) 2024-08-21 14:49:28 +03:00
plugindashboards chore(perf): Pre-allocate where possible (enable prealloc linter) (#88952) 2024-06-14 14:16:36 -04:00
pluginsintegration ManagedServiceAccounts: Add a config option to disable the feature on-prem (#93571) 2024-09-27 09:11:59 +02:00
preference Bookmarks: Store URLs instead of ids (#91121) 2024-07-31 13:56:39 +01:00
provisioning Correlations: Allow correlations to target URLs (#92442) 2024-09-24 09:38:17 -05:00
publicdashboards Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
query Chore: Bump Go to 1.23.0 (#92105) 2024-08-21 11:40:42 -04:00
queryhistory Explore: Check for RBAC permissions when hitting query history endpoints (#91156) 2024-07-31 12:10:52 -06:00
quota Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
rendering Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
screenshot Chore: Refactor render via http (#84613) 2024-05-14 07:24:18 -03:00
search chore(tracing): add tracing for frontend and db session (#91509) 2024-08-05 17:17:39 -08:00
searchusers Chore: Bump Go to 1.23.0 (#92105) 2024-08-21 11:40:42 -04:00
searchV2 Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
secrets Refactor plugin context initialization (#88343) 2024-05-28 16:59:06 +03:00
serviceaccounts ManagedServiceAccounts: Add a config option to disable the feature on-prem (#93571) 2024-09-27 09:11:59 +02:00
shorturls Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
signingkeys Signer: Fix typo (#92928) 2024-09-04 15:01:24 +02:00
sqlstore Cloud migrations: store resource name in the cloud_migration_resource table (#93612) 2024-09-26 11:16:52 -03:00
ssosettings LDAP: Remove omitempty flag from json annotation (#91843) 2024-08-13 18:17:52 +03:00
star Identity: remove GetTypedID (#91745) 2024-08-09 18:20:24 +03:00
stats Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
store SearchV2: Fix reading library panels (#92961) 2024-09-05 13:42:15 +02:00
supportbundles Chore: Move identity and errutil to apimachinery module (#89116) 2024-06-13 07:11:35 +03:00
tag Chore: Update test database initialization (#81673) 2024-02-09 09:35:39 -05:00
team Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
temp_user Chore: removing (more) redundant transactions (#89373) 2024-06-25 09:19:49 -04:00
updatechecker Chore: Making versioncheck url rely on config instead of being hardcoded (#85855) 2024-04-11 12:04:53 +02:00
user Revert read replica POC (#93551) 2024-09-25 15:21:39 -08:00
validations chore: move validations model into the validations service (#61953) 2023-01-23 15:10:14 -05:00