feat: enhance encrypt_fields to support nested structures#13192
Merged
Baoyuantop merged 3 commits intoapache:masterfrom Apr 10, 2026
Merged
feat: enhance encrypt_fields to support nested structures#13192Baoyuantop merged 3 commits intoapache:masterfrom
Baoyuantop merged 3 commits intoapache:masterfrom
Conversation
Enhance the encrypt_fields mechanism to support: - Arbitrary depth dotted paths (e.g., a.b.c.d) - Array traversal at intermediate nodes (e.g., instances[].auth.header) - Leaf type dispatch: string, array of strings, map of strings Add encrypt_fields to: - ai-proxy: auth.header, auth.query, auth.gcp.service_account_json - ai-proxy-multi: instances.auth.header, instances.auth.query, instances.auth.gcp.service_account_json - ai-rag: embeddings_provider.azure_openai.api_key, vector_search_provider.azure_ai_search.api_key
Add op_name parameter to process_encrypt_field for backward-compatible
log messages ('failed to decrypt...' / 'failed to encrypt...' instead
of generic 'failed to encrypt/decrypt...').
Reorder plugin_checker to run decrypt_conf before check_schema, matching the gateway's approach. This fixes content-level validation failures (e.g. ai-proxy's service_account_json JSON parsing) when fields are encrypted — the encrypted values are now decrypted back to plaintext before validation runs.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Enhances APISIX data encryption support for plugin encrypt_fields by enabling recursive traversal of nested objects/arrays and ensuring decryption occurs before schema validation for content-level checks.
Changes:
- Add recursive
process_encrypt_field()traversal for arbitrarily nested dotted paths and array/map leaf handling. - Reorder
plugin_checkerto decrypt plugin configs before schema validation. - Extend plugin schemas to declare additional
encrypt_fields, and add a new test suite covering nested/enhanced cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
apisix/plugin.lua |
Replaces flat/2-level encryption logic with recursive traversal; changes validation flow to decrypt before schema checks. |
apisix/plugins/ai-proxy/schema.lua |
Adds encrypt_fields for nested auth header/query/GCP JSON fields (including multi-instance paths). |
apisix/plugins/ai-rag.lua |
Adds encrypt_fields for nested Azure API keys. |
t/node/data_encrypt3.t |
Adds integration tests covering nested paths, maps, arrays, regressions, and a direct helper test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
moonming
approved these changes
Apr 10, 2026
membphis
approved these changes
Apr 10, 2026
Baoyuantop
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Enhance the
encrypt_fieldsmechanism inplugin.luato support nested and complex field structures. The current implementation only handles flat keys and 2-level dotted paths (e.g.,sasl.password).What's changed
Core: Rewrite encrypt/decrypt traversal logic (
apisix/plugin.lua)Replace the flat/2-level
if/elseiflogic with a recursiveprocess_encrypt_field()helper that supports:auth.gcp.service_account_jsontraverses 3 levels deepinstances), iterate each element and continue recursionstring→ encrypt/decrypt directlyarray of strings→ iterate and encrypt/decrypt each elementmap of strings→ iterate and encrypt/decrypt each valueUses
core.table.isarray()for reliable array vs map detection.Fix: Decrypt before schema validation in
plugin_checkerReorder
plugin_checkerto rundecrypt_confbeforecheck_schema, matching the gateway's approach. This is necessary because plugins like ai-proxy perform content-level validation (e.g., parsingservice_account_jsonas JSON) — without decrypting first, encrypted values fail these checks during config sync.Plugin schema updates:
auth.header,auth.query,auth.gcp.service_account_jsoninstances.auth.header,instances.auth.query,instances.auth.gcp.service_account_jsonembeddings_provider.azure_openai.api_key,vector_search_provider.azure_ai_search.api_keyBackward compatibility
password) continue to work unchangedsasl.password,auth.password) continue to workTests
Added
t/node/data_encrypt3.twith 7 test cases covering:auth.header,auth.query)auth.gcp.service_account_json, ai-rag API keys)instances[].auth.header)password)sasl.password)process_encrypt_field