Push Secrets 가이드
ExternalSecret이 프로바이더에서 시크릿을 끌어와 kind=Secret을 만드는 것과 달리, PushSecret은 클러스터 안의 로컬 kind=Secret을 읽어 그 내용을 시크릿 프로바이더로 밀어 넣습니다. 방향이 반대인 셈이에요.
출처: External Secrets
본문
PushSecret의 갱신 동작은 spec.updatePolicy로 제어합니다. 기본 정책은 Replace라서, 프로바이더의 해당 위치에 시크릿이 이미 있든 없든 덮어씁니다. 기존 시크릿을 덮어쓰고 싶지 않다면 spec.updatePolicy를 IfNotExists로 설정하세요. 이 정책에서는 프로바이더가 진실의 원천(source of truth)이 됩니다. 다만 updatePolicy=IfNotExists를 쓰면 클러스터 안 PushSecret이 참조하는 시크릿 값이 프로바이더의 해당 위치 값과 다를 수 있다는 점 유의하세요.기본적으로 프로바이더에 만들어진 시크릿은 PushSecret을 삭제해도 삭제되지 않습니다. spec.deletionPolicy를 Delete로 설정하면 삭제돼요.
---
# 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, its 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.
백업 사용 사례
kind=PushSecret의 흥미로운 사용 사례는 현재 시크릿을 한 프로바이더에서 다른 프로바이더로 백업하는 거예요.시크릿이 GCP에 있고 Azure Key Vault로 백업하고 싶다고 상상해 보세요. 각 프로바이더에 SecretStore를 만들고, GCP에서 시크릿을 끌어올 ExternalSecret도 만듭니다. 그러면 클러스터에 kind=Secret이 생기는데, 이걸 Azure SecretStore로 구성한 PushSecret의 소스로 쓰면 됩니다.
전체 시크릿 밀어 넣기
모든 키를 개별적으로 정의하지 않고 전체 시크릿을 밀어 넣는 방법은 두 가지가 있어요.
1. 시크릿 키와 원격 프로퍼티 옵션을 둘 다 비워 두기
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: pokedex-credentials # Customisable
namespace: default # Same of the SecretStores
spec:
deletionPolicy: Delete # the provider secret will be deleted if the PushSecret is deleted
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
selector:
secret:
name: pokedex-credentials # Source Kubernetes secret to be pushed
data:
- match:
remoteRef:
remoteKey: my-first-parameter # Remote reference (where the secret is going to be pushed)
그러면 모든 키가 그대로 원격 위치로 밀어 넣어집니다.
2. 시크릿 키는 비우고 원격 프로퍼티 옵션만 설정하기
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: pokedex-credentials # Customisable
namespace: default # Same of the SecretStores
spec:
deletionPolicy: Delete # the provider secret will be deleted if the PushSecret is deleted
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
selector:
secret:
name: pokedex-credentials # Source Kubernetes secret to be pushed
data:
- match:
secretKey: best-pokemon # Source Kubernetes secret key to be pushed
remoteRef:
remoteKey: my-first-parameter # Remote reference (where the secret is going to be pushed)
property: single-value-secret # the property to use to push into
전체 시크릿 데이터를 마샬링해 이 단일 프로퍼티에 JSON 객체로 밀어 넣습니다.경고: 시크릿 데이터가 마샬링 가능할 때만 이렇게 해야 합니다. 바이너리 데이터 같은 값은 마샬링할 수 없어서 에러가 나거나 잘못된 시크릿 데이터가 됩니다.
키 변환 전략 (Key conversion strategy)
data[*].conversionStrategy: ReverseUnicode로 설정하면, ExternalSecret 객체에서 conversionStrategy: Unicode가 대체했던 잘못된 문자를 되돌릴 수 있습니다. (문서에 설명된 대로)
시크릿 회전 (Rotate Secrets)
ESO는 PushSecret과 Generator 리소스로 시크릿을 회전할 수 있습니다. ESO는 Kind=Generator에 물어 새 시크릿을 생성하고 저장해요. spec.refreshInterval마다 시크릿이 회전해 스토어의 값이 교체됩니다. 단 spec.updatePolicy=IfNotExist를 설정하면 ESO는 시크릿을 한 번만 생성하고 회전하지 않습니다.
apiVersion: generators.external-secrets.io/v1alpha1
kind: Password
metadata:
name: strong-password
spec:
length: 128
digits: 5
symbols: 5
symbolCharacters: -_$@
noUpper: false
allowRepeat: true
---
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: pushsecret-example
spec:
refreshInterval: 6h0m0s
secretStoreRefs:
- name: aws-parameter-store
kind: SecretStore
selector:
generatorRef:
apiVersion: generators.external-secrets.io/v1alpha1
kind: Password
name: strong-password
data:
- match:
secretKey: password # property in the generator output
remoteRef:
remoteKey: prod/myql/password