App Security
The SecureTextAppConfigItem config type allows tenant admins to store sensitive values such as API keys, passwords, and connection strings in app configuration without exposing them in plaintext.
The encryption model is asymmetric: your app generates an RSA keypair and publishes the public key in its manifest. When a tenant admin sets a secure_text config value, Benchling encrypts it using your public key before storing it. Your app retrieves the encrypted value via the API and decrypts it using the private key, which never leaves your infrastructure.
How It Works
Step 1: Generate a Keypair
Generate a 2048-bit RSA keypair. Store the private key in your secrets manager immediately. It should never be committed to source control or bundled with your app.
Step 2: Add the Public Key to Your Manifest
Declare secure_text config items and add the public key under the security field:
The security.publicKey field and any secure_text config items must be declared together. Benchling will reject a secure_text config item if no public key is present in the manifest.
See the App Manifest Reference for the full security and configuration field schemas.
Step 3: Implement a Decryption Provider
The SDK provides BaseKeyUnwrappingDecryptionProvider, an abstract base class that handles JWE decryption via python-jose. You implement one method, unwrap_key(), which receives the RSA-encrypted content encryption key as bytes and returns the decrypted key bytes using your private key from your secrets manager.
This design is intentional: the SDK never asks you to pass a raw private key. Your private key stays in your secrets manager; unwrap_key() is the bridge between Benchling’s encrypted payload and your key infrastructure.
Install the required extra first:
The local PEM pattern is for development only
Loading a private key from a file or environment variable is not suitable for production. Use a secrets manager implementation instead.
Step 4: Retrieve and Decrypt a Config Value
Use ConfigItemStore with BenchlingConfigProvider to fetch config items from Benchling’s API. The secure_text value is returned as JWE ciphertext in the standard .value field, the same field used by every other config type. Pass the ciphertext to your decryption provider to get the plaintext.
Use .required().value() for config items declared with requiredConfig: true in your manifest. For optional items, use .value() directly; it returns None if the item is not set.
Testing
The SDK provides several helpers in benchling_sdk.apps.config.mock_config for testing config handling without real keys or a live Benchling tenant.
MockDecryptionProviderStatic
Always returns the same plaintext regardless of what ciphertext is passed. Useful when your test only involves a single secret:
MockDecryptionProviderMapped
Returns different plaintext values based on the input ciphertext. Useful when testing multiple secrets simultaneously:
MockConfigItemStore
The recommended testing pattern is to build a MockConfigItemStore from your manifest file, then use with_replacement() to inject specific values for secure_text items using mock_secure_text_app_config_item():
MockConfigItemStore.from_manifest() generates randomized but valid mock values for all config items in your manifest. Use with_replacement() to selectively override specific items with controlled test values without having to mock the entire config manually.
Security Considerations
- Never commit your private key. Store it in AWS KMS, Azure Key Vault, HashiCorp Vault, or equivalent. The
unwrap_key()pattern is designed so your private key never needs to be present in application memory as a raw value. - Rotate keys by updating your manifest. To rotate, generate a new keypair, update
publicKeyin your manifest, re-upload the manifest, and have the tenant admin re-enter anysecure_textconfig values. Benchling will re-encrypt them with the new public key automatically. - One keypair per app. All
secure_textconfig items for a given app are encrypted with the same public key. If you need encrypted values accessible to different services with different key access, consider separate apps with separate manifests. - Do not log ciphertext values. Although they are encrypted, logging JWE tokens unnecessarily increases exposure surface.
Related
- App Manifest Reference:
securityandconfigurationfield schemas - App Configuration: setting and retrieving config values
- Building your first app with App Configuration: end-to-end app config walkthrough
- Webhook Security: verifying webhook signatures (similar pattern)