> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Log In to the Endpoint with OIDC

> Log in to the Formal Endpoint with OIDC or an API key

## Log In with OIDC

Use OIDC when the Formal Endpoint should authenticate as a machine identity. This flow avoids long-lived Formal credentials on the host.

The Endpoint exchanges source OIDC tokens for short-lived Formal credentials. It refreshes those credentials while the source can provide valid tokens.

**1. Create an OIDC integration**

Create an [OIDC integration](https://docs.formal.ai/docs/guides/integrations/oidc.md) for the workload. Map the integration to a Formal machine user.

Configure a claim condition that restricts access to the intended workload. You can also configure an end-user email expression.

Copy the integration ID after creating the integration.

**2. Configure a token source**

Add one token source to `~/.formal/config.toml`.

> [tab] AWS
>
> Use AWS on hosts with credentials from the standard AWS credential chain.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> provider = "aws"
> integration_id = "integrationoidc_<id>"
> ```
>
> The Endpoint uses the standard AWS credential chain. Supported sources include environment variables, shared configuration, IRSA, EKS Pod Identity, and EC2 instance profiles.
>
> If no region is set in the environment or shared config, the Endpoint uses EC2 instance metadata.

> [tab] Azure
>
> Use Azure on AKS with Workload Identity or on Azure compute with managed identity.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> provider = "azure"
> integration_id = "integrationoidc_<id>"
> ```
>
> Set `AZURE_FEDERATED_TOKEN_FILE` for Workload Identity. Set `AZURE_CLIENT_ID` when using a user-assigned managed identity.
>
> Azure uses the fixed Azure Resource Manager audience. Your integration must validate that audience and the expected Azure identity claims.
>
> This token source does not support Azure DevOps Pipelines.

> [tab] GCP
>
> Use GCP on GKE, Compute Engine, or Cloud Run. You can also use Application Default Credentials for a service account.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> provider = "gcp"
> integration_id = "integrationoidc_<id>"
> ```
>
> On Google Cloud, the Endpoint requests a Google-signed ID token from the metadata server. Elsewhere, it uses Application Default Credentials.
>
> Supported credentials include service account keys, impersonated service accounts, and Workload Identity Federation with service account impersonation. User credentials from `gcloud auth application-default login` are not supported.
>
> On GKE, annotate the Kubernetes ServiceAccount with `iam.gke.io/gcp-service-account`. Google only issues ID tokens for IAM service accounts.
>
> Set the integration issuer to `https://accounts.google.com`. Restrict the claim condition to the expected service account:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> claims.email == "<SERVICE_ACCOUNT>@<PROJECT_ID>.iam.gserviceaccount.com" &&
> claims.email_verified == true
> ```

> [tab] GitHub Actions
>
> Use GitHub Actions on GitHub-hosted or self-hosted runners.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> provider = "github"
> integration_id = "integrationoidc_<id>"
> ```
>
> Grant the job the `id-token: write` permission. GitHub then sets `ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` in each step.
>
> ```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> permissions:
>   id-token: write
>   contents: read
> ```
>
> Start the Endpoint in the background inside the job that uses it, so it inherits these variables. A `run` step, a composite action, or a self-hosted runner [job started hook](https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/run-scripts) all work. In a reusable workflow, start it in each job that needs Formal.
>
> The Endpoint requests tokens with the audience `oidc.formal.ai/<INTEGRATION_ID>`. It fetches a new token before the current one expires, for as long as the job runs.
>
> Create the integration from the **GitHub Actions** preset. Restrict the claim condition to the expected repository:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> claims.repository_owner_id == "<OWNER_ID>" && claims.repository_id == "<REPOSITORY_ID>"
> ```

> [tab] SPIFFE
>
> Use SPIFFE on workloads that get identities from SPIRE or another SPIFFE Workload API.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> provider = "spiffe"
> integration_id = "integrationoidc_<id>"
> ```
>
> Set `SPIFFE_ENDPOINT_SOCKET` to the Workload API address, such as `unix:///run/spire/sockets/agent.sock`. The Endpoint fetches a JWT-SVID with the audience `oidc.formal.ai/<INTEGRATION_ID>` and fetches a new one before it expires.
>
> Create the integration from the **SPIFFE / SPIRE** preset. Set the SPIRE server `jwt_issuer` to the integration issuer. See [SPIFFE and SPIRE](https://docs.formal.ai/docs/guides/integrations/oidc.md#spiffe-and-spire) for the full setup.
>
> Restrict the claim condition to the expected SPIFFE ID:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> claims.sub == "spiffe://<TRUST_DOMAIN>/ns/<NAMESPACE>/sa/<SERVICE_ACCOUNT>"
> ```

> [tab] Environment variable
>
> Use this source when your CI system provides an OIDC JWT. On GitHub Actions, use the **GitHub Actions** source instead so the Endpoint can renew its token.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> env = "GITLAB_OIDC_TOKEN"
> ```
>
> Request `oidc.formal.ai/<INTEGRATION_ID>` as the token audience.
>
> For providers with a fixed audience, also set the integration ID:
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> env = "SPACELIFT_OIDC_TOKEN"
> integration_id = "integrationoidc_<id>"
> ```
>
> The Endpoint reads the variable when it starts. Start it from the same environment:
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> export GITLAB_OIDC_TOKEN="<OIDC_JWT>"
> formal agent --headless
> ```
>
> > [!WARNING]
> >
> > The Endpoint cannot renew a token supplied through an environment variable. Restart it with a new token before the current token expires.

> [tab] File
>
> Use this source when a JWT is written to disk and rotated in place, such as a projected Kubernetes ServiceAccount token.
>
> ```toml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> auth_mode = "oidc"
>
> [oidc]
> file = "/var/run/secrets/formal/token"
> ```
>
> The Endpoint reads the file on every refresh, so it picks up rotated tokens without a restart. Set `integration_id` when the JWT audience is not `oidc.formal.ai/<INTEGRATION_ID>`.
>
> On Kubernetes, project a ServiceAccount token with the Formal audience:
>
> ```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> volumes:
>   - name: formal-token
>     projected:
>       sources:
>         - serviceAccountToken:
>             path: token
>             audience: oidc.formal.ai/<INTEGRATION_ID>
>             expirationSeconds: 3600
> ```
>
> Mount the volume at `/var/run/secrets/formal` in the Endpoint container.
>
> Set the integration issuer to the cluster's ServiceAccount issuer. Formal must reach its discovery document or JWKS over public HTTPS. Find the issuer with:
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> kubectl get --raw /.well-known/openid-configuration | jq -r .issuer
> ```
>
> The token `sub` is `system:serviceaccount:<NAMESPACE>:<SERVICE_ACCOUNT>`. Restrict the claim condition to the expected workloads:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> claims.sub.startsWith("system:serviceaccount:<NAMESPACE>:")
> ```

**3. Start the Formal Endpoint**

Unset `FORMAL_API_KEY` because API key authentication takes precedence.

Restart the desktop app, or start a headless agent:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
unset FORMAL_API_KEY
formal agent --headless
```

**4. Verify**

Run these commands from another terminal:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
formal auth whoami
formal ls
```

`formal auth whoami` should show the integration's machine user. `formal ls` should show resources available to that identity.

## Log In with an API Key

Use an API key when the Formal Endpoint should skip the browser login flow. This works for human users and machine users.

**1. Create an API key**

Go to [API Keys](https://app.formal.ai/api-keys) and click **Create API Key**.

To authenticate as a machine user, assign the key to that machine user.

**2. Start the Formal Endpoint**

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
FORMAL_API_KEY=<api-key> formal agent
```

For a server without a GUI or keyring, add `--headless`:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
FORMAL_API_KEY=<api-key> formal agent --headless
```

**3. Verify**

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
formal auth whoami
```

The output should show the human or machine user that owns the key.


## Related topics

- [Formal Endpoint for Amazon ECS](https://docs.formal.ai/docs/guides/client-apps/ecs-egress.md)
- [Formal Endpoint](https://docs.formal.ai/docs/guides/client-apps/desktop-app.md)
- [Troubleshoot the Endpoint](https://docs.formal.ai/docs/guides/client-apps/endpoint-troubleshooting.md)
- [Logs](https://docs.formal.ai/docs/guides/observability/logs.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.