Skip to content

Commit 7c4cb09

Browse files
committed
Allow FedRAMP deployments to avoid default initializer identities
FedRAMP Gatekeeper can reject pods that fall back to the default service account. TidbInitializer creates a Job pod directly, so the CRD needs an explicit field that users can bind to a dedicated ServiceAccount without carrying operator-side patches. The initializer spec now exposes serviceAccountName and passes it through to the generated Job pod template. The CRD and OpenAPI schema are updated so users can configure the field through the v1 API. Constraint: FedRAMP block-default-service-account policy rejects implicit default service account usage Rejected: Hardcode tidb-initializer in the manager | forces one service account name on all users and keeps requiring operator code patches Confidence: high Scope-risk: narrow Directive: Keep this field as a pass-through to the Job pod spec; do not add defaulting here without checking backward compatibility Tested: go test ./pkg/manager/member Tested: cd pkg/apis && go test ./pingcap/v1alpha1 Tested: git diff --check
1 parent a043946 commit 7c4cb09

6 files changed

Lines changed: 31 additions & 0 deletions

File tree

manifests/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63536,6 +63536,8 @@ spec:
6353663536
x-kubernetes-int-or-string: true
6353763537
type: object
6353863538
type: object
63539+
serviceAccountName:
63540+
type: string
6353963541
timezone:
6354063542
type: string
6354163543
tlsClientSecretName:

manifests/crd/v1/pingcap.com_tidbinitializers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ spec:
158158
x-kubernetes-int-or-string: true
159159
type: object
160160
type: object
161+
serviceAccountName:
162+
type: string
161163
timezone:
162164
type: string
163165
tlsClientSecretName:

pkg/apis/pingcap/v1alpha1/openapi_generated.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/pingcap/v1alpha1/tidbinitializer_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ type TidbInitializerSpec struct {
7373
// +optional
7474
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
7575

76+
// ServiceAccountName is the name of the ServiceAccount to use to run TiDB initializer Pods.
77+
// +optional
78+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
79+
7680
// permitHost is the host which will only be allowed to connect to the TiDB.
7781
// +optional
7882
PermitHost *string `json:"permitHost,omitempty"`

pkg/manager/member/tidb_init_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (m *tidbInitManager) makeTiDBInitJob(ti *v1alpha1.TidbInitializer) (*batchv
353353
},
354354
Spec: corev1.PodSpec{
355355
ImagePullSecrets: ti.Spec.ImagePullSecrets,
356+
ServiceAccountName: ti.Spec.ServiceAccountName,
356357
SecurityContext: ti.Spec.PodSecurityContext,
357358
AutomountServiceAccountToken: pointer.BoolPtr(false),
358359
InitContainers: []corev1.Container{

pkg/manager/member/tidb_init_manager_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ func TestMakeTiDBInitJobDisablesServiceAccountTokenAutomount(t *testing.T) {
143143
g.Expect(*job.Spec.Template.Spec.AutomountServiceAccountToken).To(BeFalse())
144144
}
145145

146+
func TestMakeTiDBInitJobUsesServiceAccountName(t *testing.T) {
147+
g := NewGomegaWithT(t)
148+
tim, _, indexers := newFakeTiDBInitManager()
149+
ti := newTidbInitializerForTiDB()
150+
ti.Spec.ServiceAccountName = "tidb-initializer"
151+
tc := newTidbClusterForTiDB()
152+
153+
err := indexers.tc.Add(tc)
154+
g.Expect(err).NotTo(HaveOccurred())
155+
156+
job, err := tim.makeTiDBInitJob(ti)
157+
g.Expect(err).NotTo(HaveOccurred())
158+
g.Expect(job.Spec.Template.Spec.ServiceAccountName).To(Equal("tidb-initializer"))
159+
}
160+
146161
func newFakeTiDBInitManager() (*tidbInitManager, *tidbMemberManager, *fakeIndexers) {
147162
tmm, _, _, indexers := newFakeTiDBMemberManager()
148163
indexers.job = tmm.deps.KubeInformerFactory.Batch().V1().Jobs().Informer().GetIndexer()

0 commit comments

Comments
 (0)