Commit Graph

182 Commits

Author SHA1 Message Date
Dave Henderson
5687243d0b
Feature Flags: use FeatureToggles interface where possible (#85131)
* Feature Flags: use FeatureToggles interface where possible

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>

* Replace TestFeatureToggles with existing WithFeatures

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>

---------

Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
2024-04-04 12:22:31 -04:00
Serge Zaitsev
faa1244518
Chore: Replace sqlstore with db interface (#85366)
* replace sqlstore with db interface in a few packages

* remove from stats

* remove sqlstore in admin test

* remove sqlstore from api plugin tests

* fix another createUser

* remove sqlstore in publicdashboards

* remove sqlstore from orgs

* clean up orguser test

* more clean up in sso

* clean up service accounts

* further cleanup

* more cleanup in accesscontrol

* last cleanup in accesscontrol

* clean up teams

* more removals

* split cfg from db in testenv

* few remaining fixes

* fix test with bus

* pass cfg for testing inside db as an option

* set query retries when no opts provided

* revert golden test data

* rebase and rollback
2024-04-04 15:04:47 +02:00
Xavi Lacasa
a813046f3d
Better tracing during extSvcAcc registration (#84719) 2024-03-21 16:41:10 +01:00
Charandas
759cefd94c
ExtSvcAccounts: FIX tests that accidently depended on enterprise (#84535)
* ExtSvcAccounts: FIX tests that accidently depended on enterprise

* fix
2024-03-15 08:18:11 +01:00
Gabriel MABILLE
2795f9827a
ExtSvcAccounts: FIX prevent service account deletion (#84502)
* ExtSvcAccounts: Fix External Service Accounts Login check

Co-authored-by: Karl Persson <kalle.persson@grafana.com>

* Remove service accounts assignments and permissions on delete

* Fix first set of tests

* Fix second batch of tests

* Fix third batch of tests

---------

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2024-03-14 19:11:02 +01:00
Eric Leijonmarck
e611a736ed
Serviceaccounts: Add ability to add samename SA for different orgs (#83893)
* add ability to add samename SA for different orgs

* Update pkg/services/user/userimpl/user.go

* fix tests

* refactor name

* removed tests

* add migration

* fix linting
2024-03-06 09:53:58 +01:00
Gabriel MABILLE
80d6bf6da0
AuthN: Remove embedded oauth server (#83146)
* AuthN: Remove embedded oauth server

* Restore main

* go mod tidy

* Fix problem

* Remove permission intersection

* Fix test and lint

* Fix TestData test

* Revert to origin/main

* Update go.mod

* Update go.mod

* Update go.sum
2024-02-26 11:29:09 +01:00
Gabriel MABILLE
846eadff63
RBAC Search: Replace userLogin filter by namespacedID filter (#81810)
* Add namespace ID

* Refactor and add tests

* Rename maxOneOption -> atMostOneOption

* Add ToDo

* Remove UserLogin & UserID for NamespaceID

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

* Remove unecessary import of the userSvc

* Update pkg/services/accesscontrol/acimpl/service.go

* fix 1 -> userID

* Update pkg/services/accesscontrol/accesscontrol.go

---------

Co-authored-by: jguer <joao.guerreiro@grafana.com>
2024-02-16 11:42:36 +01:00
Dan Cech
790e1feb93
Chore: Update test database initialization (#81673)
* streamline initialization of test databases, support on-disk sqlite test db

* clean up test databases

* introduce testsuite helper

* use testsuite everywhere we use a test db

* update documentation

* improve error handling

* disable entity integration test until we can figure out locking error
2024-02-09 09:35:39 -05:00
Jo
fb86ed79fc
Stats: Remove ACL references (#82112)
remove acl references
2024-02-08 17:19:24 +01:00
Gabriel MABILLE
722b78f3e0
RBAC: Add userLogin filter to the permission search endpoint (#81137)
* RBAC: Search add user login filter

* Switch to a userService resolving instead

* Remove unused error

* Fallback to use the cache

* account for userID filter

* Account for the error

* snake case

* Add test cases

* Add api tests

* Fix return on error

* Re-order imports
2024-01-26 09:43:16 +01:00
Marcus Efraimsson
6768c6c059
Chore: Remove public vars in setting package (#81018)
Removes the public variable setting.SecretKey plus some other ones. 
Introduces some new functions for creating setting.Cfg.
2024-01-23 12:36:22 +01:00
Ryan McKinley
1caaa56de0
FeatureFlags: Use interface rather than manager (#80000) 2024-01-09 10:38:06 -08:00
Gabriel MABILLE
72d32eed27
ExtSvcAuth: Assign roles locally (#78669)
* ExtSvcAuth: Assign roles locally

* Fix test

* HandlePluginStateChanged in the OrgID

* Remove Global from command

* Use AssignmentOrgID instead of OrgID

* Remove unecessary test case
2023-11-29 12:12:30 +01:00
Gabriel MABILLE
25c2d99350
ExtSvcAuth: Add traces to external service accounts setup (#76779)
* AuthN: Add traces to external service accounts setup
2023-11-16 20:45:31 +01:00
Gabriel MABILLE
ba717454e1
ExtSvcAuth: Clean up orphaned external services on start up (#77951)
* Plugin: Remove external service on plugin removal

* Early exit no service account

* Add log

* WIP

* Cable OAuth2Server client removal

* Move function lower

* Add function to test removal

* Add test to RemoveExternalService

* Test RemoveExtSvcAccount

* remove apostrophy in comment

* Add cfg to plugin installer to check features

* Add feature flag check in the service registration service

* Comments

* Move metrics Inc

* Initialize map

* Reorder

* Initialize mutex as well

* Add HasExternalService as suggested

* WIP: CleanUpOrphanedExternalServices

* Commit suggestion

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>

* Nit on test.

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>

* oauthserver return names

* Name is not Slug

* Use plugin ID not slug

* Add background job

* remove negation on feature check

* Add test to the CleanUp function

* Test GetExternalServiceNames

* rename test

* Add test for ExtSvcAccountsService_GetExternalServiceNames

* Add a todo

* Add todo

* Option based on mix

* Rewrite a bit the comment

* Opinionated choice use slugs instead of names everywhere

* Nit.

* Comments and re-ordering

* Comment

* Add log

* Add context

---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
2023-11-16 12:07:42 +01:00
Julien Duchesne
c551c9e71f
Swagger: Fix listTokensResponse (#78155)
* Swagger: Fix listTokensResponse
It should return a list of Tokens, not a single one
Also regenerated the API spec from the latest changes + this branch

* Remove pointer
2023-11-15 08:59:54 -05:00
Ryan McKinley
f69fd3726b
FeatureToggles: Add context and and an explicit global check (#78081) 2023-11-14 12:50:27 -08:00
linoman
408dab8c57
IAM: Protect managed service account frontend details page (#77839)
* Add `isManaged` property to frontend model

* Remove enabled and token buttons for managed SA

* Replace trash icon for lock icon for managed SA

* Block the role picker for managed SA

* Filter SA list usiong the managed filter

* Rename external for managed

* Add only managed filter

* Toggle the enable buttons for managed sa

* Disable add token and delete token buttons

* Remove the edit name button

* Disable the Role picker for managed sa

* Hide the permissions section

* Add managed by row

---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
2023-11-14 17:52:48 +01:00
Gabriel MABILLE
fe8d0e6381
ExtSvcAuth: Refactor external service registry to use ExternalServiceRegistry variables (#78056)
ExtSvcAuth: Refactor external service registry to use ExternalServiceRegistry
2023-11-13 16:23:11 +01:00
Gabriel MABILLE
20a2840046
Plugin: Remove external service on plugin removal (#77712)
* Plugin: Remove external service on plugin removal

* Add feature flag check in the service registration service

* Initialize map

* Add HasExternalService as suggested

* Commit suggestion

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>

* Nit on test.

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>


---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
2023-11-13 13:18:13 +01:00
linoman
5bc4f56c79
IAM: Protect external service accounts frontend list page (#77834)
* Add `isExternal` property to frontend model

* Remove enabled and token buttons for external SA

* Replace trash icon for lock icon for external SA

* Block the role picker for external SA

* Filter SA list using the external filter

* Add only external filter at backend

---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-11-09 17:45:46 +01:00
Gabriel MABILLE
bf363b3234
ServiceAccounts: Use isManaged in DTO instead of isExternal (#77634)
* ServiceAccounts: Use IsManaged in DTO instead of isExternal

* Revert omitempty

* Modify the other DTO

* Swagger
2023-11-03 17:49:11 +01:00
linoman
c50ada3a1a
auth: wire service account proxy (#77215)
* Add interface verification compliance

* rework service account api to a provider

* wire the service accounts api

* rewire the implementation of sa srv for the proxy

---------

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2023-11-03 10:27:43 +01:00
Gabriel MABILLE
25b30aeb6d
Plugin: Enable service account based on plugin settings on init (#77193)
* Disable plugin service account

* Revert extsvc injection

* handle plugin state changes

* Use isProxyEnabled

* Remove plugininteg changes

* Change update function to also work for mysql 😩

* Plugin: enable service account based on plugin settings on
initialization

* Remove misleading comment

* Fix tests

* test message

* Clean up tests

* Simplify tests

* Re-order imports

* Remove unecessary comment

* Enable datasource plugins by default

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>

---------

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
2023-10-27 14:27:06 +02:00
Gabriel MABILLE
2727f41474
AuthN: Change the external service account state on plugin state change (#77157)
* Disable plugin service account

* Revert extsvc injection

* handle plugin state changes

* Use isProxyEnabled

* Remove plugininteg changes

* Change update function to also work for mysql 😩

* Change test to also check no collateral update

* Update pkg/services/serviceaccounts/database/store_test.go

* Update pkg/services/serviceaccounts/database/store_test.go
2023-10-27 13:46:25 +02:00
linoman
dff7403b29
auth: implement feature flag for service account proxy (#77129)
* add FlagExternalServiceAccounts to proxy service

* add FlagExternalServiceAccounts value to tests

---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-10-25 16:44:05 +02:00
linoman
1bc81b7bd1
auth: migrate api interface implementation (#77040)
* expand serviceaccount service interface

* implemet FakeServiceAccountService

* Replace SA service interface from api

* merge sa proxy tests with new fake service

* implement DeleteServiceAccountToken

* add test for DeleteServiceAccountToken
2023-10-25 12:40:30 +02:00
Gabriel MABILLE
897e3a4dab
AuthN: Add metrics to external service accounts management (#76789)
* AuthN: Add metrics to external service accounts management

* Add a new metric to count stored external service accounts

* Update variable names

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>

* Add test to SearchOrgServiceAccounts

* Add feature flags checks before registering and using the metrics

---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
2023-10-24 15:54:14 +02:00
Gabriel MABILLE
3015e5921f
Chore: Move extsvcaccounts package to serviceaccounts (#76977)
* Chore: Move extsvcaccounts package to serviceaccounts

* Fix proxy

* Fix tests

* Fix linting
2023-10-24 11:01:04 +02:00
linoman
359d84799e
auth: add serviceaccount proxy (#76815)
* Add proxy service template

* Replace SA srv with proxy for external SA srv

* Move service account prefix to a constant

* Prevent deletion from external service account

* Make SA validation a resusable function

* Add protection for creating service accounts

* Add protection when updating service accounts

* Add IsExternal field for service account

* Protect ext service account token generation

* Add verbose errors for form name or sa name

* add tests

* Add logs

* Adjusts tests

---------

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-10-23 14:09:42 +02:00
Carl Bergquist
764478b9e7
Instrumentation: Set auth as owners for more routes (#75105)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
2023-09-20 10:18:52 +02:00
Serge Zaitsev
8187d8cb66
Chore: capitalise log message for auth packages (#74332) 2023-09-04 18:49:47 +02:00
Ryan McKinley
025b2f3011
Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
Ieva
6885b3d577
Chore: remove checks for whether RBAC is disabled (#73812)
* remove checks for whether access control is disabled, as it is always enabled now

* linting
2023-08-25 14:19:58 +01:00
Marcus Efraimsson
040b7d2571
Chore: Add errutils helpers (#73577)
Add helpers for the errutil package in favor of errutil.NewBase.
2023-08-22 12:52:24 +02:00
linoman
1c7f89c41b
Auth: Add empty role usage metrics for service and user accounts (#73108)
* Add tests for service accounts metrics usage

* Add service account store implementation

* Add service account service implementation

* Add tests for org metrics usage

* Add org implementation

* Add service implementation
2023-08-16 10:56:47 +02:00
Jo
67de18ff06
Auth: Move Service Account service to SignedInUser Interface (#73142)
* move service account service to identity interface

* Update pkg/services/auth/identity/requester.go
2023-08-10 14:20:58 +02:00
Jo
3300488667
AccessControl: Remove acmock.New from accesscontrol service tests (#71942)
* remove mock ac provider from service accounts

* remove mock ac provider from accesscontrol tests

* remove mock ac from ac service tests
2023-07-20 10:00:46 +02:00
Jo
d6c468c1c2
Auth: Add empty role definition (#64694)
* Allow setting role as None

Co-authored-by: gamab <gabi.mabs@gmail.com>

Seeking for places where role.None would be used

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

Adding None role to the frontend

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

unify org role declaration and remove from add permission

fix backend test

fix backend lint

* remove role none from frontend

* Simplify checks

Co-authored-by: Kalle Persson <kalle.persson@grafana.com>

* nits

---------

Co-authored-by: Kalle Persson <kalle.persson@grafana.com>
2023-07-06 15:40:06 +02:00
Eric Leijonmarck
5dceb5dff3
Service accounts: API key migration refactoring to parse as json object of the results (#69771)
refactoring to parse as json object of the results
2023-06-08 12:12:26 +02:00
Eric Leijonmarck
081f59feba
Service accounts: UI migration results (#68789)
* ui migration WIP

* merge

* migration tests for api

* revert chagnes to align with main

* revert chagnes to align with main

* revert chagnes to align with main

* remove unused code and comments

* revert gen files

* retry logic inplace

* fix a any

* fixed types

* migraiton results now show only result if no failures

* review comments

* wording to make it more actionable

* add migraiton summary text onyl for failed apikeys

* fixed wording and added a close button to the modal

* made the button close the modal

* moved state into component

* fix based on review, naming and removed unused code

* service account migration state optional

* making migration result undefined

* showing total and migrated numbers for a successful migration

* fix payload const to take the payload
2023-06-08 10:09:30 +02:00
Ieva
d8b66d5c4b
RBAC: remove some IsDisabled checks (#69272)
* remove some access contorl IsDisabled() checks

* cleaning up tests

* update tests

* linting
2023-05-31 09:58:57 +01:00
Gabriel MABILLE
edf1775d49
AuthN: Embed an OAuth2 server for external service authentication (#68086)
* Moving POC files from #64283 to a new branch

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* Adding missing permission definition

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* Force the service instantiation while client isn't merged

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* Merge conf with main

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* Leave go-sqlite3 version unchanged

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* tidy

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* User SearchUserPermissions instead of SearchUsersPermissions

* Replace DummyKeyService with signingkeys.Service

* Use user🆔<id> as subject

* Fix introspection endpoint issue

* Add X-Grafana-Org-Id to get_resources.bash script

* Regenerate toggles_gen.go
* Fix basic.go

* Add GetExternalService tests

* Add GetPublicKeyScopes tests

* Add GetScopesOnUser tests

* Add GetScopes tests

* Add ParsePublicKeyPem tests

* Add database test for GetByName

* re-add comments

* client tests added

* Add GetExternalServicePublicKey tests

* Add other test case to GetExternalServicePublicKey

* client_credentials grant test

* Add test to jwtbearer grant

* Test Comments

* Add handleKeyOptions tests

* Add RSA key generation test

* Add ECDSA by default to EmbeddedSigningKeysService

* Clean up org id scope and audiences

* Add audiences to the DB

* Fix check on Audience

* Fix double import

* Add AC Store mock and align oauthserver tests

* Fix test after rebase

* Adding missing store function to mock

* Fix double import

* Add CODEOWNER

* Fix some linting errors

* errors don't need type assertion

* Typo codeowners

* use mockery for oauthserver store

* Add feature toggle check

* Fix db tests to handle the feature flag

* Adding call to DeleteExternalServiceRole

* Fix flaky test

* Re-organize routes comments and plan futur work

* Add client_id check to Extended JWT client

* Clean up

* Fix

* Remove background service registry instantiation of the OAuth server

* Comment cleanup

* Remove unused client function

* Update go.mod to use the latest ory/fosite commit

* Remove oauth2_server related configs from defaults.ini

* Add audiences to DTO

* Fix flaky test

* Remove registration endpoint and demo scripts. Document code

* Rename packages

* Remove the OAuthService vs OAuthServer confusion

* fix incorrect import ext_jwt_test

* Comments and order

* Comment basic auth

* Remove unecessary todo

* Clean api

* Moving ParsePublicKeyPem to utils

* re ordering functions in service.go

* Fix comment

* comment on the redirect uri

* Add RBAC actions, not only scopes

* Fix tests

* re-import featuremgmt in migrations

* Fix wire

* Fix scopes in test

* Fix flaky test

* Remove todo, the intersection should always return the minimal set

* Remove unecessary check from intersection code

* Allow env overrides on settings

* remove the term app name

* Remove app keyword for client instead and use Name instead of ExternalServiceName

* LogID remove ExternalService ref

* Use Name instead of ExternalServiceName

* Imports order

* Inline

* Using ExternalService and ExternalServiceDTO

* Remove xorm tags

* comment

* Rename client files

* client -> external service

* comments

* Move test to correct package

* slimmer test

* cachedUser -> cachedExternalService

* Fix aggregate store test

* PluginAuthSession -> AuthSession

* Revert the nil cehcks

* Remove unecessary extra

* Removing custom session

* fix typo in test

* Use constants for tests

* Simplify HandleToken tests

* Refactor the HandleTokenRequest test

* test message

* Review test

* Prevent flacky test on client as well

* go imports

* Revert changes from 526e48ad45

* AuthN: Change the External Service registration form (#68649)

* AuthN: change the External Service registration form

* Gen default permissions

* Change demo script registration form

* Remove unecessary comment

* Nit.

* Reduce cyclomatic complexity

* Remove demo_scripts

* Handle case with no service account

* Comments

* Group key gen

* Nit.

* Check the SaveExternalService test

* Rename cachedUser to cachedClient in test

* One more test case to database test

* Comments

* Remove last org scope

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>

* Update pkg/services/oauthserver/utils/utils_test.go

* Update pkg/services/sqlstore/migrations/oauthserver/migrations.go

Remove comment

* Update pkg/setting/setting.go

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

---------

Co-authored-by: Mihály Gyöngyösi <mgyongyosi@users.noreply.github.com>
2023-05-25 15:38:30 +02:00
Ieva
4980b64274
RBAC: Remove legacy ac from authorization middleware (#68898)
remove legacy AC fallback from RBAC middleware, and some unused auth logic
2023-05-24 09:49:42 +01:00
Jo
f9fd15c01e
fix shadow log in service accounts (#67643)
* fix shadow log in service accounts
2023-05-02 13:57:46 +02:00
Karl Persson
e4d998dc1a
ApiKeyGenPrefix: rename package (#65623)
* Rename package to satokengen to make it clearer that it is for service
account tokens
2023-03-30 17:04:10 +02:00
Serge Zaitsev
743d66396a
Chore: Remove result field from API keys commands and queries (#65055)
* Chore: remove result field from api keys

* fix shadowing

* actually shadowing was all right
2023-03-21 13:26:33 +01:00
Jo
0e565a2e6c
ServiceAccounts: Collect usage stat for service account forced expiry (#64833)
collect usage stat for service account forced expiry
2023-03-16 16:36:31 +01:00
Ieva
1d1f58f0ed
Service accounts: fix usage of errutil errors and convert more errors to errutil (#64299)
* fix usage of errutil errors and convert more errors to errutil

* fix tests
2023-03-08 11:32:09 +00:00