Repository navigation
sshpop: optionally verify client IP against source-address - #7191
amartinezfayo merged 6 commits into
Conversation
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]>
Satisfies markdownlint MD060 (aligned table column style). Signed-off-by: samuraiXwandering <[email protected]>
amartinezfayo
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Dropped TestCheckSourceAddress. Its cases were all covered by the table-driven test above.
| } | ||
| sourceAddrs, ok := cert.CriticalOptions[sourceAddressCriticalOption] | ||
| if !ok || sourceAddrs == "" { | ||
| return nil |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Thank you @samuraixwandering for addressing the comments. A couple of very small things and we should be good to merge 🚀
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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]>
…t-ip-source-address
Pull Request check list
Affected functionality
Server-side
sshpopnode attestor. Optional config only; default behavior is unchanged.Description of change
Adds
verify_client_ipto the sshpop server plugin (defaultfalse), following the x509pop option introduced in #6911.When enabled, if the host certificate includes an OpenSSH
source-addresscritical option, the connecting peer IP (fromX-Forwarded-Client-IPon the node attestor facade) is checked against that option. The option is a comma-separated list of IPs and/or CIDRs, matchinggolang.org/x/crypto/ssh.CheckCertacceptssource-addressbut only enforces it during user authentication. sshpop validates host certificates viaCheckHostKey, so the option was previously ignored after being accepted. Certificates withoutsource-addressare 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/Part of #6769