ข้ามไปยังเนื้อหา
AggregaAggregaAggregaAggrega
เลือกภาษา: ไทย
หน้านี้ถูกแปลด้วยเครื่อง อ่านต้นฉบับภาษาอังกฤษ

การส่งมอบข้อมูลรับรอง — `secretKeyRef` ตั้งแต่ต้นจนจบ

ฐานข้อมูล PostgreSQL หนึ่งตัวที่รหัสผ่านมาจากระบบย่อยข้อมูลรับรอง แสดงตามผู้ให้บริการ สล็อต password เดียวกันบน core/datastore/postgres รับตระกูลข้อมูลรับรองได้ทั้งสอง ตระกูลที่นักพัฒนาแนบเป็นตัวกำหนดวิธีส่งมอบรหัสผ่าน และ Recipe ฐานข้อมูลอ่านสล็อตตามที่ผู้ให้บริการของตนรองรับ

ร่างตัวอย่าง

คุณบิลด์ตัวอย่างนี้ได้ด้วยคำสั่งด้านล่าง หรือ ให้ผู้ช่วย AI บิลด์ให้คุณ

เขียนตัวอย่างลงในโฟลเดอร์ใหม่ที่ตั้งชื่อตามตัวอย่าง:

Terminal window
aggrega draft --example credential-secretkeyref

จากนั้นจะพิมพ์คำสั่งที่ต้องรันถัดไป คำสั่งแรกเปลี่ยนเข้าไปในโฟลเดอร์ใหม่:

Terminal window
cd credential-secretkeyref

บิลด์

ตัวอย่างนี้มี Releases สามรายการ บิลด์หนึ่งรายการต่อการรัน:

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 ของพื้นที่ทำงานนี้ จากรีจิสทรี hub ที่ระบุเป็นค่าเริ่มต้น จึงไม่จำเป็นต้องใช้แฟล็ก --catalog และ --auto-pull เขียนไฟล์ล็อกที่โคลนใหม่ไม่มีระหว่างการบิลด์

กับผู้ช่วย AI

ผู้ช่วย AI ที่ ตั้งค่าด้วยเครื่องมือของ Aggrega ทำสิ่งเดียวกันได้ โดยวางพรอมต์นี้ลงไป

ใช้เครื่องมือของ Aggrega เท่านั้น และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์พื้นที่ทำงานยังไม่มีโฟลเดอร์ `credential-secretkeyref` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `credential-secretkeyref` และไม่ระบุ `dir` เครื่องมือจะเขียนตัวอย่างลงในโฟลเดอร์ `credential-secretkeyref` ใหม่ จากนั้นเรียกเครื่องมือ `build` หนึ่งครั้งต่อ Release ตามลำดับนี้ — `release-helm.yaml`, `release-compose.yaml` — โดยแต่ละครั้งตั้ง `workspace_root` เป็น `credential-secretkeyref` ตั้ง `release` เป็นไฟล์นั้น ตั้ง `auto_pull` เป็น true และตั้ง `write` เป็น true จากนั้นเรียกเครื่องมือ `build` แบบเดียวกันโดยตั้ง `release` เป็น `release-negative.yaml` ซึ่งตั้งใจให้ถูกปฏิเสธ จึงอ่านการปฏิเสธนั้นให้ฉันฟัง บอกฉันว่าการบิลด์แต่ละครั้งเขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `credential-secretkeyref/dist/`

Helm — Secret ที่อ้างอิงได้ + secretKeyRef

aggregate-helm.yaml แนบ core/referenced-secret กับสล็อต password Manifest แมปการแนบนั้นไปยัง k8s-secret-from-parameter ซึ่งสร้าง Secret ของ Kubernetes และเผยแพร่ตัวตนของ Secret เป็น provides {name, key} Recipe helm ของ postgres อ้างอิงสล็อตผ่าน containers.attachments ซึ่งตัวสังเคราะห์เรนเดอร์เป็น secretKeyRef ของ env

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-resource / secretKeyRef Manifest จึงแมปข้อมูลรับรองไปยัง dotenv-secret ซึ่งส่งมอบค่าบนท่อ inject ภายใต้คีย์ที่การแนบระบุใน values.key คือ POSTGRES_PASSWORD ที่นี่ และ Recipe compose ของ postgres อ่านค่าภายใต้คีย์นั้น

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 แนบ core/secret-value แบบ inject-value กับสล็อต password จากนั้นบิลด์บน helm ซึ่ง Recipe ของ postgres อ้างอิงสล็อตผ่าน 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 แทนที่จะรายงานความสำเร็จ ราวกั้นจึงมองเห็นได้ทั้งสำหรับผู้อ่านและสคริปต์ใดๆ ที่รัน

มีทางแก้สองทาง แนบข้อมูลรับรองที่อ้างอิงได้ (core/referenced-secret) ดังใน aggregate-helm.yaml หรือคงการแนบ core/secret-value ไว้และแมปใน Manifest ไปยัง k8s-secret-from-value ซึ่งเป็นการทำให้เป็นรูปธรรมของ Helm สำหรับ core/secret-value ที่เขียนค่าลงใน Secret ที่ส่งออก และเผยแพร่ชื่อและคีย์ของ Secret นั้น การอ้างอิงจึงมีทรัพยากรให้ชี้ไป เมื่อผูกกับ env-secret ข้อมูลรับรองแบบ inject-value ไปถึงคอนเทนเนอร์ผ่านท่อ inject แทน ไม่เคยผ่านการอ้างอิง containers.attachments เลย