drift Docs
Pages
drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Moving off Azure
Estimate, snapshot and transform a resource group.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Teams
More than one person on one account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

Backbone Secrets

Encrypted at rest with AES-256-GCM. Declare the secret with a secret block, name it in the secrets list of each function that may read it (see the Driftfile's function reference), then read it with the SDK:

Driftfile
backbone {
  secret "STRIPE_KEY" {
    value = env("STRIPE_KEY")
  }
}

atomic {
  backend "default" {
    function "POST /charge" {
      handler = "PostCharge"
      memory  = "32MiB"
      secrets = ["STRIPE_KEY"]

      auth {
        api_key = env("CHARGE_KEY")
      }
    }
  }
}

A secret's value is always env("NAME"): the file names the environment variable the value is read from at apply and never holds the value. The variable comes from the terminal, then --var NAME=value, then .env.<environment>, then .env beside the Driftfile. A literal, a var. reference or a file() is refused, and the refusal never prints the value. A function reads only the secrets its own secrets list names, though the slice holds more.

Go
key, _ := drift.Backbone.Secret.Get("STRIPE_KEY")

Before the subprocess starts, the runner fetches each declared secret and injects it twice: as the environment variable DRIFT_SECRET_<NAME> with the name uppercased, which is what Secret.Get reads, and inline in the request envelope's secrets field. Every language but Go exposes that field directly as req.secrets (or the local equivalent); Go's generated Request struct does not declare it, so a Go function reads a secret through Secret.Get only.

Shell
drift backbone secret set    STRIPE_KEY=sk-123abc
drift backbone secret get    STRIPE_KEY
drift backbone secret list
drift backbone secret delete STRIPE_KEY

The Driftfile is the whole list of the slice's secrets. A secret is write-only, so drift plan never compares a value: a declared secret the slice already holds is set again from its variable on apply, and one whose variable is not set is marked ! and stops the apply before anything is sent. A secret the slice holds that the file does not name appears as - secret NAME deleted, and drift apply asks before removing it (--approve-remove "secret NAME" answers without a terminal). The slice holds at most limits.secrets secrets, each no larger than limits.secret_size.

Replacing a secret keeps the value it replaced readable for 24 hours. That is for a credential your handler verifies rather than presents: a webhook signing secret's sender keeps signing with the old value until they catch up, and checking only the current one would reject every request in between as forged. Read it with Secret.Previous, and ask whether the window is open with drift backbone secret previous KEY.

At runtime a function reads secrets and does not create them. The subprocess starts with a cleared environment and never holds the slice's internal token, so a secret the function did not declare cannot be fetched over HTTP, and Secret.Set answers 401. Secrets are provisioned out of band: by drift apply, from the secret blocks of the Driftfile, or directly with drift backbone secret set. A secret set directly and not declared is deleted by the next apply, so declare every secret the slice should keep.

That makes Secrets the right home for a value your app must keep stable across cold starts, like a signing key: generate it out of band, declare it, then read it, validating the length so a missing or unreadable secret fails loudly instead of signing with garbage. Because apply sets a declared secret from its variable each time, keep the generated value where the variable is read from, such as a .env file you do not commit, and the key stays the same from one apply to the next.

# generate once, out of band, never from inside a function
echo "SIGNING_KEY=$(openssl rand -hex 32)" >> .env
Driftfile
backbone {
  secret "SIGNING_KEY" {
    value = env("SIGNING_KEY")
  }
}
Go
// Driftfile: function "POST /sign", handler = "PostSign", secrets = ["SIGNING_KEY"]
func signingKey() ([]byte, error) {
    hex, err := drift.Backbone.Secret.Get("SIGNING_KEY")   // from DRIFT_SECRET_SIGNING_KEY
    if err != nil || len(hex) != 64 {
        return nil, fmt.Errorf("SIGNING_KEY missing or malformed")
    }
    return decodeHex(hex)
}

If all you need is a token for user sessions, you don't need a key of your own at all: the platform's JWT signing key is managed for you.