Skip to content

Commit 3fe4e9e

Browse files
committed
fine tune comment
1 parent c71d872 commit 3fe4e9e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

modules/ssh/ssh.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import (
4545
// set conn.Permissions from serverAuthenticate
4646
// sessionHandler(conn)
4747
//
48-
// Then sessionHandler should only use the "verified keyID" from the conn.
49-
// Otherwise, if a users provides 2 keys A and B, if A succeeds to authenticate, sessionHandler will see B's keyID
48+
// Then sessionHandler should only use the "verified keyID" from the original ssh conn, but not the ctx one.
49+
// Otherwise, if a user provides 2 keys A and B, if A succeeds to authenticate, sessionHandler will see B's keyID
5050

5151
const giteaPermissionExtensionKeyID = "gitea-perm-ext-key-id"
5252

@@ -75,7 +75,7 @@ func getExitStatusFromError(err error) int {
7575
}
7676

7777
// sessionPartial is the private struct from "gliderlabs/ssh/session.go"
78-
// we need to read the original "conn" field from "ssh.Session interface" which contains the "*session pointer"
78+
// We need to read the original "conn" field from "ssh.Session interface" which contains the "*session pointer"
7979
// https://github.com/gliderlabs/ssh/blob/d137aad99cd6f2d9495bfd98c755bec4e5dffb8c/session.go#L109-L113
8080
// If upstream fixes the problem and/or changes the struct, we need to follow.
8181
// If the struct mismatches, the builtin ssh server will fail during integration tests.
@@ -96,7 +96,8 @@ func ptr[T any](intf any) *T {
9696
}
9797

9898
func sessionHandler(session ssh.Session) {
99-
// it can't use session.Permissions() because it only use the ctx one, so we must use the original ssh conn
99+
// it can't use session.Permissions() because it only use the value from ctx, which might not be the authenticated one.
100+
// so we must use the original ssh conn, which always contains the correct (verified) keyID.
100101
sshConn := ptr[sessionPartial](session)
101102
keyID := sshConn.conn.Permissions.Extensions[giteaPermissionExtensionKeyID]
102103

0 commit comments

Comments
 (0)