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

AWS Parameter Store

원문 보기 위키 갱신

AWS SSM Parameter Store를 External Secrets Operator로 연동하는 방법을 다뤄요.

출처: External Secrets

본문

Parameter Store

ParameterStore는 특정 리전 내 특정 계정의 AWS SSM Parameter Store를 가리켜요. 개별 시크릿에 대한 세밀한 접근을 정의하는 Roles를 만들고, spec.provider.aws.role로 ESO에 전달해야 해요. 이렇게 하면 SecretStore 사용자들이 필요한 시크릿에만 접근할 수 있어요.

apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
  name: parameterstore
spec:
  provider:
    aws:
      service: ParameterStore
      # define a specific role to limit access
      # to certain secrets
      role: arn:aws:iam::123456789012:role/external-secrets
      region: eu-central-1
      auth:
        secretRef:
          accessKeyIDSecretRef:
            name: awssm-secret
            key: access-key
          secretAccessKeySecretRef:
            name: awssm-secret
            key: secret-access-key

참고: ClusterSecretStore를 사용할 때는 accessKeyIDSecretRef와 secretAccessKeySecretRef에 시크릿이 있는 네임스페이스를 namespace로 반드시 제공하세요.

API 가격 및 스로틀링 (API Pricing & Throttling)
SSM Parameter Store API는 처리량(throughput)에 따라 요금이 부과되고, 서로 다른 티어로 제공돼요(pricing 참고). ESO를 사용하기 전에 비용을 예상해 보세요. 비용은 ExternalSecret의 RefreshInterval에 따라 달라져요.

IAM 정책 (IAM Policy)

파라미터 가져오기 (Fetching Parameters)

아래 예시 정책은 SSM 파라미터를 가져오기 위한 최소 필수 권한을 보여줘요. 이 정책은 dev-*와 일치하는 경로를 가진 시크릿에 대한 접근만 허용하도록 제한할 수 있어요. 다른 작업은 추가 권한이 필요할 수 있어요. 예를 들어 태그를 기반으로 파라미터를 찾으려면 ssm:DescribeParameters와 tag:GetResources 권한("Resource": "*" 포함)이 필요해요. 일반적으로 필요한 특정 권한은 작업이 실패하면 에러로 기록돼요.

자세한 내용은 AWS Documentation을 참고하세요.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameter*",
      ],
      "Resource": "arn:aws:ssm:us-east-2:1234567889911:parameter/dev-*"
    }
  ]
}

파라미터 밀어넣기 (Pushing Parameters)

아래 예시 정책은 SSM 파라미터를 밀어넣기 위한 최소 필수 권한을 보여줘요. 가져오기 정책과 마찬가지로 시크릿을 밀어넣을 수 있는 경로도 제한해요.

{
    "Action": [
        "ssm:GetParameter*",
        "ssm:PutParameter*",
        "ssm:AddTagsToResource",
        "ssm:ListTagsForResource"
    ],
    "Effect": "Allow",
    "Resource": "arn:aws:ssm:us-east-2:1234567889911:parameter/dev-*"
}

JSON 시크릿 값 (JSON Secret Values)

파라미터에 JSON 객체를 저장할 수 있어요. gjson 문법을 사용해 중첩된 값이나 배열에 접근할 수 있어요.

Parameter Store 키 friendslist에 저장된 다음 JSON 객체를 생각해 봅시다:

{
  "name": {"first": "Tom", "last": "Anderson"},
  "friends": [
    {"first": "Dale", "last": "Murphy"},
    {"first": "Roger", "last": "Craig"},
    {"first": "Jane", "last": "Murphy"}
  ]
}

위 JSON 객체에서 중첩된 키를 조회하는 방법의 예시예요:

apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: extract-data
spec:
  # [omitted for brevity]
  data:
  - secretKey: my_name
    remoteRef:
      key: friendslist
      property: name.first # Tom
  - secretKey: first_friend
    remoteRef:
      key: friendslist
      property: friends.1.first # Roger

  # metadataPolicy to fetch all the tags in JSON format
  - secretKey: tags
    remoteRef:
      metadataPolicy: Fetch
      key: database-credentials

  # metadataPolicy to fetch a specific tag (dev) from the source secret
  - secretKey: developer
    remoteRef:
      metadataPolicy: Fetch
      key: database-credentials
      property: dev

파라미터 버전 (Parameter Versions)

ParameterStore는 파라미터가 새 값으로 업데이트될 때마다 새 버전을 만들어요. 파라미터는 version 프로퍼티로 참조할 수 있어요.

SetSecret

Parameter Store의 SetSecret 메서드는 사용자가 Kubernetes 클러스터 안에 저장된 값을 원격 AWS Parameter Store로 설정할 수 있게 해줘요.

Push Secret 만들기 (Creating a Push Secret)

---
# 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.

PushSecret을 위한 추가 메타데이터 (Additional Metadata for PushSecret)

선택 사항으로 파라미터에 대한 추가 옵션을 설정할 수 있어요. 다음과 같아요:

  • type
  • keyID
  • tier & policies
  • encodeAsDecoded

이 동작을 제어하려면 provider의 metadata를 다음과 같이 설정하면 돼요:

apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
  name: pushsecret-example # 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)
      metadata:
        apiVersion: kubernetes.external-secrets.io/v1alpha1
        kind: PushSecretMetadata
        spec:
          description: "This is a secret for the API credentials"
          secretType: SecureString
          kmsKeyID: bb123123-b2b0-4f60-ac3a-44a13f0e6b6c
          tier:
            type: Advanced # default is Standard
            policies:
              - type: "Expiration"
                version: "1.0"
                attributes:
                  timestamp: "2024-12-02T21:34:33.000Z"
              - type: "ExpirationNotification"
                version: "1.0"
                attributes:
                  before: "2"
                  unit: "Days"
              - type: "ExpirationNotification"
                version: "1.0"
                attributes:
                  before: "30"
                  unit: "Days"
              - type: "NoChangeNotification"
                version: "1.0"
                attributes:
                  after: "30"
                  unit: "Days"
          tags:
            environment: sandbox
            team: pokedex
            secret-store: aws-parameterstore
            refresh-interval: 1h
  • secretType는 String, StringList, SecureString 세 가지 옵션이 있고, 기본값은 String이에요.
  • kmsKeyID는 string으로 KMS Key $ID 또는 $ARN(다른 계정에서 키 소스가 생성된 경우)을 받아요. 기본값은 alias/aws/ssm이에요. 이 프로퍼티는 secretType이 SecureString으로 설정됐을 때만 사용돼요.
  • tier & policies는 ExpirationNotification 같은 고급 정책 설정을 포함해요.
  • encodeAsDecoded를 true로 설정하면, 시크릿 전체를 밀어넣을 때 시크릿의 []byte 값을 base64 인코딩하는 대신 시크릿을 가져와 일반 값으로 밀어넣어요.

성공적인 시크릿 동기화 확인 (Check successful secret sync)

시크릿이 제대로 동기화됐는지 확인하려면 다음 명령을 실행하면 돼요:

kubectl get pushsecret pushsecret-example

시크릿이 성공적으로 동기화되면 상태가 "Synced"로 표시돼요.

AWS CLI로 새 시크릿 테스트 (Test new secret using AWS CLI)

AWS Parameter Store에서 파라미터를 보려면 AWS CLI를 설치하고 그 가이드(AWS CLI)에 따라 로그인하세요.

AWS Parameter Store에서 동기화된 파라미터를 가져오려면 다음 명령을 실행하세요:

aws ssm get-parameter --name=my-first-parameter --region=us-east-1

다음과 비슷한 출력이 보일 거예요:

{
    "Parameter": {
        "Name": "my-first-parameter",
        "Type": "String",
        "Value": "charmander",
        "Version": 4,
        "LastModifiedDate": "2022-09-15T13:04:31.098000-03:00",
        "ARN": "arn:aws:ssm:us-east-1:1234567890123:parameter/my-first-parameter",
        "DataType": "text"
    }
}

인증 (Authentication)

지원되는 모든 방법은 AWS Authentication을 참고하세요: controller pod identity, IRSA, static credentials, session tokens, assuming roles, session tags, remote key prefixes.

더 알아보기 (Learn more)