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/web/admin_access.go +8−37

@@ -26,7 +26,6 @@ type aclRow struct {
26 26 Role string // repository-specific entry, or none when inherited
27 27 InstanceRole string
28 28 EffectiveRole string
29 Runner bool
30 29 }
31 30
32 31 // accessView is the access section. It is built only for an instance admin: the
@@ -103,17 +102,14 @@ func (w *Web) SaveRepositoryAccess(rw http.ResponseWriter, r *http.Request) {
103 102 }
104 103
105 104 // The rows this page rendered, and what the form said about each one. Anything
106 // the form did not submit is not this submission's to change: an entry or a
107 // runner another admin added while this page was open must survive the save.
108 rendered := map[string]bool{}
105 // the form did not submit is not this submission's to change: an entry another
106 // admin added while this page was open must survive the save.
109 107 type roleChange struct {
110 108 name string
111 109 role access.Role
112 110 }
113 111 var roles []roleChange
114 var runners []string
115 112 for _, row := range w.aclRows(acl) {
116 rendered[row.Name] = true
117 113 if raw, present := r.PostForm["role:"+row.Name]; present {
118 114 role, err := access.ParseRole(raw[0])
119 115 if err != nil {
@@ -122,9 +118,6 @@ func (w *Web) SaveRepositoryAccess(rw http.ResponseWriter, r *http.Request) {
122 118 }
123 119 roles = append(roles, roleChange{name: row.Name, role: role})
124 120 }
125 if r.PostFormValue("runner:"+row.Name) != "" {
126 runners = append(runners, row.Name)
127 }
128 121 }
129 122
130 123 if _, err := m.UpdateACL(pr.account.Name, func(cur *access.ACL) error {
@@ -140,16 +133,6 @@ func (w *Web) SaveRepositoryAccess(rw http.ResponseWriter, r *http.Request) {
140 133 }
141 134 cur.Entries[rc.name] = rc.role.String()
142 135 }
143 // Runners for accounts this page did not render stay as they are; the
144 // rendered ones are exactly what the form said.
145 var kept []string
146 for _, existing := range cur.Runners {
147 if !rendered[existing] {
148 kept = append(kept, existing)
149 }
150 }
151 cur.Runners = nil
152 cur.SetRunners(append(kept, runners...))
153 136 return nil
154 137 }); err != nil {
155 138 w.serverError(rw, r, "cannot save access rules: "+err.Error())
@@ -241,19 +224,10 @@ func splitLines(raw string) []string {
241 224 return out
242 225 }
243 226
244 // aclRows lists only the accounts this repository actually mentions: an
245 // explicit role entry or a runner allowlist entry. The roster is not enumerated
246 // here, because a repository with three entries should not render every account
247 // on the instance.
227 // aclRows lists only the accounts this repository actually mentions: an explicit
228 // role entry. The roster is not enumerated here, because a repository with three
229 // entries should not render every account on the instance.
248 230 func (w *Web) aclRows(a *access.ACL) []aclRow {
249 isRunner := func(id string) bool {
250 for _, runner := range a.Runners {
251 if runner == id {
252 return true
253 }
254 }
255 return false
256 }
257 231 role := func(id string) string {
258 232 if r, ok := a.Entries[id]; ok {
259 233 return r
@@ -276,7 +250,7 @@ func (w *Web) aclRows(a *access.ACL) []aclRow {
276 250 }
277 251 rows = append(rows, aclRow{
278 252 Name: name, Status: w.accountStatus(name),
279 Role: role(name), Runner: isRunner(name),
253 Role: role(name),
280 254 InstanceRole: instance.String(),
281 255 EffectiveRole: a.EffectiveRole(name, instanceAdmin).String(),
282 256 })
@@ -284,15 +258,12 @@ func (w *Web) aclRows(a *access.ACL) []aclRow {
284 258 for id := range a.Entries {
285 259 add(id)
286 260 }
287 for _, id := range a.Runners {
288 add(id)
289 }
290 261 sort.Slice(rows, func(i, j int) bool { return rows[i].Name < rows[j].Name })
291 262 return rows
292 263 }
293 264
294 // addableAccounts are active accounts with no explicit role or runner entry in
295 // this repository. They are the choices for the "Add account" control.
265 // addableAccounts are active accounts with no explicit role entry in this
266 // repository. They are the choices for the "Add account" control.
296 267 func (w *Web) addableAccounts(rows []aclRow) []string {
297 268 if w.Ident == nil {
298 269 return nil