feat(passwd): self-service password reset across git, mail & chat (#59)

Add a key-gated `ssh passwd@host` route (alias `password@`) that sets ONE
member-chosen password across every service with its own credential:

  - git  (Forgejo)        new forgejo.SetPassword (PATCH /admin/users, clears
                          must_change; EnsureUser first so the account exists)
  - mail (Mailu webmail)  existing mailu.SetPassword
  - chat (IRC/Ergo + The Lounge)  new internal/ircpass package

Because the route authenticates by the member's registered SSH key, it also
serves as the forgot-password path — no old password required.

The BBS runs as a non-root service user, but the Ergo password store and The
Lounge user files are root-owned. internal/ircpass bridges this by shelling out
to scripts/set-irc-password.sh through a narrow sudoers rule (installed by
setup.sh). The new password travels on stdin (a new `set-irc-password.sh
<member> -` form), so it never appears in the process table or sudo's log.

UX: masked entry typed twice (readSecret); no-PTY reads stdin; empty input
generates a strong password and shows it once. Each service leg is independent
and best-effort with a per-service ✓/✗ summary, plus a confirmation email that
never contains the password.

Tests: ircpass (stdin contract + member/password rejection), forgejo.SetPassword,
auth IsPasswdName + reservation. Docs: credentials.md (passwd@ section) + irc.md.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-06-27 03:46:23 -07:00 committed by GitHub
parent f2bcb7e063
commit 54da317f4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 625 additions and 3 deletions

View file

@ -148,6 +148,60 @@ func TestEnsureUserResetPatchesWhenExists(t *testing.T) {
}
}
func TestSetPasswordPatchesChosenPassword(t *testing.T) {
var body map[string]any
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == http.MethodGet && r.URL.Path == "/api/v1/users/alice":
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"id":1}`))
case r.Method == http.MethodPatch && r.URL.Path == "/api/v1/admin/users/alice":
_ = json.NewDecoder(r.Body).Decode(&body)
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"id":1}`))
default:
t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
w.WriteHeader(http.StatusTeapot)
}
}))
defer srv.Close()
c := Config{BaseURL: srv.URL, Token: "secret"}
if err := c.SetPassword("alice", "member-chosen-pw"); err != nil {
t.Fatalf("SetPassword: %v", err)
}
if body["password"] != "member-chosen-pw" {
t.Errorf("sent password %v, want member-chosen-pw", body["password"])
}
// They chose it, so don't force another change on next sign-in.
if body["must_change_password"] != false {
t.Errorf("expected must_change_password=false, got %v", body["must_change_password"])
}
}
func TestSetPasswordErrorsWhenMissing(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
w.WriteHeader(http.StatusNotFound)
return
}
t.Errorf("must not PATCH a non-existent user (%s %s)", r.Method, r.URL.Path)
w.WriteHeader(http.StatusTeapot)
}))
defer srv.Close()
c := Config{BaseURL: srv.URL, Token: "secret"}
if err := c.SetPassword("ghost", "pw"); err == nil {
t.Fatal("expected an error when the account does not exist")
}
}
func TestSetPasswordUnconfigured(t *testing.T) {
if err := (Config{}).SetPassword("alice", "pw"); err == nil {
t.Fatal("expected an error when Forgejo is not configured")
}
}
func TestEnsureUserNoOpWhenExists(t *testing.T) {
created := false
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {