From 67b6ba901aec9e018990c392caa905976138f5fe Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:49:10 +0000 Subject: [PATCH 1/8] fix(api): log why an SFTP login was refused The cause went to debug level only, so a refused SFTP login could not be diagnosed on a live cluster. Log it at info with the user and cluster; the client and the audit trail still get one generic reason. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- api/internal/handlers/sftp_login.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/internal/handlers/sftp_login.go b/api/internal/handlers/sftp_login.go index 4a7eedfc0..82eab33e3 100644 --- a/api/internal/handlers/sftp_login.go +++ b/api/internal/handlers/sftp_login.go @@ -95,7 +95,9 @@ func (h *sftpLoginHandler) login(w http.ResponseWriter, req *http.Request) { base, rawTarget, hasTarget := splitSFTPUsername(body.Username) actor := truncateRunes(base, sftpActorMaxRunes) refuse := func(cause string) { - slog.Debug("sftp login refused", "cause", cause) + // The client and the audit trail get one generic reason; the operator's log names the cause so a + // refused login can be diagnosed (key not registered, wrong account, no access to the target, …). + slog.Info("sftp login refused", "user", actor, "cluster", caller.Cluster, "cause", cause) h.auditLoginFailure(ctx, req, actor) httperr.WriteMessage(w, req, messages.New("server.sftp.login_failed", nil)) } From 06a633fc53f650733548314b637a738221fa6e4a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:52:42 +0000 Subject: [PATCH 2/8] fix(api): let SSO accounts named by email log in over SFTP SFTP login checked the username against the local-account pattern, which has no @, so every SSO account (named by its email address) was refused before the user lookup. Accept any name an account can hold (no whitespace, control characters or /, at most 254 runes) and let the lookup decide. Document the email form in docs/sftp.md. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- api/internal/handlers/sftp_login.go | 24 +++++++++- .../handlers/sftp_login_sso_username_test.go | 46 +++++++++++++++++++ docs/sftp.md | 8 ++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 api/internal/handlers/sftp_login_sso_username_test.go diff --git a/api/internal/handlers/sftp_login.go b/api/internal/handlers/sftp_login.go index 82eab33e3..57dc85df0 100644 --- a/api/internal/handlers/sftp_login.go +++ b/api/internal/handlers/sftp_login.go @@ -10,6 +10,8 @@ import ( "net/netip" "strings" "time" + "unicode" + "unicode/utf8" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" @@ -118,7 +120,7 @@ func (h *sftpLoginHandler) login(w http.ResponseWriter, req *http.Request) { refuse("credential-shape") return } - if !identifierRE.MatchString(base) { + if !validSFTPUsername(base) { refuse("username") return } @@ -352,6 +354,26 @@ func (h *sftpServersHandler) list(w http.ResponseWriter, req *http.Request) { writeJSON(w, map[string]any{"items": items}) } +// sftpUsernameMaxRunes bounds an SFTP login name: long enough for an SSO account named by its email +// address (RFC 5321 caps a path at 254), far below anything that costs real work. +const sftpUsernameMaxRunes = 254 + +// validSFTPUsername reports whether name can be a panel username. Local accounts follow identifierRE, +// but SSO accounts are named by the identity provider (usually an email address), so the check only +// refuses what no account can hold: an empty or overlong name, whitespace, control characters and "/". +// The user lookup decides the rest. +func validSFTPUsername(name string) bool { + if name == "" || !utf8.ValidString(name) || utf8.RuneCountInString(name) > sftpUsernameMaxRunes { + return false + } + for _, r := range name { + if unicode.IsSpace(r) || unicode.IsControl(r) || r == '/' { + return false + } + } + return true +} + // splitSFTPUsername splits "name+target" at the last "+". The base is what authenticates. func splitSFTPUsername(raw string) (base, target string, hasTarget bool) { i := strings.LastIndex(raw, "+") diff --git a/api/internal/handlers/sftp_login_sso_username_test.go b/api/internal/handlers/sftp_login_sso_username_test.go new file mode 100644 index 000000000..2167f30ae --- /dev/null +++ b/api/internal/handlers/sftp_login_sso_username_test.go @@ -0,0 +1,46 @@ +package handlers + +import ( + "net/http" + "strings" + "testing" +) + +// An SSO account is named by its email address. Such a user can log in over SFTP with that name. +func TestSFTPLogin_SSOEmailUsername(t *testing.T) { + env := newSFTPLoginEnv(t) + h := sftpLoginRouter(env) + const name = "valgul.sso@example.com" + if _, err := env.store.DB.ExecContext(t.Context(), + `INSERT INTO users(username, display_name, email, role, pw_hash) VALUES (?, ?, ?, ?, ?)`, + name, "valgul", name, "viewer", "x"); err != nil { + t.Fatalf("insert sso user: %v", err) + } + uid := userIDOf(t, env, name) + pw, err := env.sessions.GenerateAndStoreSFTPPassword(t.Context(), uid, 24) + if err != nil { + t.Fatalf("set sftp password: %v", err) + } + if rr := env.login(t, h, map[string]any{"username": name, "password": pw}); rr.Code != http.StatusOK { + t.Fatalf("login as %s: status %d body %s", name, rr.Code, rr.Body.String()) + } +} + +func TestValidSFTPUsername(t *testing.T) { + for name, want := range map[string]bool{ + "alice": true, + "valgul.sso@example.com": true, + "": false, + "has space": false, + "tab\tname": false, + "ctrl\x01": false, + "a/b": false, + "\xff": false, + strings.Repeat("a", sftpUsernameMaxRunes): true, + strings.Repeat("a", sftpUsernameMaxRunes+1): false, + } { + if got := validSFTPUsername(name); got != want { + t.Errorf("validSFTPUsername(%q) = %v, want %v", name, got, want) + } + } +} diff --git a/docs/sftp.md b/docs/sftp.md index dccb70d3e..e4344b43a 100644 --- a/docs/sftp.md +++ b/docs/sftp.md @@ -128,6 +128,14 @@ The username chooses where the session starts. Both forms use the same password or key and the same permission checks. You only see the servers you can read. +`alice` stands for your panel username, shown on the profile page. An account +created through SSO is usually named by its email address, for example +`alice@example.com`. OpenSSH splits the host at the last `@`, so +`sftp -P 2222 alice@example.com@sftp.example.com` and +`sftp -P 2222 alice@example.com+survival@sftp.example.com` work as written. +A username that itself contains `+` cannot be used over SFTP, because `+` +starts the server part. + Permissions: - Reading needs `servers:read` on the server, or the usual ownership or From 0ffdcb17e15d1769f6def727bc14bce84ce2bf77 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:53:05 +0000 Subject: [PATCH 3/8] docs(changelog): SFTP login for SSO accounts Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- changelog/unreleased/1086-sftp-sso-usernames.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/unreleased/1086-sftp-sso-usernames.md diff --git a/changelog/unreleased/1086-sftp-sso-usernames.md b/changelog/unreleased/1086-sftp-sso-usernames.md new file mode 100644 index 000000000..5f974c959 --- /dev/null +++ b/changelog/unreleased/1086-sftp-sso-usernames.md @@ -0,0 +1,3 @@ +# SFTP login works for SSO accounts + +Accounts created through SSO are named by their email address, and the SFTP login refused every such name before checking the password or key. They can now log in with their panel username, for example `sftp -P 2222 alice@example.com@sftp.example.com`. The API log now names the cause of each refused SFTP login, for operators. [PR #1086](https://github.com/GameplanePanel/Gameplane/pull/1086) From 3e60030fe444052d18250ab84e289b8d8deeb0fb Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:58:22 +0000 Subject: [PATCH 4/8] chore: bump sftp so a refused SSH key falls back to the password (sftp#3) Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- sftp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sftp b/sftp index 2d695cc3f..c5baacfc5 160000 --- a/sftp +++ b/sftp @@ -1 +1 @@ -Subproject commit 2d695cc3f72b176691bbfbe5ec0af4410920c16a +Subproject commit c5baacfc522d5b5b193764b1472135f866ddd574 From a48fa785cca010240f24d5d2e68bc87fdeada292 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:58:34 +0000 Subject: [PATCH 5/8] docs(changelog): note the SSH key fallback Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- changelog/unreleased/1086-sftp-sso-usernames.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/unreleased/1086-sftp-sso-usernames.md b/changelog/unreleased/1086-sftp-sso-usernames.md index 5f974c959..f44819e95 100644 --- a/changelog/unreleased/1086-sftp-sso-usernames.md +++ b/changelog/unreleased/1086-sftp-sso-usernames.md @@ -1,3 +1,3 @@ # SFTP login works for SSO accounts -Accounts created through SSO are named by their email address, and the SFTP login refused every such name before checking the password or key. They can now log in with their panel username, for example `sftp -P 2222 alice@example.com@sftp.example.com`. The API log now names the cause of each refused SFTP login, for operators. [PR #1086](https://github.com/GameplanePanel/Gameplane/pull/1086) +Accounts created through SSO are named by their email address, and the SFTP login refused every such name before checking the password or key. They can now log in with their panel username, for example `sftp -P 2222 alice@example.com@sftp.example.com`. An SSH key that is not registered no longer drops the connection: the client falls back to the password prompt. The API log now names the cause of each refused SFTP login, for operators. [PR #1086](https://github.com/GameplanePanel/Gameplane/pull/1086) From 62b4a60055456fb3933a63b76d3941b03a48cd2e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 22:00:27 +0000 Subject: [PATCH 6/8] docs: correct the sftp login actor comment for long SSO names Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- api/internal/handlers/sftp_login.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/internal/handlers/sftp_login.go b/api/internal/handlers/sftp_login.go index 57dc85df0..4c23c3aa6 100644 --- a/api/internal/handlers/sftp_login.go +++ b/api/internal/handlers/sftp_login.go @@ -107,7 +107,8 @@ func (h *sftpLoginHandler) login(w http.ResponseWriter, req *http.Request) { // Rate limits run before any validation or credential work (so refusals cannot flood the audit // trail either), keyed like /auth/login: the source address the endpoint reports and the // username. The request IP is always the SFTP pod, so it is not used. actor is the username - // capped to 64 runes, identical to base for every valid username. + // capped to 64 runes for the audit trail and the rate-limit key; a longer SSO email name is + // truncated there but still authenticates by its full value (base). auth.SetActor(ctx, actor) if !auth.LoginLimiter.RequestBudget(w, req, sftpSourceKey(body.RemoteAddr, req)) { return From 8e6f60728f32adb504aeabfa809ef20b66a582db Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 22:00:50 +0000 Subject: [PATCH 7/8] fix(api): key the sftp username budget on the full name; document the login rule Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- api/internal/handlers/sftp_login.go | 8 ++++---- api/specs.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/internal/handlers/sftp_login.go b/api/internal/handlers/sftp_login.go index 4c23c3aa6..361fc1e75 100644 --- a/api/internal/handlers/sftp_login.go +++ b/api/internal/handlers/sftp_login.go @@ -106,14 +106,14 @@ func (h *sftpLoginHandler) login(w http.ResponseWriter, req *http.Request) { // Rate limits run before any validation or credential work (so refusals cannot flood the audit // trail either), keyed like /auth/login: the source address the endpoint reports and the - // username. The request IP is always the SFTP pod, so it is not used. actor is the username - // capped to 64 runes for the audit trail and the rate-limit key; a longer SSO email name is - // truncated there but still authenticates by its full value (base). + // full username. The request IP is always the SFTP pod, so it is not used. actor is the username + // capped to 64 runes for the audit trail only; the username budget keys on the full base, so two + // long SSO email names that share a 64-rune prefix do not share a budget. auth.SetActor(ctx, actor) if !auth.LoginLimiter.RequestBudget(w, req, sftpSourceKey(body.RemoteAddr, req)) { return } - if !auth.LoginUserLimiter.RequestBudget(w, req, actor) { + if !auth.LoginUserLimiter.RequestBudget(w, req, base) { return } diff --git a/api/specs.md b/api/specs.md index 989a43b31..7d4521eff 100644 --- a/api/specs.md +++ b/api/specs.md @@ -352,7 +352,7 @@ trust assumptions, rotation behavior and surfaces outside this protocol. - `POST /clusters/{name}/sftp-token`: mint a `gpsftps_` service token, returned once (201). At most two active per cluster; a third returns 409 `server.sftp.token_limit_reached`. Only the digest is stored. - `DELETE /clusters/{name}/sftp-token/{id}`: revoke (204). Tokens of other clusters are not found. -**Endpoint-facing routes** (`sftp_login.go`, mounted under `/sftp/v1` outside the protected group, authenticated by the service token or the session token the endpoint holds, never by a dashboard cookie): `POST /sftp/v1/login` resolves username and credential to a session; `POST /sftp/v1/sessions/check` re-validates open sessions (revocation and user disable end them within 60 s, SC-006); `POST /sftp/v1/sessions/end`; `GET /sftp/v1/servers` lists the servers the session can read. Every file operation after login goes to the agent through the normal file routes as the signed-in user, with the same RBAC checks as the Files tab, and is audited with `source: sftp`. +**Endpoint-facing routes** (`sftp_login.go`, mounted under `/sftp/v1` outside the protected group, authenticated by the service token or the session token the endpoint holds, never by a dashboard cookie): `POST /sftp/v1/login` resolves username and credential to a session; `POST /sftp/v1/sessions/check` re-validates open sessions (revocation and user disable end them within 60 s, SC-006); `POST /sftp/v1/sessions/end`; `GET /sftp/v1/servers` lists the servers the session can read. Login accepts the panel username as the part before the last `+` (local accounts and SSO accounts named by email address alike): non-empty valid UTF-8, at most 254 runes, no whitespace, control characters or `/`; the user lookup then decides whether the account exists. The username rate-limit budget keys on that full name. Every refusal gives the endpoint and the audit trail one generic `server.sftp.login_failed`, and the API logs the cause at info level with the username and calling cluster. Every file operation after login goes to the agent through the normal file routes as the signed-in user, with the same RBAC checks as the Files tab, and is audited with `source: sftp`. **Permissions:** reading needs `servers:read` (or ownership or collaborator access); writing, renaming and deleting need `servers:write` (or the same ownership or collaborator access). The data-root and server folders are read-only over SFTP. From 80ecd9b399ae32241d4db3d86d97fd11d6b22520 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 22:01:08 +0000 Subject: [PATCH 8/8] fix(api): bound the sftp username budget key Co-Authored-By: Claude Opus 5.5 Signed-off-by: Claude --- api/internal/handlers/sftp_login.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/internal/handlers/sftp_login.go b/api/internal/handlers/sftp_login.go index 361fc1e75..1b4dc53e3 100644 --- a/api/internal/handlers/sftp_login.go +++ b/api/internal/handlers/sftp_login.go @@ -108,12 +108,13 @@ func (h *sftpLoginHandler) login(w http.ResponseWriter, req *http.Request) { // trail either), keyed like /auth/login: the source address the endpoint reports and the // full username. The request IP is always the SFTP pod, so it is not used. actor is the username // capped to 64 runes for the audit trail only; the username budget keys on the full base, so two - // long SSO email names that share a 64-rune prefix do not share a budget. + // long SSO email names that share a 64-rune prefix do not share a budget. The key is capped one rune + // past the longest valid name, so an oversized name cannot grow the limiter's keys. auth.SetActor(ctx, actor) if !auth.LoginLimiter.RequestBudget(w, req, sftpSourceKey(body.RemoteAddr, req)) { return } - if !auth.LoginUserLimiter.RequestBudget(w, req, base) { + if !auth.LoginUserLimiter.RequestBudget(w, req, truncateRunes(base, sftpUsernameMaxRunes+1)) { return }