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.
Run the exec verbs on a session, not an SSH channel
5ff8dfc964d8e05c5f5b7a8ec5e5f229178e5e4c · Keenan Nemetz · 16d ago · parent 22e290b0
Run the exec verbs on a session, not an SSH channel Every handler behind the exec verb took an *xssh.Channel, and the two that answer the exec request took the request too. That tied twenty functions to the SSH transport, but the front door needs the same verbs, with the same access rules, from a forced command that reaches the service over a local socket. A Session is now what a verb runs on: stdin, stdout, a separate error stream, Accept, CloseWrite, Exit, and Close. sshSession is the only implementation that knows what an SSH channel is, so the handlers no longer name a transport and a second one cannot become a second copy of the access rules. No behaviour change. The handlers keep their names and bodies; the refusal and exit-status paths move behind the interface, which is also what removes the standalone exit helper. A new test drives vole-whoami and git-upload-pack over SSH and over a session with no channel behind it, comparing stdout, stderr, and the exit status of both.
server/ssh/server.go +39−40
| @@ -452,12 +452,15 @@ func (s *Server) handleSession(ch xssh.Channel, reqs <-chan *xssh.Request, user, | |||
| 452 | 452 | case "exec": | |
| 453 | 453 | var payload struct{ Command string } | |
| 454 | 454 | xssh.Unmarshal(req.Payload, &payload) | |
| 455 | s.exec(ch, req, payload.Command, user, fp, remote) | ||
| 455 | s.exec(&sshSession{ch: ch, req: req}, payload.Command, user, fp, remote) | ||
| 456 | 456 | return | |
| 457 | 457 | case "shell", "pty-req", "subsystem": | |
| 458 | // The request was refused, so there is no exec request to accept; the | ||
| 459 | // exit status is what turns a client's attempt at a shell into a | ||
| 460 | // failure instead of a hang. | ||
| 458 | 461 | req.Reply(false, nil) | |
| 459 | 462 | fmt.Fprintf(ch, "vole: interactive shells are not available; push and fetch with git\n") | |
| 460 | exit(ch, 1) | ||
| 463 | (&sshSession{ch: ch}).Exit(1) | ||
| 461 | 464 | return | |
| 462 | 465 | case "env": | |
| 463 | 466 | // Accepting client env would let a session rewrite VOLE_ACTOR. | |
| @@ -468,15 +471,15 @@ func (s *Server) handleSession(ch xssh.Channel, reqs <-chan *xssh.Request, user, | |||
| 468 | 471 | } | |
| 469 | 472 | } | |
| 470 | 473 | ||
| 471 | func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, remote string) { | ||
| 474 | func (s *Server) exec(ch Session, command, user, fp, remote string) { | ||
| 472 | 475 | // A refusal is still answered on the channel rather than at the request | |
| 473 | 476 | // layer: replying false makes the client print "exec request failed on | |
| 474 | 477 | // channel 0" and the reason is lost. Nothing is ever executed on these | |
| 475 | 478 | // paths — the message is the whole response. | |
| 476 | 479 | refuse := func(format string, args ...any) { | |
| 477 | req.Reply(true, nil) | ||
| 480 | ch.Accept() | ||
| 478 | 481 | fmt.Fprintf(ch, "vole: "+format+"\n", args...) | |
| 479 | exit(ch, 1) | ||
| 482 | ch.Exit(1) | ||
| 480 | 483 | } | |
| 481 | 484 | ||
| 482 | 485 | // The exec line is the only client-supplied payload on this path. Refuse an | |
| @@ -511,9 +514,9 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 511 | 514 | // than introducing a token, and it is a stream: the runner leases jobs and | |
| 512 | 515 | // reports results over this channel. | |
| 513 | 516 | if len(argv) == 1 && argv[0] == "vole-runner" { | |
| 514 | req.Reply(true, nil) | ||
| 517 | ch.Accept() | ||
| 515 | 518 | s.serveRunner(ch, user) | |
| 516 | exit(ch, 0) | ||
| 519 | ch.Exit(0) | ||
| 517 | 520 | return | |
| 518 | 521 | } | |
| 519 | 522 | // `vole change merge` lands a change request. It moves a branch, so the rules | |
| @@ -527,8 +530,8 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 527 | 530 | return | |
| 528 | 531 | } | |
| 529 | 532 | defer release() | |
| 530 | req.Reply(true, nil) | ||
| 531 | exit(ch, s.serveChangeMerge(ch, argv, user, remote)) | ||
| 533 | ch.Accept() | ||
| 534 | ch.Exit(s.serveChangeMerge(ch, argv, user, remote)) | ||
| 532 | 535 | return | |
| 533 | 536 | } | |
| 534 | 537 | // `vole change show` asks the instance about the combined result; the clone has | |
| @@ -541,77 +544,77 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 541 | 544 | return | |
| 542 | 545 | } | |
| 543 | 546 | defer release() | |
| 544 | req.Reply(true, nil) | ||
| 545 | exit(ch, s.serveChangeStatus(ch, argv, user, remote)) | ||
| 547 | ch.Accept() | ||
| 548 | ch.Exit(s.serveChangeStatus(ch, argv, user, remote)) | ||
| 546 | 549 | return | |
| 547 | 550 | } | |
| 548 | 551 | // Reading the queue is the CLI counterpart of the runs page and a run's log. | |
| 549 | 552 | // The verbs check the repository's read capability and scope a run id to the | |
| 550 | 553 | // repository that owns it, exactly as the pages do. | |
| 551 | 554 | if len(argv) >= 1 && argv[0] == "vole-run-list" { | |
| 552 | req.Reply(true, nil) | ||
| 553 | exit(ch, s.serveRunList(ch, argv, user)) | ||
| 555 | ch.Accept() | ||
| 556 | ch.Exit(s.serveRunList(ch, argv, user)) | ||
| 554 | 557 | return | |
| 555 | 558 | } | |
| 556 | 559 | if len(argv) >= 1 && argv[0] == "vole-run-show" { | |
| 557 | req.Reply(true, nil) | ||
| 558 | exit(ch, s.serveRunShow(ch, argv, user)) | ||
| 560 | ch.Accept() | ||
| 561 | ch.Exit(s.serveRunShow(ch, argv, user)) | ||
| 559 | 562 | return | |
| 560 | 563 | } | |
| 561 | 564 | if len(argv) >= 1 && argv[0] == "vole-run-log" { | |
| 562 | req.Reply(true, nil) | ||
| 563 | exit(ch, s.serveRunLog(ch, argv, user)) | ||
| 565 | ch.Accept() | ||
| 566 | ch.Exit(s.serveRunLog(ch, argv, user)) | ||
| 564 | 567 | return | |
| 565 | 568 | } | |
| 566 | 569 | // Canceling and rerunning a run are writes to the repository's CI queue, not to a | |
| 567 | 570 | // ref. The verbs are the CLI counterparts of the buttons on the run page, and the | |
| 568 | 571 | // handlers ask the same maintainer capability before they touch the queue. | |
| 569 | 572 | if len(argv) >= 1 && argv[0] == "vole-run-cancel" { | |
| 570 | req.Reply(true, nil) | ||
| 571 | exit(ch, s.serveRunCancel(ch, argv, user)) | ||
| 573 | ch.Accept() | ||
| 574 | ch.Exit(s.serveRunCancel(ch, argv, user)) | ||
| 572 | 575 | return | |
| 573 | 576 | } | |
| 574 | 577 | if len(argv) >= 1 && argv[0] == "vole-run-rerun" { | |
| 575 | req.Reply(true, nil) | ||
| 576 | exit(ch, s.serveRunRerun(ch, argv, user)) | ||
| 578 | ch.Accept() | ||
| 579 | ch.Exit(s.serveRunRerun(ch, argv, user)) | ||
| 577 | 580 | return | |
| 578 | 581 | } | |
| 579 | 582 | // A manual workflow run is a write to the repository's CI queue, not to a ref. | |
| 580 | 583 | // The verb is the CLI counterpart of the browser's Run workflow form; the | |
| 581 | 584 | // dispatcher re-checks the maintainer capability before it queues anything. | |
| 582 | 585 | if len(argv) >= 1 && argv[0] == "vole-workflow-dispatch" { | |
| 583 | req.Reply(true, nil) | ||
| 584 | exit(ch, s.serveWorkflowDispatch(ch, argv, user)) | ||
| 586 | ch.Accept() | ||
| 587 | ch.Exit(s.serveWorkflowDispatch(ch, argv, user)) | ||
| 585 | 588 | return | |
| 586 | 589 | } | |
| 587 | 590 | // Repository secrets are a server-side store, so the CLI asks the instance for | |
| 588 | 591 | // them over the same key it pushes with: reading, writing and deleting are all | |
| 589 | 592 | // maintainer capabilities, re-checked here rather than trusted from the client. | |
| 590 | 593 | if len(argv) >= 1 && argv[0] == "vole-secret" { | |
| 591 | req.Reply(true, nil) | ||
| 592 | exit(ch, s.serveSecret(ch, argv, user)) | ||
| 594 | ch.Accept() | ||
| 595 | ch.Exit(s.serveSecret(ch, argv, user)) | ||
| 593 | 596 | return | |
| 594 | 597 | } | |
| 595 | 598 | // Release channels are server-side state, so the CLI asks the instance for | |
| 596 | 599 | // them over the same key it pushes with. The verbs re-check the repository | |
| 597 | 600 | // role and record the move in the audit log. | |
| 598 | 601 | if len(argv) >= 1 && argv[0] == "vole-channel" { | |
| 599 | req.Reply(true, nil) | ||
| 600 | exit(ch, s.serveChannel(ch, argv, user)) | ||
| 602 | ch.Accept() | ||
| 603 | ch.Exit(s.serveChannel(ch, argv, user)) | ||
| 601 | 604 | return | |
| 602 | 605 | } | |
| 603 | 606 | // The admin API is a fixed command set, not a shell. It is available only to | |
| 604 | 607 | // accounts marked as instance admins. | |
| 605 | 608 | if len(argv) >= 1 && argv[0] == "vole-admin" { | |
| 606 | req.Reply(true, nil) | ||
| 607 | exit(ch, s.serveAdmin(ch, argv[1:], user, remote)) | ||
| 609 | ch.Accept() | ||
| 610 | ch.Exit(s.serveAdmin(ch, argv[1:], user, remote)) | ||
| 608 | 611 | return | |
| 609 | 612 | } | |
| 610 | 613 | // git-lfs speaks its own protocol over an SSH remote: the client runs | |
| 611 | 614 | // `git-lfs-transfer <repo> upload|download` on the same connection family as | |
| 612 | 615 | // the push. No token changes hands; the key is the identity. | |
| 613 | 616 | if len(argv) == 3 && argv[0] == "git-lfs-transfer" { | |
| 614 | s.serveLFS(ch, req, argv[1], argv[2], user) | ||
| 617 | s.serveLFS(ch, argv[1], argv[2], user) | ||
| 615 | 618 | return | |
| 616 | 619 | } | |
| 617 | 620 | // The client cannot see the server's database, so the roster is served | |
| @@ -620,12 +623,12 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 620 | 623 | // against the active roster, and it is the whole surface — nothing here is | |
| 621 | 624 | // writable. | |
| 622 | 625 | if len(argv) == 1 && argv[0] == "vole-roster" { | |
| 623 | req.Reply(true, nil) | ||
| 626 | ch.Accept() | ||
| 624 | 627 | for _, name := range s.cfg.Identity.Roster() { | |
| 625 | 628 | fmt.Fprintln(ch, name) | |
| 626 | 629 | } | |
| 627 | 630 | s.cfg.Log.Info("ssh roster", "user", user, "accounts", s.cfg.Identity.Snapshot().Count) | |
| 628 | exit(ch, 0) | ||
| 631 | ch.Exit(0) | ||
| 629 | 632 | return | |
| 630 | 633 | } | |
| 631 | 634 | // `vole whoami` asks the instance which account the presented key is. That | |
| @@ -650,8 +653,8 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 650 | 653 | } | |
| 651 | 654 | repoArg = argv[1] | |
| 652 | 655 | } | |
| 653 | req.Reply(true, nil) | ||
| 654 | exit(ch, s.serveWhoAmI(ch, user, repoArg)) | ||
| 656 | ch.Accept() | ||
| 657 | ch.Exit(s.serveWhoAmI(ch, user, repoArg)) | ||
| 655 | 658 | return | |
| 656 | 659 | } | |
| 657 | 660 | if len(argv) != 2 { | |
| @@ -712,7 +715,7 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 712 | 715 | } | |
| 713 | 716 | defer release() | |
| 714 | 717 | ||
| 715 | if err := req.Reply(true, nil); err != nil { | ||
| 718 | if err := ch.Accept(); err != nil { | ||
| 716 | 719 | return | |
| 717 | 720 | } | |
| 718 | 721 | ||
| @@ -753,7 +756,7 @@ func (s *Server) exec(ch xssh.Channel, req *xssh.Request, command, user, fp, rem | |||
| 753 | 756 | } | |
| 754 | 757 | s.cfg.Log.Info("ssh git", "user", user, "verb", strings.TrimPrefix(verb, "git-"), | |
| 755 | 758 | "repo", name, "exit", code, "duration", time.Since(start).String()) | |
| 756 | exit(ch, code) | ||
| 759 | ch.Exit(code) | ||
| 757 | 760 | } | |
| 758 | 761 | ||
| 759 | 762 | // repoName turns a git SSH path argument into a repo name. git sends either | |
| @@ -827,10 +830,6 @@ func splitCommand(s string) ([]string, error) { | |||
| 827 | 830 | return out, nil | |
| 828 | 831 | } | |
| 829 | 832 | ||
| 830 | func exit(ch xssh.Channel, code int) { | ||
| 831 | ch.SendRequest("exit-status", false, xssh.Marshal(struct{ Status uint32 }{uint32(code)})) | ||
| 832 | } | ||
| 833 | |||
| 834 | 833 | func loadOrCreateHostKey(path string, log *slog.Logger) (xssh.Signer, error) { | |
| 835 | 834 | // The host key is the instance's long-term secret. A copy another account can | |
| 836 | 835 | // read is already disclosed, so a loose mode is corrected before the key is | |