Skip to content

Log backend local address for each forwarded connection - #48

Merged
kilo666mj merged 1 commit into
mainfrom
log-backend-local-port
Sep 27, 2026
Merged

kilo666mj merged 1 commit into
mainfrom
log-backend-local-port

Conversation

@kilo666mj

Copy link
Copy Markdown
Owner

Why

When sshd listens only behind sshgate (for example 127.0.0.1:22), it sees every client as the gate and logs Accepted publickey for alice from 127.0.0.1 port 54321. The real client IP only exists in sshgate's log, and nothing ties the two together. That also means sshgate correlate, which matches client IPs in auth.log, can't match sessions on hosts set up this way.

What

  • After the backend dial succeeds, log one line with the backend socket's local address:
    [203.0.113.7] CONNECTED <fingerprint> backend=127.0.0.1:22 local=127.0.0.1:54321
    
    The local port is the port sshd reports, so the two lines can be joined on host + port + a short time window to recover client IP and fingerprint per authenticated session. It's logged after the approve/pending decision, so it covers approved and pending-allowed connections that actually reached the backend.
  • TestConnectedLogsBackendLocalAddress checks the logged address equals the peer address the backend sees (fails on the old code).
  • docs/operations.md: short note on the join in the Correlate section.

Updating correlate itself to use this join is left for a follow-up.

Testing

go vet ./..., gofmt -l ., go test -race ./... pass locally.

🤖 Generated with Claude Code

When sshd listens only behind sshgate it sees every client as the gate
and logs "from 127.0.0.1 port N". Log a CONNECTED line after the backend
dial with the socket's local address, so that port can be joined back to
the real client IP and fingerprint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kilo666mj
kilo666mj merged commit e48c80a into main Sep 27, 2026
7 checks passed
@kilo666mj
kilo666mj deleted the log-backend-local-port branch September 27, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant