본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Flux Mirror 시크릿 명령

원문 보기 위키 갱신

공식 Flux CLI 플러그인 문서예요. flux mirror secret <name> 명령은 선택된 각 호스트에 대해 hosts 아래에 구성된 자격 증명을 해석해 kubernetes.io/dockerconfigjson 타입의 Kubernetes Secret으로 써넣어요 — 이는 kubectl create secret docker-registry가 만드는 것과 같은 형태예요. 이들은 sync와 login이 해석하는 것과 같은 자격 증명이므로, 이 Secret은 imagePullSecret으로 또는 Flux OCIRepository/HelmRepository .spec.secretRef로 참조되어 구성된 아이덴티티를 이해하는 레지스트리에서 pull할 수 있어요.

출처: 문서

본문

주요 사용 사례는 CronJob에서 수명이 짧은 pull Secret을 회전하는 것이에요.

개요 (Synopsis)

flux mirror secret <name> [flags]

<name>은 생성하거나 교체할 Secret의 이름이에요.

기본적으로 Secret은 upsert돼요. 같은 이름의 것이 이미 존재하면 제자리에서 교체돼요. kubectl create secret docker-registry와 일치하게, 이미 존재하면 대신 실패하도록 하려면 --create를 전달하세요.

구성 소스 (Configuration source)

구성 경로는 다음과 같이 해석돼요: --config/-f 플래그, 아니면 $FLUX_MIRROR_CONFIG, 아니면 <executable>.config. -f -는 stdin에서 구성을 읽어요. login처럼 secret은 hosts 섹션만 읽고 hosts만 있는 구성을 허용해요.

플래그 (Flags)

| 플래그 | 기본값 | 설명 | | -f, --config | $FLUX_MIRROR_CONFIG, 아니면 .config | flux-mirror 구성 경로, 또는 stdin용 -. | | --host | 모든 호스트 | 구성에서 포함할 레지스트리 호스트. 반복 가능; 기본값은 모든 호스트. | | --create | false | Secret이 이미 존재하면 교체 대신 실패. |

추가로 이 명령은 표준 kubectl 연결 플래그와 그 환경 변수를 받아요 — --kubeconfig ($KUBECONFIG), --context, --cluster, -n/--namespace, --user, --server, --token, --request-timeout, --as, --certificate-authority, --insecure-skip-tls-verify 등. 네임스페이스는 기본적으로 활성 kubeconfig 컨텍스트의 것, 또는 pod 안에서 실행 중일 때는 in-cluster ServiceAccount 네임스페이스로 설정돼요.

전역 --timeout 플래그(기본 1m)는 자격 증명 해석을 제한하며, provider 소스의 경우 토큰을 발행하는 네트워크 호출이 포함돼요. 전역 --no-envsubst 플래그는 구성 환경 치환을 비활성화해요.

동작 (Behavior)

  • 로컬(kubeconfig)과 in-cluster(in-cluster 구성과 ServiceAccount 네임스페이스로 폴백) 모두에서 작동해요.
  • 기본적으로 Secret은 upsert돼요 (생성, 또는 존재하면 교체). --create를 사용하면 같은 이름의 기존 Secret은 오류예요. 교체 시 기존 라벨과 어노테이션은 보존돼요.
  • --host가 없으면 hosts의 모든 호스트가 포함돼요. 구성에 없는 --host는 오류예요.
  • Secret의 .dockerconfigjson은 호스트별로 하나의 auths 항목을 담아요. 클라우드 provider 호스트와 username이 설정된 credential 호스트는 username/password/auth를 작성해요(kubelet과 Flux가 이해). username이 없는 credential 호스트는 bearer registrytoken 필드를 작성해요(go-containerregistry와 Flux가 이해, kubelet은 아님). Bearer 토큰 vs. username/password를 참고하세요.
  • TLS 전용 호스트(tls만 있고 credential/provider가 없음)는 Secret에 쓸 것이 없으며 • skipping <host> 메시지와 함께 건너뛰어져요.
  • 자격 증명은 수명이 짧아요(provider 토큰, 방금 서명된 JWT). 만료 전에 Secret을 새로고침하려면 명령을 다시 실행하세요. 기본적으로 기존 것을 제자리에서 교체해요.

예시 (Examples)

CronJob에서 ECR, ACR 또는 GAR pull 자격 증명 회전

ECR, ACR, GAR 같은 클라우드 레지스트리는 수명이 짧은 자격 증명만 발급하므로, CronJob이 pod의 워크로드 아이덴티티를 사용해 스케줄에 따라 pull Secret을 재생성해요. provider 호스트는 주변 클라우드 아이덴티티에서 레지스트리의 기본 username/password를 발행하고, secret이 그것을 imagePullSecret으로 사용할 수 있는 dockerconfigjson Secret으로 작성해요.

ServiceAccount는 각 provider의 워크로드 아이덴티티 어노테이션을 지녀요:

# EKS with IRSA (annotation mandatory; EKS Pod Identity needs none)
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flux-mirror
  namespace: flux-system
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/flux-mirror
---
# AKS Workload Identity (annotation mandatory; pod also needs the
# azure.workload.identity/use: "true" label)
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flux-mirror
  namespace: flux-system
  annotations:
    azure.workload.identity/client-id: 00000000-0000-0000-0000-000000000000
---
# GKE Workload Identity Federation (annotation only when impersonating a GSA)
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flux-mirror
  namespace: flux-system
  annotations:
    iam.gke.io/gcp-service-account: flux-mirror@my-project.iam.gserviceaccount.com

ServiceAccount는 또한 그것이 쓰는 Secret을 관리할 RBAC가 필요해요:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: flux-mirror-secret
  namespace: flux-system
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "create", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: flux-mirror-secret
  namespace: flux-system
subjects:
  - kind: ServiceAccount
    name: flux-mirror
    namespace: flux-system
roleRef:
  kind: Role
  name: flux-mirror-secret
  apiGroup: rbac.authorization.k8s.io

클라우드 레지스트리를 선택하는 hosts-only 구성(호스트와 provider로 클라우드를 전환), ConfigMap에 저장:

# mirror.yaml
apiVersion: mirror.plugin.fluxcd.io/v1beta1
kind: Config
hosts:
  - host: 123456789012.dkr.ecr.us-east-1.amazonaws.com
    provider: ecr
  # - host: myregistry.azurecr.io
  #   provider: acr
  # - host: us-docker.pkg.dev
  #   provider: gar

CronJob은 그 자체 네임스페이스에서 Secret을 회전해요:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: flux-mirror-regcreds
  namespace: flux-system
spec:
  schedule: "0 */6 * * *"          # rotate well within the credential lifetime
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            azure.workload.identity/use: "true"   # AKS Workload Identity only
        spec:
          serviceAccountName: flux-mirror
          restartPolicy: OnFailure
          containers:
            - name: flux-mirror
              image: ghcr.io/fluxcd/flux-mirror:latest
              # In-cluster: kubeconfig and namespace are auto-detected.
              args: ["secret", "regcreds", "-f", "/config/flux/mirror.yaml"]
              volumeMounts:
                - name: config
                  mountPath: /config/flux
                  readOnly: true
          volumes:
            - name: config
              configMap:
                name: flux-mirror-config   # holds mirror.yaml

결과 regcreds Secret은 username/password/auth를 보유하므로 pod imagePullSecret과 Flux OCIRepository/HelmRepository .spec.secretRef로 모두 작동해요.

ServiceAccount OIDC 토큰을 수용하는 레지스트리용 자격 증명 회전

대상 레지스트리가 클러스터의 ServiceAccount OIDC 토큰을 직접 검증할 때, audience가 레지스트리 호스트인 ServiceAccount 토큰을 프로젝션하고 이를 fromPath를 통해 credential 호스트에 공급해요. username을 설정하면 토큰이 username/password 쌍(username/password/auth)의 password로 작성되어, 결과 Secret이 pod imagePullSecret(kubelet이 사용 가능)과 Flux OCIRepository/HelmRepository .spec.secretRef로 모두 작동해요. username 값은 레지스트리가 토큰 옆에 기대하는 무엇이든 돼요 — 많은 토큰 검증 레지스트리가 그것을 무시하지만 존재하길 요구해요.

이전 예시의 ServiceAccount와 RBAC를 재사용해요(여기서 ServiceAccount는 클라우드 어노테이션이 필요 없어요 — 레지스트리가 클러스터 issuer를 직접 신뢰). 구성은 상대 경로로 토큰을 참조하고, 파일 경로 필드는 구성 자체의 디렉터리로 한정되므로 구성과 토큰이 함께 마운트돼요:

# mirror.yaml
apiVersion: mirror.plugin.fluxcd.io/v1beta1
kind: Config
hosts:
  - host: registry.example.com
    username: sa-oidc          # value the registry expects; often ignored
    credential:
      fromPath: registry-token   # the audience is set by the projected volume
apiVersion: batch/v1
kind: CronJob
metadata:
  name: flux-mirror-regcreds
  namespace: flux-system
spec:
  schedule: "*/30 * * * *"       # rotate ahead of the token's expirationSeconds
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: flux-mirror
          restartPolicy: OnFailure
          containers:
            - name: flux-mirror
              image: ghcr.io/fluxcd/flux-mirror:latest
              args: ["secret", "regcreds", "-f", "/config/flux/mirror.yaml"]
              volumeMounts:
                - name: flux
                  mountPath: /config/flux
                  readOnly: true
          volumes:
            # One projected volume holds both the config and the registry token,
            # so /config/flux/mirror.yaml can reference ./registry-token.
            - name: flux
              projected:
                sources:
                  - configMap:
                      name: flux-mirror-config   # holds mirror.yaml
                  - serviceAccountToken:
                      path: registry-token
                      audience: registry.example.com
                      expirationSeconds: 3600

SPIFFE JWT-SVID를 사용한 자격 증명 회전

레지스트리가 SPIFFE JWT-SVID를 수용할 때 jwt-svid 자격 증명 provider를 사용해요. 이는 SPIFFE Workload API에서 audience(레지스트리 호스트)용 JWT-SVID를 가져와요. username을 설정하면 JWT-SVID가 username/password 쌍의 password로 작성되어, 결과 Secret이 pod imagePullSecret(kubelet 사용 가능)과 Flux OCIRepository/HelmRepository .spec.secretRef로 모두 작동해요. Workload API는 SPIFFE CSI 드라이버가 pod에 노출하고, go-spiffe는 SPIFFE_ENDPOINT_SOCKET 환경 변수를 통해 그것을 찾아요.

첫 예시의 ServiceAccount와 시크릿 관리 RBAC를 재사용해요(클라우드 어노테이션 불필요 — 레지스트리가 SPIFFE trust domain을 신뢰).

# mirror.yaml
apiVersion: mirror.plugin.fluxcd.io/v1beta1
kind: Config
hosts:
  - host: registry.example.com
    username: spiffe           # value the registry expects; often ignored
    credential:
      provider: jwt-svid
      # aud defaults to the host (registry.example.com)
apiVersion: batch/v1
kind: CronJob
metadata:
  name: flux-mirror-regcreds
  namespace: flux-system
spec:
  schedule: "*/30 * * * *"       # rotate ahead of the JWT-SVID lifetime
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: flux-mirror
          restartPolicy: OnFailure
          containers:
            - name: flux-mirror
              image: ghcr.io/fluxcd/flux-mirror:latest
              args: ["secret", "regcreds", "-f", "/config/flux/mirror.yaml"]
              env:
                # go-spiffe reads the Workload API socket from this variable.
                - name: SPIFFE_ENDPOINT_SOCKET
                  value: unix:///spiffe-workload-api/spire-agent.sock
              volumeMounts:
                - name: config
                  mountPath: /config/flux
                  readOnly: true
                - name: spiffe-workload-api
                  mountPath: /spiffe-workload-api
                  readOnly: true
          volumes:
            - name: config
              configMap:
                name: flux-mirror-config   # holds mirror.yaml
            # The SPIFFE CSI driver exposes the SPIRE Agent Workload API socket.
            - name: spiffe-workload-api
              csi:
                driver: csi.spiffe.io
                readOnly: true

결과 Secret은 username/password/auth를 보유하므로 pod imagePullSecret과 Flux OCIRepository/HelmRepository .spec.secretRef로 모두 작동해요.

일반적인 호출

# Upsert a Secret for all hosts in the default config, in the current namespace.
flux mirror secret regcreds

# Fail if the Secret already exists, like 'kubectl create secret docker-registry'.
flux mirror secret regcreds --create

# Specific hosts, a specific namespace and kubeconfig context.
flux mirror secret regcreds -n flux-system --context prod \
  --host registry.example.com --host other.example.com -f ./flux-mirror.yaml

더 알아보기 (Learn more)