Commit Graph

150 Commits

Author SHA1 Message Date
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
Karl Persson
fd870702c7
Chore: Remove unused function TryRotateToken (#85836)
* Chore: Remove unused function

* remove unused function
2024-04-10 11:15:43 +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
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
Karl Persson
2f5e3023c2
IDFowrarding: ignore logging context canceled errors (#85141) 2024-03-26 11:36:44 +01:00
ismail simsek
6137c4e0a6
Chore: Bump golangci-lint v1.57.1 (#84998)
* bump golangci-lint v1.57.1

* update setting

* remove goconst

* fix linting issues

* prettier

* fix G601

* go mod tidy
go work sync
2024-03-25 15:28:24 +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
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
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
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
Karl Persson
28bb6979f5
IDForwading: cache based on expires in (#81136)
* IDFowarding: Cache based on expires in

* IDFowarding: Change default expires in

---------

Co-authored-by: Victor Cinaglia <victor@grafana.com>
2024-01-24 13:56:44 +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
Karl Persson
147bf01745
IDForwarding: Always forward id tokens to plugins (#81041)
* Always forward id tokens to plugins
2024-01-23 12:12:32 +01:00
Karl Persson
43b6b6b2a4
IDForwarding: add "authenticatedBy" to id token (#80622)
* IDForwading: Set authenticated by for users
2024-01-17 09:52:05 +01:00
Jo
c3d8c6e0ea
JWT: Fallthrough to fetch keyset in case of cache error (#80081)
fallthrough to fetch keyset in case of cache error. Fixes #67582
2024-01-08 16:02:31 +01: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
05d1ce4026
Auth: id response header (#79757)
* Add utility function to check if namespace is any of

* Refactor code to use identity interface
2023-12-21 14:06:28 +01:00
Misi
7128415529
Auth: Add more context to logs around token rotation, revocation (#78600)
Add more context to logs around token rotation, revocation

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2023-11-23 16:48:54 +01:00
Ryan McKinley
f69fd3726b
FeatureToggles: Add context and and an explicit global check (#78081) 2023-11-14 12:50:27 -08:00
Karl Persson
bc9fab6f30
IDForwarding: Update settings name (#77257)
Update settings name
2023-10-27 10:20:49 +02:00
Karl Persson
1b6d39f823
IDForwarding: Require that id forwarding is enabled for data source (#77131)
* Require that id forwarding is enabled for data source

* Address feedback
2023-10-27 08:30:33 +02:00
Karl Persson
e2ba399e30
IDForwarding: Use single flight for SignIdentity (#76530)
* IDForwarding: Use single flight for SignIdentity

* Update cache inside single flight call
2023-10-13 14:32:53 +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
Jo
8919cafcb4
Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112)
* Unfurl OrgRole in pkg/api to allow using identity.Requester interface

* Unfurl Email in pkg/api to allow using identity.Requester interface

* Update UserID in pkg/api to allow using identity.Requester interface

* fix authed test

* fix datasource tests

* guard login

* fix preferences anon testing

* fix anonymous index rendering

* do not error with user id 0
2023-10-09 16:07:28 +02:00
Karl Persson
a2d4ce18ad
IDForwarding: Add basic metrics (#75798)
* IDService: Add basic metrics

* IDService: Add more metrics
---------

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2023-10-05 09:17:40 +02:00
Karl Persson
09e638cd9d
IDForwarding: Use feature toggle not generate a key if feature is not enabled (#75961)
* Use feature toggle not generate a key if feature is not enabled

* Fix check
2023-10-04 16:06:24 +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
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
Karl Persson
b50f1e15a8
IDForwarding: Add service and a local signer (#75423)
* IDForwarding: Add service for handling id token and create a local signer
---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-09-27 11:36:23 +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
Eric Leijonmarck
b00f3216c1
Auth: Refactor for revoking user tokens within last hours (#74616)
* fix: revoked tokens within last hours

adds check for unlimited sessions out of index
adds a function for specifing the hours to look back when revoking users tokens, otherwise we "assume" the clean up takes care of them adds a index for the `user_auth_token` - `revoked_at` for faster queries when using `revoked_at`

* fix: sqllite datetime conversion with unixtimestamps

* fix: postgres dialect

* fix: mysql dialect

* fix: mysql dialect missing closing )

* refactor: delete revoked tokens directly

* fix: tests for sqlite

* AuthToken: Simplify DeleteUserRevokedTokens and add test

* fix: linting newline

* Reset get time after test

* fix: test order by revoked

* fix: order by different db

* ascending

* test with seen at

---------

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2023-09-13 10:24:37 +01:00
Jo
77e4d477e5
Auth: Optimize auth token operations (#74602)
* add token count

* wip

* user count method for tag reporting

* remove non functioning mysql clientFoundRows check

* Update pkg/services/auth/authtest/testing.go

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>

* add user ID guard

---------

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
2023-09-11 10:24:57 +02: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
Eric Leijonmarck
47a756d524
Auth: Move to requester interface (#74276)
add identity interface for auth
2023-09-04 09:32:20 +01:00
Ryan McKinley
025b2f3011
Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
Jo
5eed495cce
Chore: Port user services to identity.Requester (#73851)
* port api key api to signedinuser

* port users to signed in user interface

* fix tests
2023-08-28 10:42:24 +02:00
Jo
26339f978b
Auth: Move access control API to SignedInUser interface (#73144)
* move access control api to SignedInUser interface

* remove unused code

* add logic for reading perms from a specific org

* move the specific org logic to org_user.go

* add a comment

---------

Co-authored-by: IevaVasiljeva <ieva.vasiljeva@grafana.com>
2023-08-18 11:42:18 +01: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
5d8e6aa162
Auth: Org Invite and Team API SignedInUser interfacing (#73085)
* fix ngalert Evaluate sig change

* interface for teams and org invites

* Update pkg/api/org_invite.go

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

---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-08-09 12:33:35 +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
Misi
bba11d04cb
Auth: Add key_id config param to auth.jwt (#72711)
* Specify keyID for public key provided in PEM format for JWT Auth

* Update docs

* Update sample.ini
2023-08-03 09:13:23 +02:00
Jo
30274a4f88
Auth: Move Team service to SignedInUserInterface (#72674)
* move SignedInUser to specific file

* add primitive interface for signedInUser
2023-08-02 10:43:56 +02:00
Jo
5e5c751ecd
Auth: Respect cache control for JWKS in auth.jwt (#68872)
* respect cache control for auth.jwt

* add documentation

* add small note on cache control header ignores

* make distinction of env
2023-05-23 12:29:10 +02:00
Karl Persson
382b24742a
Auth: Add feature flag to move token rotation to client (#65060)
* FeatureToggle: Add toggle to use a new way of rotating tokens

* API: Add endpoints to perform token rotation, one endpoint for api request and one endpoint for redirectsd

* Auth: Aling not authorized handling between auth middleware and access
control middleware

* API: add utility function to get redirect for login

* API: Handle token rotation redirect for login page

* Frontend: Add job scheduling for token rotation and make call to token rotation as fallback in retry request

* ContextHandler: Prevent in-request rotation if feature flag is enabled and check if token needs to be rotated

* AuthN: Prevent in-request rotation if feature flag is enabled and check if token needs to be rotated

* Cookies: Add option NotHttpOnly

* AuthToken: Add helper function to get next rotation time and another function to check if token need to be rotated

* AuthN: Add function to delete session cookie and set expiry cookie

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-03-23 14:39:04 +01:00
Carl Bergquist
eb507dca89
Remotecache: rename setbytearray/getbytearray to set/get and remove codec (#64470)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
2023-03-10 13:57:29 +01:00
Jo
45fde4235b
Deps: Replace go-jose v2 with go-jose v3 (#64228)
replace go-jose v2 with go-jose v3
2023-03-06 15:12:51 +01:00