Skip to content

sshpop: optionally verify client IP against source-address - #7191

Merged
amartinezfayo merged 6 commits into
spiffe:mainfrom
samuraixwandering:sshpop-verify-client-ip-source-address
Aug 25, 2026
Merged

amartinezfayo merged 6 commits into
spiffe:mainfrom
samuraixwandering:sshpop-verify-client-ip-source-address

Conversation

@samuraixwandering

Copy link
Copy Markdown
Contributor

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Server-side sshpop node attestor. Optional config only; default behavior is unchanged.

Description of change

Adds verify_client_ip to the sshpop server plugin (default false), following the x509pop option introduced in #6911.

When enabled, if the host certificate includes an OpenSSH source-address critical option, the connecting peer IP (from X-Forwarded-Client-IP on the node attestor facade) is checked against that option. The option is a comma-separated list of IPs and/or CIDRs, matching golang.org/x/crypto/ssh.

CheckCert accepts source-address but only enforces it during user authentication. sshpop validates host certificates via CheckHostKey, so the option was previously ignored after being accepted. Certificates without source-address are unaffected even when the flag is on.

This is the first of two remaining plugins from #6769 (httpchallenge to follow in a separate PR, per maintainer guidance).

Test plan

  • go test ./pkg/common/plugin/sshpop/ ./pkg/server/plugin/nodeattestor/sshpop/ ./pkg/agent/plugin/nodeattestor/sshpop/
  • Unit coverage for flag off, no option, exact/CIDR match and mismatch, missing/invalid client IP

Part of #6769

When verify_client_ip is enabled, enforce the OpenSSH source-address
critical option on host certificates against the peer IP forwarded by
the node attestor facade. golang.org/x/crypto/ssh accepts the option in
CheckCert but only enforces it during user authentication, so sshpop's
host-cert path previously ignored it. Certificates without the option
are unchanged. Default remains off, matching x509pop.

Part of spiffe#6769

Signed-off-by: samuraiXwandering <[email protected]>
Satisfies the modernize/stringsseq linter.

Signed-off-by: samuraiXwandering <[email protected]>
@samuraixwandering
samuraixwandering marked this pull request as draft August 4, 2026 18:07
Satisfies markdownlint MD060 (aligned table column style).

Signed-off-by: samuraiXwandering <[email protected]>
@samuraixwandering
samuraixwandering marked this pull request as ready for review August 4, 2026 18:56

@amartinezfayo amartinezfayo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution, @samuraixwandering!


handshaker := p.sshserver.NewHandshake()
if err := handshaker.VerifyAttestationData(payload); err != nil {
if err := handshaker.VerifyAttestationData(payload, clientIPFromContext(stream.Context())); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be worth adding a test that exercises this path through the facade, along the lines of TestVerifyClientIP in the x509pop plugin tests, which builds a context with peer.NewContext and asserts the allow and deny outcomes. The new tests cover the handshake layer well, but as I read it nothing currently verifies that the IP observed by the server actually flows through the metadata into clientIPFromContext.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestVerifyClientIP in the plugin tests, modelled on the x509pop one. It mints a certificate carrying source-address (the fixtures have none) and attests through the facade with a peer context, covering the matching, mismatching and missing client IP cases. I checked it actually exercises the plumbing by stubbing the metadata forwarding in the facade, which makes the test fail.

}, nil
}

func clientIPFromContext(ctx context.Context) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since the x509pop plugin already has the same extraction inline and httpchallenge will follow, would it make sense to add a shared helper next to XForwardedClientIPKey in the nodeattestor package so the three plugins read the metadata the same way? x509pop also warns when multiple values are present, so a shared helper would keep that behavior consistent too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ClientIPFromContext next to XForwardedClientIPKey and moved sshpop onto it, including the warning when the metadata carries more than one value. I left the x509pop call site alone to keep this change scoped to sshpop. Happy to migrate x509pop too, here or separately, if you would prefer all three plugins on the helper from the start.

| `cert_authorities_path` | A file that contains a list of trusted CAs in ssh `authorized_keys` format. | |
| `canonical_domain` | A domain suffix for validating the hostname against the certificate's valid principals. See CanonicalDomains in ssh_config(5). | |
| `agent_path_template` | A URL path portion format of Agent's SPIFFE ID. Describe in text/template format. | `"{{ .PluginName}}/{{ .Fingerprint }}"` |
| `verify_client_ip` | If `true`, match peer IP to host-cert `source-address` when set (IPs/CIDRs). No-op if absent. Peer may be a load balancer. | false |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the row reads a bit terse, especially "Peer may be a load balancer." Maybe we could phrase it closer to the x509pop row, something like "Reflects the immediate connecting peer, which may be a load balancer rather than the agent behind it."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded closer to the x509pop row, and it now also states that a certificate without the option is rejected. Realigned the table since the longer row broke the aligned pipe style.

}
}

func TestCheckSourceAddress(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think these cases all duplicate scenarios already covered by the table-driven test above, so this could probably be dropped, or kept table-driven with named cases if testing the helper in isolation is valuable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped TestCheckSourceAddress. Its cases were all covered by the table-driven test above.

Comment thread pkg/common/plugin/sshpop/handshake.go Outdated
}
sourceAddrs, ok := cert.CriticalOptions[sourceAddressCriticalOption]
if !ok || sourceAddrs == "" {
return nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think enabling verify_client_ip should reject certificates that lack the source-address option, matching x509pop where a cert with no matching IP SAN fails closed. As written, the flag silently provides no IP verification for certs issued without the option, so an operator can believe the check is active when it isn't. That would also keep the same option name meaning the same guarantee across the two plugins.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and changed. A certificate without the source-address option is now rejected when verify_client_ip is enabled, so enabling the option always means the client IP was verified. You are right that it was silently verifying nothing otherwise, which is the worse failure mode because the operator has no signal. Updated the docs and inverted the test case that asserted the old no-op behaviour.

Reject certificates without the source-address critical option when
verify_client_ip is enabled, so the option always means the client IP was
verified rather than silently verifying nothing. This matches x509pop, where a
certificate with no matching IP SAN fails closed, and keeps the option name
meaning the same thing in both plugins.

Move the client IP extraction to a shared helper next to XForwardedClientIPKey
so plugins read the metadata the same way, including the warning x509pop emits
when the metadata carries more than one value.

Add a test that attests through the plugin facade with a peer context, covering
the matching, mismatching and missing client IP cases. The existing tests only
exercised the handshake layer, so nothing verified that the IP observed by the
server reaches the plugin through the metadata.

Reword the configuration table entry to match the x509pop wording, and drop the
standalone source-address test whose cases the table-driven test already
covers.

Signed-off-by: samuraiXwandering <[email protected]>

@amartinezfayo amartinezfayo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @samuraixwandering for addressing the comments. A couple of very small things and we should be good to merge 🚀

Comment thread pkg/common/plugin/sshpop/sshpop.go Outdated
AgentPathTemplate string `hcl:"agent_path_template"`
// VerifyClientIP, when true, checks the connecting peer's IP against a
// source-address critical option on the host certificate when that option
// is present. Certificates without source-address are unaffected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment still describes the earlier behavior, where a certificate without source-address was unaffected. We should update it to match the current behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. It now says the option is required and that certificates without source-address are rejected. I also swept the other mentions of the option across pkg/ and doc/ and the remaining four already describe the current behaviour, so this and the example below were the last two.

# Change the agent's SPIFFE ID format
# agent_path_template = "static/{{ index .ValidPrincipals 0 }}"

# Optional: when true, enforce source-address critical option if present

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the commented example still says the option is enforced "if present". Maybe we could reword it along the lines of "# Optional: when true, require and enforce the source-address critical option".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded to your suggestion.

The configuration comment and the commented example still described the
behavior before certificates without the source-address critical option
started being rejected.

Signed-off-by: samuraiXwandering <[email protected]>

@amartinezfayo amartinezfayo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@amartinezfayo amartinezfayo added this to the 1.16.0 milestone Aug 21, 2026
@amartinezfayo
amartinezfayo added this pull request to the merge queue Aug 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 21, 2026
@amartinezfayo
amartinezfayo added this pull request to the merge queue Aug 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 25, 2026
@amartinezfayo
amartinezfayo added this pull request to the merge queue Aug 25, 2026
Merged via the queue into spiffe:main with commit 573f990 Aug 25, 2026
53 checks passed
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.

2 participants