Skip to content

fix: preserve Admin API keys from environment variables - #14184

Open
Ymmcc wants to merge 2 commits into
apache:masterfrom
Ymmcc:fix/admin-key-env-string
Open

Ymmcc wants to merge 2 commits into
apache:masterfrom
Ymmcc:fix/admin-key-env-string

Conversation

@Ymmcc

@Ymmcc Ymmcc commented Nov 10, 2026 •

Copy link
Copy Markdown

Description

An Admin API key from config.yaml can lose its type or spelling during environment-variable substitution. For example, 00123456 becomes the number 123456, which does not match the request header.

Keep substitutions under deployment.admin.admin_key[].key as strings, including when the YAML field name itself comes from an environment variable. Keep numeric and boolean inference for other fields.

Which issue(s) this PR fixes:

Fixes #14178

Testing

  • Reproduced the conversion in the production Lua resolver under LuaJIT. The same check passes after the change and covers leading zeros, boolean-looking secrets, multiple keys, defaults, and regular numeric/boolean fields.
  • Added a standalone CLI integration regression for both valid keys and the rejected key without leading zeros.
  • bash -n t/cli/test_standalone.sh and git diff --check passed.
  • Ran the same Admin API requests in the official APISIX 3.19.0 Debian container, mounting the upstream and patched resolver in turn. The numeric key, boolean-looking key, and incorrect key without leading zeros returned 401/401/401 before and 200/200/401 after.

Checklist

  • Explained the need and the change
  • Added regression coverage
  • Updated the Admin API documentation in English and Chinese
  • Verified existing numeric and boolean substitutions

AI assistance: Codex helped implement and verify the change.

@Ymmcc
Ymmcc marked this pull request as ready for review November 10, 2026 10:44

@moonming moonming left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field-specific handling makes sense for the Admin API fix. There are two related cases worth covering here or tracking separately: deployment.etcd.password (and the top-level etcd.password) and apisix.data_encryption.keyring. Their schemas require strings, but substitutions outside deployment.admin.admin_key[].key still go through tonumber / boolean conversion. A numeric etcd password or a digit-only keyring entry therefore still loses its original type. Could we add regression coverage for those fields and make the remaining scope explicit?

Please also add an upgrade note: environment-supplied Admin API keys such as 0 or false, which previously did not match a request, will start matching their exact text after this change. Deployments using those values as placeholders should replace or remove them before upgrading. This concerns environment-variable substitutions; it does not mean this PR converts numeric YAML literals into strings.

References: the current field allowlist, etcd string fields, and keyring string schema.

@Ymmcc

Ymmcc commented Nov 14, 2026

Copy link
Copy Markdown
Author

Thanks, @moonming. I updated the PR in 10bd0e0 to preserve environment-substituted values as strings for both etcd password paths and for apisix.data_encryption.keyring. The CLI regression cases cover both password paths and the scalar and list forms of the keyring. Other fields retain the existing number and boolean inference.

I added an upgrade note to the English and Chinese Admin API docs. It asks operators to replace or remove environment-supplied placeholder keys such as 0 and false before upgrading because requests with those exact header values can now authenticate. Numeric YAML literals retain their original type.

I verified the new CLI configurations in the APISIX Docker image and checked the Admin API over HTTP. 00123456, false, and 0 each returned 200, while the truncated 123456 returned 401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: an admin key injected with ${{VAR}} that contains only digits becomes a number, so the correct key gets 401

2 participants