Skip to content

Conversation

nimish-ks
Copy link
Member

@nimish-ks nimish-ks commented Aug 23, 2025

🔍 Overview

This PR extends Service Account key management system to add support for service-side key management. Server-side key management allows the Phase service to securely manage cryptographic keys on behalf of users on the backend. This allows the Phase API to create and manage Access Tokens for service accounts. This also opens the door for newer features such as external identities which allows Phase to use third-parry identity systems such as AWS IAM, Kubernetes API, GitHub Actions, and other providers that support OIDC etc. to authenticate clients and issue Access Tokens.

Dependency for: #654

💡 Proposed Changes

  • Added the ability to switch key KMS (Key management system) modes between client-side key management to server-side key management and vice-versa.

🖼️ Screenshots or Demo

Service Account KMS dialog when client-side key management is enabled

image

Service Account KMS dialog when server-side key management is enabled

image

Switching back to client-side key management

image

📝 Release Notes

  • Added cryptographic utils & GraphQL queries that will will wrap Service Account keys with server keys and store them on the backend.
  • Added support for one service account to mint Access Tokens on behalf of other Service Accounts
  • Renamed types correctly from third_party_auth_enabled -> server_side_key_management_enabled, resolve_third_party_auth_enabled, resolve_server_side_key_management_enabled.
  • Switching from server-side key management to client-side key management will delete wrapped service account keys from the backend (server_wrapped_keyring, server_wrapped_recovery)
  • Updated PhaseTokenAuthentication class to support Service Account user model for when a Access Token is not created by a User.

🎯 Reviewer Focus

  • Audit cryptographic utils in frontend/utils/crypto/service-accounts.ts used to wrap Service Account keys with server keys
  • server_wrapped_keyring, server_wrapped_recovery when switching between KMS modes
  • Service Account user model mock in auth.py to satisfy DRF requirements.
  • Migrations in backend/api/migrations/0106_serviceaccounttoken_created_by_service_account.py

💚 Did You...

  • Ensure linting passes (code style checks)?
  • Update dependencies and lockfiles (if required)
  • Update migrations (if required)
  • Regenerate graphql schema and types (if required)
  • Verify the app builds locally?
  • Manually test the changes on different browsers/devices?

Note

Adds server-side key management for Service Accounts and introduces External Identities with AWS IAM auth to mint tokens, with full API/GraphQL and UI to manage identities and link them to accounts.

  • Backend:
    • Identity model & relations: New Identity model with M2M on ServiceAccount; migrations 0110, 0111.
    • AWS IAM auth: Public endpoint to validate SigV4 STS GetCallerIdentity and mint ServiceAccount tokens; utilities for STS endpoints and token minting; unit tests added.
    • ServiceAccount tokens: Add created_by_service_account; DRF auth updated to support service-account-originated tokens; serializer targets ServiceAccountToken.
    • Permissions & roles: Add ExternalIdentities permissions across roles.
    • GraphQL: Identity CRUD (create/update/delete), queries (aws_sts_endpoints, identity_providers, identities), SA key-management mutations (enable server/client), schema/types updated (e.g., serverSideKeyManagementEnabled, Identity*).
    • Crypto utils: Add helpers (xor_bytes, secret splitting/wrapping, ed25519→curve25519, random_hex).
    • Routing: Add public route public/identities/external/v1/aws/iam/auth/.
  • Frontend:
    • Identities UI: New identities page, provider cards, AWS IAM form, edit/delete flows; TTL input utilities.
    • Service Accounts: Key management dialog (toggle server/client), associate identities to accounts; show token creator (user or service account).
    • GQL ops: New queries/mutations for identities, SA key management, and schema updates reflected in types.

Written by Cursor Bugbot for commit c751c8a. This will update automatically on new commits. Configure here.

…elationship

- Added `created_by_service_account` field to associate tokens with service accounts.
- Implemented validation in `clean` method to ensure only one creator field is set.
- Introduced `get_creator_account` method to retrieve the creator, whether an organisation member or a service account.
- Introduced a new ForeignKey field to associate service account tokens with their creator service accounts.
- This migration enhances the model's relationship capabilities.
- Added a new ServiceAccountUser class to represent service account users in the authentication process.
- Updated PhaseTokenAuthentication to utilize ServiceAccountUser when the creator is not an organization member, enhancing the handling of service account tokens.
- Introduced a new field `createdByServiceAccount` to the ServiceAccountTokenType to enhance the model's relationship with service accounts.
- This addition supports better tracking of token creation by service accounts.
- Introduced `EnableServiceAccountSseMutation` to facilitate enabling third-party authentication for service accounts.
- Added `createdByServiceAccount` field to `ServiceAccountTokenType` for better tracking of token creation.
- Updated `GetServiceAccountTokensQuery` to include `createdByServiceAccount` information, enhancing the query's detail on token origins.
…ntTokens query

- Introduced `EnableServiceAccountSSE` mutation to enable third-party authentication for service accounts.
- Updated `GetServiceAccountTokens` query to include `createdByServiceAccount` field, enhancing token origin tracking.
…t-side key management mutation

- Renamed `EnableServiceAccountThirdPartyAuthMutation` to `EnableServiceAccountServerSideKeyManagementMutation` for clarity.
- Introduced `EnableServiceAccountClientSideKeyManagementMutation` to manage client-side key management, allowing for the deletion of server-wrapped keys and enhancing service account security management.
- Renamed `EnableServiceAccountThirdPartyAuthMutation` to `EnableServiceAccountServerSideKeyManagementMutation` for improved clarity.
- Added `EnableServiceAccountClientSideKeyManagementMutation` to support client-side key management, enhancing service account security features.
- Renamed `EnableServiceAccountThirdPartyAuthMutation` to `EnableServiceAccountServerSideKeyManagementMutation` for better clarity.
- Added `EnableServiceAccountClientSideKeyManagementMutation` to facilitate client-side key management, improving service account security features.
- Replaced `EnableServiceAccountSSE` mutation with `EnableSAClientKeyManagement` and `EnableSAServerKeyManagement` mutations to enhance key management capabilities.
- Updated `GetServiceAccountDetail` query to include `thirdPartyAuthEnabled` field, improving service account detail retrieval.
- Introduced `EnableServiceAccountClientSideKeyManagementMutation` and `EnableServiceAccountServerSideKeyManagementMutation` to improve key management capabilities.
- Updated `GetServiceAccountDetail` query to include `thirdPartyAuthEnabled` field for better service account detail retrieval.
- Renamed existing mutations for clarity and consistency in naming conventions.
- Introduced `wrapServiceAccountSecretsForServer` to securely wrap service account keyring and recovery for server-side encryption.
- Added `unwrapServiceAccountSecretsForUser` to decrypt and retrieve the original keyring and recovery for the current user.
- Enhanced documentation with detailed JSDoc comments for both functions, improving code clarity and usability.
- Introduced `KeyManagementDialog` component to manage service account key settings, allowing users to switch between client-side and server-side key management.
- Integrated Apollo Client for querying and mutating service account data, enhancing user experience with real-time updates.
- Added user permission checks to ensure only authorized users can manage key settings, improving security and usability.
- Included visual alerts and feedback for actions taken within the dialog, enhancing user interaction and clarity.
…mation

- Updated the `ServiceAccountTokens` component to conditionally render the creator's information, supporting both user and service account creators.
- Added fallback text for unknown creators, improving user experience and clarity in token origin tracking.
- Enhanced the `GetServiceAccountTokens` query by including the `createdByServiceAccount` field, which provides details about the creator of the service account tokens, improving tracking and transparency of token origins.
@nimish-ks nimish-ks self-assigned this Aug 23, 2025
@nimish-ks nimish-ks marked this pull request as draft August 23, 2025 12:05
…nabled in ServiceAccountType

- Updated the `ServiceAccountType` to replace the `third_party_auth_enabled` field with `server_side_key_management_enabled`, reflecting a clearer purpose for server-side key management.
- Adjusted the corresponding resolver method to match the new field name, ensuring consistency in the API.
- Replaced the `thirdPartyAuthEnabled` field with `serverSideKeyManagementEnabled` in the `ServiceAccountType` to better reflect the functionality of server-side key management.
- Updated the `GetServiceAccountDetail` query and related mutations to utilize the new field, ensuring consistency across the API.
- Adjusted the GraphQL documents and types to align with the new schema changes, enhancing clarity and usability in service account management.
…tail query

- Updated the `GetServiceAccountDetail` query to include the `serverSideKeyManagementEnabled` field, enhancing the detail provided for service accounts and aligning with recent schema changes for key management.
…gement for service accounts

- Introduced `EnableSAClientKeyManagement` mutation to enable client-side key management for service accounts.
- Added `EnableSAServerKeyManagement` mutation to enable server-side key management, requiring additional parameters for secure key handling.
- Enhanced service account management capabilities by providing distinct mutations for both client-side and server-side key management.
- Replaced instances of thirdPartyAuthEnabled with serverSideKeyManagementEnabled in KeyManagementDialog component to ensure accurate state management for key management modes.
- Adjusted modal open/close behavior and save logic to reflect the new field, enhancing the functionality and clarity of service account key management.
- Added visual indicators for server-side and client-side key management modes in the ServiceAccount component.
- Integrated KeyManagementDialog for managing key settings, allowing users to switch between management modes.
- Improved user experience by providing clear labels and management options based on the service account's key management configuration.
…ssary state updates

- Updated the save handler in KeyManagementDialog to close the modal immediately after saving, improving user experience.
- Removed redundant state updates and comments related to mode changes, simplifying the code and enhancing clarity.
- Adjusted the rendering logic to eliminate unnecessary alerts, focusing on relevant user feedback for key management actions.
- Eliminated the alert related to server-side key management in the KeyManagementDialog component, streamlining the user interface and focusing on relevant feedback for client-side management.
- This change enhances clarity and reduces visual clutter for users managing service account keys.
- Introduced a new module with functions to parse, format, and validate TTL strings, enhancing the handling of time-related data.
- Added examples for common TTL formats, improving usability and clarity for developers working with time-to-live values.
…rations

- Introduced a new IdentityProviders class to encapsulate configurations for supported identity providers, enhancing the structure for identity authentication.
- Implemented methods to retrieve all providers, supported providers, and specific provider configurations, improving the usability and maintainability of identity management.
- Introduced a new Identity model to manage third-party identity configurations at the organization level, allowing multiple service accounts to be associated with a single identity.
- Added fields for provider-specific configurations, token settings, and methods to retrieve trusted principals, enhancing the flexibility and usability of identity management.
@nimish-ks
Copy link
Member Author

@cursor review

cursor[bot]

This comment was marked as outdated.

nimish-ks and others added 18 commits September 10, 2025 14:22
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
feat: external identities - AWS IAM
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the service account key management system to support server-side key management (KMS) alongside the existing client-side approach. The implementation introduces external identities for third-party authentication and adds AWS IAM as the first supported provider.

  • Added server-side key management toggle for service accounts with cryptographic utilities
  • Implemented external identity system with AWS IAM provider support
  • Refactored TTL utilities to shared module and enhanced service account token tracking

Reviewed Changes

Copilot reviewed 52 out of 58 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
frontend/utils/ttl.ts New utility module for TTL parsing and formatting
frontend/utils/crypto/service-accounts.ts Added crypto functions for wrapping/unwrapping SA keys
frontend/components/service-accounts/KeyManagementDialog.tsx Dialog for switching between client/server KMS modes
frontend/components/identities/providers/aws/iam.tsx AWS IAM identity configuration form
backend/api/models.py Added Identity model and ServiceAccount relationships
backend/api/views/identities/aws/iam.py AWS IAM authentication endpoint
backend/api/utils/crypto.py New crypto utilities for key splitting and wrapping

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

} else if (selectedMode === 'client' && serviceAccount.serverSideKeyManagementEnabled) {
// Disable server-side encryption (switch to client-side)
await handleDisableSSE()
} else {
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Empty else block should be removed as it serves no purpose.

Suggested change
} else {

Copilot uses AI. Check for mistakes.

@nimish-ks
Copy link
Member Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


nimish-ks and others added 3 commits October 5, 2025 14:10
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
Signed-off-by: rohan <rohan.chaturvedi@protonmail.com>
@nimish-ks nimish-ks merged commit 21b76d1 into main Oct 5, 2025
7 checks passed
@nimish-ks nimish-ks deleted the feat--service-account-kms branch October 5, 2025 16:05
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