PushSecret
PushSecret은 네임스페이스 스코프 리소스로, 어떤 데이터를 시크릿 프로바이더로 밀어 넣을지를 정의해요. 시크릿을 반대 방향(클러스터 → 외부 저장소)으로 동기화하는 역할을 해요.
출처: External Secrets
본문
PushSecret은 네임스페이스 스코프이며, 시크릿 프로바이더로 밀어 넣어야 할 데이터가 무엇인지 정의해요.
spec.selector로 어떤 시크릿을 밀어 넣을지 오퍼레이터에게 알려줘요.spec.data로 어떤 시크릿 키를 밀어 넣을지 지정할 수 있어요.spec.dataTo로 패턴 매칭을 이용해 시크릿을 벌크로 밀어 넣을 수 있어요.- 템플릿을 이용해 결과 속성 값도 만들 수 있어요.
예제 (Example)
아래는 PushSecret을 사용하는 예시예요.
---
# The source secret that will be pushed to the destination secret by PushSecret.
apiVersion: v1
kind: Secret
metadata:
name: pushsecret-example
stringData:
best-pokemon-src: "Pikachu"
---
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: pushsecret-example # Customisable
namespace: default # Same of the SecretStores
spec:
updatePolicy: Replace # Policy to overwrite existing secrets in the provider on sync
deletionPolicy: Delete # delete the provider secret when the PushSecret is deleted (default: None, which keeps it)
refreshInterval: 1h0m0s # Refresh interval for which push secret will reconcile
secretStoreRefs: # A list of secret stores to push secrets to
- name: aws-parameterstore
kind: SecretStore
# Exactly one of selector.secret or selector.generatorRef may be set.
selector:
secret:
name: pokedex-credentials # Source Kubernetes secret to be pushed
# Alternatively (mutually exclusive with secret), point to a generator
# that produces the values to be pushed:
# generatorRef:
# apiVersion: generators.external-secrets.io/v1alpha1
# kind: ECRAuthorizationToken
# name: prod-registry-credentials
template:
metadata:
annotations: { }
labels: { }
data:
# If the key source secret key has dashes, then it cannot be accessed directly,
# and the "index" function should be used.
best-pokemon: "{{ index . \"best-pokemon-src\" | toString | upper }} is the really best!"
# Also, it's possible to use an existing template from configmap where Secret is fetched,
# merged and templated within the referenced configMap data.
# It does not update the configmap, it creates a secret with: data["config.yml"] = ...result...
templateFrom:
- configMap:
name: application-config-tmpl
items:
- key: config.yml
data:
- conversionStrategy: None # Also supports the ReverseUnicode strategy
match:
# The secretKey is used within PushSecret (it should match key under spec.template.data)
secretKey: best-pokemon
remoteRef:
remoteKey: destination-secret # The destination secret object name (where the secret is going to be pushed)
property: best-pokemon-dst # The key within the destination secret object.
생성된 Secret 오브젝트의 결과는 이렇게 생겨요:
# The destination secret that will be templated and pushed by PushSecret.
apiVersion: v1
kind: Secret
metadata:
name: destination-secret
stringData:
best-pokemon-dst: "PIKACHU is the really best!"
DataTo
spec.dataTo 필드는 키 하나씩 설정하지 않고도 시크릿을 벌크로 밀어 넣을 수 있게 해줘요. 여러 개의 관련 시크릿을 밀어 넣어야 하는데 장황한 YAML을 피하고 싶을 때 유용해요.
기본 예제 (Basic Example)
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: push-db-secrets
spec:
secretStoreRefs:
- name: aws-secret-store
selector:
secret:
name: app-secrets
dataTo:
- storeRef:
name: aws-secret-store
match:
regexp: "^db-.*" # Push all keys starting with "db-"
rewrite:
- regexp:
source: "^db-"
target: "myapp/database/" # db-host -> myapp/database/host
필드 (Fields)
storeRef (필수)
어떤 SecretStore로 밀어 넣을지 지정해요. 각 dataTo 항목은 특정 스토어를 타깃하기 위해 storeRef를 포함해야 해요.
name(string, optional): 타깃할 SecretStore의 이름.labelSelector(object, optional): 라벨로 스토어를 선택.name또는labelSelector중 하나만 사용.kind(string, optional):SecretStore또는ClusterSecretStore. 기본값은SecretStore.
dataTo:
# Target a specific store by name
- storeRef:
name: aws-secret-store
# Target stores by label
- storeRef:
labelSelector:
matchLabels:
env: production
storeRef vs spec.data
spec.data 항목은 스토어 타깃을 생략할 수 있지만, 모든 dataTo 항목은 storeRef가 필요해요. 이렇게 해서 실수로 "모든 스토어에 밀어 넣는" 동작을 막는 거예요. storeRef는 spec.secretStoreRefs에 나열된 스토어를 참조해야 해요.
match (optional)
소스 Secret에서 어떤 키를 선택할지 정의해요.
regexp(string, optional): 키를 매칭할 정규 표현식 패턴. 생략하면 모든 키가 매칭돼요.
예시:
# Match all keys
dataTo:
- storeRef:
name: my-store
# Match keys starting with "db-"
dataTo:
- storeRef:
name: my-store
match:
regexp: "^db-.*"
# Match keys ending with "-key"
dataTo:
- storeRef:
name: my-store
match:
regexp: ".*-key$"
rewrite (array, optional)
키 이름을 변환하는 rewrite 연산의 배열이에요. 연산은 순서대로 적용돼요.
각 rewrite는 다음 중 하나가 될 수 있어요:
Regexp Rewrite:
rewrite:
- regexp:
source: "^db-" # Regex pattern to match
target: "app/db/" # Replacement string (supports capture groups like $1, $2)
Transform Rewrite (Go Template):
rewrite:
- transform:
template: "secrets/{{ .value | upper }}" # .value contains the key name
Chained Rewrites:
rewrite:
- regexp: {source: "^db-", target: ""} # Remove "db-" prefix
- regexp: {source: "^", target: "prod/"} # Add "prod/" prefix
metadata (object, optional)
밀어 넣는 모든 시크릿에 붙일 프로바이더별 메타데이터예요. 구조는 프로바이더에 따라 달라져요.
dataTo:
- storeRef:
name: my-store
match:
regexp: "^db-.*"
metadata:
labels:
app: myapp
env: production
conversionStrategy (string, optional)
매칭과 rewrite 전에 시크릿 키 이름을 변환하는 전략이에요. 변환은 키(값이 아님)에 적용되고, match 패턴과 rewrite 연산은 변환된 키 이름을 대상으로 동작해요. 기본값: "None"
"None": 변환 없음"ReverseUnicode": 키 이름의 유니코드 이스케이프 시퀀스를 역변환 (ExternalSecret의Unicode전략과 함께 쓸 때 유용)
dataTo:
- storeRef:
name: my-store
conversionStrategy: ReverseUnicode
dataTo와 data 결합하기 (Combining dataTo with data)
dataTo와 data 필드를 함께 사용할 수 있어요. 같은 소스 키에 대해 명시적인 data 항목이 dataTo를 덮어써요:
spec:
secretStoreRefs:
- name: my-store
dataTo:
- storeRef:
name: my-store # Push all keys with original names
data:
- match:
secretKey: db-host
remoteRef:
remoteKey: custom-db-host # Override for db-host only
이 예시에서는 모든 키가 dataTo로 밀려 나가지만, db-host는 data의 사용자 정의 remote key를 대신 사용해요.
여러 dataTo 항목 (Multiple dataTo Entries)
다른 패턴을 가진 dataTo 항목을 여러 개 지정할 수 있어요:
spec:
secretStoreRefs:
- name: my-store
dataTo:
# Push db-* keys with database/ prefix
- storeRef:
name: my-store
match:
regexp: "^db-.*"
rewrite:
- regexp: {source: "^db-", target: "database/"}
# Push api-* keys with api/ prefix
- storeRef:
name: my-store
match:
regexp: "^api-.*"
rewrite:
- regexp: {source: "^api-", target: "api/"}
오류 처리 (Error Handling)
- 잘못된 정규 표현식: PushSecret이 status에 세부 내용과 함께 에러 상태로 들어가요.
- 중복된 remote key: rewrite가 중복 키를 만들면 연산이 실패해요.
- 매칭되는 키 없음: 경고가 로깅되고 PushSecret은 Ready 상태를 유지해요.
더 많은 예시와 사용 사례는 PushSecret dataTo 가이드를 참고하세요.
템플릿 (Template)
컨트롤러가 PushSecret을 리컨사일할 때 spec.template을 청사진으로 사용해서 새 속성을 만들어요. golang 템플릿으로 청사진을 정의하고, 템플릿 함수로 속성을 변환할 수 있어요. templateFrom을 사용하면 golang 템플릿 데이터를 담은 ConfigMap도 가져올 수 있어요. 자세한 내용은 advanced templating을 참고하세요.