Repository navigation
Conversation
| } | ||
|
|
||
| spiffeProfile, ok := cfg.EndpointProfile.(bundleClient.HTTPSSPIFFEProfile) | ||
| if !ok { |
There was a problem hiding this comment.
Fails open for profiles it doesn't recognize.
It rejects HTTPSWebProfile explicitly, then does spiffeProfile, ok := cfg.EndpointProfile.(bundleClient.HTTPSSPIFFEProfile) and returns nil (accept) when the assertion fails.
So the trust-domain check on the next line is skipped entirely for anything that isn't one of those two types.
Today that's unreachable: EndpointProfileInfo has exactly two implementations (manager.go:63 and :72), and both are handled, so this isn't a live hole.
But the default direction is backwards for a check whose whole job is constraining when a file on disk becomes a TLS trust anchor, adding a third profile silently reopens what this function was written to close.
Inverting it to an allow-list (if !ok { return errors.New(...) }) makes the HTTPSWebProfile case above redundant and makes a future third profile fail closed until someone decides otherwise.
There was a problem hiding this comment.
Inverted to an allow-list. Anything that is not https_spiffe gets the same error as https_web. Added a test for an unknown profile type.
|
|
||
| if localEndpointBundle == nil { | ||
| return nil, errors.New("can't perform SPIFFE Authentication: local copy of bundle not found") | ||
| rootCAs, err := rootCAsForSPIFFEAuth(localEndpointBundle, trustDomainConfig, trustDomain) |
There was a problem hiding this comment.
The invariant that makes bootstrap auth safe (that the endpoint's trust domain equals the federated one) is enforced only in cmd/spire-server/cli/run/run.go, and this package does not validate that.
newClient resolves trustDomain from spiffeAuth.EndpointSPIFFEID and passes it to rootCAsForSPIFFEAuth, which will fall back to the bootstrap file whenever that trust domain has no local bundle, regardless of whether it matches u.td.
Asserting spiffeAuth.EndpointSPIFFEID.TrustDomain() == u.td before using the bootstrap path would make the property local to the code that depends on it.
There was a problem hiding this comment.
The updater now refuses the bootstrap file unless the endpoint SPIFFE ID is in the federated trust domain. Non-self-serving with no stored bundle fails closed.
| } | ||
| } | ||
|
|
||
| func TestBundleUpdaterBootstrapCreateOnly(t *testing.T) { |
There was a problem hiding this comment.
TestBundleUpdaterBootstrapCreateOnly is not validating what he name say.
countingDataStore wraps a fakedatastore that starts empty, so CreateBundle always succeeds and the new AlreadyExists handling at updater.go:97 is never excersized,
Exercising it needs a datastore that reports no local bundle from FetchBundle and returns AlreadyExists from CreateBundle.
There was a problem hiding this comment.
Added a datastore that Fetch-misses and Create-returns AlreadyExists. That path no longer returns the fetched bundle as if it were stored. Also covered the case where a bundle appears after bootstrap auth: still Create, no Set.
https_spiffe federation currently fails until someone runs bundle set. Add bootstrap_bundle_path on federates_with so the first fetch can authenticate when the datastore has no bundle. The fetched bundle is created, not updated. Later polls use the stored copy. Fixes spiffe#6322 Signed-off-by: samuraiXwandering <[email protected]>
Signed-off-by: samuraiXwandering <[email protected]>
The path is https_spiffe only. The updater will not use the file unless the endpoint SPIFFE ID is in the federated domain. A racing CreateBundle does not count as a stored refresh. Signed-off-by: samuraiXwandering <[email protected]>
4c35570 to
2b18f04
Compare
MarcosDY
left a comment
There was a problem hiding this comment.
Looks great, I just added a couple comments sorry about delay
| if err != nil { | ||
| return localFederatedBundleOrNil, nil, fmt.Errorf("failed to store fetched federated bundle: %w", err) | ||
| // Create if the store was empty at auth time so bootstrap roots cannot overwrite a bundle that appears before persist. | ||
| if localFederatedBundleOrNil == nil || usedBootstrap { |
There was a problem hiding this comment.
Thanks for the rework here, the usedBootstrap flag and the AlreadyExists fix from the last round both look good.
One thing I think we missed: localFederatedBundleOrNil == nil isn't gated on bootstrap, so this also changes the store path for federations that never enabled it.
Before, UpdateBundle always used SetBundle, which is an upsert. Now the first store uses CreateBundle, including https_web and https_spiffe without bootstrap_bundle_path. I checked on the head commit with a quick test, https_web, no bootstrap, empty datastore: creates=1 sets=0.
Where I think it bites is the branch below. sqlstore.go:1091 maps any constraint violation to AlreadyExists, and sqlcommon/constraint.go:14 treats the whole postgres class 23 as one, so NOT NULL, FK and CHECK errors land there too and return nil. runUpdateOnce only logs on error, so a real store failure would retry silently every minute on a path that worked before.
I think gating on usedBootstrap alone keeps the property you're after, bootstrap roots still can't overwrite a stored bundle, and leaves existing configs on SetBundle:
if usedBootstrap {
_, err = u.ds.CreateBundle(ctx, bundle)
...
} else {
_, err = u.ds.SetBundle(ctx, bundle)
...
}
One more idea while you're in here, no strong feelings: on AlreadyExists you could re-fetch to confirm someone else stored it and return the error if not, so it only covers the race it's meant for.
There was a problem hiding this comment.
Create is only used when bootstrap roots were used. https_web first store is SetBundle again.
| // Create if the store was empty at auth time so bootstrap roots cannot overwrite a bundle that appears before persist. | ||
| if localFederatedBundleOrNil == nil || usedBootstrap { | ||
| _, err = u.ds.CreateBundle(ctx, bundle) | ||
| if err != nil { |
There was a problem hiding this comment.
Thanks for adding the test for this path, it made the behavior easy to see.
Now that it's visible I think the handling needs another look. Returning nil here means the fetch worked but nothing was stored, and nobody finds out.
spire-server bundle refresh returns 200 OK in this case, so an operator asks for a refresh and is told it worked when the bundle was dropped.
The other thing is the error class is wider than the race we're targeting. The datastore maps any constraint violation to AlreadyExists, not just duplicates, so things like NOT NULL or FK errors land here too and would retry every minute with nothing in the logs.
What I'd suggest: on AlreadyExists, re-fetch and check if someone else actually stored it. If it's there, that's the real race and a no-op. If not, return the error so it surfaces.
There was a problem hiding this comment.
On AlreadyExists we re-fetch. If a bundle is there, no-op. If not, the error is returned.
| if local != nil { | ||
| return local.X509Authorities(), false, nil | ||
| } | ||
| if cfg.BootstrapBundlePath == "" || endpointTD != federatedTD { |
There was a problem hiding this comment.
NIT: this folds two different cases into the same message.
If someone sets bootstrap_bundle_path but the endpoint SPIFFE ID is in another trust domain, they get "local copy of bundle not found", which sends them to the datastore and bundle set. The file they configured is just ignored and never mentioned.
Config validation catches this at startup for the HCL path, so it's mostly the datastore-backed relationships that would hit it at runtime.
Could you split the two conditions so the mismatch says what's actually wrong, something like that the bootstrap file can't be used because the endpoint is in a different trust domain?
There was a problem hiding this comment.
Split it. Mismatch now says the bootstrap file cannot be used because the endpoint SPIFFE ID is in a different trust domain.
AlreadyExists re-fetches so a constraint error is not a silent refresh. Endpoint trust-domain mismatch has its own error. Signed-off-by: samuraiXwandering <[email protected]>
) * feat: bootstrap federated bundles from a path in server config https_spiffe federation currently fails until someone runs bundle set. Add bootstrap_bundle_path on federates_with so the first fetch can authenticate when the datastore has no bundle. The fetched bundle is created, not updated. Later polls use the stored copy. Fixes spiffe#6322 Signed-off-by: samuraiXwandering <[email protected]> * chore: retrigger CI after flaky k8s job Signed-off-by: samuraiXwandering <[email protected]> * federation: fail closed bootstrap auth on profile and store The path is https_spiffe only. The updater will not use the file unless the endpoint SPIFFE ID is in the federated domain. A racing CreateBundle does not count as a stored refresh. Signed-off-by: samuraiXwandering <[email protected]> * federation: keep SetBundle unless bootstrap roots were used AlreadyExists re-fetches so a constraint error is not a silent refresh. Endpoint trust-domain mismatch has its own error. Signed-off-by: samuraiXwandering <[email protected]> --------- Signed-off-by: samuraiXwandering <[email protected]>
Pull Request check list
Affected functionality
SPIRE Server federation (
federates_with). Optional config; default behavior is unchanged.Description of change
https_spiffe federation currently fails with
local copy of bundle not founduntil someone runsspire-server bundle set. Following the design on #6322, this addsbootstrap_bundle_path(and optionalbootstrap_bundle_format, defaultpem) so the first fetch can authenticate from a file when the datastore has no bundle.The fetched bundle is stored with create, not update. Later polls use the stored copy. The path is not watched. Rejected on
https_weband when the endpoint SPIFFE ID is outside the federated trust domain.Which issue this PR fixes
Fixes #6322
Test plan
go test ./pkg/server/bundle/client/ ./cmd/spire-server/cli/run/make lint