Commit Graph

239 Commits

Author SHA1 Message Date
Karl Persson
c4cfee8d96
User: support setting org and help flags though update function (#86535)
* User: Support setting active org through update function

* User: add support to update help flags through update function
2024-04-29 08:53:05 +02:00
Karl Persson
cd724d74aa
Authn: move namespace id type (#86853)
* Use RoleType from org package

* Move to identity package and re-export from authn

* Replace usage of top level functions for identity

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2024-04-25 12:54:36 +02:00
Charandas
d46b163810
Authn (jwt_auth): add tracing spans for validating newer use cases (#86812) 2024-04-24 02:40:00 -07:00
Karl Persson
0fa983ad8e
AuthN: Use typed namespace id inside authn package (#86048)
* authn: Use typed namespace id inside package
2024-04-24 09:57:34 +02:00
Ieva
036f826b87
AuthZ: Further protect admin endpoints (#86285)
* only users with Grafana Admin role can grant/revoke Grafana Admin role

* check permissions to user amdin endpoints globally

* allow checking global permissions for service accounts

* use a middleware for checking whether the caller is Grafana Admin
2024-04-16 15:48:12 +01:00
Karl Persson
0f06120b56
User: Clean up update functions (#86341)
* User: remove unused function

* User: Remove UpdatePermissions and support IsGrafanaAdmin flag in Update function instead

* User: Remove Disable function and use Update instead
2024-04-16 16:33:50 +02:00
Karl Persson
8520892923
User: Fix GetByID (#86282)
* Auth: Remove unused lookup param

* Remove case sensitive lookup for GetByID
2024-04-16 15:24:34 +02:00
linoman
51da96d94e
Auth: Add IsClientEnabled and IsEnabled for the authn.Service and authn.Client interfaces (#86034)
* Add `Service. IsClientEnabled` and `Client.IsEnabled` functions

* Implement `IsEnabled` function for authn clients

* Implement `IsClientEnabled` function for authn services
2024-04-15 10:54:50 +02:00
Karl Persson
73fecc8d80
Authn: Identity resolvers (#85930)
* AuthN: Add NamespaceID struct. We should replace the usage of encoded namespaceID with this one

* AuthN: Add optional interface that clients can implement to be able to resolve identity for a namespace

* Authn: Implement IdentityResolverClient for api keys

* AuthN: use idenity resolvers

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2024-04-12 11:38:20 +02:00
Karl Persson
895222725c
Session: set authID and authenticatedBy (#85806)
* Authn: Resolve authenticate by and auth id when fethcing signed in user

* Change logout client interface to only take Requester interface

* Session: Fetch external auth info when authenticating sessions

* Use authenticated by from identity

* Move call to get auth-info into session client and use GetAuthenticatedBy in various places
2024-04-11 10:25:29 +02:00
Alexander Zobnin
3127566a20
Access control: Use ResolveIdentity() for authorizing in org (#85549)
* Access control: Use ResolveIdentity() for authorizing in org

* Fix tests

* Fix middleware tests

* Use ResolveIdentity in HasGlobalAccess() function

* remove makeTmpUser

* Cleanup

* Fix linter errors

* Fix test build

* Remove GetUserPermissionsInOrg()
2024-04-10 12:42:13 +02:00
Karl Persson
ebb4bb859e
Authn: allow ResolveIdentity to authenticate in "global" scope (#85835)
* Authn: allow ResolveIdentity to authenticate in "global" scope

* Use constant
2024-04-10 11:53:45 +02:00
Karl Persson
46ee87a0fc
Authn: Ignore context.Canceled errors when logging auth errors (#85707)
Ignore context.Canceled errors when logging auth errors
2024-04-08 10:25:24 +02:00
Misi
8796d2d307
Auth: Convert SetDefaultOrgHook to PostLoginHook (#85649)
* Convert SetDefaultOrgHook to PostLoginHook
2024-04-05 16:03:51 +02:00
Karl Persson
b1fc0861f1
AuthN: reset email verified on email change (#85643)
* AuthN: reset email verified on email change

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2024-04-05 14:19:12 +02:00
Karl Persson
ba41954854
Email: trigger email verification flow (#85587)
* Add email and email_verified to id token if identity is a user

* Add endpoint to trigger email verification for user

* Add function to clear stored id tokens and use it when email verification is completed
2024-04-05 12:05:46 +02:00
Karl Persson
504870f10a
Auth: Decouple client and hook registration (#85084) 2024-04-04 09:33:00 +02:00
Jo
5340a6e548
Auth: Extended JWT client for OBO and Service Authentication (#83814)
* reenable ext-jwt-client

* fixup settings struct

* add user and service auth

* lint up

* add user auth to grafana ext

* fixes

* Populate token permissions

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

* fix tests

* fix lint

* small prealloc

* small prealloc

* use special namespace for access policies

* fix access policy auth

* fix tests

* fix uncalled settings expander

* add feature toggle

* small feedback fixes

* rename entitlements to permissions

* add authlibn

* allow viewing the signed in user info for non user namespace

* fix invalid namespacedID

* use authlib as verifier for tokens

* Update pkg/services/authn/clients/ext_jwt.go

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

* Update pkg/services/authn/clients/ext_jwt_test.go

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

* fix parameter names

* change asserts to normal package

* add rule for assert

* fix ownerships

* Local diff

* test and lint

* Fix test

* Fix ac test

* Fix pluginproxy test

* Revert testdata changes

* Force revert on test data

---------

Co-authored-by: gamab <gabriel.mabille@grafana.com>
Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2024-04-02 17:45:15 +02:00
linoman
e4250a72db
JWT: Find login and email claims with JMESPATH (#85305)
* add function to static function to static service

* find email and login claims with jmespath

* rename configuration files

* Replace JWTClaims struct for map

* check for subclaims error
2024-03-28 17:25:26 +01:00
Karl Persson
152cb47692
AuthN: Add IsAuthenticatedBy to identity interface and replace checks (#85262)
Add IsAuthenticatedBy to identity interface and replace checks
2024-03-27 15:22:13 +01:00
Jo
da40158fed
Auth: Improve org role sync debugging (#85146)
add login to the context of the logger
2024-03-26 17:22:10 +01:00
Karl Persson
2f3a01f79f
OAuth: Make sub claim required for generic oauth behind feature toggle (#85065)
* Add feature toggle for sub claims requirement

* OAuth: require valid auth id

* Fix feature toggle description
2024-03-25 14:22:24 +01:00
Eric Leijonmarck
bb792ff540
Auth: Remove oauth skip org role sync (#84972)
* remove oauth wide skip org role sync

* we are warning from config

* set it to false

* removed from config ini files and updated docs
2024-03-22 15:34:05 +01:00
Karl Persson
d4e802dd47
Authn: Add function to resolve identity from org and namespace id (#84555)
* Add function to get the namespaced id

* Add function to resolve an identity through authn.Service from org and namespace id

* Switch to resolve identity for re-authenticate in another org
2024-03-15 15:08:15 +01:00
Misi
63f1c30313
Auth: Set the default org after User login (#83918)
* poc

* add logger, skip hook when user is not assigned to default org

* Add tests, move to hook folder

* docs

* Skip for OrgId < 1

* Address feedback

* Update docs/sources/setup-grafana/configure-grafana/_index.md

* lint

* Move the hook to org_sync.go

* Update pkg/services/authn/authnimpl/sync/org_sync.go

* Handle the case when GetUserOrgList returns error

---------

Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2024-03-12 09:35:13 +01:00
Karl Persson
6ea9f0c447
AuthN: Use fetch user sync hook for render keys connected to a user (#84080)
* Use fetch user sync hook for render keys connected to a user
2024-03-12 09:15:14 +01:00
Karl Persson
9c292d2c3f
AuthN: Use sync hook to fetch service account (#84078)
* Use sync hook to fetch service account
2024-03-11 15:56:53 +01:00
Jo
36a19bfa83
AuthProxy: Allow disabling Auth Proxy cache (#83755)
* extract auth proxy settings

* simplify auth proxy methods

* add doc mentions
2024-03-01 11:31:06 +01:00
Jo
2182cc47ac
LDAP: Fix LDAP users authenticated via auth proxy not being able to use LDAP active sync (#83715)
* fix LDAP users authenticated via auth proxy not being able to use ldap sync

* simplify id resolution at the cost of no fallthrough

* remove unused services

* remove unused cache key
2024-03-01 10:14:32 +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
Klesh Wong
9282c7a7a4
AuthProxy: Invalidate previous cached item for user when changes are made to any header (#81445)
* fix: sign in using auth_proxy with role a -> b -> a would end up with role b

* Update pkg/services/authn/clients/proxy.go

Co-authored-by: Karl Persson <kalle.persson92@gmail.com>

* Update pkg/services/authn/clients/proxy.go

Co-authored-by: Karl Persson <kalle.persson92@gmail.com>
2024-02-22 10:02:31 +01:00
Karl Persson
9e04fd0fb7
AuthToken: Remove client token rotation feature toggle (#82886)
* Remove usage of client token rotation flag

* Remove client token rotation feature toggle
2024-02-16 15:03:37 +01:00
Misi
bb9d5799cf
Auth: Load oauth_allow_insecure_email_lookup using the SettingsProvider (#82460)
* wip

* Introduce fixed:server.config:writer role

* Fix tests

* Update name
2024-02-16 12:05:00 +01:00
linoman
ac84069071
Password policy (#82268)
* add password service interface

* add password service implementation

* add tests for password service

* add password service wiring

* add feature toggle

* Rework from service interface to static function

* Replace previous password validations

* Add codeowners to password service

* add error logs

* update config files


---------

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2024-02-16 04:58:05 -06:00
Jo
6f62d970e3
JWT Authentication: Add support for specifying groups in auth.jwt for teamsync (#82175)
* merge JSON search logic

* document public methods

* improve test coverage

* use separate JWT setting struct

* correct use of cfg.JWTAuth

* add group tests

* fix DynMap typing

* add settings to default ini

* add groups option to devenv path

* fix test

* lint

* revert jwt-proxy change

* remove redundant check

* fix parallel test
2024-02-09 16:35:58 +01:00
Gabriel MABILLE
596e828150
Fix: Refresh token when id_token is expired (#79569)
* Fix: Refresh token when id_token is expired

* add id_token comparison

* Fix wire

* Use userID as cache key

* Apply suggestions from code review

---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2024-02-05 16:44:25 +01:00
Gabriel MABILLE
3df0611f81
RBAC: Fix authorize in org (#81552)
* RBAC: Fix authorize in org

* Implement option 2

* Fix typo

* Fix alerting test

* Add test to cover the not member case
2024-02-01 12:37:01 +01:00
Jo
f3f36e37fa
AuthInfo: No mandatory auth_id in Auth Info service (#81335)
* fix auth info update not having mandatory auth_id

* remove uneeded newline
2024-01-26 11:54:00 +01:00
Misi
20bb0a3ab1
AuthN: Support reloading SSO config after the sso settings have changed (#80734)
* Add AuthNSvc reload handling

* Working, need to add test

* Remove commented out code

* Add Reload implementation to connectors

* Align and add tests, refactor

* Add more tests, linting

* Add extra checks + tests to oauth client

* Clean up based on reviews

* Move config instantiation into newSocialBase

* Use specific error
2024-01-22 14:54:48 +01:00
Karl Persson
7b58f71b33
AuthN: Add auth hook that can sync grafana cloud role to rbac cloud role (#80416)
* AuthnSync: Rename files and structures

* AuthnSync: register rbac cloud role sync if feature toggle is enabled

* RBAC: Add new sync function to service interface

* RBAC: add common prefix and role names for cloud fixed roles

* AuthnSync+RBAC: implement rbac cloud role sync

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2024-01-17 10:55:47 +01:00
arukiidou
bffb28c177
refactor: use golang.org/x/oauth2 pkce option (#80511)
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
2024-01-15 16:24:02 +01:00
Ryan McKinley
1caaa56de0
FeatureFlags: Use interface rather than manager (#80000) 2024-01-09 10:38:06 -08:00
Vardan Torosyan
63cd5a5625
Chore: Cleanup namespace and ID resolution (#79360)
* Chore: Cleanup namespace ID resolution

* Check for negative userID when relevant

* Reuse existing function for parsing ID as int

* Fix imports
2023-12-21 20:42:05 +01:00
Karl Persson
8cb351e54a
Authn: Handle logout logic in auth broker (#79635)
* AuthN: Add new client extension interface that allows for custom logout logic

* AuthN: Add tests for oauth client logout

* Call authn.Logout

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-12-19 10:17:28 +01:00
Misi
9e5826f40f
OAuth: Remove accessTokenExpirationCheck feature toggle (#79455)
* Remove accessTokenExpirationCheck from code and align docs

* Apply suggestions from code review

* lint

---------

Co-authored-by: lwandz13 <126723338+lwandz13@users.noreply.github.com>
2023-12-15 13:20:17 +01:00
Vardan Torosyan
a35146f7ed
Service account: Update last used timestamp when token is used (#79254) 2023-12-08 16:53:11 +01:00
Misi
50f4e78a39
Auth: Use SSO settings service to load social connectors + refactor (#79005)
* Refactor to prevent cyclic dependencies

* Move list authorization to the API layer

* Init connectors using the SSO settings service in case the ssoSettingsApi feature toggle is enabled

* wip, need to handle the cyclic dep

* Remove cyclic dependency

* Align tests + refactor

* Move back OAuthInfo to social

* Delete pkg/login/social/constants

* Move reloadable registration to the social providers

* Rename connectors.Error to connectors.SocialError
2023-12-08 11:20:42 +01:00
Karl Persson
687ffb4a0c
Authn: Only resolve org id once (#78811) 2023-11-29 15:55:39 +01:00
Gabriel MABILLE
059ba25973
AuthN: Check API Key is not trying to access another organization (#78749)
* AuthN: Check API Key is not trying to access another organization

* Revert local change

* Add test

* Discussed with Kalle we should set r.OrgID

* Syntax sugar

* Suggestion org-mismatch
2023-11-29 10:25:46 +01:00
Jo
7d559bc69a
AuthProxy: Do not allow sessions to be assigned with other methods (#78602)
do not allow login token with other methods
2023-11-24 11:00:53 +01:00
Kevin Wang
8bdfb7e1cf
chore(authn.service): fix typo in log statement (#76205) 2023-11-23 09:06:19 +01:00
Karl Persson
1eb19befaa
Login: refactor auth info package (#78459)
* Remove unused stats and metrics

* No longer collect metrics

* Remove unused dependency

* Move database from sub package
2023-11-21 14:47:23 +01:00
Karl Persson
d42201dbf4
Login: remove unused function (#78442)
* Move test to the db so we test the queries and not just testing the mock

* Remove unused function and dependencies

* Remove unused functions from the database

* Add some integration tests
2023-11-21 11:44:13 +01:00
Karl Persson
140b5b4a61
AuthN: Add debug logs and check error during oauth token sync (#78323)
Add some debug logs and handle error
2023-11-17 16:03:25 +01:00
Ryan McKinley
f69fd3726b
FeatureToggles: Add context and and an explicit global check (#78081) 2023-11-14 12:50:27 -08:00
Ryan McKinley
5d5f8dfc52
Chore: Upgrade Go to 1.21.3 (#77304) 2023-11-01 09:17:38 -07:00
Gabriel MABILLE
83e9088314
AuthN: Set oauth client grant_types based on plugin state (#77248)
* Disable plugin service account

* Fix bug seen by linoman 💯

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

* Account for PR feedback

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

* Fix test data

* Enable datasource plugins by default

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

* Update pkg/services/extsvcauth/oauthserver/oasimpl/service.go

* Handle error differently

* Fix service reg

---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
2023-10-27 14:45:04 +02:00
Misi
1e81ffccac
Auth: Handle when access token has already been refreshed in OAuth token sync (#77118)
* Use singleflight to prevent logging error if the token has already been refreshed

* Change order of error checks

* align tests, change error name

* Change sf key

* Update based on the review

* refactor
2023-10-25 18:15:41 +02:00
Karl Persson
ed1c50233f
Revert "AuthN: move oauth token hook into session client" (#76882)
Revert "AuthN: move oauth token hook into session client (#76688)"

This reverts commit 455cede699.
2023-10-20 16:09:46 +02:00
Karl Persson
455cede699
AuthN: move oauth token hook into session client (#76688)
* Move rotate logic into its own function

* Move oauth token sync to session client

* Add user to the local cache if refresh tokens are not enabled for the provider so we can skip the check in other
requests
2023-10-18 12:51:15 +02:00
Karl Persson
1528d6f5c4
Authn: Prevent empty username and email during sync (#76330)
* Move errors to error file

* Move check for both empty username and email to user service

* Move check for empty email and username to user service Update

* Wrap inner error

* Set username in test
2023-10-11 14:27:43 +02:00
Karl Persson
ceb6f8b409
Authn: error logs (#76264)
* Reduce to debug for session need rotation error

* try to extract log level from error and fallback to warning
2023-10-10 16:30:20 +02:00
Karl Persson
ea741dda6b
Signingkeys: Add local cache (#76234)
* IDForwarding: change audience to be prefixed by org and remove JTI

* IDForwarding: Construct new signer each time we want to sign a token.

* SigningKeys: Simplify storage layer and move logic to service

* SigningKeys: Add private key to local cache
2023-10-10 14:17:16 +02:00
Karl Persson
81b366e2c8
AuthN: Make logger less noisy (#76044)
* Change to debug for token needs rotation errors
2023-10-05 16:11:36 +02:00
Misi
bd2191c158
Auth: OAuth token sync improvements (#75943)
* Add metric, improve token refresh

* changes

* handle ctx cancelled

* Fix import order
2023-10-05 11:19:43 +02:00
Gabriel MABILLE
193ec8de2b
AuthN: Move oauthserver to extsvcauth (#75972)
* AuthN: Move oauthserver to extsvcauth

* Codeowners
2023-10-04 16:53:17 +02:00
Jo
44fa0697ce
Auth: Signing Key persistence (#75487)
* signing key wip

use db keyset storage

add signing_key table

add testing for key storage

add ES256 key tests

Remove caching and implement UpdateOrCreate

Stabilize interfaces

* Encrypt private keys

* Fixup signer

* Fixup ext_jwt

* Add GetOrCreatePrivate with automatic key rotation

* use GetOrCreate for ext_jwt

* use GetOrCreate in id

* catch invalid block type

* fix broken test

* remove key generator

* reduce public interface of signing service
2023-10-04 10:37:27 +02:00
Marcus Efraimsson
e4c1a7a141
Tracing: Standardize on otel tracing (#75528) 2023-10-03 14:54:20 +02:00
Karl Persson
7a38090bc0
AuthN: Fix namespaces for anonymous and render (#75661)
* AuthN: remove IsAnonymous from identity struct and set correct namespace for anonymous and render

* Don't parse user id for render namespace
2023-09-29 09:10:33 +02:00
Karl Persson
fd2235b5ad
AuthN: Implement requester interface for identity (#75618)
* AuthN: Implement identity.Requester interface for authn.Identity

* AuthN: Replace OrgRole with GetOrgRole

* IDForwarding: skip converting to SignedInUser

* Pass identity directly in permission sync hook
2023-09-28 16:37:32 +02:00
Karl Persson
b9b4246432
IDForwarding: Add auth hook to generate id token (#75555)
* AuthN: Move identity struct to its own file

* IDForwarding: Add IDToken property to usr and identity structs and add GetIDToken to requester interface

* Inject IDService into background services

* IDForwarding: Register post auth hook when feature toggle is enabled
2023-09-28 09:22:05 +02:00
Gabriel MABILLE
0ed649b108
AuthN: Change EnableDisabledUserHook to EnableUserHook (#75248)
* Replace the enable disable user hook by a hook that systematically enable users

* Fix tests

* Remove the skip test
2023-09-27 11:16:53 +02:00
Jo
40a1f8434d
Anon: Scaffold anon service (#74744)
* remove API tagging method and authed tagging

* add anonstore

move debug to after cache

change test order

fix issue where mysql trims to second

* add old device cleanup

lint

utc-ize everything

trim whitespace

* remove dangling setting

* Add delete devices

* Move anonymous authnclient to anonimpl

* Add simple post login hook

* move registration of Background Service

cleanup

* add updated_at index

* do not untag device if login err

* add delete device integration test
2023-09-25 16:25:29 +02:00
Gabriel MABILLE
c8149d50f9
LDAP: FIX Enable users on successfull login (#75073)
* LDAP: Enable users on successfull login

* Force enable ldap users on successful login

* Fix tests

* Fix tests
2023-09-20 17:26:50 +02:00
Karl Persson
cebae4fb9a
Requester: Update GetCacheKey (#74834)
* AuthN: re-export all namespaces

* Identity: Change signature of GetCacheKey

* User: check HasUniqueID

* Default to org role None if role is empty
2023-09-14 09:19:33 +02:00
Artur Wierzbicki
d50ccd6741
Chore: AuthN/IdentitySynchronizer interface/impl compatibility wire fix (#74400)
authn/identitysynchronizer fix
2023-09-06 15:10:07 +04:00
linoman
13f4382214
Auth: Implement requester interface in access control module (#74289)
* Implement requester interface in the access control module
2023-09-06 11:16:10 +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
Gabriel MABILLE
f900098cc9
[LDAP] Disable removed users on login (#74016)
* [LDAP] Disable removed users on login

* Fix tests

* Add test for user disabling

* Add tests for disabling user behind auth proxy

* Linting.

* Rename setup func

* Account for reviews comments

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

---------

Co-authored-by: Kalle Persson <kalle.persson@grafana.com>
2023-08-30 10:59:35 +02:00
Karl Persson
37ceffb74c
Authn: Standardize errors (#74012) 2023-08-29 15:44:04 +02:00
Jo
fe1563882a
Chore: Port oauth token service to identity requester (#73988)
* port oauth token service to identity requester

* fix broken test

* no need to check for render
2023-08-29 11:55:58 +02:00
Gabriel MABILLE
9e52414a91
LDAP: Fix active sync with large quantities of users (#73834) 2023-08-25 16:10:48 +02:00
Karl Persson
5d14b6ba19
AuthProxy: Fix user retrieval through cache (#73802)
* AuthProxy: Change auth proxy sync cache key
2023-08-25 13:59:45 +02: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
Karl Persson
618daf0518
Login: remove login.Service (#73542) 2023-08-21 13:15:31 +02:00
Karl Persson
124e0efe1f
Authn: external identity sync (#73461)
* Authn: Add interface for external identity sync

This interface is implemented by authnimpl.Service and just triggers PostAuthHooks and skipping last seen update by default

* Authn: Add SyncIdentity to fake and add a new mock
2023-08-18 11:11:44 +02:00
Karl Persson
e53e22ef2a
Contexthandler: Remove code that is no longer used (#73101)
* Contexthandler: remove dead code

* Contexthandler: Add tests

* Update pkg/tests/api/alerting/api_alertmanager_test.go

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

---------

Co-authored-by: Jo <joao.guerreiro@grafana.com>
2023-08-09 15:17:59 +02:00
Jo
bd1a856d33
Auth: Add SignedIn user interface NamespacedID (#72944)
* wip

* scope active user to 1 org

* remove TODOs

* add render auth namespace

* import cycle fix

* make condition more readable

* convert Evaluate to user Requester

* only use active OrgID for SearchUserPermissions

* add cache key to interface definition

* change final SignedInUsers to interface

* fix api key managed roles fetch

* fix anon auth id parsing

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

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>

---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-08-09 09:35:50 +02:00
Karl Persson
144e4887ee
Auth: Use authn.Service for all tests (#72921)
* Dashboards: Fix tests when authn broker is enabled.
StarService was not configured for tests, the call was guarded by !c.IsSignedIn

* Change default to be anon user to match expectations from tests

* OAuth: rewrite tests to work with authn.Service

* Setup template renderer by default

* Extract cookie options from cfg instead of relying on global variables

* Fix test to work with authn service

* Middleware: rewrite auth tests

* Remvoe session cookie if we cannot refresh access token
2023-08-09 08:54:52 +02:00
Ryan McKinley
7431c0ddb1
UserSync: Avoid UpdateLastSeenAt with invalid user ids (#72776)
* avoid user zero

* more errors

* more tests

* split
2023-08-03 08:26:02 +02:00
Jo
7d347cd428
Auth: remove org count from signedInUser (#72661)
* tweaks

* remove org count from signedinUser

* remove org count from signedinUser store

* fix broken tests

* restore frontend interface
2023-08-01 14:04:37 +02:00
Aksel Skaar Leirvaag
6d98d06f6e
Auth: Check id token expiry date (#69829)
* fixed: added id token expiry check to oauth token sync

* use go-jose and id token in cache

* Update pkg/services/authn/authnimpl/sync/oauth_token_sync.go

* refactored getOAuthTokenCacheTTL and added unit tests

* Small changes to oauth_token_sync

* Remove unnecessary contexthandler changes

---------

Co-authored-by: linoman <2051016+linoman@users.noreply.github.com>
Co-authored-by: Mihaly Gyongyosi <mgyongyosi@users.noreply.github.com>
2023-08-01 09:23:47 +02:00
Jo
3353b1a8aa
Auth: Add authed device tagging (#72442)
* add authed device tagging

* fix config

* implement feedback

* implement feedback

* add reverse untag behavior

* remove duplicate stat

* Update pkg/services/anonymous/anonimpl/impl.go
2023-07-31 18:04:28 +02:00
Jo
e04a6fb08e
Auth: Fix static test fake (#72514)
fix static fake
2023-07-31 10:41:37 +02:00
Jo
a4a87f6228
Auth: Rename Sessions to Devices in counting (#72432)
* rename session to device

* rename session to device
2023-07-27 11:09:08 +02:00
Jo
ed780ce0e9
Auth: Fix Last Seen being updated on every request (#72036)
* make sure LastSeen hook has information to decide if update is necessary

* make user service check if it should update the user's last seen

* do not run last seen hook if is a login request

* make service return error when last seen is up to date

* fix err

* Update pkg/services/contexthandler/contexthandler.go

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

* fix golint

---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-07-24 16:37:35 +02:00
Misi
dcf26564db
OAuth: Introduce user_refresh_token setting and make it default for the selected providers (#71533)
* First changes

* WIP docs

* Align current tests

* Add test for UseRefreshToken

* Update docs

* Fix

* Remove unnecessary AuthCodeURL from generic_oauth

* Change GitHub to disable use_refresh_token by default
2023-07-14 14:03:01 +02:00
Misi
5efc3386d3
AuthZ: Extend /api/search to work with self-contained permissions (#70749)
* Search sql filter draft, unfinished

* Search works for empty roles

* Add current AuthModule to SignedInUser

* clean up, changes to the search

* Use constant prefixes

* Change AuthModule to AuthenticatedBy

* Add tests for using the permissions from the SignedInUser

* Refactor and simplify code

* Fix sql generation for pg and mysql

* Fixes, clean up

* Add test for empty permission list

* Fix

* Fix any vs all in case of edit permission

* Update pkg/services/authn/authn.go

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

* Update pkg/services/sqlstore/permissions/dashboard_test.go

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

* Fixes, changes based on the review

---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-07-12 12:31:36 +02:00
Ieva
a65cb4d808
RBAC: remove simple RBAC disabled checks (#71137)
* remove simple RBAC disabled checks

* fixing tests

* remove old AC tests
2023-07-10 15:14:21 +03:00