Environment Variables
Zerops manages environment variables at two scopes (project and service) with strict build/runtime isolation. Variables are set via zerops.yml, import.yml vault, GUI, or API. Project vars auto-inherit into every runtime service — read them directly, no declaration. Managed services (databases, caches, search, queues, storage) do not receive project vars. Cross-service (sibling) vars do NOT auto-inject under the default envIsolation=service — reference a sibling's value explicitly as ${hostname_varname} in run.envVariables (siblings are injected as bare <host>_KEY vars only when the owning service shares them via none or service@<reader-hostname>). Every user-defined var, project or service, is plain or sensitive. Sensitive values are encrypted at rest and plain text inside containers; the API returns REDACTED for them unless the request is in sudo mode and the role isn't read-only. A running process keeps its boot-time env — restart it (not reload) to pick up a changed value. Adding or editing more than one variable? Use the .env file endpoint — one request and one process for the whole set, never one request per variable.
Scope Hierarchy
| Scope | Defined In | Visibility | Editable Without Redeploy |
|---|---|---|---|
| Project (plain or sensitive) | import.yml project.vault, GUI, API | All runtime services (auto-inherited), not managed services | Yes (restart to apply) |
| Service custom / secret (plain / sensitive) | import.yml vault, dotEnvVariables, dotEnvSecrets, GUI, API | Single service | Yes (restart to apply) |
| Service basic (build) | zerops.yml build.envVariables | Build container only | No (redeploy required) |
| Service basic (runtime) | zerops.yml run.envVariables | Runtime container only | No (redeploy required) |
Bulk Changes — Use the .env File Endpoint
When you add, edit or delete more than one variable, send them all at once as a .env file. Each single-variable API call starts its own process, so setting 30 variables one by one starts 30 processes. The env file endpoint applies the whole set in one request and one process. In the GUI, the equivalent is the bulk editor on the Environment variables page.
Look up the env file endpoints by operation ID in the OpenAPI spec (plain-text YAML; search it for the ID to get the current path and request body):
| Scope | Read the file | Write the file |
|---|---|---|
| Service | GetUserDataEnvFileForEdit | UpdateUserDataEnvFile |
| Project | GetProjectEnvFileForEdit | UpdateProjectEnvFile |
The sensitive flag picks the group. Variables are either sensitive or non-sensitive, and each request works on one group only. A PUT makes that group match the file exactly:
- Keys in the file are upserted (created or updated).
- Keys in the group that are not in the file are deleted.
- A key that already exists in the other group makes the request fail.
Workflow:
GETthe current file for the group (sensitive=trueorfalse). It comes back in exactly the form thePUTaccepts. Reading sensitive values requires sudo mode.- Edit the file: add, change or remove
KEY=valuelines. PUTthe whole file back with the samesensitivevalue:
- Wait for the single returned process, then restart the affected services once.
DO NOT loop over variables and call the single-variable endpoint for each one. DO NOT PUT only the new or changed keys: every key of the group left out of the file is deleted. Use the single-variable endpoints only when changing exactly one variable. When creating services, set the variables in import.yml with vault, dotEnvVariables or dotEnvSecrets (see Import: vault and .env keys).
Variable Precedence
Total order for the bare key (highest wins): system/platform > yaml-baked run.envVariables > service custom/secret var > project.
- yaml-baked
run.envVariablesowns its key — a service custom or secret var set on the same key is rejected (userDataDuplicateKey); the two never coexist. To change a yaml-baked value, editzerops.ymland redeploy. - Service-level wins over project-level.
- Build and runtime are separate environments -- same key can have different values in each.
DO NOT set a custom or secret service var on a key already declared in run.envVariables — the platform rejects it. The yaml var owns the key; edit the yaml and redeploy instead.
Build/Runtime Isolation
Build and runtime run in separate containers. Variables from one phase are not visible in the other unless explicitly referenced with prefixes:
| Want to access | From | How |
|---|---|---|
Runtime var API_KEY | Build container | ${RUNTIME_API_KEY} — runtime run.envVariables are known at build time, so the build can read them |
Build var BUILD_ID | Runtime container | Not available. The build container is destroyed after build and its vars are not carried into the runtime env store — ${BUILD_BUILD_ID} reaches the runtime process as the literal string ${BUILD_BUILD_ID}. Persist the value into a deployed file, or recompute it at runtime. |
Cross-Service References — Explicit ${hostname_varname} Required
Under the default envIsolation=service, a service does NOT automatically see another service's variables — not even a managed database's connection vars. To use a sibling's value, reference it explicitly in run.envVariables; the left-hand key is the name your app reads, the right-hand ${hostname_varname} is the source:
- The reference resolves at container start, independent of isolation mode — the referenced var does not need to exist at definition time.
- An unresolved ref stays literal (
${db_hostname}reaches the process verbatim) — no error, no blank. A wrong hostname/var on the right-hand side becomes a literal string and the app fails at connect time. - Hostname charset: service hostnames are lowercase alphanumeric only (
[a-z0-9]) — the platform rejects dashes, underscores, and uppercase withserviceStackNameInvalid. So a ref is simply${hostname_varname}with the literal hostname (servicecache→${cache_port}); there is no dash-to-underscore rewrite to reason about, because a dashed hostname cannot exist.
Sibling vars are auto-injected as bare <host>_KEY OS env vars only when the owning service shares them, via none or a service@<reader-hostname> grant — see Isolation Modes. New projects are service; rely on explicit refs.
Cross-Service References in API vs Runtime
Cross-service references (${hostname_varname}) are resolved at container start time, not at definition time:
zerops_discoverwithincludeEnvs=truereturns the literal template (e.g.,${db_password}), NOT the resolved value. The service-env API stores templates, not resolved values, and returns only the service's own user-set + intrinsic vars — yaml-bakedrun.envVariablescome from the app-version, project vars from the project scope. Assemble across scopes (or read in-container) for the effective env.- Inside the running container, environment variables contain the actual resolved values.
- Restarting a service does NOT change what
zerops_discoverreturns — it always shows templates. To verify resolved values, check from inside the container.
Isolation Modes (envIsolation)
envIsolation is a space-separated rule list set at project scope and optionally overridden per service (the service value replaces the project value, no merge). It is owner-side and directional: a service's own rules decide who sees ITS vars. The reader's rules never widen what the reader receives, so a compromised container cannot grant itself access to sibling secrets.
| Rule | Behavior |
|---|---|
service (default) | Siblings are isolated. A service sees only its own vars + project vars (runtime services only) + the explicit ${hostname_varname} refs it declares in run.envVariables. Managed-service connection vars also require an explicit ref. |
none | Every service sees this service's vars as bare <host>_KEY OS env vars. Broad — prefer service@name for new projects. |
service@name | The service with hostname name additionally sees this service's vars as bare <host>_KEY vars. |
-service@name | The service with hostname name never sees this service's vars, even when none is present. |
Evaluation for reader R against owner O's rules: -service@R → hidden, else service@R → visible, else none → visible, else hidden. A service always sees its own vars.
Set in import.yml at project or service level:
project:
envIsolation: service@zcp # zcp sees every service that inherits this value
services:
- hostname: db
envIsolation: none # per-service: expose THIS service's vars to all siblings
- hostname: api
envIsolation: service # per-service: opt out of the project grant, nobody sees api vars
- hostname: cache
envIsolation: none -service@api # everyone except api sees cache vars
Default (service) is the right choice. Wire cross-service explicitly with ${hostname_varname} — it works in every mode, so code stays correct if isolation ever changes. When one tooling or admin service needs broad read access, grant it with service@<hostname> at project level instead of switching to none.
Project Variables -- Auto-Inherited
Project variables are automatically available in every runtime service, in both runtime AND build containers — injected as OS env vars at container start.
Managed services do NOT receive project variables: PostgreSQL, MariaDB, MySQL, ClickHouse, Valkey, Kafka, NATS, Elasticsearch, Meilisearch, Typesense, Qdrant, Object Storage and SeaweedFS. Their own vars, ${hostname_varname} references to other services' vars, and envIsolation work as usual.
In runtime services, read them directly from application code (process.env.API_URL). From zerops.yaml, reference them by name with ${VAR_NAME} — no RUNTIME_ prefix (that prefix is only for lifting a service's own runtime var into its build context).
In shell commands (buildCommands, initCommands, start) project vars are directly readable:
In build.envVariables / run.envVariables YAML (to forward a project var under a framework-conventional name) reference it directly without prefix:
To override a project variable for one service, define a service-level variable with the same key and a DIFFERENT VALUE (not a reference to the project var):
Self-Shadow Trap — same name on both sides
Writing varname: ${varname} (the left key identical to the source on the right) is always wrong:
The interpolator sees the service-level variable of that name first, can't recurse back to the inherited/referenced value, and the OS env var resolves to the literal string ${varname} — the app then connects to "${db_hostname}:5432" and crashes.
- For a project var you only want to read: delete the line — it already auto-inherits.
- For a cross-service value: use a different left-hand name (
DB_HOST: ${db_hostname}), never the same name.
Typical pattern: project-level URL constants for dual-runtime recipes
Dual-runtime recipes (frontend SPA + backend API) use project-level URL constants as the single source of truth for cross-service URLs, derived from ${zeropsSubdomainHost} (a platform-generated project-scope var present from project creation):
The frontend consumes API_URL via plain ${API_URL} in build.envVariables (baked into the bundle at compile time). The API consumes FRONTEND_URL via plain ${FRONTEND_URL} in run.envVariables (CORS allow-list). Set the same names on the workspace project via zerops_env project=true action=set after provision.
Secret (Sensitive) Variables
- Every user-defined var, project or service, has a
sensitiveflag. Sensitive = "secret": encrypted at rest with a per-project key, masked in the GUI, plain text inside the containers (the app needs it). Plain = "custom" var. - Set via GUI (Secret variables section), import.yml (
vaultwithsensitive: true,dotEnvSecrets), or API (sensitive: true).sensitivedefaults tofalsein every API request body — omit it and the var is stored plain. - A sensitive system var (e.g. a generated database password) cannot be changed to plain.
- Can be updated without redeploy, but the service must be restarted to pick it up.
- A yaml-baked
run.envVariableskey and a secret on the same key cannot coexist — the platform rejects the secret withuserDataDuplicateKey. The yaml owns the key; edit the yaml and redeploy to change it.
Reading Sensitive Values
Endpoints below are named by operation ID; search the OpenAPI spec for the ID to get the current path.
- List and detail endpoints return
REDACTEDfor a sensitive value unless the request is in sudo mode AND the role is not read-only. The read-only role never gets the value. - Reveal one value:
GetUserDataSensitiveValue(service var) orGetProjectEnvSensitiveValue(project var). Both require sudo mode. - Sudo mode: a GUI user enters it by re-authorizing. An API token has it only if created with
sudo: true, and creating such a token itself requires sudo mode. A token without sudo always getsREDACTED. - Export (
ExportProject,ExportServiceStack) writes sensitive entries asvalue: REDACTEDunless called withreveal=true(sudo mode). The project env file endpoint (GetProjectEnvFile) takes the samerevealparameter.
API Request Bodies
- Single-variable create and update (service and project vars) accept
sensitive(defaultfalse). Responses includesensitive,editableandinternal. - Project create:
envVariables(plain) andenvSecrets(sensitive), each an array of{key, content}. - Service create and trigger-pipeline:
envVarsFile(plain) andenvSecretsFile(sensitive), both.envtext.userDataEnvFileis deprecated. - Env file read/write: see Bulk Changes.
DO NOT re-import an export containing value: REDACTED — the literal string REDACTED is stored as the value. Export with reveal=true or fill the values in first.
Import: vault and .env Keys
Import.yml keys for env vars (project and service level unless noted):
#yamlPreprocessor=on
project:
name: my-project
vault:
LOG_LEVEL: info # plain
services:
- hostname: app
type: nodejs@22
vault:
APP_KEY: # sensitive: block form, never inline {...}
value: <@generateRandomString(<32>)>
sensitive: true
PORT_OFFSET: 10 # unquoted numbers/booleans are accepted
dotEnvSecrets: | # service level only, all entries sensitive
DB_PASSWORD=secure123
dotEnvVariables: | # service level only, all entries plain
MAIL_HOST=smtp.example.com
- A
vaultentry is eitherKEY: value(plain) or an object with onlyvalueandsensitive. Any other key in the object is rejected — a typo likesensitvefails the import, so a secret is never silently stored as plain. - Write sensitive entries in block form, never inline
{ value: ..., sensitive: true }. Preprocessor functions can contain commas and brackets that break inline YAML. envVariablesandenvSecretsare deprecated at both levels but still accepted. Export always writesvault.- Requires
#yamlPreprocessor=onif using generator functions.
envReplace -- File-Level Substitution
Replaces placeholders in deployed files with environment variable values during deployment (not at runtime).
| Parameter | Required | Description |
|---|---|---|
delimiter | Yes | Wrapping characters (e.g., %% makes %%VAR%%). String or array |
target | Yes | Files or directories to process. String or array |
DO NOT expect directory targets to recurse into subdirectories. ./config/ processes only files directly in config/, not config/jwt/. Specify each subdirectory explicitly.
Naming Restrictions
Key: must match [a-zA-Z_]+[a-zA-Z0-9_]*. Case-sensitive. Must be unique within scope regardless of case.
Value: ASCII only. No EOL characters.
Restart Requirement
An env-store change (secret or project) propagates to the container in ~5–10s without a redeploy, but the running process keeps its boot-time environ — only newly-spawned processes see it.
DO NOT expect hot-reload of env vars. After changing secrets or project vars, restart the service (not reload — reload does not re-read env for the running process; PHP-FPM keeps its boot config). For zerops.yml run.envVariables changes, a full redeploy is required (they are baked into the app version).
System-Generated Variables
Zerops auto-generates variables per service (e.g., hostname, PATH, DB connection strings). Some are hard-reserved and rejected if you try to set them — PATH returns userDataUseOfSystemKey in any envVariables block. System keys and the ZEROPS_ prefix are matched case-insensitively, so path and zerops_foo are rejected too. config is reserved for both project and service variables. port is not reserved on runtime services. Overridable platform vars include envIsolation / sshIsolation / zeropsSubdomainHost (and the CDN URLs) — but never PATH. Reference any of them from another service with an explicit ${hostname_varname}.