Run identity
Every function, component and workflow runs as an explicit identity. That identity is the code's run_as. The code gets the identity's permissions and role memberships, never more. It does not run with the permissions of whoever last saved it or triggered it.
Whoever can change a piece of code acts as its identity and reads its secrets. The code gives them nothing they lack. Choosing the identity is the decision the platform checks. What goes into the code is your project's own review. See the security model for what stays with you.
Identities
run_as holds the identity as a PRN:
| PRN | Identity |
|---|---|
prn:role:<uuid> |
A project role |
prn:role:maintainer |
The project's Maintainer role. The alias resolves per project, so code copied between projects keeps working |
prn:api-user:<uuid> |
An API user |
prn:forge:<app-uuid> |
A Forge app. Only the app's own install and update flows, and its pages when the Owner or a Maintainer uses them, choose it. See Forge apps |
These are never identities:
- A user, or an OAuth token. An OAuth token that writes code chooses an identity as its user would.
- A role with admin rights, or an API user that holds one. Code never runs with the Owner's authority.
- An API user created by an OAuth grant.
Each container has one identity:
| Container | Identity covers |
|---|---|
| Platform function | The function |
| Component | Its functions, its extension functions, its event graph and its extension workflows |
| Workflow | Its code nodes and its Kortex nodes |
A component's identity belongs to the component, not to a version. Publishing or forking a version never changes it, and dev and live run as the same identity.
Code runs with the identity's current permissions and role memberships. Widening or narrowing the identity reaches the code at its next run.
Every GET of a function, component or workflow includes run_as.
Code with no identity
Code saved before run identities existed has no run_as. It runs as Maintainer. Only the Owner and Maintainers can change it until one of them gives it a narrower identity. The dashboard says:
This code has no run identity, so only the Owner and Maintainers can change it until one of them gives it a narrower identity.
Narrowing it is your project's call. Pick the narrowest identity the code needs.
Choosing an identity
You can choose an identity only if you hold it:
- Any role you are a member of.
- The Owner and Maintainers:
prn:role:maintainer, any role that isn't an admin role, and any API user. - An API user: itself.
- Code running as an identity: whatever that identity may choose.
Membership counts, not matching permission strings. Field policies match roles, so holding the same permissions in another role is not enough.
The identity picker in the dashboard lists only identities you may choose. It says:
Roles you are not a member of are left out of this list. Anyone who can edit this code can act as its run identity, so pick the narrowest identity the code needs.
If you may not choose any identity yet, it says:
You may not choose any identity yet. Ask the Owner or a Maintainer to add you to a role.
The same rule applies to every client: the dashboard, the API, the toolkit and OAuth clients.
Creating code without an identity
New code with no run_as runs as Maintainer. Only the Owner and Maintainers can choose that. Anyone else must name an identity they may choose.
The dashboard always sends one. It asks:
A run identity is required. Pick one of the identities in the list before saving.
The API refuses with 403 identity_required:
{
"code": 403,
"error": "identity_required",
"message": "identity required: pass run_as naming one of the listed identities (toolkit: --run-as <prn>)",
"identities": [
{ "prn": "prn:role:5f0c1c1e-2a58-4a38-a7c1-7d2f3a1f8b11", "kind": "role", "name": "Editors" }
]
}
identities lists what the caller may choose. It can be empty. Send one of them as run_as at the top level of the create body.
The toolkit takes --run-as <prn> on ptkl functions create, ptkl component create and ptkl workflow create. Interactively it asks you to pick from the list. Without a terminal it needs the flag:
ptkl functions create -d '{"name":"send_welcome_email"}' \
--run-as prn:role:5f0c1c1e-2a58-4a38-a7c1-7d2f3a1f8b11
Without --run-as and without a terminal, the toolkit sends no identity: the code runs as Maintainer if you are the Owner or a Maintainer, and anyone else gets this 403. The toolkit prints the identities you may choose and ends with Pass one with --run-as <prn>.
To list your choices first: GET /v1/system/run-identity/choices returns { "identities": [...] }.
Choosing an identity you don't hold
The API refuses with 403 identity_not_held, naming the identity:
{
"code": 403,
"error": "identity_not_held",
"message": "identity not held: prn:role:5f0c1c1e-2a58-4a38-a7c1-7d2f3a1f8b11",
"identity": "prn:role:5f0c1c1e-2a58-4a38-a7c1-7d2f3a1f8b11"
}
The dashboard says:
You do not hold the run identity {identity}. You must be a member of it to choose it or to change code that runs as it. Choose an identity you hold, or ask the Owner or a Maintainer.
The fix: choose an identity you hold, or ask the Owner or a Maintainer.
The same 403 applies to changing code that already runs as an identity you don't hold, even if you leave run_as alone.
A template installation's identity answers 403 identity_locked to everyone. See Templates.
Changing the identity
The new identity may lack what the code uses, and the code then breaks. The dashboard asks for confirmation first and lists what the code loses:
The code will run as {identity} instead of {from}. It loses the following. Nothing is saved until you save.
under Permissions lost and Role memberships lost. If the new identity covers everything: "The code loses nothing by moving to {identity}."
Changing run_as needs you to hold both the current and the new identity.
For the API, GET /v1/system/run-identity/check?run_as=<prn> takes the run_as you plan to set. On its own it only checks that you may choose that identity, and returns it as { "identity": { … } }.
To learn what the code would lose, also pass stored=<current run_as>, the identity the code runs as now (empty for Maintainer). Add code_changed=true when the same save changes the code, and create=true when the code is new. The answer is then a decision, and for a change it lists what the code would lose:
{ "run_as": "prn:role:…", "changed": true, "loses": { "permissions": ["edit orders"], "memberships": ["<role-uuid>"] } }
A save that doesn't carry run_as keeps the stored identity. Existing clients keep updating code as before. A run_as that differs from the stored one is a change and follows the rules above.
Toolkit: --run-as <prn> on ptkl functions update, ptkl component update-settings and ptkl workflow update.
What changing code needs
Changing code needs the permission the action needs today, plus everything the code receives:
- Its run identity, as above.
- The read on its own secrets, when it has any:
| Code | Extra permission |
|---|---|
| A component that declares secrets | secrets::read <ref>, on top of settings <ref> |
| A function whose env has encrypted values | secrets::read base_functions, on top of manage base_functions |
| A Spark whose env has encrypted values | spark::secrets::read sandbox, on top of the deploy permission |
The Owner and Maintainers hold these. For anyone else, add them to a role.
These paths change code: create, update, clone, fork, schema fork, install in place, a dry run with nodes in the body, options.expression on a component function run, and changing run_as. Deleting code, publishing a component version, reading, and running saved code keep their usual permissions.
When you lack the read permission the API refuses with 403 permissions_not_held, naming it:
{
"code": 403,
"error": "permissions_not_held",
"message": "permissions not held: requires secrets::read base_functions",
"missing": ["secrets::read base_functions"]
}
The dashboard says:
You lack the permissions this needs: {missing}. Ask the Owner or a Maintainer to grant them, or choose an identity that has them.
Read-only editors
When you open code you may not change, the code editors are read-only and say why. Settings that aren't code stay editable. The banner starts "The code is read-only:" and continues with one of:
| Reason | Text |
|---|---|
| Identity not held | it runs as {identity}, which you do not hold. Choose an identity you hold to change it, or ask the Owner or a Maintainer. |
| Template identity | it runs as {identity}, which belongs to a template installation and cannot be chosen by hand. |
| Identity gone | the identity it ran as ({identity}) no longer exists. Choose another run identity below, and the code can be changed. |
| Secrets read missing | it receives secrets and you lack {missing}. Ask the Owner or a Maintainer for the permission. |
| Owner only | only the Owner may change it. |
| Access not checked | access could not be checked, so the code is read-only. Settings that are not code stay editable. |
Component dry run
A dry run of posted nodes against a component runs as that component's identity only for a caller who holds settings <ref> on it and everything else above. Without settings <ref> it is refused with 403 permissions_not_held naming settings <ref>. The dashboard says:
A dry run of this component needs {permission}. Ask the Owner or a Maintainer to grant it.
The fix: get settings <ref> on that component, or name an identity you may choose for the dry run.
options.config on a component function run stays a run input, with the usual run permission. It needs settings <ref> only when the component declares secrets or the run receives encrypted global env.
Code whose identity is gone
An identity can go away: a template or Forge app is uninstalled, or a role or API user is deleted. A role or API user that is some code's identity can't be deleted while it is in use. The delete is refused with 409 identity_in_use, which lists where it is used:
code still runs as this identity: move it to another identity first
Code whose identity is gone is refused when it runs or when you change it, with 409 identity_gone:
{
"code": 409,
"error": "identity_gone",
"message": "the identity this code runs as no longer exists: pass run_as naming another one",
"run_as": "prn:api-user:…",
"reassign_by": "editor_holding_new_identity"
}
The fix: pass run_as naming another identity you hold. Anyone who may edit the code and holds the new identity can reassign it.
In the dashboard, the code's editor says the identity no longer exists. Choose another run identity there, and the code can be changed again.
GET /v1/system/run-identity/gone lists this code for the Owner and Maintainers. Anyone else gets 403.
Workflows and Kortex
A Kortex node is checked when it runs, against the run identity. See Kortex nodes and the run identity.
Forge apps
Code that a Forge app creates runs as the app's identity, prn:forge:<app-uuid>. It holds the app's approved permission set. No person holds that identity, so nobody changes that code by hand. The app's install and update flows change it. So do the app's own pages, but only when the Owner or a Maintainer uses them: they may create and change the app's code as the app. A member's view of a page, and a public view, cannot. See Forge security.
Inputs are untrusted
Treat every input as untrusted: request bodies, query strings, payloads, event data, options.config. Code that lets an input choose where data goes, or skip a check, is a bug in that code. Run identity limits what the code can reach. It does not make a bad destination or a skipped check safe.
- Don't build a collection name, URL or ref from an input without checking it against a fixed list.
- Don't let an input switch off a permission or validation step.
- Choose the narrowest identity the code needs.