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.
Move release channels to an authoritative channels.db
262e516e838cfc4b16b5d00fd98d5e4ef135aa85 · Keenan Nemetz · 19d ago · parent 24019cb3
Move release channels to an authoritative channels.db Channels are consumed from the public URL and are server-side publication state, so they no longer live on the vole branch or in the derived index. - forge/channel: authoritative SQLite store with schema, validation, and CRUD - config: data/channels.db, opened and closed with the instance - CLI: release channel set|list|clear over a new vole-channel SSH verb - server: maintain for set/clear, read for list, annotated-tag validation, audit channel.set/channel.clear, JSON list - web: channel page and tree read the store; release badges query it - remove the metadata-branch channel parser/validator, the index-derived channel table, and the hook path rules - backup, instance-data, and architecture docs include channels.db Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
server/ssh/channel.go +201
| @@ -0,0 +1,201 @@ | |||
| 1 | package ssh | ||
| 2 | |||
| 3 | // Release channels over the SSH verb. | ||
| 4 | // | ||
| 5 | // vole-channel list <repository> | ||
| 6 | // vole-channel set <repository> <name> <tag> (description on stdin) | ||
| 7 | // vole-channel clear <repository> <name> | ||
| 8 | // | ||
| 9 | // The channel store is server-side source state, so the CLI asks the instance | ||
| 10 | // over the same key it pushes with. The verbs re-check the repository role: | ||
| 11 | // listing is a read capability, moving a channel is maintainer work. A move is | ||
| 12 | // recorded in the audit log before the row is written. | ||
| 13 | |||
| 14 | import ( | ||
| 15 | "encoding/json" | ||
| 16 | "fmt" | ||
| 17 | "io" | ||
| 18 | "strings" | ||
| 19 | "time" | ||
| 20 | |||
| 21 | xssh "golang.org/x/crypto/ssh" | ||
| 22 | |||
| 23 | "rodent.software/vole/core/git" | ||
| 24 | "rodent.software/vole/forge/access" | ||
| 25 | "rodent.software/vole/forge/channel" | ||
| 26 | "rodent.software/vole/internal/audit" | ||
| 27 | ) | ||
| 28 | |||
| 29 | type channelLine struct { | ||
| 30 | Name string `json:"name"` | ||
| 31 | Release string `json:"release"` | ||
| 32 | ReleaseObject string `json:"release_object"` | ||
| 33 | UpdatedBy string `json:"updated_by"` | ||
| 34 | UpdatedAt time.Time `json:"updated_at"` | ||
| 35 | Description string `json:"description"` | ||
| 36 | Dangling bool `json:"dangling"` | ||
| 37 | } | ||
| 38 | |||
| 39 | func (s *Server) serveChannel(ch xssh.Channel, argv []string, user string) int { | ||
| 40 | if s.cfg.Channels == nil { | ||
| 41 | fmt.Fprint(ch, "vole: this instance has no channel store\n") | ||
| 42 | return 1 | ||
| 43 | } | ||
| 44 | if len(argv) < 3 { | ||
| 45 | fmt.Fprint(ch, "vole: usage: vole-channel list|set|clear <repository> [<name> <tag>]\n") | ||
| 46 | return 129 | ||
| 47 | } | ||
| 48 | op := argv[1] | ||
| 49 | repo, ok := repoName(argv[2]) | ||
| 50 | if !ok { | ||
| 51 | fmt.Fprint(ch, "vole: invalid repository name\n") | ||
| 52 | return 129 | ||
| 53 | } | ||
| 54 | m, err := s.cfg.Repos.Open(repo) | ||
| 55 | if err != nil { | ||
| 56 | fmt.Fprintf(ch, "vole: repository %q not found\n", repo) | ||
| 57 | return 1 | ||
| 58 | } | ||
| 59 | a, err := m.ACL() | ||
| 60 | if err != nil { | ||
| 61 | fmt.Fprintf(ch, "vole: cannot read access rules for %s\n", repo) | ||
| 62 | return 1 | ||
| 63 | } | ||
| 64 | role := a.EffectiveRole(user, s.cfg.Identity != nil && s.cfg.Identity.IsAdmin(user)) | ||
| 65 | |||
| 66 | switch op { | ||
| 67 | case "list": | ||
| 68 | if len(argv) != 3 { | ||
| 69 | fmt.Fprint(ch, "vole: usage: vole-channel list <repository>\n") | ||
| 70 | return 129 | ||
| 71 | } | ||
| 72 | if !role.AtLeast(access.Read) { | ||
| 73 | fmt.Fprintf(ch, "vole: %s may not read channels in %s\n", user, repo) | ||
| 74 | return 1 | ||
| 75 | } | ||
| 76 | list, err := s.cfg.Channels.List(m.ID) | ||
| 77 | if err != nil { | ||
| 78 | fmt.Fprintf(ch, "vole: cannot read channels: %v\n", err) | ||
| 79 | return 1 | ||
| 80 | } | ||
| 81 | lines := make([]channelLine, 0, len(list)) | ||
| 82 | for _, ch := range list { | ||
| 83 | lines = append(lines, channelLine{ | ||
| 84 | Name: ch.Name, | ||
| 85 | Release: ch.Release, | ||
| 86 | ReleaseObject: ch.ReleaseObject, | ||
| 87 | UpdatedBy: ch.UpdatedBy, | ||
| 88 | UpdatedAt: ch.UpdatedAt, | ||
| 89 | Description: ch.Description, | ||
| 90 | Dangling: !channelTargetOK(m.Git(), ch), | ||
| 91 | }) | ||
| 92 | } | ||
| 93 | if err := json.NewEncoder(ch).Encode(lines); err != nil { | ||
| 94 | fmt.Fprintf(ch, "vole: cannot write the channel list: %v\n", err) | ||
| 95 | return 1 | ||
| 96 | } | ||
| 97 | return 0 | ||
| 98 | |||
| 99 | case "set": | ||
| 100 | if len(argv) != 5 { | ||
| 101 | fmt.Fprint(ch, "vole: usage: vole-channel set <repository> <name> <tag>\n") | ||
| 102 | return 129 | ||
| 103 | } | ||
| 104 | if !role.AtLeast(access.Maintain) { | ||
| 105 | fmt.Fprintf(ch, "vole: moving a release channel requires maintain access (role: %s)\n", role) | ||
| 106 | return 1 | ||
| 107 | } | ||
| 108 | name := argv[3] | ||
| 109 | if err := channel.ValidName(name); err != nil { | ||
| 110 | fmt.Fprintf(ch, "vole: %v\n", err) | ||
| 111 | return 129 | ||
| 112 | } | ||
| 113 | tag := argv[4] | ||
| 114 | t, err := m.Git().Tag(tag) | ||
| 115 | if err != nil { | ||
| 116 | fmt.Fprintf(ch, "vole: no tag %s in %s\n", tag, repo) | ||
| 117 | return 1 | ||
| 118 | } | ||
| 119 | if !t.Annotated { | ||
| 120 | fmt.Fprintf(ch, "vole: %s is a lightweight tag; a channel names an annotated release\n", tag) | ||
| 121 | return 1 | ||
| 122 | } | ||
| 123 | description, err := io.ReadAll(io.LimitReader(ch, channel.MaxDescription+1)) | ||
| 124 | if err != nil { | ||
| 125 | fmt.Fprintf(ch, "vole: cannot read the channel description: %v\n", err) | ||
| 126 | return 1 | ||
| 127 | } | ||
| 128 | if len(description) > channel.MaxDescription { | ||
| 129 | fmt.Fprintf(ch, "vole: the channel description is larger than %d bytes\n", channel.MaxDescription) | ||
| 130 | return 129 | ||
| 131 | } | ||
| 132 | if err := audit.Append(s.cfg.AuditPath, audit.Record{ | ||
| 133 | Action: "channel.set", | ||
| 134 | Actor: user, | ||
| 135 | Subject: repo, | ||
| 136 | Detail: name + " -> " + tag, | ||
| 137 | }); err != nil { | ||
| 138 | fmt.Fprintf(ch, "vole: cannot record the channel move, refusing it: %v\n", err) | ||
| 139 | return 1 | ||
| 140 | } | ||
| 141 | if err := s.cfg.Channels.Set(m.ID, channel.Channel{ | ||
| 142 | Name: name, | ||
| 143 | Release: tag, | ||
| 144 | ReleaseObject: t.OID, | ||
| 145 | UpdatedBy: user, | ||
| 146 | UpdatedAt: time.Now().UTC(), | ||
| 147 | Description: string(description), | ||
| 148 | }); err != nil { | ||
| 149 | fmt.Fprintf(ch, "vole: %v\n", err) | ||
| 150 | return 1 | ||
| 151 | } | ||
| 152 | fmt.Fprintf(ch, "channel %s -> %s\n", name, tag) | ||
| 153 | return 0 | ||
| 154 | |||
| 155 | case "clear": | ||
| 156 | if len(argv) != 4 { | ||
| 157 | fmt.Fprint(ch, "vole: usage: vole-channel clear <repository> <name>\n") | ||
| 158 | return 129 | ||
| 159 | } | ||
| 160 | if !role.AtLeast(access.Maintain) { | ||
| 161 | fmt.Fprintf(ch, "vole: moving a release channel requires maintain access (role: %s)\n", role) | ||
| 162 | return 1 | ||
| 163 | } | ||
| 164 | name := argv[3] | ||
| 165 | if err := channel.ValidName(name); err != nil { | ||
| 166 | fmt.Fprintf(ch, "vole: %v\n", err) | ||
| 167 | return 129 | ||
| 168 | } | ||
| 169 | if _, found, err := s.cfg.Channels.Get(m.ID, name); err != nil { | ||
| 170 | fmt.Fprintf(ch, "vole: cannot read the channel: %v\n", err) | ||
| 171 | return 1 | ||
| 172 | } else if !found { | ||
| 173 | fmt.Fprintf(ch, "vole: no channel %s\n", name) | ||
| 174 | return 1 | ||
| 175 | } | ||
| 176 | if err := audit.Append(s.cfg.AuditPath, audit.Record{ | ||
| 177 | Action: "channel.clear", | ||
| 178 | Actor: user, | ||
| 179 | Subject: repo, | ||
| 180 | Detail: name, | ||
| 181 | }); err != nil { | ||
| 182 | fmt.Fprintf(ch, "vole: cannot record the channel change, refusing it: %v\n", err) | ||
| 183 | return 1 | ||
| 184 | } | ||
| 185 | if _, err := s.cfg.Channels.Clear(m.ID, name); err != nil { | ||
| 186 | fmt.Fprintf(ch, "vole: %v\n", err) | ||
| 187 | return 1 | ||
| 188 | } | ||
| 189 | fmt.Fprintf(ch, "cleared channel %s\n", name) | ||
| 190 | return 0 | ||
| 191 | } | ||
| 192 | fmt.Fprintf(ch, "vole: unknown channel command %q; use list, set, or clear\n", op) | ||
| 193 | return 129 | ||
| 194 | } | ||
| 195 | |||
| 196 | // channelTargetOK is the server's dangling check: an annotated tag whose object | ||
| 197 | // id is still the one the row recorded. | ||
| 198 | func channelTargetOK(g *git.Repo, ch channel.Channel) bool { | ||
| 199 | t, err := g.Tag(ch.Release) | ||
| 200 | return err == nil && t.Annotated && strings.EqualFold(t.OID, ch.ReleaseObject) | ||
| 201 | } | ||