Sign in

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

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Answer whoami --role from the repository's rules

eec0e60344bf5686fc278ba5a8415dc0777ba9e2 · Keenan Nemetz · 6d ago · parent f422c24f

Answer whoami --role from the repository's rules

A role is per repository, so whoami cannot print one truth without knowing which repository is meant. Keep the default answer name-only, for the scripts that call it, and make the role an explicit query on the remote's repository.

The server's vole-whoami verb now accepts a repository path and returns the effective role after the same private-repository rule as a fetch. A run credential may ask only about its own repository. Update the CLI help and the contributor and account docs to point at the new query.

server/ssh/whoami.go +47

@@ -0,0 +1,47 @@
1 package ssh
2
3 import (
4 "fmt"
5 "io"
6
7 "github.com/rodent-software/vole/forge/access"
8 )
9
10 // serveWhoAmI answers the identity query. Without a repository it is the account
11 // name and the public URL, as it has always been. With one it also reports the
12 // account's effective role there, after applying the same private-repository rule
13 // as a fetch: a repository the account cannot read is reported as not found, not
14 // as a role.
15 func (s *Server) serveWhoAmI(ch io.Writer, user, repoArg string) int {
16 if repoArg == "" {
17 fmt.Fprintf(ch, "%s\t%s\n", user, s.cfg.PublicURL)
18 return 0
19 }
20 name, ok := repoName(repoArg)
21 if !ok {
22 fmt.Fprintln(ch, "vole: invalid repository path")
23 return 1
24 }
25 m, err := s.cfg.Repos.Meta(name)
26 if err != nil {
27 fmt.Fprintf(ch, "vole: repository %q not found\n", name)
28 return 1
29 }
30 a, err := m.ACL()
31 if err != nil {
32 s.cfg.Log.Warn("ssh: cannot read access rules", "user", user, "repo", name, "err", err)
33 fmt.Fprintf(ch, "vole: cannot read access rules for %s\n", name)
34 return 1
35 }
36 var admin bool
37 if s.cfg.Identity != nil {
38 admin = s.cfg.Identity.IsAdmin(user)
39 }
40 effective := a.EffectiveRole(user, admin)
41 if !a.Public() && !effective.AtLeast(access.Read) {
42 fmt.Fprintf(ch, "vole: repository %q not found\n", name)
43 return 1
44 }
45 fmt.Fprintf(ch, "%s\t%s\t%s\n", user, s.cfg.PublicURL, effective)
46 return 0
47 }