Commit Graph

167 Commits

Author SHA1 Message Date
Yuriy Tseretyan
c85567f490
fix logging of resolving scopes (#50173) 2022-06-03 10:53:53 -04:00
Kat Yang
bc8578524b
Chore: Remove last build tag (#50120) 2022-06-02 17:36:34 +00:00
Karl Persson
896a101f48
RBAC: Extract method from access control impl to a function in domain packge (#49947)
* Remove GetUserBuiltInRoles and create it as a util function in
accesscontrol domain package
2022-06-02 16:10:41 +02:00
Ieva
5dbea9996b
RBAC: Make RBAC action names more consistent (#49730)
* update action names

* correctly retrieve teams for signed in user

* remove test

* undo swagger changes

* undo swagger changes pt2

* add migration from old action names to the new ones

* rename from list to read

* linting

* also update alertign actions

* fix migration
2022-06-02 13:14:48 +01:00
Karl Persson
bdff63d4a8
RBAC: Include alert.rules action when setting folder permissions (#49946)
* Generate additional actions when setting folder permissions in acl list

* Add migration for managed folder permissions to include alert rule
actions
2022-06-01 15:29:37 +02:00
Karl Persson
d82eb5902d
AccessControl: Cleanup access control interface (#49783)
* removed unused function

* Rename interface
2022-05-30 17:48:12 +02:00
Karl Persson
5caf97be40
AccessControl: Replace IsEnterprise checks with license checks (#49572) 2022-05-25 20:40:41 +02:00
sh0rez
3ca3a59079
pkg/web: remove dependency injection (#49123)
* pkg/web: store http.Handler internally

* pkg/web: remove injection

Removes any injection code from pkg/web.

It already was no longer functional, as we already only injected into
`http.Handler`, meaning we only inject ctx.Req and ctx.Resp.

Any other types (*Context, *ReqContext) were already accessed using the
http.Request.Context.Value() method.

* *: remove type mappings

Removes any call to the previously removed TypeMapper, as those were
non-functional already.

* pkg/web: remove Context.Invoke

was no longer used outside of pkg/web and also no longer functional
2022-05-24 15:35:08 -04:00
sh0rez
3d5d8c785b
pkg/web: restrict handler types (#48495)
Makes `pkg/web` only accept handles from the following set:

```go
	handlerStd       = func(http.ResponseWriter, *http.Request)
	handlerStdCtx    = func(http.ResponseWriter, *http.Request, *web.Context)
	handlerStdReqCtx = func(http.ResponseWriter, *http.Request, *models.ReqContext)
	handlerReqCtx    = func(*models.ReqContext)
	handlerReqCtxRes = func(*models.ReqContext) Response
	handlerCtx       = func(*web.Context)
```

This is a first step to reducing above set to only `http.Handler`.

---

Due to a cyclic import situation between `pkg/models` and `pkg/web`, parts of this PR were put into `pkg/api/response`, even though they definitely do not belong there. This however is _temporary_ until we untangle `models.ReqContext`.
2022-05-20 12:45:18 -04:00
Yuriy Tseretyan
258b3ab18b
Alerting: Fix RBAC actions for notification policies (#49185)
* squash actions "alert.notifications:update", "alert.notifications:create", "alert.notifications:delete" to "alert.notifications:write"
* add migration
* update UI to use the write action
* update docs
* changelog
2022-05-20 10:55:07 -04:00
Karl Persson
f5ec4bcbd2
remove action to manage plugin that is not used or documented (#49309) 2022-05-20 11:52:29 +02:00
Karl Persson
4a61f4111f
Remove unused error from evaluator Evaluate (#49305) 2022-05-20 10:26:57 +02:00
Yuriy Tseretyan
f7f2253072
Alerting: Fix anonymous access to alerting (#49203)
* introduce a fallback handler that checks that role is Viewer.
* update UI nav links to allow alerting tabs for anonymous user
* update rule api to check for Viewer role instead of SignedIn when RBAC is disabled
2022-05-19 09:22:26 -04:00
Gabriel MABILLE
5b6d20fbce
Access Control: Remove built-in role assignment by default (#49058)
* Remove FF-bultins

* Add a param to test br-simplifying
2022-05-19 09:29:36 +02:00
Kristin Laemmert
1df340ff28
backend/services: Move GetDashboard from sqlstore to dashboard service (#48971)
* rename folder to match package name
* backend/sqlstore: move GetDashboard into DashboardService

This is a stepping-stone commit which copies the GetDashboard function - which lets us remove the sqlstore from the interfaces in dashboards - without changing any other callers.
* checkpoint: moving GetDashboard calls into dashboard service
* finish refactoring api tests for dashboardService.GetDashboard
2022-05-17 14:52:22 -04:00
Karl Persson
34be8f28b9
AccessControl: Add metadata to search result (#48879)
* Add access control metadata to search hits if access control query string is passed
2022-05-17 15:51:44 +02:00
Ieva
f256f625d8
AccessControl: Enable RBAC by default (#48813)
* Add RBAC section to settings

* Default to RBAC enabled settings to true

* Update tests to respect RBAC

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2022-05-16 12:45:41 +02:00
Karl Persson
1c679e814b
AccessControl: Only return action and scope for user permissions and make them unique (#48939)
* Only return action and scope for user permissions and make them unique
2022-05-12 17:15:18 +02:00
Karl Persson
58fa119270
sort user permissions by scope (#48928) 2022-05-12 11:46:56 +02:00
Gabriel MABILLE
d31d300ce1
Accesscontrol: Rename scope permissions:delegate (#48898) 2022-05-11 17:22:43 +02:00
Karl Persson
61772a66b6
AccessControl: Create own interface and impl for each permission service (#48871)
* Create own interfaces for team, folder, dashboard and data source permissions services
* Remove service container and inject them individually
2022-05-10 15:48:47 +02:00
Ieva
3c78196d0b
fix a bug (#48782) 2022-05-06 09:36:11 +01:00
Ieva
a5672758d8
Access control: further reduce access control feature toggle checks (#48171)
* reduce the usage of access control flag further by removing it from SQL store methods

* fixing tests

* fix another test

* linting

* remove AC feature toggle use from API keys

* remove unneeded function
2022-05-05 17:31:14 +02:00
Karl Persson
2738d1c557
Access Control: Move dashboard actions and create scope provider (#48618)
* Move dashboard actions and create scope provider
2022-05-04 16:12:09 +02:00
Jguer
6a303bb6b8
AccessControl: Rename builtin role roles to basic roles (#48519)
* AccessControl: Rename grafana:builtins roles to basic

* AccessControl: rename macro references to basic

Co-authored-by: gamab <gabi.mabs@gmail.com>
2022-05-03 13:59:16 +02:00
Karl Persson
de50f39c12
Access Control: Refactor scope resolvers with support to resolve into several scopes (#48202)
* Refactor Scope resolver to support resolving into several scopes

* Change permission evaluator to match at least one of passed scopes
2022-05-02 09:29:30 +02:00
Karl Persson
9622e7457e
Fix permission query for postgres (#48543) 2022-05-02 09:25:23 +02:00
Gabriel MABILLE
2cc276567d
AccessControl: Hide basic roles (#48549)
Co-authored-by: Jguer <joao.guerreiro@grafana.com>

Co-authored-by: Jguer <joao.guerreiro@grafana.com>
2022-04-29 17:35:41 +02:00
Karl Persson
6c6137f45a
Access control: Pass access control metadata for api keys (#48445)
* Move ApiKeyDTO to dtos package

* Add access control filter to api keys

* pass user in GetApiKeysQuery

* Add api key metadata to DTO

* Remove scope all requirement from get api keys endpoint

* Handle api key access control metadata in frondend
2022-04-29 15:30:24 +02:00
Karl Persson
c207ea30eb
Access Control: Remove unused option (#48317)
* Remove unused option
2022-04-29 11:05:51 +02:00
Artur Wierzbicki
736be74128
Chore: Add Usage stats providers registry (#48357)
* add usage stats providers

* migrate thumbnails service to `registry.ProvidesUsageStats`

* snake -> camel

* lint fix

* migrate accesscontrol to `registry.ProvidesUsageStats`

* add accesscontrol to usage stats providers registry

* fix test

* added a note about errors
2022-04-28 13:06:49 +04:00
Karl Persson
e9a93ebfc9
Access Control: Move access control middlewares to domain package (#48322)
* Move access control middleware to domain package
2022-04-28 10:46:18 +02:00
Gabriel MABILLE
9ed7e48454
AccessControl: Modify provisioning to prevent built-in role assignment (#48031)
* Add basic and managed prefixes to avoid magic strings
For now let's stick with grafana_builtins
add function isBasic to RoleDTO
add function isBasic to Role

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Add team store to wire

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

Co-authored-by: Jguer <joao.guerreiro@grafana.com>
2022-04-21 14:14:45 +02:00
Jguer
3456793e0f
AccessControl: fix value copying in method access and add LogID (#47694)
* AccessControl: fix value copying in method access and add LogID

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>

* Lint.

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
Co-authored-by: gamab <gabi.mabs@gmail.com>
2022-04-13 17:22:53 +02:00
Gabriel MABILLE
8bd825e16c
AccessControl: Make the built-in role definitions public (#47525)
* AccessControl: Make the built-in role definitions public

* Add context to RegisterFixedRoles

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Making BuiltInRolesWithParents public to the AccessControl package

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

Co-authored-by: Jguer <joao.guerreiro@grafana.com>
2022-04-12 09:53:43 +02:00
Ieva
ef4c2672b3
Access control: SQL filtering for annotation listing (#47467)
* pass in user to attribute scope resolver

* add SQL filter to annotation listing

* check annotation FGAC permissions before exposing them for commenting

* remove the requirement to be able to list all annotations from annotation listing endpoint

* adding tests for annotation listing

* remove changes that got moved to a different PR

* unused var

* Update pkg/services/sqlstore/annotation.go

Co-authored-by: Ezequiel Victorero <evictorero@gmail.com>

* remove unneeded check

* remove unneeded check

* undo accidental change

* undo accidental change

* doc update

* move tests

* redo the approach for passing the user in for scope resolution

* accidental change

* cleanup

* error handling

Co-authored-by: Ezequiel Victorero <evictorero@gmail.com>
2022-04-11 13:18:38 +01:00
Gabriel MABILLE
f7305965a4
AccessControl: Remove package lists for roles and grants (#47141)
* AccessControl: Remove package variables for roles and grants

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Check for inheritance during role registration

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Moving back role definition to accessscontrol

* Make settings reader role public

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Nits

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Forgot to update this

* Account for declaration error

* Fixing pkg/api init ossac

* Account for error in tests

* Update test to verify inheritance

* Nits.

* Place br inheritance behind a feature toggle

* Parent -> Parents

* Nit.

Co-authored-by: Jguer <joao.guerreiro@grafana.com>
2022-04-06 09:31:14 +02:00
Jguer
90a94eab74
Dashboard/Folder permission fix session (#47174)
* Fix inherited scopes for dashboard to use folder uid

* Add inherited evaluators

* Slight modification of the commments

* Add test for inheritance

* Nit.

* extract shared function from tests

* Nit. Extra line

* Remove unused comment

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: gamab <gabi.mabs@gmail.com>
2022-04-05 14:28:23 +02:00
Ieva
bc9b5325a0
update docs, simplify actions and scopes (#47067) 2022-04-04 13:53:58 +01:00
Karl Persson
a5e4a533fa
Access control: use uid for dashboard and folder scopes (#46807)
* use uid:s for folder and dashboard permissions

* evaluate folder and dashboard permissions based on uids

* add dashboard.uid to accept list

* Check for exact suffix

* Check parent folder on create

* update test

* drop dashboard:create actions with dashboard scope

* fix typo

* AccessControl: test id 0 scope conversion

* AccessControl: store only parent folder UID

* AccessControl: extract general as a constant

* FolderServices: Prevent creation of a folder uid'd general

* FolderServices: Test folder creation prevention

* Update pkg/services/guardian/accesscontrol_guardian.go

* FolderServices: fix mock call expect

* FolderServices: remove uneeded mocks

Co-authored-by: jguer <joao.guerreiro@grafana.com>
2022-03-30 15:14:26 +02:00
Gabriel MABILLE
3440e7c8f7
AccessControl: Fix locked role picker in orgs/edit page (#46539)
* AccessControl: Fix locked role picker in orgs/edit page

* Use correct org when computing metadata
2022-03-24 08:58:10 +01:00
Gabriel MABILLE
ff3c1e3144
AccessControl: Handle ':' in attribute resolution (#46742)
* AccessControl: Handle ':' in attribute resolution

* Simplify based on assumption that prefixes will have maximum 2 parts
2022-03-23 08:48:32 +01:00
Karl Persson
bfb03d779d
Access Control: Correctly check for id suffix (#46824)
* Correctly check for id suffix
2022-03-22 13:48:15 +01:00
Karl Persson
faf4a3f751
Access Control: Rename global users scope (#46794)
* Rename scope from global:users to global.users to match scope convention
2022-03-22 12:48:46 +01:00
Ezequiel Victorero
c717320942
Adding FGAC annotations validation for creation and deletion (#46736)
Access Control: Adding FGAC annotations validation for creation and deletion
Co-authored-by: IevaVasiljeva <ieva.vasiljeva@grafana.com>
2022-03-21 14:28:39 -03:00
Karl Persson
7ab1ef8d6e
Access Control: Support other attributes than id for resource permissions (#46727)
* Add option to set ResourceAttribute for a permissions service
* Use prefix in access control sql filter to parse scopes
* Use prefix in access control metadata to check access
2022-03-21 17:58:18 +01:00
Ieva
f2450575b3
Access control: FGAC for annotation updates (#46462)
* proposal

* PR feedback

* fix canSave bug

* update scope naming

* linting

* linting

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
2022-03-18 17:33:21 +01:00
Karl Persson
4df7bf5ab2
Access control: Display inherited folder permissions in dashboards (#46421) 2022-03-17 17:08:51 +01:00
Yuriy Tseretyan
7df22c1573
Access Control: Fix Filter to correctly handle duplicated scopes (#46667) 2022-03-16 16:59:19 -04:00
Karl Persson
943a8508a6
Handle case where there are no matching ids for all actions passed to (#46646) 2022-03-16 16:31:33 +01:00