vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Replace the runner allowlist with a runner role
648cd81bde97042f682a528ebb9ce6353b95bf3f · Keenan Nemetz · 1d ago · parent ea92d754
server/ssh/repos_filter_test.go +21−27
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | package ssh | |
| 2 | 2 | ||
| 3 | 3 | // --repos lets one runner narrow what it will take, and the narrowing is done on the | |
| 4 | // server against what the account's allowlist grants. These tests are about the | ||
| 4 | // server against what the account's runner role grants. These tests are about the | ||
| 5 | 5 | // direction of that: an operator's filter may shrink a grant, and a client's request | |
| 6 | 6 | // may never grow it. The pure half (narrow) is pinned directly; the wire half is pinned | |
| 7 | 7 | // through a real session, because the thing that could regress is a request field that | |
| @@ -48,31 +48,34 @@ func TestNarrowCanOnlySubtract(t *testing.T) { | |||
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | 50 | // A lease request that names a repository the account may not run for gets nothing, | |
| 51 | // rather than that repository. The allowlist is what decides; the flag only filters | ||
| 51 | // rather than that repository. The runner role is what decides; the flag only filters | ||
| 52 | 52 | // what it produced. | |
| 53 | func TestARequestCannotLeaseBeyondTheAllowlist(t *testing.T) { | ||
| 53 | func TestARequestCannotLeaseBeyondTheGrant(t *testing.T) { | ||
| 54 | 54 | t.Parallel() | |
| 55 | 55 | h := newHarness(t) | |
| 56 | c := h.runner(t, h.keyPath) | ||
| 57 | if rep := c.call(runnerRequest{Op: "ping"}); rep.Error != "" { | ||
| 58 | t.Fatal(rep.Error) | ||
| 59 | } | ||
| 60 | 56 | ||
| 61 | // A second repository the writer's account is not a runner for. Its ACL gives the | ||
| 62 | // writer write access, which is exactly the distinction that matters: writing to a | ||
| 63 | // repository is not permission to execute its code. | ||
| 64 | other, err := h.repos.Create("other", repo.CreateOptions{Owner: h.writerID}) | ||
| 57 | // The reader account is a runner for demo, and only demo. | ||
| 58 | demo, err := h.repos.Open("demo") | ||
| 65 | 59 | if err != nil { | |
| 66 | 60 | t.Fatal(err) | |
| 67 | 61 | } | |
| 68 | a, err := other.ACL() | ||
| 62 | a, err := demo.ACL() | ||
| 69 | 63 | if err != nil { | |
| 70 | 64 | t.Fatal(err) | |
| 71 | 65 | } | |
| 72 | if err := a.SetEntry(h.writerID, "maintain"); err != nil { | ||
| 66 | a.Entries["reader"] = "runner" | ||
| 67 | if err := demo.SetACL(a, "test"); err != nil { | ||
| 73 | 68 | t.Fatal(err) | |
| 74 | 69 | } | |
| 75 | if err := other.SetACL(a, "test"); err != nil { | ||
| 70 | |||
| 71 | c := h.runner(t, h.roKey) | ||
| 72 | if rep := c.call(runnerRequest{Op: "ping"}); rep.Error != "" { | ||
| 73 | t.Fatal(rep.Error) | ||
| 74 | } | ||
| 75 | |||
| 76 | // A second repository the reader has no role in. Its owner is an admin, which | ||
| 77 | // makes it a runner there, but that grant does not reach this account. | ||
| 78 | if _, err := h.repos.Create("other", repo.CreateOptions{Owner: h.writerID}); err != nil { | ||
| 76 | 79 | t.Fatal(err) | |
| 77 | 80 | } | |
| 78 | 81 | runID, err := id.New(time.Now().UTC()) | |
| @@ -98,7 +101,8 @@ func TestARequestCannotLeaseBeyondTheAllowlist(t *testing.T) { | |||
| 98 | 101 | t.Fatalf("leased %q from %q, which the account may not run for", rep.Run.Job, rep.Run.Repo) | |
| 99 | 102 | } | |
| 100 | 103 | ||
| 101 | // The work is still there for somebody who is allowed: an admin is implicit. | ||
| 104 | // The work is still there for somebody who is allowed: the repository's owner | ||
| 105 | // is an admin and therefore a runner. | ||
| 102 | 106 | admin, err := h.runs.Lease(runs.LeaseRequest{ | |
| 103 | 107 | Owner: h.writerID, Repos: []string{"other"}, TTL: time.Minute, | |
| 104 | 108 | }, time.Now().UTC()) | |
| @@ -121,21 +125,11 @@ func TestARepoFilterTakesOnlyWhatItNames(t *testing.T) { | |||
| 121 | 125 | ||
| 122 | 126 | // Two repositories the account may run for, one job in each. | |
| 123 | 127 | for _, name := range []string{"demo", "second"} { | |
| 124 | m, err := h.repos.Open(name) | ||
| 125 | if err != nil { | ||
| 126 | m, err = h.repos.Create(name, repo.CreateOptions{Owner: h.writerID}) | ||
| 127 | if err != nil { | ||
| 128 | if _, err := h.repos.Open(name); err != nil { | ||
| 129 | if _, err := h.repos.Create(name, repo.CreateOptions{Owner: h.writerID}); err != nil { | ||
| 128 | 130 | t.Fatal(err) | |
| 129 | 131 | } | |
| 130 | 132 | } | |
| 131 | a, err := m.ACL() | ||
| 132 | if err != nil { | ||
| 133 | t.Fatal(err) | ||
| 134 | } | ||
| 135 | a.SetRunners([]string{h.writerID}) | ||
| 136 | if err := m.SetACL(a, "test"); err != nil { | ||
| 137 | t.Fatal(err) | ||
| 138 | } | ||
| 139 | 133 | runID, err := id.New(time.Now().UTC()) | |
| 140 | 134 | if err != nil { | |
| 141 | 135 | t.Fatal(err) | |