Skip to content

feat: add automountServiceAccountToken support to TidbMonitor#6906

Open
tennix wants to merge 2 commits into
pingcap:release-1.xfrom
tennix:feat/tidbmonitor-automount-sa-token
Open

feat: add automountServiceAccountToken support to TidbMonitor#6906
tennix wants to merge 2 commits into
pingcap:release-1.xfrom
tennix:feat/tidbmonitor-automount-sa-token

Conversation

@tennix
Copy link
Copy Markdown
Member

@tennix tennix commented May 20, 2026

What problem does this PR solve?

FedRAMP clusters enforce a Gatekeeper policy (block-automount-serviceaccount-token-pod) that blocks pods where automountServiceAccountToken is not explicitly false. The tidb-operator creates a {name}-monitor ServiceAccount and spawns prometheus/reloader/initializer pods using it — these pods are blocked by the policy since the SA-level field is unset and cannot be overridden externally.

What is changed and how it works

This PR adds automountServiceAccountToken to the TidbMonitorSpec and implements the same pattern already used for TidbCluster components (#6826 / #6815):

  • When unset (default): no change to existing behavior.
  • When false:
    • Sets automountServiceAccountToken: false on the {name}-monitor ServiceAccount.
    • Injects a projected SA token volume (kube-api-access) into the StatefulSet pod template, mounting it at /var/run/secrets/kubernetes.io/serviceaccount in all containers: monitor-initializer, dm-initializer (if DM enabled), prometheus, reloader, thanos-sidecar (if Thanos enabled), prometheus-reloader (if enabled), grafana (if enabled), and any additionalContainers.
  • When true: sets automountServiceAccountToken: true on the SA; no projected volume injected.

The projected volume uses the same util.SATokenProjectionVolume() / util.SATokenProjectionVolumeMount() helpers from pkg/util/util.go as the rest of the operator.

Example

apiVersion: pingcap.com/v1alpha1
kind: TidbMonitor
metadata:
  name: basic
spec:
  automountServiceAccountToken: false
  # ... rest of spec

Checklist

Related issues / PRs

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented May 20, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

When automountServiceAccountToken is set to false on the TidbMonitor
spec, the operator now sets the same field on the {name}-monitor
ServiceAccount and automatically injects a projected SA token volume
(kube-api-access) into all monitor pods (prometheus, reloader,
initializer). This satisfies Gatekeeper policies that require
automountServiceAccountToken: false without breaking in-cluster
API access.

This follows the same pattern already implemented for TidbCluster
components in pingcap#6826.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tennix tennix force-pushed the feat/tidbmonitor-automount-sa-token branch from ce7c1da to 0921150 Compare May 20, 2026 01:27
@tennix tennix changed the base branch from master to release-1.x May 20, 2026 01:28
@ti-chi-bot ti-chi-bot Bot added size/L and removed size/XXL labels May 20, 2026
@tennix tennix marked this pull request as ready for review May 20, 2026 01:29
@ti-chi-bot ti-chi-bot Bot requested review from howardlau1999 and shonge May 20, 2026 01:29
@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 20, 2026

/test pull-e2e-kind-tidbcluster

@tennix tennix enabled auto-merge (squash) May 20, 2026 05:53
@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-br

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented May 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign wangle1321 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-dmcluster

@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-tidbcluster

1 similar comment
@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-tidbcluster

@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-dmcluster

@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 21, 2026

/test pull-e2e-kind-across-kubernetes

1 similar comment
@tennix
Copy link
Copy Markdown
Member Author

tennix commented May 22, 2026

/test pull-e2e-kind-across-kubernetes

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.

1 participant