# GitHub Actions

> Let GitHub Actions workflows reach your private servers to deploy and test, with no secret stored in GitHub.

A **trusted workflow** lets jobs from one GitHub repository join your workspace, to deploy to or test against private servers. Nothing is stored in GitHub: no auth key, no API token.

Each job proves which repository, branch and run it is with GitHub's own signed identity token. Underpass checks it against the trusted workflow and gives the job a key that works once and expires after 10 minutes. The job joins as a temporary machine with the tags you chose, and leaves when it ends.

## Connect GitHub

Open **Keys → GitHub Actions** and click **Connect GitHub**. Owners and admins only. On GitHub, pick the account or organization and which of its repositories Underpass may see. You can change that later from the account's menu, **Choose repositories on GitHub**.

The app reads repository names, default branches and environments. It never reads your code, and it can't change anything. Connecting is optional: without it, you type the repository instead.

> [!NOTE]
> In an organization, only its owners can install apps. If you aren't one, GitHub asks them to approve it, and you connect again once they have.

## Set it up

1. Click **Add trusted workflow**.
2. Fill in:

| Field | Means |
|---|---|
| **Repository** | Picked from your connected accounts, or typed as `owner/name` (a pasted GitHub link works too). A picked repository is pinned to its GitHub ID right away |
| **Branches** | Whose workflows may join, comma-separated: `main`, a pattern like `release/*`, `*` for any branch, or tags like `refs/tags/v*` |
| **GitHub environment** | Optional. Only jobs in this [environment](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments) can join, so its required reviewers and wait timers apply |
| **Tags** | What the machines join as, like `tag:ci`. [Access rules](/features/access-controls) decide what they can reach |

3. Click **Create the workflow on GitHub**: GitHub's editor opens with a workflow file written for your branches and environment. Change its last step to your deploy and commit. Or copy just the steps into a workflow you have:

```yaml
permissions:
  id-token: write # lets the job prove which repository and branch it is
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: getunderpass/connect@v1
        with:
          trust: wf_abc123
      - run: ssh deploy@web-1 ./deploy.sh
```

The `trust` value is the trusted workflow's ID. It isn't a secret: it only says which rule to check, and GitHub vouches for everything else.

4. Give the tag access to what the job needs, and nothing more:

```json
{ "src": ["tag:ci"], "dst": ["tag:prod"], "proto": "tcp", "ports": ["22"] }
```

> [!TIP]
> **Setup** on the trusted workflow's row shows the steps again at any time.

## What can join

- **Only that repository.** The rule is pinned to the repository's GitHub ID: when you pick it from GitHub, or else when the first job joins. Renaming the repository keeps working; a repository deleted and created again under the same name, or moved to another owner, is refused. Remove the trusted workflow and add it again if you moved it on purpose.
- **Only the branches you listed.** A job on any other branch is refused.
- **Never pull requests**, including ones from forks, and never workflows started by `pull_request_target`, which run with your branch's permissions on a pull request's code.
- **Only the environment you named**, if you named one.

CI machines are **ephemeral** and **pre-approved**: they skip [device approval](/manage/machines#device-approval) and are removed as soon as the job signs out, or after 10 minutes offline if it can't.

## In the audit log

Each job shows in the [audit log](/manage/logs#audit-log) as `github:owner/name`, with its branch, commit, run number and who started it:

- **got a one-time key** when a job is let in
- **was refused a key**, with the reason, when it isn't
- **joined**, then **removed**, for its machine

## The action

The `getunderpass/connect` action runs on Linux and macOS runners, GitHub-hosted or your own (with `sudo`). It installs the client, joins, and signs out when the job ends, even when it fails.

| Input | Default | |
|---|---|---|
| `trust` | (required) | The trusted workflow's ID |
| `hostname` | `gh-<repository>-<run ID>` | The machine's name |
| `server` | `https://coord.getunderpass.com` | Your coordination server, if you run your own |
| `audience` | `underpass` | The identity token's audience, if your server sets `TS_CI_AUDIENCE` |

It outputs the job's address (`ip`) and full name (`name`).

## Without the action

Any job that can get a GitHub identity token can join:

```bash
# 1. GitHub's identity token, for the audience "underpass"
TOKEN=$(curl -sH "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
  "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=underpass" | jq -r .value)

# 2. A one-time key for it
KEY=$(curl -s https://coord.getunderpass.com/machine/ci/github \
  -d "{\"trust\":\"wf_abc123\",\"token\":\"$TOKEN\"}" | jq -r .authKey)

# 3. Join with it, as with any auth key
curl -fsSL https://coord.getunderpass.com/download/install.sh | UNDERPASS_AUTH_KEY="$KEY" sh
```
