Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Adds k8s secret storage to helm tokengen job #10713

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rbrady
Copy link

@rbrady rbrady commented Feb 20, 2025

What this PR does

Adds k8s secret storage to the tokengen job exactly as Loki has it. This is needed for FedRAMP deployment and day 2 operations.

Which issue(s) this PR fixes or relates to

Fixes #5237
Fixes #deployment_tools/218045

Checklist

  • Tests updated.
  • [] Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@rbrady rbrady requested a review from a team as a code owner February 20, 2025 20:57
@CLAassistant
Copy link

CLAassistant commented Feb 20, 2025

CLA assistant check
All committers have signed the CLA.

To create a k8s secret we need a Role and RoleBinding that can perform the action.
Only adds if enterprise and tokengen are enabled, and federation frontend hasn't disabled
other components (prevents tokengen from running in federation-only mode).

Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
The tokengen job will now store the result in a k8s secret as it does with Loki.

Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
… why it fails call-lint-test in CI

Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
Signed-off-by: Ryan Brady <ryan.brady@grafana.com>
@rbrady rbrady force-pushed the rbrady/218045-store-tokengen-secrets branch from 04cf96f to dc61d91 Compare February 25, 2025 16:08
@rbrady
Copy link
Author

rbrady commented Feb 25, 2025

From the helm test in CI:

Admin token generated successfully
secret/mimir-distributed-o87t1onquz-admin-token created
Admin token secret created/updated successfully

*/}}
{{- define "mimir.kubectlImage" -}}
{{ .Values.kubectlImage.repository }}:{{ .Values.kubectlImage.tag | default "latest" }}
{{- end -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{{- end -}}
{{- end -}}

- |
if [ -f /shared/admin-token ]; then
echo "Admin token generated successfully"
{{- if .Values.tokengenJob.storeTokenInSecret | default true }}
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this true by default already due to the values.yaml? why do we need the |default true?

# -- Overrides the image tag whose default is the chart's appVersion
tag: null
# -- Overrides the image tag with an image digest
digest: null
Copy link
Contributor

Choose a reason for hiding this comment

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

none of the other images have the digest overridable. Why is this necessary here?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, but this isn't even used in this chart. I'd rather be consistent within this chart than semi-consistent with another chart.

{{- end }}
{{- end }}
securityContext:
{{- toYaml .Values.tokengenJob.containerSecurityContext | nindent 12 }}
containers:
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way to make this somehow conditional? Otherwise, this will add an additional image to GEM installations. I think some people running GEM are very frugal for what images they allow pulled.

Maybe we can have a regular container which polls for the token in the shared location and then uploads it. That way we don't deploy a new image only to echo "skipping creating secret"

# -- Controls whether to store the generated admin token in a Kubernetes secret
storeTokenInSecret: true
# -- Name of the secret to store the admin token. If not specified, defaults to "<release-name>-admin-token"
adminTokenSecret: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have the default string here instead? it's self-documenting and it won't go out of date

kind: Role
name: {{ include "mimir.resourceName" (dict "ctx" . "component" "tokengen") }}
apiGroup: rbac.authorization.k8s.io
{{- end -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a new line?

{{- toYaml .Values.tokengenJob.annotations | nindent 4 }}
{{- end }}
namespace: {{ .Release.Namespace | quote }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a new line?

@@ -29,6 +29,7 @@ Entries should include a reference to the Pull Request that introduced the chang

## main / unreleased

* [CHANGE] Tokengen: Added k8s secret storage for the admin token. #5237
Copy link
Contributor

Choose a reason for hiding this comment

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

can you clarify that now the token is stored in a secret by default?

kubectl image reference
*/}}
{{- define "mimir.kubectlImage" -}}
{{ .Values.kubectlImage.repository }}:{{ .Values.kubectlImage.tag | default "latest" }}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's less surprising if the tag is just latest in the default values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tokengen-job should be able to write the admin token to a secret like loki helm chart
4 participants