Repository navigation
feat: move Key Encryption onto Secrets API - #1107
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
dkotter
left a comment
There was a problem hiding this comment.
If I'm following correctly, looks like the changes here require someone to manually install the new Secrets API plugin, correct? If so, that's not the direction we were wanting to go, ideally we can bundle that plugin ourselves, matching what we already do with the older version of that plugin.
|
Thanks for clarifying, @dkotter! That makes sense. I’ll update the PR to bundle the new Secrets API ( I’ll:
I’ll push the updated changes shortly! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1107 +/- ##
=============================================
+ Coverage 85.11% 85.12% +0.01%
- Complexity 4361 4403 +42
=============================================
Files 172 173 +1
Lines 16127 16213 +86
=============================================
+ Hits 13726 13801 +75
- Misses 2401 2412 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…to feat/secrets-api-integration
dkotter
left a comment
There was a problem hiding this comment.
On a quick review, this seems to be headed in the right direction, thanks for all the work here!
As I continue to test, one initial question is are we purposely leaving the old Displace plugin code behind? Is there a reason to keep that? I guess I would expect for all of those files to be removed and replaced with the new code
|
One other quick thing as I'm reviewing, the Secrets API made it's way into WordPress Core just a few days ago. We should ensure the code we are shipping here includes the latest version of that, noting the code hosted at https://github.com/ericmann/secrets-api may not be the exact same code that was shipped in Core. Should look at the upstream commits to Core to see if there's anything new we need to pull in |
|
Thank you @dkotter and @whyisjake for the thorough review and testing against Core trunk! All points are completely valid:
I'll push an update with these changes shortly! |
whyisjake
left a comment
There was a problem hiding this comment.
Thanks @Pranjal1423, the unreadable-secret handling, the read-back check, the namespace-wide uninstall and the tests all look right. CI is green across the matrix, and locally against trunk (7.2-alpha-64345) the Key Encryption, Uninstall and Upgrade tests pass (116 tests; the 3 skips are multisite-only).
Two things are still open from the last round:
1. The bundled Secrets API isn't synced with core yet. includes/Vendor/Secrets/ is unchanged. I compared it file by file with src/wp-includes/secrets.php and src/wp-includes/secrets/ on trunk (r64337 plus the follow-up 7a47d39442).
- Storage looks compatible. The cipher, record shape, option names and key derivation match, so a secret written by the bundled copy on 7.0.x should read under core after an upgrade. That's from reading the code; I haven't run a real upgrade.
- Core has changes the bundled copy lacks:
wp_secret_changedpasses a 7th$networkargument on set, delete and retire.decode_canonical_base64_32()replacesis_canonical_base64_32()plusbase64_decode()inWP_Secrets_Config_Key_Provider.- The
slot_fingerprint()helper inWP_Secrets_Libsodium_Provider, used byretire_previous(). demote_slot()type-checkscreatedandneeds_rotation.list_secrets()checks thatcurrentis an array, and usesstr_starts_with().- The key manager's root-key cache check is on
cached_root_key, notcached_wrapped. list_names()in the option store skips option names that aren't strings.
- Other differences: no scalar type declarations,
'default'text domains,--in place of en dashes,ABSPATHguards and some extrais_string()/is_int()checks. Some of these are needed for PHP 7.4 or Plugin Check, but it'd help to say in the README which are intentional.
2. Careful with removing the old Displace code. set_secret() still falls back to Secrets::set(), and get_secret() and the V1_5_0 migration both still decrypt legacy _secret_ai/* rows. Whatever goes, the legacy read path has to stay until we drop migration support, or sites that haven't migrated lose their keys.
Not blocking: turning Key Encryption off with an unreadable key keeps the stored secret and logs a warning, but the connector field just shows blank. get_unreadable_secrets() has no callers yet, so an admin notice could use it in a follow-up.
Offer: I have some time right now, so I'll open a stacked PR against your branch that does the vendor sync (item 1). You can review and merge it into this PR, or cherry-pick from it. I'll leave the Displace cleanup to you unless you'd rather I take that too.
AI assistance: Yes. Tool(s): Claude Code. Used for: comparing the bundled Secrets API against core trunk, running the PHPUnit suites, and drafting this review.
Replaces the `src/wp-includes/` copy of the Secrets API, taken from ericmann/secrets-api, with core trunk at r64344, the follow-up to the API's introduction in r64337 (#66187). Two changes are kept from the old copy, for Plugin Check: the `ABSPATH` guard, and the 'default' text domain on translation calls. This brings in core's scalar type declarations, the `$network` argument to `wp_secret_changed`, `decode_canonical_base64_32()`, `slot_fingerprint()`, and the stricter record checks in `demote_slot()`, `list_secrets()` and `list_names()`. The stored record format is unchanged. The `plugin/` adapters still come from ericmann/secrets-api, since they are not part of core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Pranjal1423 the vendor sync is up as a stacked PR against your branch: Pranjal1423#1. It's core trunk r64344 with only the |
Sync the bundled Secrets API with core trunk
|
Thanks @whyisjake, I've merged the vendor sync PR! Regarding the Displace files: since However, if you feel we should still prune or clean up parts of it for this PR, please let me know and I'd be happy to work on it! |
Resolves the conflict with WordPress#1186 in Secrets_Bridge and its tests: - keeps this branch's get_secret()/set_secret()/delete_secret(); - on_write() keeps the plaintext and deletes a stale secret when a key can't be stored, as WordPress#1186 does; - the legacy Secrets::set() fallback no longer throws when the master key can't be decrypted; - WordPress#1186's tests break core's root key as well as the legacy master key, since writes go through the Secrets API first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e's legacy reader Keys stored before 1.5.0 are read once with the bundled read-only Secrets_API_Legacy_Reader and moved to the Secrets API, so the Displace classes and their tests can go. set_secret() no longer falls back to writing a legacy row. WordPress#1186's tests now break only core's root key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Pranjal1423 two updates on your branch:
AI assistance: Yes. Tool(s): Claude Code. Used for: resolving the merge, writing the cleanup and its tests, and running the checks. |
Key Encryption: drop the bundled Displace Secrets Manager
|
Thank you so much @whyisjake! I've reviewed and merged your stacked PR (#2). Using The branch is now fully synced with core trunk and the legacy Displace code is dropped. All checks and tests are ready for final review! |
|
@whyisjake @dkotter back to y'all for final review ahead of potential merge into 1.5.0 this week |
What?
Closes #1012
Moves the Key Encryption experiment onto the proposed WordPress Secrets API feature plugin (slated for WordPress 7.2 Core).
Why?
The Key Encryption experiment originally vendored a subset of
ericmann/displace-secrets-manager. That upstream repository has been archived and superseded byericmann/secrets-api.To align with the WordPress 7.2 Core roadmap and avoid data loss for existing sites:
_secret_ai/*) need an automated migration because the new Secrets API prototype fallback only maps unnamespaced names.wp_get_secret()and friends when present, while retaining the bundled internal provider as a zero-dependency fallback so the "zero-install" experience remains intact.How?
Secrets_Bridge Integration:
get_secret(),set_secret(), anddelete_secret()methods toSecrets_Bridge.wp_get_secret(),wp_set_secret(), andwp_delete_secret()under theai/namespace with caller context['plugin' => 'ai'].Automated Migration (
V1_5_0):V1_5_0upgrade routine inincludes/Admin/Upgrades/V1_5_0.phpand registered it inUpgrades.php._secret_ai/*options into memory, writes towp_set_secret(), verifies read-back matches, and only then deletes the legacy option row.Uninstall Cleanup:
wp_delete_secret()upon plugin uninstallation.Tests & Docs:
V1_5_0Test.phpand updatedKey_EncryptionTest.php.docs/experiments/key-encryption.mdandincludes/Vendor/Secrets/README.md.Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Implementation, migration routine, and integration tests;
I have reviewed and verified it locally with unit tests and static analysis.
Testing Instructions
wp_get_secret()._secret_ai/*rows: verify theV1_5_0migration moves keys to the new Secrets API without data loss or user intervention.decrypt_all().Changelog Entry