FerriteDocs

Secrets & Egress

Store write-only secrets, read them from AppContext at runtime, and constrain outbound HTTP traffic to declared HTTPS URL prefixes.

Secrets on Ferrite are write-only across every management surface: the CLI, MCP tools, and the Dashboard application page let you set, list, and delete secrets, and none of them ever returns a stored value. At runtime, your deployed application reads plaintext values from its context, and every outbound HTTP request passes through the platform gateway. The gateway records each call and rejects any destination absent from ferrite.json.

Write a secret safely

From your project directory, pipe the secret value into ferrite secrets set and confirm with ferrite secrets list that only the name appears:

printf %s "$STRIPE_KEY" | ferrite secrets set STRIPE_KEY
ferrite secrets list

When working without a shell, call the MCP set_secret tool with the application name, secret name, and value, then verify with list_secrets. Both paths work before your first deploy, which is the best time to configure secrets.

Secret configuration follows these rules:

  • Names must match [A-Za-z0-9_.-] and stay within 64 characters.
  • Values are capped at 64 KiB, and each application holds at most 64 secrets.
  • ferrite secrets set <name> reads from standard input or --value-file <path>, refuses values passed as command-line arguments, and strips one trailing line ending.
  • Remove secrets with ferrite secrets delete <name> or the MCP delete_secret tool.
  • Pass --app and --dir to ferrite secrets commands to target an application outside the current directory, or manage secrets from the Dashboard’s application page.
  • Never place a secret in a shell argument or commit it to ferrite.json.

When the application sees a new value

Secrets reach running processes only through a deploy. Live instances never observe updated or deleted values, and scale does not refresh them either: scaling from 0 to 1 restarts the instance with its existing deployment context.

To roll out a new value, deploy again. Redeploying runs a full build and incurs a deploy fee even when source code has not changed. ferrite deploy detects updates made through ferrite secrets and triggers a build automatically; after changing secrets through MCP, pass --force to ferrite deploy.

Missing secrets at deploy

The platform does not block a deploy for an unset secret, and Ferrite Core rejects required_secrets if that key reaches the submitted manifest. Instead, the CLI reads required_secrets from each application block in ferrite.json, strips it prior to upload, and checks every listed name against list_secrets. If any required name is absent, ferrite deploy exits with DEPLOY_REQUIRED_SECRETS_MISSING, runs no build, and charges nothing. If list_secrets fails to respond, every listed name counts as missing.

Applications vendoring the auth package receive the same pre-flight check for the secrets auth reads (DEPLOY_AUTH_SECRETS_MISSING), with one difference: if list_secrets fails to respond, the CLI prints a warning that auth secrets were unchecked and continues with the submission.

Pass --allow-missing-secrets to downgrade either refusal into a warning. The deployed application then runs without the missing values until you set them and redeploy; the standard convention is to return 503 naming the missing secret.

Direct MCP deploy_source calls skip these CLI checks. Before calling deploy_source, an agent should call list_secrets and verify that every secret the application reads is already set.

Read a secret in the application

Read secrets by name from AppContext inside your handler:

let Some(stripe_key) = ctx.secret("STRIPE_KEY") else {
    return IngressReply::to(request, 503, b"STRIPE_KEY is not set".to_vec());
};

ctx.secret returns None when no secret of that name existed at deploy time, and ctx.secret_names() returns the configured names without their values. Ferrite stores secret values encrypted at rest and decrypts them into the application’s context during deployment. Because source admission forbids std::env, AppContext is the only runtime channel for reading secrets.

Declare egress

List every external HTTP endpoint your application calls under egress in ferrite.json:

{
  "services": [],
  "applications": [{
    "name": "shop",
    "artifact_key": "apps/shop@v1",
    "artifact_sha256": "0000000000000000000000000000000000000000000000000000000000000000",
    "egress": [{
      "handle": "stripe",
      "destinations": ["https://api.stripe.com/v1/checkout/sessions"]
    }]
  }]
}

Open the handle with ctx.egress("stripe") and call deliver_http(method, dest, &[EgressHeader], body) for buffered requests or deliver_stream_http for streamed responses.

Destination matching is a literal, character-by-character prefix check. Declaring https://api.stripe.com/v1/checkout/sessions admits https://api.stripe.com/v1/checkout/sessions/cs_123/expire. Whenever you declare an entire host, end it with / (such as https://hooks.example.com/). Without a trailing slash, that prefix also matches longer hostnames that start with the same characters. Declare only the specific path prefixes your application needs rather than opening an entire host for convenience.

Admission and call-time validation enforce these rules:

  • Every destination must be an absolute https:// URL prefix (APP_EGRESS_DESTINATION_MALFORMED), and an egress entry with no destinations is refused (APP_EGRESS_UNSCOPED).
  • Internal, loopback, link-local, metadata, and platform-domain destinations are rejected at admission (APP_EGRESS_INTERNAL_DESTINATION), so egress cannot reach another Ferrite application or the platform. Internal addresses are rejected again at connect time after DNS resolution.
  • Before connecting, the gateway also rejects as Err any destination containing userinfo, #, a backslash, a non-ASCII byte, or a . or .. path segment after percent-decoding.

Handle both success and refusal variants explicitly:

  • Buffered calls return Ok(EgressOutcome::Delivered { status, body }) or Ok(EgressOutcome::Denied { reason }). Undeclared destinations and rights, quota, or budget refusals return Denied before any network connection opens, so match both variants instead of treating every Ok as delivered.
  • deliver_stream_http uses the same split through EgressStreamOutcome (Streaming or Denied).
  • Err indicates either a transport failure, where the remote call may already have executed, or a refused egress handshake, which arrives with error kind PermissionDenied.

The gateway applies fixed transport limits to every outbound call:

Behavior or boundValue
Response headersStripped; pagination links, rate-limit headers, and set-cookie never reach the app
RedirectsNever followed; 3xx responses return with their original status code
Connect timeout2 seconds
TLS handshake timeout2 seconds
Response timeout10 seconds
Total deadline25 seconds for a full buffered delivery or for opening a stream
Buffered body frame1 MiB maximum
Stream idle timeout30 seconds before the stream drops

These bounds are fixed and the transport accepts no per-call deadline. If an outbound call must finish sooner, wrap it in your own application timeout. Design provider integrations around these platform limits rather than provider SDK defaults.

What this does not stop

Because your running application receives plaintext secret values, Ferrite cannot stop buggy or malicious code from logging a secret, returning it in an HTTP response, writing it to storage, or sending it to any declared destination.

Nothing binds a secret to a specific egress handle or host. Any declared destination can receive any value your code sends, and the gateway checks the destination URL without scanning outbound bodies or headers for secret values. The gateway also attaches no credentials to outbound calls on your behalf, so your application constructs its own authorization header from ctx.secret. Audit every code path that touches a secret and keep your declared destination list as narrow as the work allows.

Local development

ferrite dev blocks real outbound egress by default. Run ferrite dev --egress allow only when you intend to reach the destinations declared in ferrite.json. Keep deterministic tests against provider fixtures instead of live endpoints.

Logging

Your application holds its plaintext secrets in memory, so keeping sensitive material out of logs belongs in your handler code. Never log secret values, authorization headers, session cookies, password or reset material, TOTP seeds, raw SAML assertions, or complete payment payloads. Log a provider request ID and a redacted reason class instead.

Next: verify inbound provider requests in Webhooks or route model calls through the AI Gateway.

Ferrite counts page views on this site. Privacy · Terms