From e05313be712e1b70fbd33a87efddbbcf3102dec5 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Wed, 18 Nov 2026 21:52:10 +0800 Subject: [PATCH] fix(aisix): write the standalone resources examples in format v2 api7/aisix#1449 moved the resources file to `_format_version: "2"`: every entry carries an `id`, references name ids, and an API key is stored as `key_hash`. A gateway with that change refuses a v1 file at boot, so the standalone CI values and the README example would stop loading once `appVersion` reaches a release that includes it. The CI values now carry the caller key as a literal `key_hash` (the sha256 of the old placeholder), so neither the install test nor aisix-config-boot.sh needs `CALLER_API_KEY` any more. --- .github/scripts/aisix-config-boot.sh | 2 +- charts/aisix/README.md | 32 ++++++++++++++++++-------- charts/aisix/README.md.gotmpl | 32 ++++++++++++++++++-------- charts/aisix/ci/standalone-values.yaml | 28 +++++++++++----------- 4 files changed, 60 insertions(+), 34 deletions(-) diff --git a/.github/scripts/aisix-config-boot.sh b/.github/scripts/aisix-config-boot.sh index 32c5008..a93a022 100755 --- a/.github/scripts/aisix-config-boot.sh +++ b/.github/scripts/aisix-config-boot.sh @@ -46,7 +46,7 @@ cat "$work/standalone/config.yaml" name=aisix-cfgboot-standalone-$run_id docker run -d --name "$name" -p 127.0.0.1::3000 \ -e AISIX_CONFIG_PATH=/etc/aisix/chart/config.yaml \ - -e OPENAI_API_KEY=sk-ci-placeholder -e CALLER_API_KEY=ci-caller-placeholder \ + -e OPENAI_API_KEY=sk-ci-placeholder \ -v "$work/standalone/config.yaml:/etc/aisix/chart/config.yaml:ro" \ -v "$work/standalone/resources.yaml:/etc/aisix/resources/resources.yaml:ro" \ "$image" >/dev/null diff --git a/charts/aisix/README.md b/charts/aisix/README.md index 9d2d592..68c2e96 100644 --- a/charts/aisix/README.md +++ b/charts/aisix/README.md @@ -108,23 +108,26 @@ controlPlane: standalone: resources: - _format_version: "1" + _format_version: "2" provider_keys: - - display_name: openai-main + - id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 + display_name: openai-main provider: openai adapter: openai api_key: ${OPENAI_API_KEY} api_base: https://api.openai.com/v1 models: - - display_name: gpt-4o-mini + - id: 6efd592d-a73b-573d-8e2c-e9e103692f92 + display_name: gpt-4o-mini provider: openai model_name: gpt-4o-mini - provider_key: openai-main + provider_key_id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 api_keys: - - display_name: my-caller - key_env: CALLER_API_KEY - allowed_models: - - gpt-4o-mini + - id: 4a1c9e2b-7d3f-4b6a-8c5e-1f2a3b4c5d6e + display_name: my-caller + key_hash: ${CALLER_API_KEY_SHA256} + allowed_model_ids: + - 6efd592d-a73b-573d-8e2c-e9e103692f92 extraEnvVars: - name: OPENAI_API_KEY @@ -132,11 +135,20 @@ extraEnvVars: secretKeyRef: name: openai-credentials key: api-key - - name: CALLER_API_KEY + - name: CALLER_API_KEY_SHA256 valueFrom: secretKeyRef: name: aisix-caller-keys - key: my-caller + key: my-caller-sha256 +``` + +Every entry carries an `id`, a lowercase UUID you choose, and resources refer +to each other by it (`provider_key_id`, `allowed_model_ids`). An API key is +stored as `key_hash`, the SHA-256 hex digest of the key callers send, so the +key itself never appears in the file: + +```sh +printf %s "$CALLER_API_KEY" | sha256sum | cut -d' ' -f1 ``` `standalone.existingSecret` and `standalone.existingConfigMap` read the file from diff --git a/charts/aisix/README.md.gotmpl b/charts/aisix/README.md.gotmpl index e8c20e5..47554ee 100644 --- a/charts/aisix/README.md.gotmpl +++ b/charts/aisix/README.md.gotmpl @@ -102,23 +102,26 @@ controlPlane: standalone: resources: - _format_version: "1" + _format_version: "2" provider_keys: - - display_name: openai-main + - id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 + display_name: openai-main provider: openai adapter: openai api_key: ${OPENAI_API_KEY} api_base: https://api.openai.com/v1 models: - - display_name: gpt-4o-mini + - id: 6efd592d-a73b-573d-8e2c-e9e103692f92 + display_name: gpt-4o-mini provider: openai model_name: gpt-4o-mini - provider_key: openai-main + provider_key_id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 api_keys: - - display_name: my-caller - key_env: CALLER_API_KEY - allowed_models: - - gpt-4o-mini + - id: 4a1c9e2b-7d3f-4b6a-8c5e-1f2a3b4c5d6e + display_name: my-caller + key_hash: ${CALLER_API_KEY_SHA256} + allowed_model_ids: + - 6efd592d-a73b-573d-8e2c-e9e103692f92 extraEnvVars: - name: OPENAI_API_KEY @@ -126,11 +129,20 @@ extraEnvVars: secretKeyRef: name: openai-credentials key: api-key - - name: CALLER_API_KEY + - name: CALLER_API_KEY_SHA256 valueFrom: secretKeyRef: name: aisix-caller-keys - key: my-caller + key: my-caller-sha256 +``` + +Every entry carries an `id`, a lowercase UUID you choose, and resources refer +to each other by it (`provider_key_id`, `allowed_model_ids`). An API key is +stored as `key_hash`, the SHA-256 hex digest of the key callers send, so the +key itself never appears in the file: + +```sh +printf %s "$CALLER_API_KEY" | sha256sum | cut -d' ' -f1 ``` `standalone.existingSecret` and `standalone.existingConfigMap` read the file from diff --git a/charts/aisix/ci/standalone-values.yaml b/charts/aisix/ci/standalone-values.yaml index 71ddd0a..51a6626 100644 --- a/charts/aisix/ci/standalone-values.yaml +++ b/charts/aisix/ci/standalone-values.yaml @@ -18,29 +18,31 @@ replicaCount: 1 standalone: resources: - _format_version: "1" + _format_version: "2" provider_keys: - - display_name: openai-main + - id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 + display_name: openai-main provider: openai adapter: openai api_key: ${OPENAI_API_KEY} api_base: https://api.openai.com/v1 models: - - display_name: gpt-4o-mini + - id: 6efd592d-a73b-573d-8e2c-e9e103692f92 + display_name: gpt-4o-mini provider: openai model_name: gpt-4o-mini - provider_key: openai-main + provider_key_id: 0b6f3c1e-2f0a-4c5e-9d55-7d1a8b0c2e11 api_keys: - - display_name: ci-caller - key_env: CALLER_API_KEY - allowed_models: - - gpt-4o-mini + # sha256 of `ci-caller-placeholder`; a hash is not a credential. + - id: 4a1c9e2b-7d3f-4b6a-8c5e-1f2a3b4c5d6e + display_name: ci-caller + key_hash: 4adaf08efa9183c9371238ebd87b767857dd7cbfb5d6b80e718fad5b5f666bba + allowed_model_ids: + - 6efd592d-a73b-573d-8e2c-e9e103692f92 -# Both variables are referenced by the resources file above, which fails to -# load if either is unset. No request is sent upstream during the install -# test, so the values only have to be non-empty. +# Referenced by the resources file above, which fails to load if it is unset. +# No request is sent upstream during the install test, so the value only has +# to be non-empty. extraEnvVars: - name: OPENAI_API_KEY value: sk-ci-placeholder-not-a-real-key - - name: CALLER_API_KEY - value: ci-caller-placeholder