Skip to content
Browse documentation

Workload identity

Fly.io workloads

Authenticate a Fly Machine to one Bulgur environment using its signed workload identity.

Before you start

Fly workload identity requires Bulgur CLI or SDK 1.3.0 or newer and a Bulgur Cloud project and workload identity policy. The workload must run on a Fly Machine with access to its local /.fly/api socket.

Fly tokens have been verified against a local Bulgur API; hosted Bulgur Cloud has not been tested end to end.

Create a Bulgur identity

In organization settings, create a Fly.io workload identity. Enter the Fly organization slug and the numeric organization ID and app ID represented by Fly's signed token. Select one Bulgur project and one non-Shared environment; inherited Shared values are included.

Bulgur checks the Fly issuer and signed organization and app IDs. App names and environment variables are not used as proof of identity. Changing or disabling the identity invalidates its sessions.

Find the numeric IDs

On the target Machine, run the following local Python script as the same user that will run Bulgur. It requests a token and prints only its issuer, organization ID, and app ID; it does not print the token. These decoded fields are setup hints, not authorization: Bulgur verifies the token signature and claims on exchange. Keep the token private and do not paste it into a website.

python
import base64, http.client, json, re, socket

class LocalConnection(http.client.HTTPConnection):
    def connect(self):
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.sock.settimeout(5)
        self.sock.connect("/.fly/api")

try:
    conn = LocalConnection("localhost", timeout=5)
    conn.request("POST", "/v1/tokens/oidc",
                 body='{"aud":"https://api.bulgur.dev"}',
                 headers={"Content-Type": "application/json"})
    response = conn.getresponse()
    raw = response.read(16385)
    if response.status != 200 or len(raw) > 16384:
        raise ValueError()
    token = raw.decode("ascii").strip().split(".")
    if len(token) != 3:
        raise ValueError()
    claims = json.loads(base64.urlsafe_b64decode(token[1] + "=" * (-len(token[1]) % 4)))
    issuer, org_id, app_id = claims["iss"], claims["org_id"], claims["app_id"]
    if not isinstance(issuer, str) or not re.fullmatch(r"https://oidc\.fly\.io/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?", issuer):
        raise ValueError()
    if not all(isinstance(x, str) and re.fullmatch(r"[1-9][0-9]{0,19}", x) for x in (org_id, app_id)):
        raise ValueError()
    print("Issuer:", issuer)
    print("Organization ID:", org_id)
    print("App ID:", app_id)
except Exception:
    print("Could not retrieve Fly identity details.")

The Machine user must already have access to the Fly socket. Do not make the socket world-writable to bypass a permission error.

Run on a Fly Machine

Use Bulgur CLI 1.3.0 or newer for your Machine architecture. If building from source, build inside the Linux image or cross-compile. The example targets an x86-64 Machine; use the matching architecture for yours. Include the binary in the image, then set the Bulgur identity ID and choose Fly authentication on the Machine. Bulgur requests a fresh token from the local Fly socket for the fixed https://api.bulgur.dev audience; it does not fall back to a stored token.

shell
cd bulgur-cli
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bulgur .
# On the Fly Machine:
export BULGUR_AUTH=fly-oidc
export BULGUR_IDENTITY_ID="YOUR_IDENTITY_ID"
./bulgur run -- ./start.sh

Use the Node SDK

The server-side SDK requires Bulgur 1.3.0 or newer and Node.js 18 or newer; install it with npm install bulgur@^1.3.0. It needs no Fly-specific peer dependency. loadValues returns a request-local object without changing process.env; omit a DSN to use the policy-bound target.

js
const { loadValues } = require("bulgur");

async function main() {
  const secrets = await loadValues({
    auth: "fly-oidc",
    identityId: "YOUR_IDENTITY_ID",
  });
  // Use secrets in your application.
}

main().catch(() => {
  console.error("Could not load secrets");
  process.exitCode = 1;
});

The SDK requests a fresh Fly token for each Bulgur exchange and caches the short-lived Bulgur session in memory. Fly authentication never falls back to token credentials, even with optional mode.

Troubleshooting

If token acquisition fails, confirm the process runs on the intended Fly Machine and its user can access /.fly/api. If exchange is denied, compare the issuer organization slug and numeric organization and app IDs with the Bulgur policy; the values in the Machine token are the ones Bulgur verifies.

Use bulgur pull --auth fly-oidc --identity <identity-id> --out .env --yes to write a private dotenv file. A policy update, disablement or deletion revokes its Bulgur sessions; a Fly source token is single-use for exchange.

Using Railway instead

For a Railway service, you can use a Bulgur runtime-scoped token: create a token bounded to one environment, then configure BULGUR_DSN as a Railway service variable. Treat the DSN as a secret and rotate or revoke the token if exposed. Railway variables can be available during builds as well as at runtime.

text
BULGUR_DSN=bulgur://<runtime-token>@api.bulgur.dev/<org>/<project>/<environment>