feat: turnkey migration - sync factor policy - #401
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new Turnkey migration to reconcile sync-factor authorization policies to a canonical deletion-only policy shape, while refactoring the Turnkey API client caching so one client instance can serve multiple migrations efficiently and detect cross-sub-org consistency violations. It also reorganizes and expands functional tests to cover policy create/update/delete flows and cache behavior, and adjusts the existing Apple audience migration to work with the new cached-return types.
Changes:
- Introduces
sync_factor_policymigration to create/update/prune per-sync-factor Turnkey policies usingresource+actionconditions. - Refactors
TurnkeyApiClientcaching into a per-client, single-suborgOrgCacheand adds cachedget_policiesplus policy write APIs. - Reorganizes and expands functional tests to cover policy reconciliation and cache consistency, and updates Apple audience migration planning to operate on slices / cached reads.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| bedrock/src/backup/turnkey/test.rs | Reorganizes functional tests and adds policy-migration + cache behavior coverage via new read/write mocks. |
| bedrock/src/backup/turnkey/policies.rs | Adds sync-factor policy condition/consensus/name helpers and user role classification used by migrations. |
| bedrock/src/backup/turnkey/migrations/sync_factor_policy.rs | Implements new migration to reconcile sync-factor policies (create/update/delete) based on users + policies. |
| bedrock/src/backup/turnkey/migrations/mod.rs | Registers the new migration in the ordered MIGRATIONS list. |
| bedrock/src/backup/turnkey/migrations/apple_audience.rs | Adapts planning to accept slices (works with cached Arc<Vec<User>>) and clarifies rationale/comments. |
| bedrock/src/backup/turnkey/api.rs | Adds OrgCache, returns cached Arc<Vec<_>> for reads, and introduces policy list/create/update/delete API methods with cache invalidation. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: feded97186
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…dcoin/bedrock into worktree-velvety-meandering-popcorn
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fcf1b86e70
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Changes
activity.typefor these policies. All with its relevant unit and functional tests.Real Testing
I tested all the changes in this PR with the real Turnkey API using the
run_migrations_against_real_turnkeytest:Note
High Risk
Changes live Turnkey authorization policies and can delete policies; mistakes could weaken deletion permissions or remove needed policies, though guards (exact consensus matching, skip multi-policy users, UUID validation) limit blast radius.
Overview
Adds
MigrationSyncFactorPolicyto the Turnkey migration pipeline so each sync-factor user gets the canonical DELETE policy (resource+action, not legacyactivity.type), with create/update when drifted and delete for policies bound to users no longer in the sub-org. Canonical policy text, user-role classification, and UUID-safe consensus strings live inpolicies.rs.TurnkeyApiClientreplaces the per-sub-orgHashMapuser cache withOrgCache(single sub-org per client,Arcshared reads, consistency error on sub-org mismatch), returnsArc<Vec<User>>, and adds cachedget_policiespluscreate_policy/update_policy/delete_policywith cache invalidation on writes.apple_audienceis adjusted for borrowed users and minor docs; functional tests are split by migration with shared read mocks for users + policies.Reviewed by Cursor Bugbot for commit ea3d54b. Bugbot is set up for automated code reviews on this repo. Configure here.