콘텐츠로 이동
AggregaAggrega
언어 선택: 한국어
이 페이지는 기계 번역되었습니다. 영어 원문 읽기.

자격 증명 전달 — `secretKeyRef` 엔드투엔드

자격 증명 하위 시스템이 비밀번호를 제공하는 단일 PostgreSQL 데이터베이스를 provider별로 보여 줍니다. core/datastore/postgres의 동일한 password 슬롯은 두 자격 증명 계열 중 어느 쪽이든 받아들입니다. 개발자가 연결하는 계열이 비밀번호의 전달 방식을 결정하고, 데이터베이스 Recipe는 해당 provider가 지원하는 방식으로 슬롯을 읽습니다.

예제 생성하기

아래 명령으로 이 예제를 빌드하거나, AI 어시스턴트에게 대신 빌드하게 할 수 있습니다.

예제 이름을 딴 새 폴더에 예제를 씁니다:

Terminal window
aggrega scaffold --example credential-secretkeyref

그런 다음 이어서 실행할 명령을 출력합니다. 첫 번째 명령은 새 폴더로 이동합니다:

Terminal window
cd credential-secretkeyref

빌드

이 예제에는 세 개의 release가 있습니다. 실행할 때마다 하나를 빌드합니다:

Terminal window
aggrega build --release release-helm.yaml --auto-pull
aggrega build --release release-compose.yaml --auto-pull
aggrega build --release release-negative.yaml --auto-pull # expected to fail (see below)

모든 release는 이 워크스페이스의 .aggrega-config.yaml을 통해, 이 파일이 기본값으로 지정하는 허브 레지스트리에서 카탈로그 엔터티를 해석하므로 --catalog 플래그가 필요하지 않으며, --auto-pull은 새 클론에 없는 lockfile을 빌드 중에 기록합니다.

AI 어시스턴트 사용

Aggrega 도구로 설정한 AI 어시스턴트도 같은 작업을 할 수 있습니다. 다음 프롬프트를 붙여 넣으십시오.

Aggrega 도구만 사용하고, 폴더는 직접 만들지 마십시오. 작업 영역 폴더에 아직 `credential-secretkeyref` 폴더가 없으면 `example`을 `credential-secretkeyref`로 설정하고 `dir`은 지정하지 않은 채 `scaffold` 도구를 한 번 호출하십시오. 이 도구는 예제를 새 `credential-secretkeyref` 폴더에 씁니다. 그런 다음 각 Release마다 `build` 도구를 `release-helm.yaml`, `release-compose.yaml` 순서로 한 번씩 호출하십시오. 매번 `workspace_root`를 `credential-secretkeyref`로, `release`를 해당 파일로, `auto_pull`을 true로, `write`를 true로 설정합니다. 그런 다음 같은 방식으로 `release`를 `release-negative.yaml`로 설정하여 `build` 도구를 호출하십시오. 이 빌드는 거부되도록 의도된 것이므로 거부 내용을 읽어 주십시오. 각 빌드가 쓴 파일을 알려 주십시오. 파일은 `credential-secretkeyref/dist/` 아래에 있습니다.

Helm — 참조 가능한 Secret + secretKeyRef

aggregate-helm.yaml은 password 슬롯에 **core/referenced-secret**을 연결합니다. Manifest는 이를 k8s-secret-from-parameter에 매핑하며, 이것은 Kubernetes Secret을 구체화하고 Secret의 식별 정보를 provides {name, key}로 게시합니다. postgres helm Recipe는 containers.attachments를 통해 슬롯을 참조하며, 합성기는 이를 env secretKeyRef로 렌더링합니다.

Terminal window
aggrega build --release release-helm.yaml --auto-pull

생성된 Secret(dist/helm/helm/db--password--db-secret-db-password.yaml)과 데이터베이스의 secretKeyRef(dist/helm/helm/db-statefulset.yaml)는 동일한 리소스를 가리킵니다. 둘 다 .features.password.provides.name을 읽기 때문입니다. 재도출도 없고, 양쪽이 맞춰야 할 관례도 없습니다:

db--password--db-secret-db-password.yaml
[… omitted: the apiVersion and the Secret kind]
metadata:
name: db-password
[… omitted: the labels and annotations every rendered document carries]
stringData:
POSTGRES_PASSWORD: "dev-pw-change-me"
# db-statefulset.yaml (container env)
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: db-password # == the Secret's metadata.name
key: POSTGRES_PASSWORD # == the Secret's data key

Compose — inject-value 자격 증명

aggregate-compose.yaml은 **core/secret-value**를 연결합니다. Compose에는 Secret 리소스 / secretKeyRef 기본 요소가 없으므로, Manifest는 자격 증명을 dotenv-secret에 매핑하며, 이것은 연결이 values.key에 지정한 키(여기서는 POSTGRES_PASSWORD)로 inject 파이프에 값을 전달합니다. postgres compose Recipe는 그 키로 값을 읽습니다.

Terminal window
aggrega build --release release-compose.yaml --auto-pull
# dist/compose/compose/docker-compose.yaml → POSTGRES_PASSWORD: dev-pw-change-me

실패 사례 — 참조에서 거부되는 참조 불가능한 채움

aggregate-negative.yaml은 inject-value core/secret-value를 password 슬롯에 연결한 다음 helm으로 빌드합니다. 여기서 postgres Recipe는 containers.attachments(secretKeyRef)를 통해 슬롯을 참조합니다. secretKeyRef는 가리킬 Secret 리소스가 필요하지만 inject-value 자격 증명은 아무것도 게시하지 않으므로, 빌드가 명시적으로 중단됩니다:

Terminal window
aggrega build --release release-negative.yaml --auto-pull
# [… omitted: the pull's lines, which carry the same halt, and two lint notices]
# [CATALOG_ERROR E0212] instance db
# rendering node "db"
# [… omitted: the cause, "workload attachment slot is not referenceable", naming the Recipe and its path in your catalog, then one line each for the "name" and the "key" the slot's provides does not expose]

이 release는 실패하도록 의도된 것이며, 중단 자체가 교훈입니다. 빌드는 성공을 보고하는 대신 1로 종료하므로, 이 안전장치가 독자와 이를 실행하는 모든 스크립트에 보입니다.

해결 방법은 두 가지입니다. aggregate-helm.yaml에서처럼 참조 가능한 자격 증명(core/referenced-secret)을 연결하거나, core/secret-value 연결을 유지한 채 Manifest에서 이를 k8s-secret-from-value에 매핑합니다. 이는 core/secret-value의 Helm 구현으로, 자신이 내보내는 Secret에 값을 기록하고 그 Secret의 이름과 키를 게시하므로 참조가 가리킬 리소스가 생깁니다. env-secret에 바인딩되면 inject-value 자격 증명은 대신 inject 파이프를 통해 컨테이너에 도달하며, containers.attachments 참조를 통해서는 결코 도달하지 않습니다.