vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Give a job a credential for the bot it acts as
6e1fca5115b709d31eeb51864b187d79aa104e5f · Keenan Nemetz · 6d ago · parent 446542e6
Give a job a credential for the bot it acts as A workflow can name a bot account with `bot:`. When the job is leased the instance generates a key for that run, stores the public half with the run, repository and expiry, and sends the private half on the lease channel. The runner writes it into the job's run directory with a known_hosts entry for the instance, so a step's `git push` or `vole issue comment` authenticates as the account and nothing has to be wired per job. The account's role is the permission, in full. The credential replaces exactly one requirement — that writing to the issues branch needs `maintain` — and adds no rule of its own. What a job may write there is what its account may do, asked the same way the browser asks: discuss, file an issue, manage an item it wrote, open a change from a branch it may push, triage and approve when the role allows it. Those are the ACL's own capabilities (`CanDiscuss`, `CanOpenRequest`, `CanTriage`, `CanApprove`), so a maintainer's job may do everything a maintainer's key may do, including labels, states, and other people's items. A session is scoped only when the fingerprint it authenticated with is a live credential row; an expired one reads as absent, so the push falls back to the account's own role and is refused where a contribute account cannot write. Two things end the key: the run finishing, which drops the row, and the expiry, which is what stops a credential whose runner was killed and never reported. The key is also masked in the log like a secret, since a step that cats it should not leave it in the attempt. Closes #165.
ci/agent/credential_test.go +64
| @@ -0,0 +1,64 @@ | |||
| 1 | package agent | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "strings" | ||
| 5 | "testing" | ||
| 6 | ) | ||
| 7 | |||
| 8 | // The job pushes to the instance it was leased from, so the known_hosts entry has to | ||
| 9 | // name the same host and port. OpenSSH brackets a non-default port, and getting that | ||
| 10 | // wrong turns every push into a host-key failure. | ||
| 11 | func TestKnownHostsLineNamesTheLeaseHost(t *testing.T) { | ||
| 12 | t.Parallel() | ||
| 13 | const key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIexample" | ||
| 14 | cases := []struct{ remote, want string }{ | ||
| 15 | {"ssh://git@forge.example.com/demo", "forge.example.com " + key + "\n"}, | ||
| 16 | {"ssh://git@forge.example.com:22/demo", "forge.example.com " + key + "\n"}, | ||
| 17 | {"ssh://git@127.0.0.1:2222/vole", "[127.0.0.1]:2222 " + key + "\n"}, | ||
| 18 | } | ||
| 19 | for _, c := range cases { | ||
| 20 | got, err := knownHostsLine(c.remote, key) | ||
| 21 | if err != nil { | ||
| 22 | t.Fatalf("%s: %v", c.remote, err) | ||
| 23 | } | ||
| 24 | if got != c.want { | ||
| 25 | t.Fatalf("%s: known_hosts = %q, want %q", c.remote, got, c.want) | ||
| 26 | } | ||
| 27 | } | ||
| 28 | // A job that cannot be told how to verify the host must not run with the key: a | ||
| 29 | // credential pointed at an unverified host is worse than no credential. | ||
| 30 | if _, err := knownHostsLine("https://forge.example.com/demo", key); err == nil { | ||
| 31 | t.Fatal("a non-ssh remote was accepted") | ||
| 32 | } | ||
| 33 | if _, err := knownHostsLine("ssh://git@forge.example.com/demo", ""); err == nil { | ||
| 34 | t.Fatal("an empty host key was accepted") | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | // The environment points git and the CLI at the key without a step doing anything, | ||
| 39 | // and it does not edit the run's pinned environment. | ||
| 40 | func TestCredentialEnvironmentPointsAtTheKey(t *testing.T) { | ||
| 41 | t.Parallel() | ||
| 42 | pinned := map[string]string{"GOCACHE": "/cache/go-build"} | ||
| 43 | job := &runnerJob{ID: "01M6FFY0BARR9YDQ3KK64VQ0MG", Repo: "demo"} | ||
| 44 | env, err := withCredentialEnv(pinned, "ssh://git@forge.example.com:2222/demo", job) | ||
| 45 | if err != nil { | ||
| 46 | t.Fatal(err) | ||
| 47 | } | ||
| 48 | if env["VOLE_RUN_ID"] != job.ID || env["VOLE_REPO"] != "demo" { | ||
| 49 | t.Fatalf("run identity = %q/%q", env["VOLE_RUN_ID"], env["VOLE_REPO"]) | ||
| 50 | } | ||
| 51 | if !strings.Contains(env["GIT_SSH_COMMAND"], "-i "+RunCredentialPath) || | ||
| 52 | !strings.Contains(env["GIT_SSH_COMMAND"], RunKnownHostsPath) { | ||
| 53 | t.Fatalf("GIT_SSH_COMMAND = %q", env["GIT_SSH_COMMAND"]) | ||
| 54 | } | ||
| 55 | if env["GIT_SSH_COMMAND"] != env["VOLE_SSH_COMMAND"] { | ||
| 56 | t.Fatalf("the CLI and git disagree: %q vs %q", env["VOLE_SSH_COMMAND"], env["GIT_SSH_COMMAND"]) | ||
| 57 | } | ||
| 58 | if env["GOCACHE"] != "/cache/go-build" { | ||
| 59 | t.Fatalf("the job's own environment was lost: %q", env["GOCACHE"]) | ||
| 60 | } | ||
| 61 | if _, ok := pinned["VOLE_RUN_ID"]; ok { | ||
| 62 | t.Fatal("the pinned environment was edited in place") | ||
| 63 | } | ||
| 64 | } | ||