Skip to content

Conversation

Baarsgaard
Copy link
Collaborator

@Baarsgaard Baarsgaard commented Aug 10, 2025

Use the k8s ServiceAccount token projected in at /var/run/secrets/kubernetes.io/serviceaccount/token as authentication to Grafana instances.

Users can configure [auth.jwt] to accept K8s ServiceAccounts and assign them roles depending on the name, namespace, etc in the JWT token and entirely disable the default Grafana admin account.

TODO

Questions:

  • Should the operator support a default config for JWT auth which is used? The variance in what people want might be a bit high and instead just document the options.
  • Name of the client option? useKubeAuth and useJWTAuth are both a bit vague
  • Should this be merged after Grafana v12.2.0 is released and configured as the new default version?
    Would help a lot for usability as the the full setup can be handled in the Grafana CR

@github-actions github-actions bot added documentation Issues relating to documentation, missing, non-clear etc. feature this PR introduces a new feature labels Aug 10, 2025
@Baarsgaard Baarsgaard force-pushed the feat_k8s_serviceaccont_auth branch from c62ac14 to 6f7a946 Compare August 10, 2025 18:26
@Baarsgaard Baarsgaard force-pushed the feat_k8s_serviceaccont_auth branch from 6f7a946 to 9fc4378 Compare August 26, 2025 19:22
@Baarsgaard Baarsgaard force-pushed the feat_k8s_serviceaccont_auth branch from b3fd0ff to 9f29f8f Compare August 31, 2025 12:01
@Baarsgaard Baarsgaard marked this pull request as ready for review August 31, 2025 15:10

// TODO fetch JWKS from https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}/openid/v1/jwks
// Then verify token using the keys
err = t.UnsafeClaimsWithoutVerification(&claims)
Copy link
Collaborator

@weisdd weisdd Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just omit token validation? - Even though it's relatively easy to implement basic token validation (e.g. using NewProvider + Verifier from github.com/coreos/go-oidc/v3/oidc), it's up to Grafana to do the actual token validation / authorization (like with any other Grafana credentials that the operator uses), the role of the operator here is just to fetch the token from the file and pass it to Grafana when making API requests. - It would also simplify the unit test as you would only need to check that the Authorization header is set to the contents of the file. WDYT?

(We can discuss it further during the meeting)

Copy link
Collaborator Author

@Baarsgaard Baarsgaard Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I forgot that TODO comment!
We already discussed this in a weekly meeting and agreed to not validate the token aside from reading the expiration!
I will remove that comment/Change it to the reason why we do not validate the token.

And potentially simplify the test!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it was @theSuess who suggested that, I just wanted to surface that conversation here as the code was still in place. We'll wait for further updates then :)

Copy link
Collaborator Author

@Baarsgaard Baarsgaard Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it again, since the token lifetime is fully configurable, it's probably a good idea to read the expiration but not validate the token: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#launch-a-pod-using-service-account-token-projection
This allows us to dynamically set the cache timeout of the token if someone decides to shorten the lifetime.

The discussion we had last time was verifying the token signature with the JWKS downloaded from the kubernetes API, which we decided was not worth it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues relating to documentation, missing, non-clear etc. feature this PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants