feat: add is_access_profile_managed server-computed flag to VK for RBAC-independent managed-key UI - #5858
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change adds a server-computed managed-status flag for virtual keys. Governance processing populates the flag, and the UI uses it when access-profile data is unavailable. Details rendering now requires a defined managing-profile user ID. ChangesManaged virtual key status
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant ExternalQuotaResolver
participant applyExternalBudgets
participant VirtualKeyAPI
participant useVirtualKeyUsage
participant ManagedVirtualKeyNotice
ExternalQuotaResolver->>applyExternalBudgets: returns managed quota result
applyExternalBudgets->>VirtualKeyAPI: sets is_access_profile_managed
VirtualKeyAPI->>useVirtualKeyUsage: provides managed-status flag
useVirtualKeyUsage->>ManagedVirtualKeyNotice: passes isManagedByProfile
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
is_access_profile_managed server-computed flag to VK for RBAC-independent managed-key UI
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@transports/bifrost-http/handlers/governance.go`:
- Around line 121-124: Update the two remaining managed fixtures in governance
tests around the managed response fixture definitions to explicitly set Managed:
true, ensuring the fixtures at the referenced test cases represent
access-profile-managed VKs.
- Line 956: Update the mutation and customer response paths that serialize
VirtualKeys to call applyExternalBudgets before serialization, matching the
existing list and detail hydration behavior so managed keys retain
IsAccessProfileManaged. Add response tests covering both mutation and customer
VirtualKeys paths.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: fbe25fbf-a4d5-43af-ba24-ccf5c4cbcb06
📒 Files selected for processing (6)
framework/configstore/tables/virtualkey.gotransports/bifrost-http/handlers/governance.gotransports/bifrost-http/handlers/governance_test.goui/app/workspace/virtual-keys/hooks/useVirtualKeyUsage.tsui/app/workspace/virtual-keys/views/virtualKeyDetailsSheet.tsxui/lib/types/governance.ts
06d3859 to
e326687
Compare
167ffbb to
ff6edb4
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
ff6edb4 to
3bfa186
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
e326687 to
093fdab
Compare
3bfa186 to
ccb56a0
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
The base branch was changed.
ccb56a0 to
37a4cc3
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Merge activity
|
…RBAC-independent managed-key UI (maximhq#5858) ## Summary Users without access-profile RBAC permissions were not seeing the managed-key lock and notice on virtual keys governed by an access profile. Because the managed state was derived solely from the client-side access-profile lookup (which is RBAC-gated), users lacking that permission saw the key as unmanaged and could attempt edits that should be locked. This PR introduces a server-computed `is_access_profile_managed` flag on the `VirtualKey` response that is populated during the governance read path, independent of any access-profile permission check. The UI uses this flag as the authoritative source for "is this key managed," falling back to the existing profile lookup only for resolving the profile name and actions. ## Changes - Added `IsAccessProfileManaged bool` to `TableVirtualKey` as a non-persisted, computed field (`gorm:"-"`) that is set by `applyExternalBudgets` from the external resolver result. - Added a `Managed bool` field to `ExternalQuotaBudgetResult` so resolvers can signal managed status independently of whether the profile carries any budget or rate-limit rows. - `applyExternalBudgets` now sets `vk.IsAccessProfileManaged = ext.Managed` before overwriting budgets and rate limit, ensuring the flag is present even when the profile has neither. - Updated `useVirtualKeyUsage` so `isManagedByProfile` is `true` when either the server flag is set or the client-side profile lookup finds a match. This means users without access-profile permissions still see the lock and notice. - Fixed a potential nil-dereference in `virtualKeyDetailsSheet` where `managingProfile.user_id` was accessed without first checking that `managingProfile` is non-nil. - `ManagedVirtualKeyNotice` now receives `isManagedByProfile` directly so it renders correctly even when `managingProfile` is undefined. - Added `is_access_profile_managed?: boolean` to the `VirtualKey` TypeScript interface. - Added a new test `TestApplyExternalBudgets_ManagedWithNoGovernanceFlagsAndClears` verifying that a resolver-managed VK with no AP budget and no AP rate limit is still flagged managed and has its mirror rows cleared. - Updated the existing `TestApplyExternalBudgets_RateLimitOnlyDropsNativeBudgets` test to assert `IsAccessProfileManaged=true`. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [x] UI (React) - [ ] Docs ## How to test 1. Configure a virtual key governed by an access profile. 2. Log in as a user who does **not** have RBAC permission to list access profiles. 3. Navigate to the virtual key detail sheet — the managed-key notice and edit lock should be visible. 4. Log in as a user who **does** have access-profile permissions and confirm the profile name still appears alongside the notice. ```sh # Core/Transports go test ./transports/bifrost-http/handlers/... -run TestApplyExternalBudgets # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` ## Breaking changes - [ ] Yes - [x] No ## Security considerations The `is_access_profile_managed` flag is read-only and never persisted (`gorm:"-"`). It is populated only on governance read paths and carries no sensitive data — it is a boolean indicator used solely to drive UI state. No auth or secret handling is affected. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
…RBAC-independent managed-key UI (maximhq#5858) ## Summary Users without access-profile RBAC permissions were not seeing the managed-key lock and notice on virtual keys governed by an access profile. Because the managed state was derived solely from the client-side access-profile lookup (which is RBAC-gated), users lacking that permission saw the key as unmanaged and could attempt edits that should be locked. This PR introduces a server-computed `is_access_profile_managed` flag on the `VirtualKey` response that is populated during the governance read path, independent of any access-profile permission check. The UI uses this flag as the authoritative source for "is this key managed," falling back to the existing profile lookup only for resolving the profile name and actions. ## Changes - Added `IsAccessProfileManaged bool` to `TableVirtualKey` as a non-persisted, computed field (`gorm:"-"`) that is set by `applyExternalBudgets` from the external resolver result. - Added a `Managed bool` field to `ExternalQuotaBudgetResult` so resolvers can signal managed status independently of whether the profile carries any budget or rate-limit rows. - `applyExternalBudgets` now sets `vk.IsAccessProfileManaged = ext.Managed` before overwriting budgets and rate limit, ensuring the flag is present even when the profile has neither. - Updated `useVirtualKeyUsage` so `isManagedByProfile` is `true` when either the server flag is set or the client-side profile lookup finds a match. This means users without access-profile permissions still see the lock and notice. - Fixed a potential nil-dereference in `virtualKeyDetailsSheet` where `managingProfile.user_id` was accessed without first checking that `managingProfile` is non-nil. - `ManagedVirtualKeyNotice` now receives `isManagedByProfile` directly so it renders correctly even when `managingProfile` is undefined. - Added `is_access_profile_managed?: boolean` to the `VirtualKey` TypeScript interface. - Added a new test `TestApplyExternalBudgets_ManagedWithNoGovernanceFlagsAndClears` verifying that a resolver-managed VK with no AP budget and no AP rate limit is still flagged managed and has its mirror rows cleared. - Updated the existing `TestApplyExternalBudgets_RateLimitOnlyDropsNativeBudgets` test to assert `IsAccessProfileManaged=true`. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [x] UI (React) - [ ] Docs ## How to test 1. Configure a virtual key governed by an access profile. 2. Log in as a user who does **not** have RBAC permission to list access profiles. 3. Navigate to the virtual key detail sheet — the managed-key notice and edit lock should be visible. 4. Log in as a user who **does** have access-profile permissions and confirm the profile name still appears alongside the notice. ```sh # Core/Transports go test ./transports/bifrost-http/handlers/... -run TestApplyExternalBudgets # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` ## Breaking changes - [ ] Yes - [x] No ## Security considerations The `is_access_profile_managed` flag is read-only and never persisted (`gorm:"-"`). It is populated only on governance read paths and carries no sensitive data — it is a boolean indicator used solely to drive UI state. No auth or secret handling is affected. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
…RBAC-independent managed-key UI (maximhq#5858) ## Summary Users without access-profile RBAC permissions were not seeing the managed-key lock and notice on virtual keys governed by an access profile. Because the managed state was derived solely from the client-side access-profile lookup (which is RBAC-gated), users lacking that permission saw the key as unmanaged and could attempt edits that should be locked. This PR introduces a server-computed `is_access_profile_managed` flag on the `VirtualKey` response that is populated during the governance read path, independent of any access-profile permission check. The UI uses this flag as the authoritative source for "is this key managed," falling back to the existing profile lookup only for resolving the profile name and actions. ## Changes - Added `IsAccessProfileManaged bool` to `TableVirtualKey` as a non-persisted, computed field (`gorm:"-"`) that is set by `applyExternalBudgets` from the external resolver result. - Added a `Managed bool` field to `ExternalQuotaBudgetResult` so resolvers can signal managed status independently of whether the profile carries any budget or rate-limit rows. - `applyExternalBudgets` now sets `vk.IsAccessProfileManaged = ext.Managed` before overwriting budgets and rate limit, ensuring the flag is present even when the profile has neither. - Updated `useVirtualKeyUsage` so `isManagedByProfile` is `true` when either the server flag is set or the client-side profile lookup finds a match. This means users without access-profile permissions still see the lock and notice. - Fixed a potential nil-dereference in `virtualKeyDetailsSheet` where `managingProfile.user_id` was accessed without first checking that `managingProfile` is non-nil. - `ManagedVirtualKeyNotice` now receives `isManagedByProfile` directly so it renders correctly even when `managingProfile` is undefined. - Added `is_access_profile_managed?: boolean` to the `VirtualKey` TypeScript interface. - Added a new test `TestApplyExternalBudgets_ManagedWithNoGovernanceFlagsAndClears` verifying that a resolver-managed VK with no AP budget and no AP rate limit is still flagged managed and has its mirror rows cleared. - Updated the existing `TestApplyExternalBudgets_RateLimitOnlyDropsNativeBudgets` test to assert `IsAccessProfileManaged=true`. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [x] UI (React) - [ ] Docs ## How to test 1. Configure a virtual key governed by an access profile. 2. Log in as a user who does **not** have RBAC permission to list access profiles. 3. Navigate to the virtual key detail sheet — the managed-key notice and edit lock should be visible. 4. Log in as a user who **does** have access-profile permissions and confirm the profile name still appears alongside the notice. ```sh # Core/Transports go test ./transports/bifrost-http/handlers/... -run TestApplyExternalBudgets # UI cd ui pnpm i || npm i pnpm test || npm test pnpm build || npm run build ``` ## Breaking changes - [ ] Yes - [x] No ## Security considerations The `is_access_profile_managed` flag is read-only and never persisted (`gorm:"-"`). It is populated only on governance read paths and carries no sensitive data — it is a boolean indicator used solely to drive UI state. No auth or secret handling is affected. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
Users without access-profile RBAC permissions were not seeing the managed-key lock and notice on virtual keys governed by an access profile. Because the managed state was derived solely from the client-side access-profile lookup (which is RBAC-gated), users lacking that permission saw the key as unmanaged and could attempt edits that should be locked.
This PR introduces a server-computed
is_access_profile_managedflag on theVirtualKeyresponse that is populated during the governance read path, independent of any access-profile permission check. The UI uses this flag as the authoritative source for "is this key managed," falling back to the existing profile lookup only for resolving the profile name and actions.Changes
IsAccessProfileManaged booltoTableVirtualKeyas a non-persisted, computed field (gorm:"-") that is set byapplyExternalBudgetsfrom the external resolver result.Managed boolfield toExternalQuotaBudgetResultso resolvers can signal managed status independently of whether the profile carries any budget or rate-limit rows.applyExternalBudgetsnow setsvk.IsAccessProfileManaged = ext.Managedbefore overwriting budgets and rate limit, ensuring the flag is present even when the profile has neither.useVirtualKeyUsagesoisManagedByProfileistruewhen either the server flag is set or the client-side profile lookup finds a match. This means users without access-profile permissions still see the lock and notice.virtualKeyDetailsSheetwheremanagingProfile.user_idwas accessed without first checking thatmanagingProfileis non-nil.ManagedVirtualKeyNoticenow receivesisManagedByProfiledirectly so it renders correctly even whenmanagingProfileis undefined.is_access_profile_managed?: booleanto theVirtualKeyTypeScript interface.TestApplyExternalBudgets_ManagedWithNoGovernanceFlagsAndClearsverifying that a resolver-managed VK with no AP budget and no AP rate limit is still flagged managed and has its mirror rows cleared.TestApplyExternalBudgets_RateLimitOnlyDropsNativeBudgetstest to assertIsAccessProfileManaged=true.Type of change
Affected areas
How to test
Breaking changes
Security considerations
The
is_access_profile_managedflag is read-only and never persisted (gorm:"-"). It is populated only on governance read paths and carries no sensitive data — it is a boolean indicator used solely to drive UI state. No auth or secret handling is affected.Checklist
docs/contributing/README.mdand followed the guidelines