Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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/hook/hook.go +56−11

@@ -34,6 +34,9 @@ type Config struct {
34 34 // credential may write less than the account it acts as.
35 35 KeyID string
36 36 MaxBlobBytes int64
37 // PagesRef is the branch the instance serves a repository site from. A runner
38 // role may publish it; empty means the instance default, "pages".
39 PagesRef string
37 40 // InstanceDB, when set, is the instance database, read here for access rules,
38 41 // account standing and file locks. Attribution itself is the Actor name
39 42 // resolved at the handshake.
@@ -76,6 +79,30 @@ type change struct {
76 79 old, new, ref string
77 80 }
78 81
82 // pageRef is the full ref a site is served from. An instance that configures no
83 // pages_ref serves "pages", which is the config default.
84 func pageRef(pagesRef string) string {
85 if p := strings.TrimSpace(pagesRef); p != "" {
86 return "refs/heads/" + p
87 }
88 return "refs/heads/pages"
89 }
90
91 // onlyPages reports whether every ref in a push is the site branch. An empty push
92 // is not a site publish.
93 func onlyPages(changes []change, pagesRef string) bool {
94 if len(changes) == 0 {
95 return false
96 }
97 want := pageRef(pagesRef)
98 for _, c := range changes {
99 if c.ref != want {
100 return false
101 }
102 }
103 return true
104 }
105
79 106 // PreReceive returns a process exit code: 0 allows the push, 1 rejects it.
80 107 func PreReceive(cfg Config) int {
81 108 if cfg.Out == nil {
@@ -112,7 +139,7 @@ func PreReceive(cfg Config) int {
112 139 }
113 140 defer ident.Close()
114 141 acls.InstanceRole = ident.InstanceRole
115 // An entry or a runners-list membership outlives the account: a retired
142 // An entry outlives the account: a retired
116 143 // approver or runner must not keep satisfying this gate.
117 144 acls.Active = ident.Active
118 145 // The lock table shares that database, so the push path learns what is held
@@ -160,10 +187,6 @@ func PreReceive(cfg Config) int {
160 187 }
161 188
162 189 role := a.RoleFor(actor)
163 if !role.AtLeast(access.Contribute) {
164 reject(cfg.Out, "%s does not have maintain or contribute access to %s (role: %s)", actor, m.Name, role)
165 return 1
166 }
167 190
168 191 // A session opened with a run credential acts for one job, in one repository,
169 192 // until that job ends. The role is still the account's and the per-path rules below
@@ -196,6 +219,20 @@ func PreReceive(cfg Config) int {
196 219 return 0
197 220 }
198 221
222 // A contributor may push its own namespace, and a runner adds the site branch to
223 // that. Everything else is a maintainer's write. The role gate is asked once for
224 // the whole push; the per-ref rule below answers which refs the role may move.
225 if !role.AtLeast(access.Contribute) {
226 if onlyPages(changes, cfg.PagesRef) {
227 reject(cfg.Out, "%s does not have the runner role for %s, so it cannot publish %s (role: %s); "+
228 "grant it with `vole admin acl set-role %s %s runner`, or give it maintain access",
229 actor, m.Name, pageRef(cfg.PagesRef), role, m.Name, actor)
230 } else {
231 reject(cfg.Out, "%s does not have maintain, runner, or contribute access to %s (role: %s)", actor, m.Name, role)
232 }
233 return 1
234 }
235
199 236 g := git.Open(cfg.RepoDir)
200 237 // receive-pack reveals the pushed objects through a quarantine: it points
201 238 // GIT_OBJECT_DIRECTORY at the temporary object directory and lists the real
@@ -233,15 +270,23 @@ func PreReceive(cfg Config) int {
233 270 }
234 271 // A contributor gets one branch namespace, named after the account name.
235 272 // The name is fixed at creation and never reissued, so it identifies the
236 // owner without a lookup and no rename can strand a branch. Everything
237 // else — metadata, shared branches, tags — belongs to write or admin
273 // owner without a lookup and no rename can strand a branch. A runner may
274 // also publish the site ref, which is the one branch the instance names.
275 // Everything else — shared branches and tags — belongs to maintain or admin
238 276 // access. The check is here rather than at the role gate because the gate
239 277 // only knows that the account may push something.
278 site := pageRef(cfg.PagesRef)
240 279 if !role.AtLeast(access.Maintain) && !access.IsContributorRef(actor, c.ref) &&
241 c.ref != metadata.Ref {
242 problems = append(problems, fmt.Sprintf(
243 "%s: the contribute role may only push branches under %s and the issues branch (role: %s)",
244 c.ref, access.ContributorBranchPrefix(actor), role))
280 c.ref != metadata.Ref && !(role.AtLeast(access.Runner) && c.ref == site) {
281 if role.AtLeast(access.Runner) {
282 problems = append(problems, fmt.Sprintf(
283 "%s: the runner role may push its contrib branches, the issues branch, and %s (role: %s)",
284 c.ref, site, role))
285 } else {
286 problems = append(problems, fmt.Sprintf(
287 "%s: the contribute role may only push branches under %s and the issues branch (role: %s)",
288 c.ref, access.ContributorBranchPrefix(actor), role))
289 }
245 290 continue
246 291 }
247 292 // The metadata branch is append-only in shape: linear history, no merge