Skip to content

The secrets gateway

A secret with inject is served by the daemon’s proxy. A client calls the gateway without a credential, and the daemon forwards the request over HTTPS to the secret’s host with the header set. The client never holds the value.

kind: secret
name: anthropic
spec:
encrypted: |
...
inject:
hosts: [api.anthropic.com]
header: x-api-key
value: "{value}"

hosts is required and the gateway forwards to the first. header defaults to Authorization and value to Bearer {value}, where {value} stands for the secret. A value without {value} is an Error. With inject the secret’s name and namespace must be DNS labels, see Naming.

The name is <name>.<namespace>.secret.runy.localhost, or <name>.secret.runy.localhost for a top-level secret. The secret’s status.url is http://anthropic.secret.runy.localhost, with :<proxy port> when the proxy does not listen on port 80. The URL is published as soon as the secret has inject, before it has a value, so a resource that reads ${ secret.anthropic.status.url } does not wait for the value.

Terminal window
curl http://anthropic.secret.runy.localhost/v1/models

goes to https://api.anthropic.com/v1/models. A domains entry, the daemon’s API or another secret cannot hold the same name: the second to take it gets an Error naming the first.

Most API clients take a base URL. Give them the gateway’s URL and any placeholder as the key, since the gateway replaces the header. In a process spec read the URL from the secret:

kind: process
name: agent
spec:
cmd: ./agent
env:
ANTHROPIC_BASE_URL: ${ secret.anthropic.status.url }
ANTHROPIC_API_KEY: unused

For git over HTTPS, set inject to the header the host takes and have git rewrite the host’s URLs to the gateway’s. With GitHub the header is Authorization: Basic with x-access-token:<token> encoded in base64, so the secret’s value is that encoded string and inject.value is Basic {value}:

Terminal window
git config --global url."http://github.secret.runy.localhost/".insteadOf "https://github.com/"

A package registry takes the same approach: put the gateway’s URL where the registry’s URL goes, for instance npm’s registry=http://npm.secret.runy.localhost/ in .npmrc, and let inject set the header the registry expects.

  • The request goes to the first of inject.hosts, port 443, whatever host, absolute-form target or x-forwarded-host the client names. The certificate is checked for that name against the public roots built into runy.
  • HTTP/2 is used when the host offers it, else HTTP/1.1. Request and response bodies stream.
  • Every copy of the configured header that the client sent is removed, whatever its case, and the header is set to the secret’s value. The value is read for each request, so a rotated value is used by the next request.
  • No X-Forwarded-* or Forwarded header is sent.
  • Redirects are returned to the client, never followed.
  • A response header that contains the value is dropped.
  • A request from a browser, one with an Origin or a Sec-Fetch-* header, is refused. Browsers add one of them to every request, also to image loads and navigations.
  • The gateway’s names are not announced to mesh peers, and CONNECT does not reach them. Only clients on this computer (loopback) are served.

Each request is written to the secret’s journal with its method, its path without the query, the status, the upstream and the caller (local <address>, or machine <name> for a request carried over a machine’s link). A header, the query and the value are never written.

Besides the host’s own responses the gateway answers:

status when
403 the request is from a browser; or, from a machine, the vm does not grant the secret with proxy: true
503 the secret has no value yet: it is resolving, or its source failed. The body names the secret
502 the host cannot be reached; the body has the error
500 the value cannot be sent in a header
400 a bad request target
404 in a machine, a name that is not a gateway name or that no secret holds

No answer contains the value.

Any process on this computer can send requests through a gateway name. The gateway keeps the value from being read, not the credential from being used. Bodies are not inspected: a host that echoes the credential in a response body hands it to the client. Journals mask exact occurrences of a value, which does not cover a transformed one.

A WebSocket upgrade works. The upgrade request goes over an HTTP/1.1 connection with the header set, and once the host answers 101 both connections are copied into each other.

A machine reaches the gateway at the same URL on its own proxy, for the secrets its vm lists with proxy: true. See Secrets in machines.