Skip to content

feat(rp-registration): add manager_key_dedicated field and related fu… - #2168

Open
igorosip0v wants to merge 3 commits into
mainfrom
kms-rp-manager-key
Open

feat(rp-registration): add manager_key_dedicated field and related fu…#2168
igorosip0v wants to merge 3 commits into
mainfrom
kms-rp-manager-key

Conversation

@igorosip0v

Copy link
Copy Markdown
Contributor

PR Type

  • Regular Task
  • Bug Fix
  • QA Tests

Description

New managed RPs use a shared KMS manager key when RP_REGISTRY_MANAGER_KMS_KEY_ID is set, and the database now tracks whether an RP's key is dedicated to it, so the shared key is never scheduled for deletion.

  • Adds manager_key_dedicated to rp_registration, backfilled to true for rows that already have a manager_kms_key_id.
  • Adds resolveManagerKey(): reuses the key from RP_REGISTRY_MANAGER_KMS_KEY_ID (full ARN) when set, otherwise creates a dedicated per-RP key as before.
  • Only calls scheduleKeyDeletion() for dedicated keys, in both the registration rollback and switch-to-self-managed.
  • Fails managed registration before creating a key or submitting the transaction if the migration is not applied yet.
  • Adds tests for the shared and dedicated key paths and the deletion guard.

No behavior change while the variable is unset. The key exists only in staging (worldcoin/world-id-deploy#552).

Checklist

  • I have self-reviewed this PR.
  • I have left comments in the code for clarity.
  • I have added necessary unit tests.
  • I have updated the documentation as needed.

…nctionality

- Introduced a new column `manager_key_dedicated` in the `rp_registration` table to indicate if a manager key is dedicated to a specific RP.
- Updated GraphQL mutations and queries to include the `manager_key_dedicated` field.
- Enhanced the registration flow to handle dedicated and shared manager keys appropriately, including scheduling key deletion only for dedicated keys.
- Added tests to ensure correct behavior of the new functionality and its integration with existing flows.

This change improves the management of RP registrations by allowing for more granular control over key handling.
@igorosip0v
igorosip0v requested a review from Takaros999 July 29, 2026 15:36
@igorosip0v igorosip0v self-assigned this Jul 29, 2026

@Takaros999 Takaros999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lets discuss offline, but high level:

  • manager_key_dedicated is not a very intuitive name, especially when we have mode: managed | self-managed column. Thoughts on is_shared_manager_key?

Comment on lines +131 to +137
// manager_key_dedicated is written together with the manager key at the end
// of this flow. If the migration adding it has not been applied yet, fail
// here rather than after the on-chain transaction has been submitted.
try {
await getVerifySchemaSdk(client).VerifyManagerKeySchema({
rp_id: rpIdString,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Im pretty sure the hasura migration runs before the web app deployment, I'm wondering if this case is needed.

Comment thread web/api/helpers/kms-eth.ts Outdated
* Uses the shared key from RP_REGISTRY_MANAGER_KMS_KEY_ID when set;
* otherwise creates a dedicated per-RP key.
*/
export async function resolveManagerKey(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit. If we create the shared kms key in both environments this would be simplified a lot. I also think we might be mixing the concerns between the 2 files (kms-eth.ts and rp-registration-flow.ts)

I see your need about having a mechanism for smooth migration, what if we had a ENABLE_SHARED_KEY_RP_REGISTRATION or similar boolean flag, and use that in the rp-registration-flows to determine which key to use for the first rp registration

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.

ENABLE_SHARED_KEY_RP_REGISTRATION or similar boolean flag

Plan is to test shared-key registration on staging only first, without touching prod deploys. So for now we only wire RP_REGISTRY_MANAGER_KMS_KEY_ID in staging; its presence is the switch. A separate boolean would matter if the key already existed in both envs before we were ready to use it.

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.

Actually, updated

@igorosip0v

Copy link
Copy Markdown
Contributor Author

@Takaros999

manager_key_dedicated is not a very intuitive name… Thoughts on is_shared_manager_key?

Agree the name isn't great. I'd keep this polarity though: column default is false, and we only delete the key when the flag is true. That way a missing/false value never schedules deletion of the shared key. is_shared_manager_key inverts that, so I'd rather rename to is_unique_manager_key. WDYT?

…gistration logic

- Removed the resolveManagerKey function, which previously handled both shared and dedicated key resolution.
- Updated submitManagedRpRegistration to use createManagerKey and getEthAddressFromKMS based on the new ENABLE_SHARED_KEY_RP_REGISTRATION environment variable.
- Adjusted tests to reflect the removal of resolveManagerKey and ensure proper handling of key creation and retrieval logic.
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.

2 participants