-
Notifications
You must be signed in to change notification settings - Fork 0
[] Add helm/templates/secret.yaml (lookup-idempotent), serviceaccount.yaml, rbac.yaml; update deployment.yaml and worker-deployment.yaml with SecurityContext and secret injection #290
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,26 @@ spec: | |
| {{- include "open-git.selectorLabels" . | nindent 8 }} | ||
| app.kubernetes.io/component: backend | ||
| spec: | ||
| serviceAccountName: {{ include "open-git.serviceAccountName" . }} | ||
| {{- with .Values.imagePullSecrets }} | ||
| imagePullSecrets: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| securityContext: | ||
| {{- include "open-git.podSecurityContext" . | nindent 8 }} | ||
| containers: | ||
| - name: backend | ||
| image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag }}" | ||
| imagePullPolicy: {{ .Values.image.backend.pullPolicy }} | ||
| securityContext: | ||
| {{- include "open-git.containerSecurityContext" . | nindent 12 }} | ||
| volumeMounts: | ||
| - name: tmp | ||
| mountPath: /tmp | ||
| {{- if (.Values.persistence.repositories.enabled | default true) }} | ||
| - name: repositories | ||
| mountPath: {{ include "open-git.repositoriesMountPath" . | quote }} | ||
| {{- end }} | ||
| ports: | ||
| - name: http | ||
| containerPort: 8080 | ||
|
|
@@ -66,33 +82,45 @@ spec: | |
| - name: MINIO_BUCKET | ||
| value: {{ .Values.minio.bucket | quote }} | ||
| {{- end }} | ||
| - name: JWT_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ include "open-git.secretName" . }} | ||
| key: jwt-secret | ||
| - name: OAUTH_CLIENT_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ include "open-git.secretName" . }} | ||
| key: oauth-client-secret | ||
| - name: WEBHOOK_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ include "open-git.secretName" . }} | ||
| key: webhook-secret | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /health | ||
| path: /readyz | ||
| port: 8080 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| failureThreshold: 3 | ||
| livenessProbe: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] backend の probe パスが /health から /healthz・/readyz に変更されている 本 PR の変更ファイルは Helm テンプレートのみですが、backend の probe パスが差し替えられています。 該当箇所: readinessProbe:
httpGet:
- path: /health
+ path: /readyz
port: 8080
...
livenessProbe:
httpGet:
- path: /health
+ path: /healthz
port: 8080@@ -100,7 +100,7 @@
readinessProbe:
httpGet:
- path: /readyz
+ path: /health
port: 8080
livenessProbe:
httpGet:
- path: /healthz
+ path: /health
port: 8080
|
||
| httpGet: | ||
| path: /health | ||
| path: /healthz | ||
| port: 8080 | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| failureThreshold: 3 | ||
| {{- if (.Values.persistence.repositories.enabled | default true) }} | ||
| volumeMounts: | ||
| - name: repositories | ||
| mountPath: {{ include "open-git.repositoriesMountPath" . | quote }} | ||
| {{- end }} | ||
| resources: | ||
| {{- toYaml .Values.resources | nindent 12 }} | ||
| {{- if (.Values.persistence.repositories.enabled | default true) }} | ||
| volumes: | ||
| - name: tmp | ||
| emptyDir: {} | ||
| {{- if (.Values.persistence.repositories.enabled | default true) }} | ||
| - name: repositories | ||
| persistentVolumeClaim: | ||
| claimName: {{ include "open-git.fullname" . }}-repositories | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- with .Values.nodeSelector }} | ||
| nodeSelector: | ||
| {{- toYaml . | nindent 8 }} | ||
|
|
@@ -125,13 +153,42 @@ spec: | |
| {{- include "open-git.selectorLabels" . | nindent 8 }} | ||
| app.kubernetes.io/component: frontend | ||
| spec: | ||
| serviceAccountName: {{ include "open-git.serviceAccountName" . }} | ||
| {{- with .Values.imagePullSecrets }} | ||
| imagePullSecrets: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| securityContext: | ||
| {{- include "open-git.podSecurityContext" . | nindent 8 }} | ||
| containers: | ||
| - name: frontend | ||
| image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag }}" | ||
| imagePullPolicy: {{ .Values.image.frontend.pullPolicy }} | ||
| securityContext: | ||
| {{- include "open-git.containerSecurityContext" . | nindent 12 }} | ||
| volumeMounts: | ||
| - name: tmp | ||
| mountPath: /tmp | ||
| ports: | ||
| - name: http | ||
| containerPort: 3000 | ||
| protocol: TCP | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /readyz | ||
| port: 3000 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| failureThreshold: 3 | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /healthz | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] frontend に新規 probe が追加されているが、同一 PR にアプリ変更がない frontend Deployment には従来 probe がなく、本 diff で readiness/liveness が新規追加されています。ポート 3000 の 該当箇所: + readinessProbe:
+ httpGet:
+ path: /readyz
+ port: 3000
+ initialDelaySeconds: 5
+ periodSeconds: 10
+ failureThreshold: 3
+ livenessProbe:
+ httpGet:
+ path: /healthz
+ port: 3000
|
||
| port: 3000 | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| failureThreshold: 3 | ||
| resources: | ||
| {{- toYaml .Values.resources | nindent 12 }} | ||
| volumes: | ||
| - name: tmp | ||
| emptyDir: {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| {{- if .Values.serviceAccount.create }} | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: {{ include "open-git.fullname" . }} | ||
| namespace: {{ .Release.Namespace }} | ||
| labels: | ||
| {{- include "open-git.labels" . | nindent 4 }} | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["secrets"] | ||
| resourceNames: | ||
| - {{ include "open-git.secretName" . | quote }} | ||
| {{- if eq .Values.db.type "postgres" }} | ||
| - {{ printf "%s-db" (include "open-git.fullname" .) | quote }} | ||
| {{- end }} | ||
| {{- if .Values.minio.enabled }} | ||
| - {{ printf "%s-minio" (include "open-git.fullname" .) | quote }} | ||
| {{- end }} | ||
| verbs: ["get"] | ||
| - apiGroups: [""] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] PRD 要件の 該当箇所: resources: ["secrets"]
resourceNames:
- {{ include "open-git.secretName" . | quote }}
...
verbs: ["get"]タスク仕様では - apiGroups: [""]
resources: ["configmaps"]
verbs: ["get"]
@@ -16,1 +16,1 @@
- verbs: ["get"]
+ verbs: ["get", "list", "watch"]
|
||
| resources: ["configmaps"] | ||
| verbs: ["get"] | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: {{ include "open-git.fullname" . }} | ||
| labels: | ||
| {{- include "open-git.labels" . | nindent 4 }} | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: {{ include "open-git.fullname" . }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] 該当箇所: kind: RoleBinding
metadata:
name: {{ include "open-git.fullname" . }}
labels:
{{- include "open-git.labels" . | nindent 4 }}
@@ -25,4 +25,5 @@
metadata:
name: {{ include "open-git.fullname" . }}
+ namespace: {{ .Release.Namespace }}
labels:
{{- include "open-git.labels" . | nindent 4 }}
|
||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: {{ include "open-git.serviceAccountName" . }} | ||
| namespace: {{ .Release.Namespace }} | ||
| {{- end }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| {{- if not .Values.secrets.existingSecret }} | ||
| {{- $secret := lookup "v1" "Secret" .Release.Namespace (include "open-git.secretName" .) }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 [critical] lookup の Secret 名に 該当箇所: {{- $secret := lookup "v1" "Secret" .Release.Namespace (include "open-git.secretName" .) }}
設計意図は問題ないものの、
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 [critical] 該当箇所: {{- $secret := lookup "v1" "Secret" .Release.Namespace (include "open-git.secretName" .) }}
{{- else }}
db-password: {{ randAlphaNum 32 | b64enc | quote }}
jwt-secret: {{ randAlphaNum 32 | b64enc | quote }}
oauth-client-secret: {{ randAlphaNum 32 | b64enc | quote }}
webhook-secret: {{ randAlphaNum 32 | b64enc | quote }}
{{- end }}
推奨修正:
|
||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: {{ include "open-git.secretName" . }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] 該当箇所: {{- $secret := lookup "v1" "Secret" .Release.Namespace (include "open-git.secretName" .) }}
...
name: {{ include "open-git.secretName" . }}
ただし、
|
||
| labels: | ||
| {{- include "open-git.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: secrets | ||
| type: Opaque | ||
| data: | ||
| {{- if $secret }} | ||
| db-password: {{ index $secret.data "db-password" | default (randAlphaNum 32 | b64enc) | quote }} | ||
| jwt-secret: {{ index $secret.data "jwt-secret" | default (randAlphaNum 32 | b64enc) | quote }} | ||
| oauth-client-secret: {{ index $secret.data "oauth-client-secret" | default (randAlphaNum 32 | b64enc) | quote }} | ||
| webhook-secret: {{ index $secret.data "webhook-secret" | default (randAlphaNum 32 | b64enc) | quote }} | ||
| {{- else }} | ||
| db-password: {{ randAlphaNum 32 | b64enc | quote }} | ||
| jwt-secret: {{ randAlphaNum 32 | b64enc | quote }} | ||
| oauth-client-secret: {{ randAlphaNum 32 | b64enc | quote }} | ||
| webhook-secret: {{ randAlphaNum 32 | b64enc | quote }} | ||
| {{- end }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] helm/template dry-run・CI 環境では lookup が空を返すためシークレットが毎回再生成される CWE-330: Use of Insufficiently Random Values / CWE-344: Use of Invariant Value in Dynamically Changing Context
{{- else }}
db-password: {{ randAlphaNum 32 | b64enc | quote }}
jwt-secret: {{ randAlphaNum 32 | b64enc | quote }}
oauth-client-secret: {{ randAlphaNum 32 | b64enc | quote }}
webhook-secret: {{ randAlphaNum 32 | b64enc | quote }}
{{- end }}これにより、CI パイプラインがマニフェストをキャプチャして GitOps リポジトリへ push する運用の場合、ランダム生成シークレットが平文で Git に記録されるリスクがあります。また実際のクラスタへの apply 時も 推奨: dry-run / # values.yaml に以下コメントを追加
# secrets:
# existingSecret: "" # 本番では必ず existingSecret を指定してください。
# # helm template / --dry-run 時は lookup が機能せず
# # ランダム値が出力されます。CI でマニフェストを
# # キャプチャする場合は出力を秘匿してください。
|
||
| {{- end }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {{- if .Values.serviceAccount.create }} | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: {{ include "open-git.serviceAccountName" . }} | ||
| labels: | ||
| {{- include "open-git.labels" . | nindent 4 }} | ||
| {{- with .Values.serviceAccount.annotations }} | ||
| annotations: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| automountServiceAccountToken: false | ||
| {{- end }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,22 @@ spec: | |
| {{- include "open-git.selectorLabels" . | nindent 8 }} | ||
| app.kubernetes.io/component: worker | ||
| spec: | ||
| serviceAccountName: {{ include "open-git.serviceAccountName" . }} | ||
| {{- with .Values.imagePullSecrets }} | ||
| imagePullSecrets: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [high] 該当箇所: imagePullSecrets:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
@@ -20,3 +20,5 @@
- imagePullSecrets:
- {{- toYaml .Values.imagePullSecrets | nindent 8 }}
+ {{- with .Values.imagePullSecrets }}
+ imagePullSecrets:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
|
||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| securityContext: | ||
| {{- include "open-git.podSecurityContext" . | nindent 8 }} | ||
| containers: | ||
| - name: worker | ||
| image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag }}" | ||
| imagePullPolicy: {{ .Values.image.backend.pullPolicy }} | ||
| securityContext: | ||
| {{- include "open-git.containerSecurityContext" . | nindent 12 }} | ||
| volumeMounts: | ||
| - name: tmp | ||
| mountPath: /tmp | ||
| args: | ||
| - "--worker-only" | ||
| env: | ||
|
|
@@ -59,8 +71,21 @@ spec: | |
| - name: MINIO_BUCKET | ||
| value: {{ .Values.minio.bucket | quote }} | ||
| {{- end }} | ||
| - name: JWT_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ include "open-git.secretName" . }} | ||
| key: jwt-secret | ||
| - name: WEBHOOK_SECRET | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ include "open-git.secretName" . }} | ||
| key: webhook-secret | ||
| resources: | ||
| {{- toYaml .Values.resources | nindent 12 }} | ||
| volumes: | ||
| - name: tmp | ||
| emptyDir: {} | ||
| {{- with .Values.nodeSelector }} | ||
| nodeSelector: | ||
| {{- toYaml . | nindent 8 }} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [high]
imagePullSecretsが nil チェックなしで常時展開されるため、空リストが YAML に出力される該当箇所:
.Values.imagePullSecretsがnilまたは空リストの場合、toYaml nilはnull\nを出力し、結果としてimagePullSecrets: nullという不正な YAML フィールドになります。Kubernetes はこれを空リストとして解釈することもありますが、バリデーション次第では拒否される場合があります。既存 Helm チャートの慣習に従い、
{{- with .Values.imagePullSecrets }}でガードしてください:これは
worker-deployment.yamlの同箇所(+20-+21行目)も同様です。code.helm.imagepullsecrets_always_rendered| confidence: 0.90