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

Include hint field in agent's workload api #3993

Merged
merged 12 commits into from
Apr 12, 2023

Conversation

guilhermocc
Copy link
Contributor

@guilhermocc guilhermocc commented Mar 16, 2023

Pull Request check list

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

Affected functionality

  • spire-agent fetch jwt and fetch x509 commands
  • cache and lru_cache methods that get records for a given selector set
  • spire agent's workload api FetchJWTSVID and FetchX509SVID methods

Description of change
Include hint field in agent's workload api responses, update cache methods for ensuring hint uniqueness amongst the fetched svids.

Which issue this PR fixes
ongoing work for #2588

Dependencies
This PR depends on spiffe/go-spiffe#220, please review it before this PR

go.mod Outdated
@@ -2,6 +2,8 @@ module github.com/spiffe/spire

go 1.19

replace github.com/spiffe/go-spiffe/v2 => github.com/guilhermocc/go-spiffe/v2 v2.0.0-20230308163427-b2b17d68664c
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commit that inserted this temporary dependency should be dropped after https://github.com/spiffe/go-spiffe/pull/220/files gets merged

@rturner3 rturner3 added this to the 1.6.2 milestone Mar 17, 2023
pkg/agent/manager/cache/cache.go Outdated Show resolved Hide resolved
pkg/agent/manager/cache/cache.go Outdated Show resolved Hide resolved
pkg/agent/manager/cache/cache_test.go Outdated Show resolved Hide resolved
pkg/agent/manager/cache/cache_test.go Outdated Show resolved Hide resolved
pkg/agent/manager/cache/cache_test.go Outdated Show resolved Hide resolved
pkg/agent/endpoints/workload/handler.go Outdated Show resolved Hide resolved
pkg/agent/endpoints/workload/handler.go Outdated Show resolved Hide resolved
pkg/agent/endpoints/workload/handler_test.go Outdated Show resolved Hide resolved
cmd/spire-agent/cli/api/api_test.go Outdated Show resolved Hide resolved
cmd/spire-agent/cli/api/api_test.go Outdated Show resolved Hide resolved
@@ -31,6 +31,9 @@ func printX509SVID(env *commoncli.Env, svid *X509SVID) {
// Print SPIFFE ID first so if we run into a problem, we
// get to know which record it was
env.Printf("SPIFFE ID:\t\t%s\n", svid.SPIFFEID)
if svid.Hint != "" {
env.Printf("HINT:\t\t\t%s\n", svid.Hint)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be printed a "Hint", as it's not an acronym?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we were using only uppercase here for all fields printed, but just saw that's not the case, you are right, going to update it!


for hint, recordsWithSameHint := range hintsMap {
// If there is more than one entry with the same hint, remove all but the oldest one to ensure hint uniqueness
if len(recordsWithSameHint) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be rewritten as in the other cache method?

if len(recordsWithSameHint) <= 1 {
			continue
		}

@guilhermocc guilhermocc force-pushed the include-hint-field-workload-api branch 2 times, most recently from 4e98217 to 25cab4a Compare March 22, 2023 21:03
@@ -93,6 +93,9 @@ func printPrettyResult(env *commoncli.Env, results ...interface{}) error {

for _, svid := range svidResp.Svids {
env.Printf("token(%s):\n\t%s\n", svid.SpiffeId, svid.Svid)
if svid.Hint != "" {
env.Printf("hint(%s):\n\t%s\n", svid.SpiffeId, svid.Hint)
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmm looks like spiffeID here is redundant, since you already printed spiffeID with token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also include the spiffe ID in the printed bundle (on line 101), I tried to maintain the same logic here for hint, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I cant think in another good ouput... so keeping the duplicated SPIFFEID may be good

@@ -31,6 +31,9 @@ func printX509SVID(env *commoncli.Env, svid *X509SVID) {
// Print SPIFFE ID first so if we run into a problem, we
// get to know which record it was
env.Printf("SPIFFE ID:\t\t%s\n", svid.SPIFFEID)
if svid.Hint != "" {
env.Printf("Hint:\t\t\t%s\n", svid.Hint)
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like it has 3 tabs, but spiffeID has only 2, do you want to add some hierarchy level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for maintaining the output aligned
Two tabs
image
Three tabs
image

for _, entry := range entries {
if req.SpiffeId != "" && entry.SpiffeId != req.SpiffeId {
continue
}
loopLog := log.WithField(telemetry.SPIFFEID, entry.SpiffeId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: since loopLog is used only on h.fetchJWTSVID may we remove the break line? and couple both lines?

@@ -395,6 +400,7 @@ func composeX509SVIDResponse(update *cache.WorkloadUpdate) (*workload.X509SVIDRe
X509Svid: x509util.DERFromCertificates(identity.SVID),
X509SvidKey: keyData,
Bundle: bundle,
Hint: identity.Entry.Hint,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a warranty that entry is not nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so, as you can see on line 391, we are already taking the SPIFFE ID from the entry.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

var tokenIDs []spiffeid.ID
for _, svid := range resp.Svids {
parsedSVID, err := jwtsvid.ParseInsecure(svid.Svid, tt.audience)
assert.Len(t, resp.Svids, len(tt.expectedResp))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not to create a list of responses and do a equal between expected and response list? with that we can no longer validate length and get a single error message

Copy link
Collaborator

Choose a reason for hiding this comment

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

since we are adding hint, how it will affect to SVID Store? may we add hint to persisted SVIDs too?

return records, recordsDone
}

func (c *Cache) removeEntriesWithNonUniqueHint(records recordSet) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this worry me, so we are stop propagating Identities, just because a field is set, with the same value than another entry on response,
we MUST add documentation so users can understand than that is possible it to happens, and can result in some confusion

Copy link
Collaborator

Choose a reason for hiding this comment

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

and is it something we must do at cache level? it sounds to me like this must be done on workload api instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in the last contributor sync, we decided to move this filter to the workload API layer

Copy link
Collaborator

@rturner3 rturner3 left a comment

Choose a reason for hiding this comment

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

Based on comments from @MarcosDY and discussion in today's contributor sync, this will have potentially unwanted consequences on the SDS APIs and SVID store functionality. Removing my +1 until the filtering added in the Agent cache layer is moved to the Workload API handlers.

Copy link
Member

@maxlambrecht maxlambrecht left a comment

Choose a reason for hiding this comment

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

Removing my approval based on discussion in today's contributor sync.

@guilhermocc guilhermocc force-pushed the include-hint-field-workload-api branch from 25cab4a to 970a948 Compare March 29, 2023 19:33
@guilhermocc guilhermocc requested review from rturner3 and MarcosDY and removed request for rturner3 March 29, 2023 19:58
go.mod Outdated
@@ -2,6 +2,8 @@ module github.com/spiffe/spire

go 1.19

replace github.com/spiffe/go-spiffe/v2 => github.com/guilhermocc/go-spiffe/v2 v2.0.0-20230327182353-926e51ab6802
Copy link
Member

Choose a reason for hiding this comment

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

The required change has been merged and released in version v2.1.4. Please update accordingly!

Signed-off-by: Guilherme Carvalho <guilhermbrsp@gmail.com>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
guilhermocc and others added 5 commits March 31, 2023 10:11
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Signed-off-by: Guilherme Carvalho <guilhermbrsp@gmail.com>
@guilhermocc guilhermocc force-pushed the include-hint-field-workload-api branch from dc7741f to 38b2cc2 Compare March 31, 2023 13:30
Signed-off-by: Guilherme Carvalho <guilhermocc@proton.me>
Copy link
Collaborator

@rturner3 rturner3 left a comment

Choose a reason for hiding this comment

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

Thank you for your patience on this one @guilhermocc! Really appreciate the good work.

@amartinezfayo amartinezfayo modified the milestones: 1.6.2, 1.6.3, 1.6.4 Apr 4, 2023
Copy link
Member

@maxlambrecht maxlambrecht left a comment

Choose a reason for hiding this comment

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

🚀

@azdagron azdagron merged commit 0573cf3 into spiffe:main Apr 12, 2023
Basavaraju-G pushed a commit to Basavaraju-G/spire that referenced this pull request May 3, 2023
Signed-off-by: Guilherme Carvalho <guilhermbrsp@gmail.com>
Signed-off-by: Basavaraju-G <basavaraju013@gmail.com>
d-goro pushed a commit to d-goro/spire that referenced this pull request May 18, 2023
Signed-off-by: Guilherme Carvalho <guilhermbrsp@gmail.com>
Signed-off-by: Dmitry Gorochovsky <d.goro@yahoo.com>
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.

6 participants