Skip to content

test: assert admin metadata GET decrypts on first request#13645

Merged
shreemaan-abhishek merged 2 commits into
apache:masterfrom
shreemaan-abhishek:test/metadata-gde-decrypt-assert
Jul 6, 2026
Merged

test: assert admin metadata GET decrypts on first request#13645
shreemaan-abhishek merged 2 commits into
apache:masterfrom
shreemaan-abhishek:test/metadata-gde-decrypt-assert

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

Follow-up test coverage for #12624.

The existing t/admin/plugin-metadata3.t covers the plugin.enable_data_encryption nil-init state and the 404-GET crash, but it uses example-plugin, which has no encrypt_fields. So it never asserts the primary behavior the fix restored: that the first successful GET of an encrypted metadata field returns plaintext, not ciphertext.

This PR adds a case using azure-functions.master_apikey (a real encrypt_fields metadata):

  1. PUT the metadata (stored encrypted in etcd).
  2. Assert etcd holds ciphertext.
  3. Reset plugin.enable_data_encryption = nil to simulate a fresh worker where the flag has not been lazily initialized yet.
  4. Assert the GET still returns the decrypted value - i.e. plugin.enable_gde() forces initialization on the GET path.

Without #12624 this case returns ciphertext; with it, plaintext.

Also scopes local_conf/err as locals in TEST 1 (they were previously assigned as globals).

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change (N/A - test-only)
  • I have verified that this change is backward compatible (test-only, no runtime change)

Follow-up test coverage for apache#12624. The existing plugin-metadata3.t
covered the nil-init state and the 404 crash, but used example-plugin,
which has no encrypt_fields, so it never asserted the primary behavior:
that the first successful GET of an encrypted metadata field returns
plaintext rather than ciphertext.

Add a case using azure-functions.master_apikey (a real encrypt_fields
metadata) that resets plugin.enable_data_encryption to nil to simulate a
fresh worker, then asserts the GET returns the decrypted value while
etcd still holds the ciphertext.

Also scope local_conf/err as locals in TEST 1 to avoid leaking globals.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds regression coverage for encrypted plugin metadata to ensure the Admin API returns decrypted plaintext on the first successful GET, even when apisix.plugin.enable_data_encryption hasn’t been lazily initialized yet (fresh-worker simulation). This strengthens confidence in the behavior restored by #12624 and reduces the chance of ciphertext leaking through the Admin API.

Changes:

  • Scope local_conf/err as locals in TEST 1 to avoid leaking globals between tests.
  • Add a new test using azure-functions.master_apikey (an encrypt_fields metadata) to assert:
    • etcd stores ciphertext
    • Admin GET returns plaintext even when plugin.enable_data_encryption is reset to nil

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread t/admin/plugin-metadata3.t Outdated
Comment on lines +257 to +258
local res = assert(etcd.get('/plugin_metadata/azure-functions'))
ngx.say("etcd encrypted: ", tostring(res.body.node.value.master_apikey ~= "foo"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Tightened in 0c6d9c4 to require a non-empty string that differs from the plaintext, so a missing/empty stored value no longer reads as "encrypted".

Comment thread t/admin/plugin-metadata3.t
Tighten the etcd-side check so it can't false-positive when the stored
value is missing or empty: require a non-empty string that differs from
the plaintext.
@shreemaan-abhishek shreemaan-abhishek merged commit 070a783 into apache:master Jul 6, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants