Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security] Add support for parsing SPIFFE Bundle Maps #8124

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

gtcooke94
Copy link
Contributor

@gtcooke94 gtcooke94 commented Feb 25, 2025

This adds a dependency on go-spiffe in order to parse SPIFFE bundles. More specifically, that library does not yet support SPIFFE bundle maps, but it does support SPIFFE bundles. This adds parsing of these maps to grpc-go

See the gRFC for more detail grpc/proposal#462

RELEASE NOTES: N/A

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.42%. Comparing base (dbf92b4) to head (283e9a1).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8124      +/-   ##
==========================================
+ Coverage   82.18%   82.42%   +0.24%     
==========================================
  Files         387      392       +5     
  Lines       38947    39164     +217     
==========================================
+ Hits        32007    32282     +275     
+ Misses       5613     5567      -46     
+ Partials     1327     1315      -12     
Files with missing lines Coverage Δ
internal/credentials/spiffe.go 100.00% <100.00%> (ø)

... and 46 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gtcooke94 gtcooke94 added Type: Security A bug or other problem affecting security Area: xDS Includes everything xDS related, including LB policies used with xDS. Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. labels Feb 26, 2025
@gtcooke94 gtcooke94 added this to the 1.71 Release milestone Feb 26, 2025
@gtcooke94 gtcooke94 assigned easwars and unassigned gtcooke94 Feb 28, 2025
@arjan-bal arjan-bal modified the milestones: 1.71 Release, 1.72 Release Mar 3, 2025
@gtcooke94 gtcooke94 requested a review from easwars March 5, 2025 22:12
// use other than this is specified, the parser does not fail, it
// just doesn't add an x509 authority or jwt authority to the bundle
filePath: testdata.Path("spiffe/spiffebundle_wrong_use.json"),
expectNoX509: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this field in the table since all subtests are expected to fail, and therefore this field is always set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a slight variation in expectError and expectNoX509 that needs both of them

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be taken care of still.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Had a squint a bit to figure that out :)

Can we please move that out to a separate test to simplify the test logic in both of them. Please see: https://goto.google.com/gotip/episodes/50

@easwars easwars assigned gtcooke94 and unassigned easwars Mar 5, 2025
@gtcooke94 gtcooke94 requested a review from easwars March 6, 2025 16:39
@gtcooke94 gtcooke94 assigned easwars and unassigned gtcooke94 Mar 6, 2025
// use other than this is specified, the parser does not fail, it
// just doesn't add an x509 authority or jwt authority to the bundle
filePath: testdata.Path("spiffe/spiffebundle_wrong_use.json"),
expectNoX509: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be taken care of still.

@easwars easwars assigned gtcooke94 and unassigned easwars Mar 6, 2025
Copy link
Contributor Author

@gtcooke94 gtcooke94 left a comment

Choose a reason for hiding this comment

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

Sorry I think I missed submitting this review and my comments

// use other than this is specified, the parser does not fail, it
// just doesn't add an x509 authority or jwt authority to the bundle
filePath: testdata.Path("spiffe/spiffebundle_wrong_use.json"),
expectNoX509: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a slight variation in expectError and expectNoX509 that needs both of them

@gtcooke94 gtcooke94 requested a review from easwars March 6, 2025 19:07
@gtcooke94 gtcooke94 assigned easwars and unassigned gtcooke94 Mar 6, 2025
Copy link
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

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

LGTM modulo minor changes mentioned in this round of review.

@@ -73,3 +78,40 @@ func SPIFFEIDFromCert(cert *x509.Certificate) *url.URL {
}
return spiffeID
}

type partialParsedSPIFFEBundleMap struct {
Bundles map[string]json.RawMessage `json:"trust_domains"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Sorry, didn't notice this earlier. But any specific reason for not naming it as TrustDomains to match the JSON field name?

}
bundle, err := spiffebundle.Parse(trustDomain, jsonBundle)
if err != nil {
return nil, fmt.Errorf("spiffe: failed to parse bundle in map file (%v): %v", filePath, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: also please include the trust domain name here for a more specific error message. Thanks.

// use other than this is specified, the parser does not fail, it
// just doesn't add an x509 authority or jwt authority to the bundle
filePath: testdata.Path("spiffe/spiffebundle_wrong_use.json"),
expectNoX509: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Had a squint a bit to figure that out :)

Can we please move that out to a separate test to simplify the test logic in both of them. Please see: https://goto.google.com/gotip/episodes/50

@@ -32,7 +32,7 @@ elif [[ "$#" -ne 0 ]]; then
fi

# - Check that generated proto files are up to date.
go generate google.golang.org/grpc/... && git status --porcelain 2>&1 | fail_on_output || \
go generate ./... && git status --porcelain 2>&1 | fail_on_output || \
Copy link
Contributor

@arjan-bal arjan-bal Mar 10, 2025

Choose a reason for hiding this comment

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

I think the complete fix would be to run go generate on all directories that contain a go.mod file, in addition to the root module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Security A bug or other problem affecting security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants