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/ssh/admin.go +15−91

@@ -226,7 +226,7 @@ func (s *Server) adminAccount(action string, args []string, actor string, in io.
226 226
227 227 case "role":
228 228 if len(args) != 2 {
229 return nil, nil, &adminUsageError{msg: "usage: vole-admin account role <name> <none|read|contribute|maintain|admin>"}
229 return nil, nil, &adminUsageError{msg: "usage: vole-admin account role <name> <none|read|contribute|runner|maintain|admin>"}
230 230 }
231 231 role, err := access.ParseRole(args[1])
232 232 if err != nil {
@@ -562,13 +562,13 @@ func (s *Server) adminACL(action string, args []string, actor string) (any, admi
562 562
563 563 case "set-role":
564 564 if len(args) != 3 {
565 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl set-role <repo> <account> <none|read|contribute|maintain|admin>"}
565 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl set-role <repo> <account> <none|read|contribute|runner|maintain|admin>"}
566 566 }
567 567 repoName, accountName, roleName = args[0], args[1], args[2]
568 568
569 569 case "set-default-role":
570 570 if len(args) != 2 {
571 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl set-default-role <repo> <none|read|contribute|maintain|admin>"}
571 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl set-default-role <repo> <none|read|contribute|runner|maintain|admin>"}
572 572 }
573 573 repoName, roleName = args[0], args[1]
574 574
@@ -592,7 +592,7 @@ func (s *Server) adminACL(action string, args []string, actor string) (any, admi
592 592 return nil, nil, &adminUsageError{msg: fmt.Sprintf("checks takes enable or disable, not %q", mode)}
593 593 }
594 594
595 case "protect", "runners":
595 case "protect":
596 596 if len(args) < 2 {
597 597 return nil, nil, &adminUsageError{msg: fmt.Sprintf("usage: vole-admin acl %s list|add|remove|set|clear <repo> ...", action)}
598 598 }
@@ -604,17 +604,14 @@ func (s *Server) adminACL(action string, args []string, actor string) (any, admi
604 604 }
605 605 case "add", "remove", "set":
606 606 if len(values) == 0 {
607 if action == "protect" {
608 return nil, nil, &adminUsageError{msg: fmt.Sprintf("acl protect %s needs at least one ref pattern", mode)}
609 }
610 return nil, nil, &adminUsageError{msg: fmt.Sprintf("acl runners %s needs at least one account", mode)}
607 return nil, nil, &adminUsageError{msg: fmt.Sprintf("acl protect %s needs at least one ref pattern", mode)}
611 608 }
612 609 default:
613 610 return nil, nil, &adminUsageError{msg: fmt.Sprintf("unknown acl %s command %q", action, mode)}
614 611 }
615 612
616 613 default:
617 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl <show|set-role|set-default-role|set-approvals|checks|protect|runners> <repo> ..."}
614 return nil, nil, &adminUsageError{msg: "usage: vole-admin acl <show|set-role|set-default-role|set-approvals|checks|protect> <repo> ..."}
618 615 }
619 616
620 617 m, err := s.cfg.Instance.Repos.Open(repoName)
@@ -719,63 +716,6 @@ func (s *Server) adminACL(action string, args []string, actor string) (any, admi
719 716 a.Protected = next
720 717 }
721 718 return finish()
722
723 case "runners":
724 if mode == "list" {
725 return s.aclRunnersResult(m, a)
726 }
727 resolve := func(name string) (string, error) {
728 account, err := s.cfg.Identity.Find(name)
729 if err != nil {
730 return "", err
731 }
732 return account.Name, nil
733 }
734 var next []string
735 switch mode {
736 case "clear":
737 // next stays empty
738 case "set":
739 next = make([]string, 0, len(values))
740 for _, name := range values {
741 id, err := resolve(name)
742 if err != nil {
743 return nil, nil, err
744 }
745 next = append(next, id)
746 }
747 case "add":
748 next = append(next, a.Runners...)
749 for _, name := range values {
750 id, err := resolve(name)
751 if err != nil {
752 return nil, nil, err
753 }
754 next = append(next, id)
755 }
756 case "remove":
757 next = append(next, a.Runners...)
758 for _, name := range values {
759 id, err := resolve(name)
760 if err != nil {
761 return nil, nil, err
762 }
763 kept, found := next[:0], false
764 for _, r := range next {
765 if r == id {
766 found = true
767 continue
768 }
769 kept = append(kept, r)
770 }
771 if !found {
772 return nil, nil, fmt.Errorf("%s is not a runner for %s", name, m.Name)
773 }
774 next = kept
775 }
776 }
777 a.SetRunners(next)
778 return finish()
779 719 }
780 720 return nil, nil, &adminUsageError{msg: fmt.Sprintf("unknown acl command %q", action)}
781 721 }
@@ -792,26 +732,6 @@ func (s *Server) aclProtectedResult(m *repo.Meta, a *access.ACL) (any, adminRend
792 732 }, nil
793 733 }
794 734
795 func (s *Server) aclRunnersResult(m *repo.Meta, a *access.ACL) (any, adminRender, error) {
796 runners := append([]string(nil), a.Runners...)
797 data := map[string]any{"repo": m.Name, "runners": runners}
798 return data, func(out, _ io.Writer) {
799 for _, r := range a.Runners {
800 fmt.Fprintf(out, "runner %s\n", r)
801 }
802 if len(a.Runners) > 0 {
803 fmt.Fprintln(out, "(admins may also report CI results)")
804 return
805 }
806 fmt.Fprintf(out, "runners: none named; only admins may report CI results for %s\n", m.Name)
807 for _, p := range a.Principals() {
808 if a.CanReport(p) {
809 fmt.Fprintf(out, " admin %s\n", p)
810 }
811 }
812 }, nil
813 }
814
815 735 func (s *Server) repoData(m *repo.Meta) (map[string]any, *access.ACL, error) {
816 736 a, err := m.ACL()
817 737 if err != nil {
@@ -841,8 +761,12 @@ func (s *Server) aclResult(m *repo.Meta, a *access.ACL) (any, adminRender, error
841 761 "role": a.Entries[principal],
842 762 })
843 763 }
844 runners := make([]string, 0, len(a.Runners))
845 runners = append(runners, a.Runners...)
764 runners := make([]string, 0)
765 for _, principal := range a.Principals() {
766 if a.RepositoryRoleFor(principal) == access.Runner {
767 runners = append(runners, principal)
768 }
769 }
846 770 data := map[string]any{
847 771 "repo": m.Name,
848 772 "public": a.Can("", access.Read),
@@ -872,14 +796,14 @@ func (s *Server) aclResult(m *repo.Meta, a *access.ACL) (any, adminRender, error
872 796 } else {
873 797 fmt.Fprintln(out, "checks: not required")
874 798 }
875 if len(a.Runners) == 0 {
876 fmt.Fprintln(out, "runners: none named (admins may report CI results)")
799 if len(runners) == 0 {
800 fmt.Fprintln(out, "runners: none besides maintainers and admins")
877 801 return
878 802 }
879 803 for _, r := range runners {
880 804 fmt.Fprintf(out, "runner %s\n", r)
881 805 }
882 fmt.Fprintln(out, "(admins may also report CI results)")
806 fmt.Fprintln(out, "(maintainers and admins also report CI results)")
883 807 }, nil
884 808 }
885 809