Files
claude f374cd2e49
Helm Chart Release / release-chart (push) Successful in 6s
Secrets 一元管理チャート secret-manager v0.1.0 を実装
クラスター横断で使う認証情報を1チャートで管理し、複数ネームスペースへ
同一 Secret として配布する仕組みを実装。

- distribution: namespaces への複製 / kubernetes-reflector 自動同期 /
  stakater-Reloader 連携を選択可能
- common: namePrefix・共通ラベル/アノテーション・immutable
- mail.providers: SMTP/IMAP/POP3 のサーバ情報 + パスワードを一元管理。
  source 可能な smtp.env と任意の msmtprc スニペットを Secret に同梱
- api.credentials: 任意のキー/値集合を Opaque Secret 化(envFrom 向け)
- generic.secrets: 任意 type(dockerconfigjson / tls / basic-auth 等)
- values.schema.json による厳格バリデーション
- examples/(Gmail・M365・SendGrid・SES・Mailgun・reflector)
- .gitea/workflows/helm-release.yaml で Package Registry へ自動発行
- README.md にセキュリティモデル・values リファレンス・参照方法を記載
- 平文資格情報の混入防止に .gitignore を整備
2026-08-31 09:41:41 +09:00

117 lines
4.6 KiB
Smarty
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{/*
==========================================================================
secret-manager — 共通ヘルパー
==========================================================================
*/}}
{{/* チャート短縮名 */}}
{{- define "secret-manager.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* フルネーム(リリース名 + チャート名) */}}
{{- define "secret-manager.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name (include "secret-manager.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{/* Chart.yaml 由来のチャートラベル */}}
{{- define "secret-manager.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* 生成する全 Secret に付ける共通ラベル(+ common.labels) */}}
{{- define "secret-manager.commonLabels" -}}
app.kubernetes.io/name: {{ include "secret-manager.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: secret-manager
helm.sh/chart: {{ include "secret-manager.chart" . }}
{{- with .Values.common.labels }}
{{ toYaml . }}
{{- end }}
{{- end -}}
{{/*
配布先ネームスペースの実効リストをカンマ区切りで返す。
distribution.namespaces + (includeReleaseNamespace のとき Release.Namespace) を
重複排除してソートしたもの。
*/}}
{{- define "secret-manager.distributionNamespaces" -}}
{{- $ns := concat (list) (.Values.distribution.namespaces | default (list)) -}}
{{- if .Values.distribution.includeReleaseNamespace -}}
{{- $ns = append $ns .Release.Namespace -}}
{{- end -}}
{{- if not $ns -}}
{{- fail "distribution.namespaces が空です。少なくとも1つのネームスペースを指定するか、distribution.includeReleaseNamespace: true にしてください。" -}}
{{- end -}}
{{- $ns | uniq | sortAlpha | join "," -}}
{{- end -}}
{{/*
1つの論理 Secret を、実効ネームスペースそれぞれに複製して出力する。
引数: dict
ctx (必須) ルートコンテキスト ($)
name (必須) プレフィックス適用前の Secret 名
stringData (必須) map[string]string。全ての値は文字列であること
type (任意) Secret type。既定 "Opaque"
annotations (任意) map。このエントリ固有の追加アノテーション
namespacesOverride (任意) list。指定時はこのリストへ配布(distribution を無視)
*/}}
{{- define "secret-manager.secret" -}}
{{- $ctx := .ctx -}}
{{- $root := $ctx.Values -}}
{{- $fullName := printf "%s%s" $root.common.namePrefix .name -}}
{{- $type := .type | default "Opaque" -}}
{{- $reflector := $root.distribution.reflector -}}
{{- /* 配布先ネームスペースの決定 */ -}}
{{- $namespaces := list -}}
{{- $useReflector := false -}}
{{- if .namespacesOverride -}}
{{- $namespaces = .namespacesOverride | uniq -}}
{{- else if $reflector.enabled -}}
{{- $namespaces = list $ctx.Release.Namespace -}}
{{- $useReflector = true -}}
{{- else -}}
{{- $namespaces = splitList "," (include "secret-manager.distributionNamespaces" $ctx) -}}
{{- end -}}
{{- /* 共通アノテーションの組み立て */ -}}
{{- $ann := dict -}}
{{- range $k, $v := ($root.common.annotations | default dict) -}}{{- $_ := set $ann $k $v -}}{{- end -}}
{{- range $k, $v := (.annotations | default dict) -}}{{- $_ := set $ann $k $v -}}{{- end -}}
{{- if $useReflector -}}
{{- $_ := set $ann "reflector.v1.k8s.emberstack.com/reflection-allowed" "true" -}}
{{- $_ := set $ann "reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces" $reflector.namespaceRegex -}}
{{- $_ := set $ann "reflector.v1.k8s.emberstack.com/reflection-auto-enabled" "true" -}}
{{- $_ := set $ann "reflector.v1.k8s.emberstack.com/reflection-auto-namespaces" $reflector.namespaceRegex -}}
{{- end -}}
{{- if $root.distribution.reloader.enabled -}}
{{- $_ := set $ann "reloader.stakater.com/match" "true" -}}
{{- end -}}
{{- range $ns := $namespaces }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ $fullName }}
namespace: {{ $ns }}
labels:
{{- include "secret-manager.commonLabels" $ctx | nindent 4 }}
secret-manager.cafepieters.com/entry: {{ $.name | quote }}
{{- if $ann }}
annotations:
{{- toYaml $ann | nindent 4 }}
{{- end }}
type: {{ $type }}
{{- if $root.common.immutable }}
immutable: true
{{- end }}
stringData:
{{- toYaml $.stringData | nindent 2 }}
{{- end -}}
{{- end -}}