Skip to content

Component Secrets

Component secrets hold values that functions need but that must never appear in settings, config or API responses: signing keys, SMTP passwords, third-party API tokens. You declare them in the component's settings. Functions read them as $secrets.


Declaring Secrets

Declarations live under secrets in the component settings, next to config. Each entry is one string:

{
  "secrets": {
    "session_key": "secretgen::random(64)",
    "smtp_password": "secret::"
  }
}
You write Meaning Reads back as
secretgen::<generator> Generated by the platform. A settings write creates a missing value only for the environments currently running the version being written; any other environment gets its value on the first function run or the first status read there, whichever comes first. An existing value is kept. secretgen::<generator>
secret::<value> Supplied. Stores the value for the environment of the request, replacing the value there. secretref::
secret:: Supplied, no value yet. secretref::
secretref:: Keeps the stored value. secretref::

Any other string, including a plain value, is refused with 422. A plain value can never end up in settings, and the error does not echo it.

Every settings read returns secretref:: for a supplied secret, whether or not it has a value. Sending settings back unchanged therefore keeps all values. A settings write that leaves out the secrets key keeps the existing declarations; a present secrets replaces them, and "secrets": {} removes them all.

Note

Removing a declaration deletes that name's values, in every environment, unless another version of the component still declares the name; then they are kept. Re-declaring a removed name later starts without a value: a generated one is created again, and a supplied one must be set again. When another version still declares the name, declaring it again in a version reuses the kept value; rotate it or set it again if it should not carry over.


Generated Secrets

secretgen::random(n[, alnum|alpha|hex|digits|base64url])
Part Rule
n Length of the value, at most 4096
charset Optional. One of alnum (default), alpha, hex, digits, base64url

A declaration whose result would carry less than 128 bits of entropy is refused with 422. secretgen::random(8, digits) is refused for that reason. uuid is not a generator: an identifier is not a secret, and a UUIDv4 does not reach the entropy floor.

Dev and live each get their own generated value. A generated value changes only when you rotate it.


Supplied Secrets

A supplied value is 8 characters to 32 KiB of text. Anything shorter or longer is refused with 422.

  • Values are per environment. Dev and live are separate, and a write sets only the environment named by the X-Project-Env header. A request without that header acts on live.
  • A value written through a settings save (secret::<value>) is stored for the environment of that request, whichever version of the component is being written.
  • Setting a value equal to the stored one is a no-op.
  • A supplied secret with no value yet is missing. Functions that use the component still run and see $secrets.<name> as undefined, so check for it in code that needs the value.

You can supply the value inside a settings write (secret::<value>), or with the set route below.


Write-Only

secrets::write <ref> decides who can save secret values and generate new ones (set and rotate). No route returns a value. Every run of the component's functions receives $secrets, so anyone who can change the component's code (settings <ref>) can use its secrets in that code. Settings reads carry secretref:: and the status route carries only whether a value exists. If you forget a value, set a supplied secret again or rotate a generated one. Neither the API nor the dashboard shows a stored value. See the security model for what you are responsible for and what the platform guarantees.

The dashboard says the same: "Write-only. To replace the value, set it again." Setting a value is disabled without secrets::write <ref>, and the dashboard names that permission as the reason.


Using Secrets in Functions

Functions read secrets from $secrets. See Functions.

const key = $secrets.session_key

if (!$secrets.smtp_password) {
  throw new Error("smtp_password is not set for " + $currentEnv)
}

Model events and workflow expressions do not receive secrets.

A function run that sends its own code (options.expression) receives no secrets, and no encrypted environment values either.

A function run that overrides config needs settings <ref> when the component declares secrets or the project's global environment holds encrypted values, otherwise it is refused with 403. The run receives those values decrypted, so a changed config could leak them. Otherwise, the run permission is enough. A run that sends its own code (options.expression) is not affected by the encrypted environment condition.

Error output and captured logs returned to the caller are scrubbed of the run's secret values. This is best effort against accidental leaks. It does not protect against code that logs or returns a value on purpose.


Permissions

Changing a secret needs secrets::write <ref>, where <ref> is the component reference:

  • the set and rotate routes below;
  • any settings write that adds, changes or removes a declaration under secrets, or carries secret::<value>.

A settings write that leaves out secrets, or sends the declarations back unchanged, needs only settings <ref>, so editing the rest of the component keeps working. Without secrets::write <ref>, a write that changes secrets gets 403 naming the missing permission, and nothing is saved.

The project Owner and Maintainers hold secrets::write <ref> implicitly. So does anyone whose role holds secrets::write <ref>, including code that runs as such an identity.

Changing declarations and code

Declarations are code, and code receives $secrets when it runs. To change what a component declares, or the code or config of a component that declares secrets, you need secrets::read <ref> as well as settings <ref>. You also need the component's run identity. No route returns a value for secrets::read <ref>; it only gates the change.

Without it, the request is refused with 403 and permissions_not_held, naming secrets::read <ref>, and nothing is saved. In the dashboard the declarations are read-only: "Changing what this component declares, or its code or config when it declares secrets, needs the secrets::read permission. Declarations are read-only for you."

The project Owner and Maintainers hold secrets::read <ref> implicitly.

Forge apps that declare or set secrets in their install script list secrets::write <ref> in install_permissions.


API

All routes are under /v4/system/component/{ref}. The status read needs settings <ref>; set and rotate need secrets::write <ref>.

Status

GET /v4/system/component/{ref}/secrets

Response: 200 OK

{
  "secrets": [
    {
      "name": "session_key",
      "declaration": "secretgen::random(64)",
      "envs": {
        "dev":  { "status": "set", "origin": "generated", "updated_at": "2026-10-27T09:12:44Z" },
        "live": { "status": "set", "origin": "generated", "updated_at": "2026-10-27T09:12:44Z" }
      }
    },
    {
      "name": "smtp_password",
      "declaration": "secretref::",
      "envs": {
        "dev":  { "status": "set", "origin": "supplied", "updated_at": "2026-10-27T09:15:02Z" },
        "live": { "status": "missing" }
      }
    }
  ]
}

status is set or missing. origin and updated_at appear only when a value exists. The response never carries a value.

Set a Supplied Secret

PUT /v4/system/component/{ref}/secrets/{name}
X-Project-Env: dev

Request body:

{ "value": "s3cr3t-password" }

Response: 200 OK

{ "name": "smtp_password", "env": "dev" }

Error Responses:

  • 422 Unprocessable Entity — the secret is generated (use rotate), the value is shorter than 8 characters or longer than 32 KiB, or the name is not declared
  • 403 Forbidden — caller lacks secrets::write <ref>

Rotate a Generated Secret

POST /v4/system/component/{ref}/secrets/{name}/rotate
X-Project-Env: live

Generates a new value for the environment named by X-Project-Env (live when the header is absent). There is no request body.

Response: 200 OK

{ "name": "session_key", "env": "live" }

The response never carries the new value.

Error Responses:

  • 422 Unprocessable Entity — the secret is supplied (set a new value instead), or the name is not declared
  • 403 Forbidden — caller lacks secrets::write <ref>

Templates and Copies

Copying a component into another project, or installing it from a template, carries the declarations only:

  • generated secrets are created fresh in the new project;
  • supplied secrets start as missing.

A template's secrets may hold only secretgen::<generator>, secret:: and secretref::. A template that carries a value (secret::<value>) is refused when it is published.


Install Scripts

A Forge install script declares secrets in the settings it already writes. Generated secrets need nothing more, and the app never sees the value. For a supplied secret, pass it from an app variable for the environment the script runs in:

{ "secrets": { "smtp_password": "secret::${$variables.SMTP_PASSWORD}" } }

Running the script again with a changed variable updates the secret; an unchanged one is a no-op.

The SDK's Component class (@ptkl/sdk/beta) also has getSecrets() for the status read, setSecret(name, value, env?) and rotateSecret(name, env?), for use in install scripts.