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.

Authentication

A function's auth block is enforced inside your slice, immediately before the function is invoked, not at the platform edge. The edge authenticates nothing on /api/*: it forwards X-API-Key and Authorization through untouched. A 401 or 403 on a function call came from your slice, and it read the same headers your own application code can read.

Declared Behaviour
no auth blockPublic. Anyone can call it.
auth { api_key = env("NAME") }Requires the configured key. Missing credential → 401. Wrong key → 403 (compared in constant time). No key ever set for this function → 503 api key not configured for this function.
Driftfile
slice "orders" {}

atomic {
  backend "default" {
    function "POST /orders" {
      handler = "PostOrders"
      memory  = "32MiB"

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

    function "GET /health" {
      handler = "GetHealth"
      memory  = "16MiB"
    }
  }
}

POST /orders answers only a caller presenting the key held in $ORDERS_KEY when the file is applied; GET /health is public. The Driftfile never holds the key: api_key is written env("NAME") and nothing else, and a literal is refused. The variable is read from the terminal, then --var ORDERS_KEY=..., then .env.<environment>, then .env beside the Driftfile.

The key may arrive as X-API-Key or in Authorization: bare, Bearer <key> or ApiKey <key>. A browser app that cannot set a custom header can use Authorization instead.

Keys and the Driftfile

drift plan lists each declared key beside its function and drift apply sets it, only where the slice holds none or a different one. The slice fingerprints a key by its last four characters, and the plan compares that fingerprint with the key in the variable:

Plan line Meaning
+ function POST /orders key set from $ORDERS_KEYThe slice holds no key for it; apply sets one.
function POST /orders key unchanged (fingerprint matches $ORDERS_KEY)The same key; apply leaves it alone.
~ function POST /orders key rotates to the key in $ORDERS_KEYA different key; apply rotates to it.
! function POST /orders key $ORDERS_KEY is not set here: apply would refuseThe variable is empty in this shell; nothing is sent.

Managing keys outside the file

drift atomic auth sets, lists and revokes keys directly, for a key you would rather not put through an environment variable or for one on a route the file does not gate:

Shell
drift atomic auth set my-function <api-key>      # --method defaults to post
drift atomic auth set my-function <api-key> -m get
drift atomic auth list my-function              # every method's fingerprint for this path
drift atomic auth revoke my-function -m get

set and revoke address one method and path, and --method/-m defaults to post. Revoking without it leaves a key on the GET function at the same path in force. list takes no method: it reports every method configured for the path. A key the file does not declare is left as it is by drift apply.

Setting a key is itself an auth-mode change.

A configured key makes that route apikey-protected even when its function has no auth block; revoking returns it to open. Keys survive a slice restart.

For richer rules (sessions, roles, expiry) mint and verify tokens inside the function with the SDK's drift.Deed.JWT primitive (a per-slice signing key you never have to manage). See the Authentication guide → for the full login → protected-route flow.