Kyora Docs

Secrets

Let sandboxes call an API with your key through kyora's egress broker, or deliver a secret into them as an env variable or a file.

Account secrets are stored once in kyora and reach sandboxes in one of two ways:

  • Bindings (the safe default): code in the sandbox sends its request to kyora's egress broker, at $KYORA_EGRESS_URL/<binding id>/<path>. The broker adds the secret as the binding says and passes the request on to the binding's host. The value never enters the sandbox. A request sent straight to the API's own URL gets nothing added.
  • Deliveries: the value is placed in the sandbox, as an env variable or a file, for software that has to hold it. Code in the sandbox can read it.

The examples use the API with curl and jq, and a token with full access in KYORA_TOKEN (create one in the dashboard under Tokens; scoped tokens can't manage secrets):

export KYORA_TOKEN=<your token>
export API=https://cloud.kyora.sh/v1

Bind a secret to an API

The example uses Postman's echo service: https://www.postman-echo.com/basic-auth answers 200 to the user postman with the password password, and 401 to anything else. Create the secret, naming the hosts it may ever be sent to:

SECRET=$(curl -sS "$API/secrets" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"name":"ECHO_PASSWORD","value":"password","hosts":["www.postman-echo.com"]}' | jq -r .id)

Bind it: on which host, how it goes into the request (here HTTP Basic, as the user postman), and which sandboxes may use it (here, those labelled app=demo). The answer carries the binding's id:

BINDING=$(curl -sS "$API/secrets/$SECRET/bindings" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"host":"www.postman-echo.com","injection":{"type":"basic","username":"postman"},"scope":{"labels":{"app":"demo"}}}' | jq -r .id)

Start a sandbox that may use bindings (proxySecrets). It gets KYORA_EGRESS_URL and KYORA_EGRESS_TOKEN in its environment; a request to the broker carries that token:

SANDBOX=$(curl -sS "$API/sandboxes" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"vcpus":2,"memoryMb":4096,"ttlSeconds":900,"network":"registries","egressAllow":["www.postman-echo.com"],"labels":{"app":"demo"},"proxySecrets":true}' | jq -r .id)
kyora vms exec "$SANDBOX" -e BINDING="$BINDING" -- sh -c 'curl -s -o /dev/null -w "%{http_code}\n" -H "authorization: Bearer $KYORA_EGRESS_TOKEN" "$KYORA_EGRESS_URL/$BINDING/basic-auth"'
kyora vms exec "$SANDBOX" -- curl -s -o /dev/null -w '%{http_code}\n' https://www.postman-echo.com/basic-auth

The first prints 200: the broker added the password, which no command in the sandbox had. The second, straight to the API, prints 401.

The ways a binding injects a secret:

injectionSent as
{"type":"header","name":"x-api-key"}the header, holding the secret (a template such as "Bearer {{secret}}" wraps it)
{"type":"basic","username":"api"}HTTP Basic, with the secret as the password
{"type":"query","name":"key"}a query parameter

A binding can also narrow the request: pathPrefix (default /), methods (default all) and expiresAt (epoch milliseconds). Its scope names the sandboxes it applies to: sandboxes (ids), labels (all of them must match), images (account image ids), or several of these.

Deliver a secret into sandboxes

A secret that may be placed in sandboxes is created with "sandbox": true (its hosts may then be empty):

DB=$(curl -sS "$API/secrets" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"name":"DB_PASSWORD","value":"example-password","hosts":[],"sandbox":true}' | jq -r .id)
curl -sS "$API/secrets/$DB/deliveries" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"env":"DB_PASSWORD","scope":{"labels":{"app":"demo"}}}'
curl -sS "$API/secrets/$DB/deliveries" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"file":"db-password","scope":{"labels":{"app":"demo"}}}'

A sandbox asks for the deliveries it takes when it is created:

WORKER=$(curl -sS "$API/sandboxes" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' \
  -d '{"vcpus":2,"memoryMb":4096,"ttlSeconds":900,"labels":{"app":"demo"},"secrets":[{"secret":"DB_PASSWORD","env":"DB_PASSWORD"},{"secret":"DB_PASSWORD","file":"db-password"}]}' | jq -r .id)
kyora vms exec "$WORKER" -- sh -c 'test -n "$DB_PASSWORD" && echo env ok; cat /run/kyora/secrets/db-password'

The cat prints asterisks, as many as the value is long: kyora masks a delivered secret's value in exec output, while the value in the sandbox is the real one, so a program reading the file or the variable gets it. The env variable is in every command's environment. The file is /run/kyora/secrets/<file>, with mode 0400 ("mode": 288 on the delivery gives 0440); read it by its name, since the directory itself can't be listed. A delivery's scope must include the sandbox, or its create is refused (secret_not_delivered).

Rotate and revoke

curl -sS -X PUT "$API/secrets/$DB/value" -H "authorization: Bearer $KYORA_TOKEN" -H 'content-type: application/json' -d '{"value":"new-password"}'
curl -sS -X POST "$API/sandboxes/$WORKER/secrets/push" -H "authorization: Bearer $KYORA_TOKEN"

A new value reaches bindings by itself, and a delivered env variable within a minute. Delivered files are replaced within 5 minutes by themselves, or at once by the push (POST /v1/sandboxes/<id>/secrets/push). Deleting a binding, a delivery or the secret (DELETE $API/secrets/<id>) takes it away from sandboxes by itself, files included.

Clean up

kyora vms rm "$SANDBOX" "$WORKER"
curl -sS -X DELETE "$API/secrets/$SECRET" -H "authorization: Bearer $KYORA_TOKEN"
curl -sS -X DELETE "$API/secrets/$DB" -H "authorization: Bearer $KYORA_TOKEN"

On this page