# Run the token relay

> How to run the open-source token relay that TARA's live service needs, on your own host with a static IP address, and how to check, update and troubleshoot it.
>
> Documentation for Oktul eID SSO for Jira, for Jira Cloud, by Oktul: https://oktul.com/docs/plugins/eid-sso/token-relay/

The token relay is a small container you run when your site uses [TARA's live
service](../tara/#the-token-relay). TARA accepts live token requests only from IP addresses
registered for your client, and an app on Atlassian Forge calls from Atlassian's shared
addresses. The relay calls TARA from your static IP address and keeps TARA's client secret on
your side.

```
Oktul eID SSO ──HTTPS──▶ your reverse proxy ──HTTP──▶ relay ──HTTPS──▶ TARA POST /oidc/token
                         (TLS, IP filter)               └──HTTPS──▶ Atlassian signing keys
```

We publish the relay as open source under the EUPL-1.2 licence, at
[github.com/Oktul/eID-TARA-remote](https://github.com/Oktul/eID-TARA-remote). The repository
holds the code, the container definition, deployment files for Docker Compose and Kubernetes, and
the full [setup guide](https://github.com/Oktul/eID-TARA-remote/blob/main/docs/SETUP.md), which
the section numbers below refer to.

Each release is a container image at `ghcr.io/oktul/eid-tara-remote`, for `linux/amd64` and
`linux/arm64`. The [releases page](https://github.com/Oktul/eID-TARA-remote/releases) lists each
version and its notes.

<Aside type="note" title="The live service is not tested yet">
We have tested the app with TARA's demo service. We have not yet run a login through TARA's
live service and a relay against RIA, because that needs a live client. The relay's own
acceptance tests, the load test among them, are not finished yet either. Test it with your own
live client and one user before you move anyone to it.
</Aside>

## What the relay does

- **It forwards only for your site.** Every call from the app carries a Forge Invocation Token that
  Atlassian signs. The relay checks the signature against Atlassian's published keys, and checks
  that the token is for this app, from your Forge environment and from a site you listed. You
  can also pin one installation with `RELAY_INSTALLATION_IDS`, and update it after a reinstall,
  which changes the installation ID.
- **It forwards only the token request.** `POST /oidc/token` reaches TARA, with TARA's
  credential added. The relay answers its own health and information routes itself. The health routes, `/livez`
  and `/readyz`, need no token, so the proxy's IP filter keeps them private.
- **It sends the credential only to TARA.** It refuses to start with any upstream other than
  `https://tara.ria.ee` or `https://tara-test.ria.ee`, unless a test setting lifts the check. With
  `RELAY_UPSTREAM_CA_FILE` set, it trusts only TARA's CA certificates for that connection.
- **It stores nothing.** It writes no files. Its logs never hold a request or response body, a
  token, the credential or an unverified site ID.
- **It cannot log anyone in by itself.** The app fetches TARA's discovery document and signing
  keys directly, and checks the ID token as it does without a relay.

## What you need

- A host with a **static outbound IP address**: Docker with Compose v2, or a Kubernetes
  cluster (1.30 or later), on `linux/amd64` or `linux/arm64`. The container's memory limit is
  128 MB.
- A **TARA client** from RIA, with its client ID and client secret.
- A **public DNS name and a TLS certificate**, served by a reverse proxy. The Compose files
  include an optional Caddy service that gets the certificate itself.
- An **accurate clock**, kept in sync with NTP. By default the relay allows 10 seconds of skew.
- **Outbound HTTPS** to TARA and to `forge.cdn.prod.atlassian-dev.net`, where Atlassian
  publishes its signing keys.

## Set it up

Choosing **Live** in the TARA row and saving adds a **Token relay** part to the row, with the
**Relay configuration** block. To test with the demo first, choose **Demo**, tick **Send token
requests through my token relay** and save, then use `https://tara-test.ria.ee` as the relay's upstream.
[Connect TARA](../tara/#try-the-relay-with-the-demo-first) has the details.

1. **Copy the deployment files from the release you deploy** deploy/compose.yaml and deploy/Caddyfile for Docker Compose, or deploy/kubernetes/ (sections 4 and 5). For Kubernetes, delete secret.yaml from your copy, or applying the folder replaces your Secret with a placeholder that stops the relay. Also set your ingress controller's namespace in networkpolicy.yaml. Then set the image tag in compose.yaml or deployment.yaml to the release you deploy, for example :1.0.1 (section 9).
2. **Put a reverse proxy in front** TLS on your public name, inbound connections only from Atlassian's egress IP ranges, and a cap on all inbound connections at your firewall or load balancer. The bundled Caddy gets its certificate over ACME, so leave ports 80 and 443 open at the firewall. In Caddyfile, replace relay.example.com with your DNS name and turn on the IP filter. Caddy does not cap inbound connections by itself (sections 6.1 to 6.5).
3. **Register the static IP address with RIA for your live client** The address your relay's traffic leaves from: your NAT, egress gateway or outbound proxy (section 6.2). The demo needs no registration. If you try the relay with the demo first, give the address when you apply for the live service.
4. **Enter the Relay URL on the admin page and select Save relay URL** An HTTPS address with no path. Atlassian asks you to confirm it.
5. **Copy the Relay configuration into the deployment file** Four values: RELAY_APP_ID, RELAY_ENVIRONMENT_ID, RELAY_CLOUD_IDS and RELAY_UPSTREAM_URL. In compose.yaml or deployment.yaml, put each value between the quotes that stand there. They pin the relay to this app, its environment and your site, so another site cannot use your IP address and credential (section 2).
6. **Write TARA's credential to a secret file** One line, an HTTP Basic Authorization header built from the form-encoded client ID and secret. With Compose, the file must be readable by user 65532. With Kubernetes, the next step puts it in a Secret. The guide has a script that keeps the secret out of your shell history (section 3.1).
7. **Add TARA's CA certificates** A PEM file with the root certificates TARA's technical specification names. The deployment files do not include one. With Compose, add it as a secret, readable by user 65532 like the credential file. With Kubernetes, create one Secret with kubectl that holds both the credential and the CA file. Then set RELAY_UPSTREAM_CA_FILE (sections 3.2 and 5).
8. **Start or restart the relay, then select Check relay** docker compose --profile caddy up -d with the bundled Caddy, docker compose up -d behind your own proxy, or kubectl -n <namespace> apply -f deploy/kubernetes/ in the namespace that holds the Secret (sections 4 and 5). Your own proxy joins the compose network eid-tara-remote_default and sends to relay:8080. A proxy on the same host can instead use the ports entry 127.0.0.1:8080:8080, which compose.yaml leaves commented out.

Never publish the relay's port 8080 on a public address. It serves plain HTTP, and only your
proxy and health probes should reach it.

### The reverse proxy

The relay does not filter addresses or cap connections itself. Your proxy does both, and it
must follow these rules (section 6.3):

- Pass `Authorization` through unchanged, exactly once, over HTTP/1.1.
- Admit only [Atlassian's egress IP ranges](https://ip-ranges.atlassian.com/), and keep them
  current. Where an ACME challenge needs ports 80 and 443 open, filter in the proxy rather than
  the firewall.
- Allow at most 100 connections to the relay and a 5 second header timeout. These are starting values, and the relay's acceptance tests may lower them.
- Never retry a request to the relay. A token request may already have used TARA's one-time
  code.
- Keep upstream keep-alive under 60 seconds, and wait more than 15 seconds for an answer.
- Log no bodies, paths, query strings or header values, and pass the relay's error answers
  through unchanged.

<Aside type="caution" title="Whatever ends TLS sees the login">
The proxy, and any load balancer, tunnel or CDN that ends TLS in front of the relay, sees the
token request and TARA's answer, which holds the person's personal code and name. Run it on
infrastructure that is yours, or cover its provider in your data processing agreements.
</Aside>

## Check it

| Check | How |
|---|---|
| Startup | The log shows `starting` with every setting and `signing keys ready`. The credential appears only as `set (from file)` |
| Ready | `docker compose exec relay /relay healthcheck --ready && echo ready` prints `ready`, or a pod at `READY 1/1` in Kubernetes |
| From the app | **Check relay** on the admin page, which the [health check](../health-check/) also runs. It reaches the relay through your proxy and reads the relay's version and whether it holds a credential. It does not call TARA |
| Through to TARA | A test login, demo or live. A fault on TARA's side shows only there and in the relay's log |
| From outside | `curl -s -o /dev/null -w '%{http_code}\n' https://<your relay name>/livez` from an address outside Atlassian's ranges. With the bundled Caddy it prints `000`. A `200` means the IP filter is off |

**Check relay** reports one of three results:

| Result | Meaning |
|---|---|
| **The relay works** | It answers as a relay, forwards to the TARA environment in use and holds a credential |
| **The relay works, with a warning** | It is older than the oldest release the app supports, or is not a release build. Update it to the current release |
| **The relay does not work** | The message names the cause, for example no relay URL, a refused call, another upstream, no credential, an unsupported protocol version, or no answer within 15 seconds |

## Updates

Images are tagged `:X.Y.Z`, which never changes, and `:X.Y`, which moves to
the newest patch of that line. There is no `latest` tag. The deployment files pin `:X.Y.Z`, and
you change the tag by hand after reading the release notes. To take patches automatically,
follow `:X.Y` with Watchtower on Docker, or with `imagePullPolicy: Always` and a scheduled
rollout restart on Kubernetes (section 9). A new minor release ends the patches for the line before it, so change the tag by hand when one comes out.

The relay's [support policy](https://github.com/Oktul/eID-TARA-remote/blob/main/docs/SUPPORT.md)
sets these terms:

- **A patch release never changes** an endpoint, response code, header or setting.
- **Every release note** says whether the update is required, recommended or optional, and why.
- **Every image** is built for both architectures, signed with cosign keyless signing, and
  carries SBOM and provenance attestations. Each release note gives the command that
  verifies the signature.
- **A new Go patch release** ships as a relay patch within a day. If the line holds other
  unreleased changes, a person releases it instead. A fix for a reachable critical or high
  vulnerability that needs a new Go minor ships within 7 days.
- **The newest minor of the current major line is supported.** When a new major line comes out,
  the previous major's newest minor stays supported for 12 months.
- **The admin page** warns you when your relay is older than the app expects.

The support policy says which lines are supported and until when. To hear about releases, watch the
repository's releases on GitHub.

## Troubleshooting

**Check relay** finds a relay that is down, refuses the app or has no credential. A fault
between the relay and TARA shows only in a login and in the relay's log, in its `error`,
`auth_reason` and `upstream_status` fields. A relay that refuses the app, or a wrong TARA credential, ends logins on *Login is not set
up correctly*. A relay that is down, cannot reach TARA or times out ends them on *The eID service
is not available*.

| You see | Check |
|---|---|
| `invalid configuration` at startup, and the relay restarts | The setting the log names. An unreplaced `"<from the admin page>"` value and a credential or CA file user 65532 cannot read are common causes |
| `auth_reason` `cloud_id`, `audience` or `environment` | The Relay configuration was not copied from this site's admin page, or was changed |
| `auth_reason` `installation` | The app was reinstalled. Update or remove `RELAY_INSTALLATION_IDS` |
| `auth_reason` `expired` or `not_yet_valid` | The host's clock. Fix NTP rather than raising the allowed skew |
| `not_ready` | The relay cannot fetch Atlassian's signing keys. Check outbound access to `forge.cdn.prod.atlassian-dev.net` |
| `upstream_unreachable` | DNS, the outbound firewall, the proxy settings, or an outdated CA file for TARA |
| TARA answers `400` or `401`, with `unauthorized_client` or `invalid_client` | The credential file's content and format, and that it holds the client of the TARA environment in use |
| TARA refuses the relay's IP address | That the address registered with RIA is the one your relay's traffic really leaves from (section 6.2) |
| **Check relay** says the relay does not serve its info endpoint | The relay is older than the app expects. Update it to the current release |
| **Check relay** says the URL did not answer as a relay | The answer did not come from the relay: no relay URL, the IP filter, the proxy's timeouts or routing, or a proxy that replaces the relay's error answers |

Sections 10 and 11 of the setup guide list every log line, error and reason.

## Report a problem

For help with the relay, open a request in the [Help Center](https://support.oktul.com). Report
a vulnerability there too, or privately through the repository's **Security** tab, **Report a
vulnerability**, as its [security policy](https://github.com/Oktul/eID-TARA-remote/blob/main/SECURITY.md)
describes. Leave out the credential, tokens and codes from a real login.

**Who needs the token relay?**

A site that uses TARA's live service. You can also send TARA's demo through it to test the path first. eeID, Signicat, Dokobit and a Custom OIDC provider work without it.

**Where do I get the relay?**

From its public repository, [github.com/Oktul/eID-TARA-remote](https://github.com/Oktul/eID-TARA-remote). It is open source under the EUPL-1.2 licence. Each release is a signed container image, `ghcr.io/oktul/eid-tara-remote`.

**Does Oktul see the TARA secret?**

No. The secret stays in your relay, on your host. TARA's answer goes through the relay to the app on Atlassian's platform, which checks it. It does not reach a server of Oktul's.
