feat: add gitdan-crates-access, a deploy-key action for the private crates repo
The job token cannot read daniel/gitdan-crates, so CI authenticates with a read-only deploy key. The action writes it 0600 outside the workspace, pins the forge's host key (RSA, the only type offered, confirmed against the trusted known_hosts record and a fresh keyscan), exports GIT_SSH_COMMAND, proves access with ls-remote, and fails on a Cargo.lock with two commits of the crates repo. The selftest is wired into selftest.sh. Existing actions and scripts are untouched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MfBCVNDv3y5gm2djeZSAk4
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
Shared Gitea Actions composite actions for the gitdan forge.
|
||||
|
||||
Currently one thing, done properly: **`cargo-cache`** — a persistent,
|
||||
Two actions. The first, done properly: **`cargo-cache`** — a persistent,
|
||||
per-branch Cargo build cache for self-hosted Gitea runners, where a pull
|
||||
request's cache is a near-free hardlink clone of an immutable snapshot its
|
||||
base branch published.
|
||||
@@ -522,6 +522,66 @@ of a merge-preview build, which is not what `dev` is.
|
||||
|
||||
---
|
||||
|
||||
## `gitdan-crates-access`
|
||||
|
||||
Gives a job read access to the private `daniel/gitdan-crates` repo. The Actions
|
||||
job token cannot read it, so the job authenticates with a read-only deploy key
|
||||
held in the user-level Actions secret `GITDAN_CRATES_DEPLOY_KEY` (created and
|
||||
rotated by gitdan#123). Call it once, before any cargo step:
|
||||
|
||||
```yaml
|
||||
- uses: https://gitdan.com/daniel/gitdan-actions/gitdan-crates-access@v1
|
||||
with:
|
||||
deploy-key: ${{ secrets.GITDAN_CRATES_DEPLOY_KEY }}
|
||||
```
|
||||
|
||||
Consumers declare the dependency as
|
||||
`ssh://git@gitdan.com:22022/daniel/gitdan-crates.git` and set
|
||||
`[net] git-fetch-with-cli = true`, so Cargo fetches through `git` and honours
|
||||
`GIT_SSH_COMMAND`. The action:
|
||||
|
||||
1. Writes the key to a `0600` file in a private directory under `$RUNNER_TEMP`
|
||||
(else `mktemp -d`), never in the workspace, and copies in the pinned host
|
||||
key for `[gitdan.com]:22022`. The key travels by environment variable only:
|
||||
not in argv, not echoed.
|
||||
2. Exports `GIT_SSH_COMMAND` through `$GITHUB_ENV`: that key only, that
|
||||
known-hosts file only, `StrictHostKeyChecking=yes`, no agent, no user ssh
|
||||
config. Every later `ssh://` git remote in the job uses it, so a job that
|
||||
fetches other hosts over SSH must not use this action. No `CARGO_*`
|
||||
variable is set; those split sccache keys.
|
||||
3. Runs `git ls-remote` on gitdan-crates, so a missing or revoked key fails
|
||||
here with an error naming `GITDAN_CRATES_DEPLOY_KEY`.
|
||||
4. Fails when `Cargo.lock` lists more than one commit of gitdan-crates (two
|
||||
commits mean two copies of every shared type). No entry passes.
|
||||
|
||||
| input | default | meaning |
|
||||
|---|---|---|
|
||||
| `deploy-key` | *(required)* | the private key; an empty value fails, naming the secret (a fork PR gets no secrets, so it fails there too) |
|
||||
| `lockfile` | `Cargo.lock` | lockfile to check, relative to the workspace; a missing file fails, an empty string skips the check |
|
||||
|
||||
The image needs an `ssh` client and `git`; the action fails with a message if
|
||||
either is missing and installs nothing.
|
||||
|
||||
### When the host key changes
|
||||
|
||||
The pin is `scripts/gitdan-known-hosts` (the server offers RSA only; SHA256
|
||||
`XAMzCdVbcQhcH/cnynQO7gPLFqHMh9wuoUysK9EhBP0`). After a forge rebuild or host
|
||||
key rotation every job fails at the `ls-remote` with `Host key verification
|
||||
failed`. Re-pin from a machine that already trusts the new key, never from a
|
||||
bare `ssh-keyscan`:
|
||||
|
||||
```bash
|
||||
ssh-keygen -F '[gitdan.com]:22022' # the trusted record; compare it with
|
||||
ssh-keyscan -p 22022 gitdan.com # what the server offers now
|
||||
```
|
||||
|
||||
Replace the file with the confirmed line(s), update `PINNED_FPR` in
|
||||
`scripts/crates-access-selftest.sh`, and merge; `v1` moves with `main`. If the
|
||||
two disagree and you did not rotate the key, stop: that is the symptom of a
|
||||
man in the middle.
|
||||
|
||||
---
|
||||
|
||||
## Multiple jobs in one workflow
|
||||
|
||||
Two jobs building the same ref — a `ci` job and a `wasm` job, say — are two
|
||||
|
||||
Reference in New Issue
Block a user