Skip to content

Python sdk support for WorkOS Vault#456

Merged
debussyman merged 14 commits intomainfrom
feature/ekm-50-python-sdk-support
Jul 2, 2025
Merged

Python sdk support for WorkOS Vault#456
debussyman merged 14 commits intomainfrom
feature/ekm-50-python-sdk-support

Conversation

@debussyman
Copy link
Contributor

Description

This PR adds complete Vault functionality to the WorkOS Python SDK, including key-value operations, object versioning, data key management, and local encryption/decryption capabilities.

Features Added

  • Key-Value Operations: Create, read, update, delete vault objects
  • Object Versioning: List and manage object version history
  • Data Key Management: Generate and decrypt data keys for local encryption
  • Local Encryption: AES-GCM encryption with WorkOS-managed keys
  • Context-based Keys: Flexible key derivation using user-defined contexts
  • Type Safety: Full Pydantic model integration with strict typing

Implementation Details

Core Components

  • VaultModule Protocol: Complete interface definition with comprehensive docstrings
  • Vault Class: Full implementation of all protocol methods with proper error handling
  • Type Models: Pydantic models for VaultObject, DataKey, KeyContext, etc.
  • CryptoProvider: Secure AES-GCM encryption operations using cryptography library
  • Test Suite: 28 comprehensive tests covering all functionality

API Coverage

  • POST /vault/v1/kv - Create vault objects
  • GET /vault/v1/kv - List vault objects (with pagination)
  • GET /vault/v1/kv/{id} - Read vault object
  • PUT /vault/v1/kv/{id} - Update vault object
  • DELETE /vault/v1/kv/{id} - Delete vault object
  • GET /vault/v1/kv/{id}/versions - List object versions
  • POST /vault/v1/keys/data-key - Generate data keys
  • POST /vault/v1/keys/decrypt - Decrypt data keys

Security Features

  • Envelope Encryption: Each encryption operation uses a unique data key
  • AES-GCM: Authenticated encryption with associated data support
  • Key Context: Flexible key derivation based on user-defined contexts
  • Forward Secrecy: New data key generated for each encryption operation

Test Plan

All tests pass (28/28):

  • ✅ Object CRUD operations with proper validation
  • ✅ Pagination support and edge cases
  • ✅ Version management functionality
  • ✅ Data key generation and decryption
  • ✅ End-to-end encryption/decryption workflows
  • ✅ Error handling and input validation
  • ✅ Type safety and model validation

Breaking Changes

None - this is a new feature addition that doesn't affect existing functionality.

Dependencies

  • Added cryptography library for AES-GCM encryption (already in requirements.txt)
  • All other dependencies are existing

🤖 Generated with Claude Code

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

debussyman and others added 2 commits May 27, 2025 10:23
## Summary
- Add full Vault module implementation with complete API coverage
- Implement local encryption/decryption using AES-GCM with WorkOS-managed keys
- Add comprehensive test coverage with 28 passing tests
- Include all Vault operations: CRUD, data key management, and crypto operations

## Key Features
- **Key-Value Operations**: Create, read, update, delete vault objects
- **Object Versioning**: List and manage object version history
- **Data Key Management**: Generate and decrypt data keys for local encryption
- **Local Encryption**: AES-GCM encryption with WorkOS key management
- **Context-based Keys**: Flexible key derivation using user-defined contexts
- **Type Safety**: Full Pydantic model integration with strict typing

## Implementation Details
- VaultModule protocol with complete method signatures and documentation
- Vault class implementing all protocol methods with proper error handling
- KeyContext using Pydantic v2 RootModel for dictionary validation
- CryptoProvider for secure AES-GCM encryption operations
- Comprehensive test suite with mock fixtures and roundtrip validation

## API Endpoints Covered
- `/vault/v1/kv` - Object CRUD operations
- `/vault/v1/kv/{id}/versions` - Version management
- `/vault/v1/keys/data-key` - Data key generation
- `/vault/v1/keys/decrypt` - Data key decryption

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@debussyman debussyman requested a review from a team as a code owner June 23, 2025 21:17
@debussyman debussyman requested a review from dandorman June 23, 2025 21:17
@linear
Copy link

linear bot commented Jun 23, 2025

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Comprehensive implementation of the WorkOS Vault feature in the Python SDK, providing secure key-value storage with encryption capabilities and object versioning.

  • New workos/vault.py implements complete Vault functionality with AES-GCM encryption, proper key management, and comprehensive type safety
  • Added workos/utils/crypto_provider.py for secure encryption operations using envelope encryption pattern and authenticated encryption
  • Introduced well-structured type definitions in workos/types/vault/ for VaultObject, DataKey, and KeyContext with Pydantic validation
  • Comprehensive test suite in tests/test_vault.py covering 28 test cases for CRUD, versioning, and cryptographic operations
  • Modified workos/types/list_resource.py to support Vault object pagination with proper type checking

8 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +1 to +2
from .key import *
from .object import *
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Use explicit imports instead of wildcard imports (*) to make imported symbols clear and prevent namespace pollution. Example: from .key import Key, DataKey

debussyman and others added 8 commits June 24, 2025 11:48
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
- Format crypto_provider.py and test_vault.py with black
- Update vault API endpoints from data_keys to keys/data-key and keys/decrypt
- Remove duplicate test case in test_vault.py

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@dandorman dandorman left a comment

Choose a reason for hiding this comment

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

seems good!

@debussyman debussyman merged commit 1b5bd23 into main Jul 2, 2025
6 checks passed
@debussyman debussyman deleted the feature/ekm-50-python-sdk-support branch July 2, 2025 23:52
@debussyman debussyman mentioned this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants