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
forge/access/acl.go +45−54
| @@ -21,6 +21,7 @@ const ( | |||
| 21 | 21 | None = role.None | |
| 22 | 22 | Read = role.Read | |
| 23 | 23 | Contribute = role.Contribute | |
| 24 | Runner = role.Runner | ||
| 24 | 25 | Maintain = role.Maintain | |
| 25 | 26 | Admin = role.Admin | |
| 26 | 27 | ) | |
| @@ -61,18 +62,6 @@ type ACL struct { | |||
| 61 | 62 | // may write: existing requests keep their history and can still be edited, | |
| 62 | 63 | // approved, and landed after the setting is turned on. | |
| 63 | 64 | RequireLinkedIssue bool `json:"require_linked_issue,omitempty"` | |
| 64 | // Runners are the accounts whose CI results count as checks here. It is an | ||
| 65 | // allowlist rather than a role because it answers a different question from | ||
| 66 | // read/write: not "may this account touch the repository" but "may this | ||
| 67 | // account's build be believed about it". Naming somebody a runner also lets | ||
| 68 | // them lease jobs for this repository, which means executing its code. | ||
| 69 | // | ||
| 70 | // Admins are implicit: they can rewrite this list, and a protected branch | ||
| 71 | // already lets them land anything with no checks at all, so restricting them | ||
| 72 | // here would be theatre. Everyone else — a maintainer who runs CI on their laptop | ||
| 73 | // included — gets their result recorded but not counted. | ||
| 74 | Runners []string `json:"runners,omitempty"` | ||
| 75 | |||
| 76 | 65 | // instanceRole is not part of the repository document. The access store | |
| 77 | 66 | // attaches the roster's instance-wide role when it loads the ACL, so every | |
| 78 | 67 | // capability check below sees a global grant without every caller having to | |
| @@ -80,10 +69,10 @@ type ACL struct { | |||
| 80 | 69 | // account, and writing one into repo_acl would freeze it at that moment. | |
| 81 | 70 | instanceRole func(string) Role | |
| 82 | 71 | // active is the roster's answer to "is this account still active", attached by | |
| 83 | // the store beside instanceRole. An explicit entry or runners-list membership | ||
| 84 | // outlives retirement otherwise: the row stays after the account is retired, | ||
| 85 | // and a retired account that still counts as an approver or a runner is a | ||
| 86 | // permission nobody revoked. Nil means the caller has no roster (a test). | ||
| 72 | // the store beside instanceRole. An explicit entry outlives retirement | ||
| 73 | // otherwise: the row stays after the account is retired, and a retired account | ||
| 74 | // that still counts as an approver or a runner is a permission nobody revoked. | ||
| 75 | // Nil means the caller has no roster (a test). | ||
| 87 | 76 | active func(string) bool | |
| 88 | 77 | // revision is the version of the row this rule set was read from, attached by | |
| 89 | 78 | // the store. It is what makes a write compare-and-swap: a rule set read before | |
| @@ -115,45 +104,16 @@ func (a *ACL) EligibleApprover(name string) bool { | |||
| 115 | 104 | } | |
| 116 | 105 | ||
| 117 | 106 | // CanReport says whether a CI result reported by this account counts as a check | |
| 118 | // for this repository. An empty account never counts: an unattributed result is not | ||
| 119 | // a result anybody is answerable for. Neither does a retired account: the runners | ||
| 120 | // list is edited by hand and the row stays after retirement, so membership alone | ||
| 121 | // would let a revoked account keep vouching for builds — and keep leasing jobs, | ||
| 122 | // which means executing repository code. | ||
| 123 | // | ||
| 124 | // A repository role is deliberately not required of an explicit runner. The | ||
| 125 | // runners list answers a different question from read/write ("may this account's | ||
| 126 | // build be believed about it"), and a machine that only builds may hold no role. | ||
| 107 | // for this repository. The runner role is the trust decision: an account allowed | ||
| 108 | // to execute this repository's code and publish its declared outputs may have its | ||
| 109 | // result believed. Maintainers and admins sit above it, so they count too; a | ||
| 110 | // retired account never does. The decision is per-repository because running code | ||
| 111 | // is a per-repository grant, not an instance-wide one. | ||
| 127 | 112 | func (a *ACL) CanReport(accountID string) bool { | |
| 128 | 113 | if accountID == "" || !a.Active(accountID) { | |
| 129 | 114 | return false | |
| 130 | 115 | } | |
| 131 | if a.RoleFor(accountID).AtLeast(Admin) { | ||
| 132 | return true | ||
| 133 | } | ||
| 134 | for _, r := range a.Runners { | ||
| 135 | if r == accountID { | ||
| 136 | return true | ||
| 137 | } | ||
| 138 | } | ||
| 139 | return false | ||
| 140 | } | ||
| 141 | |||
| 142 | // SetRunners replaces the allowlist, dropping blanks and duplicates so the file | ||
| 143 | // does not depend on how an operator typed it. | ||
| 144 | func (a *ACL) SetRunners(ids []string) { | ||
| 145 | seen := map[string]bool{} | ||
| 146 | out := a.Runners[:0] | ||
| 147 | for _, id := range ids { | ||
| 148 | id = strings.TrimSpace(id) | ||
| 149 | if id == "" || seen[id] { | ||
| 150 | continue | ||
| 151 | } | ||
| 152 | seen[id] = true | ||
| 153 | out = append(out, id) | ||
| 154 | } | ||
| 155 | sort.Strings(out) | ||
| 156 | a.Runners = out | ||
| 116 | return a.RoleFor(accountID).AtLeast(Runner) | ||
| 157 | 117 | } | |
| 158 | 118 | ||
| 159 | 119 | // RequiresChecks resolves the nil-means-true rule. | |
| @@ -184,11 +144,31 @@ func Empty(owner string) *ACL { | |||
| 184 | 144 | } | |
| 185 | 145 | return a | |
| 186 | 146 | } | |
| 147 | |||
| 148 | // aclDocument is the on-disk shape of a rule set. Runners is the retired | ||
| 149 | // allowlist: it is read so an upgrade can fold each entry into the runner role, | ||
| 150 | // and it is never written. A rule set produced by this build has no such field. | ||
| 151 | type aclDocument struct { | ||
| 152 | Version int `json:"version"` | ||
| 153 | Default string `json:"default"` | ||
| 154 | Entries map[string]string `json:"entries"` | ||
| 155 | Protected []string `json:"protected,omitempty"` | ||
| 156 | ApprovalsRequired *int `json:"approvals_required,omitempty"` | ||
| 157 | ChecksRequired *bool `json:"checks_required,omitempty"` | ||
| 158 | RequireLinkedIssue bool `json:"require_linked_issue,omitempty"` | ||
| 159 | Runners []string `json:"runners,omitempty"` | ||
| 160 | } | ||
| 161 | |||
| 187 | 162 | func Parse(data []byte) (*ACL, error) { | |
| 188 | a := &ACL{} | ||
| 189 | if err := json.Unmarshal(data, a); err != nil { | ||
| 163 | var doc aclDocument | ||
| 164 | if err := json.Unmarshal(data, &doc); err != nil { | ||
| 190 | 165 | return nil, fmt.Errorf("acl: %w", err) | |
| 191 | 166 | } | |
| 167 | a := &ACL{ | ||
| 168 | Version: doc.Version, Default: doc.Default, Entries: doc.Entries, | ||
| 169 | Protected: doc.Protected, ApprovalsRequired: doc.ApprovalsRequired, | ||
| 170 | ChecksRequired: doc.ChecksRequired, RequireLinkedIssue: doc.RequireLinkedIssue, | ||
| 171 | } | ||
| 192 | 172 | if a.Version == 0 { | |
| 193 | 173 | a.Version = 1 | |
| 194 | 174 | } | |
| @@ -210,7 +190,18 @@ func Parse(data []byte) (*ACL, error) { | |||
| 210 | 190 | } | |
| 211 | 191 | a.Entries[k] = role.String() | |
| 212 | 192 | } | |
| 213 | a.SetRunners(a.Runners) | ||
| 193 | // The runner allowlist became a role. An account named there was trusted to | ||
| 194 | // run this repository's code, so it becomes a runner unless the rule set | ||
| 195 | // already gives it more. The comparison uses the repository role, not the | ||
| 196 | // instance overlay: an instance maintainer is already a runner on public | ||
| 197 | // repositories, and adding an explicit entry must not lower that. | ||
| 198 | for _, name := range doc.Runners { | ||
| 199 | name = strings.TrimSpace(name) | ||
| 200 | if name == "" || a.RepositoryRoleFor(name) >= Runner { | ||
| 201 | continue | ||
| 202 | } | ||
| 203 | a.Entries[name] = Runner.String() | ||
| 204 | } | ||
| 214 | 205 | return a, nil | |
| 215 | 206 | } | |
| 216 | 207 | func (a *ACL) Bytes() ([]byte, error) { | |