Secret declares a named credential required by a service or ExternalSystem. Keel wraps secret values in Effect’s Redacted type so logs and JSON serialization do not expose them. verifySecrets checks that declared secrets exist at boot, and deployment scopes each secret only to the service unit that declared it.
Declaring a Secret
Plain TypeScript SDK (@chimp-labs/keel/sdk)
import { k } from "@chimp-labs/keel/sdk"
export const StripeApiKey = k.secret("STRIPE_API_KEY")
export const StripeSigningSecret = k.secret("STRIPE_SIGNING_SECRET")
Effect v4 (@chimp-labs/keel/secret)
import { Secret } from "@chimp-labs/keel/secret"
export class StripeApiKey extends Secret("STRIPE_API_KEY") {}
Attaching to a Service
Declaring a secret in Service.resources or ExternalSystem.secrets has two effects:
verifySecretschecks that the secret exists at startup and fails withMissingSecretsError, which reports every missing key in one error.@chimp-labs/keel-alchemyinjects the secret binding only into the Worker or Docker container that declared it.
export const BillingService = k.service("billing", {
resources: [InvoicesTable, StripeApiKey],
operations: { /* ... */ },
})
Operations reference
Scoped usage and redacted reads
// Recommended: unwrap raw value only inside a tight callback scope
const customer = await keel.stripeKey.use(async (apiKey) => {
const res = await fetch("https://api.stripe.com/v1/customers", {
headers: { Authorization: `Bearer ${apiKey}` },
})
return res.json()
})
// Or read as Redacted<string> (safe against accidental console.log)
const redacted = await keel.stripeKey.getRedacted()
// Or read raw string directly
const raw = await keel.stripeKey.get()
Boot preflight verification
Pass verifySecrets: true to createKeel(...) or service.live(handlers, { verifySecrets: true }) so missing credentials fail at startup instead of during a production request:
const keel = await createKeel({
backend: "postgres",
secrets: "env", // or { STRIPE_API_KEY: "..." } or { source: "dir", path: "/run/secrets" }
resources: { billing: BillingService, stripeKey: StripeApiKey },
verifySecrets: true,
})
Built-in secret store layers
| Layer or source | Description | Best for |
|---|---|---|
SecretStoreMemory(map) |
In-memory key map | Unit and integration tests |
SecretStoreEnv |
Reads process.env[name] |
Local dev, Cloudflare Workers, and PaaS hosts |
SecretStoreConfig / SecretStoreConfigFrom |
Reads Effect’s active ConfigProvider |
Composable Effect config |
SecretStoreDir(dirPath) |
Reads mounted files <dir>/<NAME> with path-traversal protection |
Docker Compose secrets: and Kubernetes /run/secrets |
SecretStoreChain(...layers) |
Falls through on SecretNotFoundError only |
Layered local, mounted dir, and env precedence |
Complete SDK and Effect API mapping
SDK method (keel.<secret>.*) |
Effect function (@chimp-labs/keel/secret) |
Description |
|---|---|---|
use(fn) |
useSecret(secret, fn) |
Unwrap the raw string inside a scoped callback. |
getRedacted() |
getSecret(secret) |
Read Redacted.Redacted<string>. |
get() |
getSecret(secret) with Redacted.value |
Read the unwrapped secret string. |
verifySecrets: true |
verifySecrets(descriptors) |
Run boot preflight and collect all missing secret names. |
Errors and failure modes
| Error tag | Category | HTTP status | Retryable | When it occurs |
|---|---|---|---|---|
SecretNotFoundError |
not_found |
404 |
No | Requested secret is missing from all configured stores. |
MissingSecretsError |
internal |
500 |
No | verifySecrets finds one or more missing secrets at boot. |
SecretStoreError |
internal |
500 |
Yes | Underlying file or environment store read fails. |
Backends and infrastructure
- Every
SecretStorelayer (memory,env,config,dir, andchain) works with PostgreSQL 17 (KeelPostgresLiveorbackend: "postgres"), SurrealDB 4, SQLite, and Memory.KeelPostgresConfigLivereadsDATABASE_URLandPOSTGRES_*credentials asRedactedvalues through Effect’sConfigProvider. - On Cloudflare Workers (
@chimp-labs/keel-alchemy/cloudflare/stack),keelCloudflareStackandprovisionKeelCloudflareTopologybind declared secrets strictly to the Worker units that reference them. On Docker and Kubernetes, mount secrets into/run/secretsand wireSecretStoreChain(SecretStoreDir("/run/secrets"), SecretStoreConfig).
Testing in memory
await using keel = await createKeel({
backend: "memory",
secrets: { STRIPE_API_KEY: "sk_test_123" },
resources: { stripeKey: StripeApiKey },
verifySecrets: true,
})
const prefix = await keel.stripeKey.use((raw) => raw.slice(0, 7))
// prefix === "sk_test"