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

Add FetchJWTSVIDs and SubscribeToJWTBundles #2789

Merged
merged 14 commits into from
Apr 5, 2022

Conversation

loveyana
Copy link
Contributor

@loveyana loveyana commented Feb 21, 2022

Signed-off-by: Yuhan Li [email protected]

Pull Request check list

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

Affected functionality

Delegated Identity API

Description of change

Add FetchJWTSVIDs and SubscribeToJWTBundles in Delegated Identity API.

Which issue this PR fixes

#2788

@amartinezfayo amartinezfayo self-assigned this Feb 24, 2022
@azdagron azdagron added this to the 1.2.2 milestone Mar 3, 2022
@loveyana loveyana marked this pull request as ready for review March 8, 2022 03:29
}
var spiffeIDs []spiffeid.ID

log = log.WithField(telemetry.Registered, true)
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 registered is set to false if spiffeIDs is empty, but errors from matching identities (278l) will have Registered = true.
May we set Registered = true, only if spiffeIDs != 0?

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 temporarily removed the Registered ID, and I looked at the description in telemetry. It is more like whether the caller is authenticated

func (s *Service) SubscribeToJWTBundles(req *delegatedidentityv1.SubscribeToJWTBundlesRequest, stream delegatedidentityv1.DelegatedIdentity_SubscribeToJWTBundlesServer) error {
ctx := stream.Context()
log := rpccontext.Logger(ctx)
cachedSelectors, err := s.isCallerAuthorized(ctx, log, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

move cachedSelectors together to error verification

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'm not sure if your comment is

var cachedSelectors []*common.Selector
if cachedSelectors, err: = s.is CallerAuthorized (ctx, log, nil); err! = nil {return err} 

I looked at the spire code and did not recommend such an implementation. Are you sure we need this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry for the confusion... it is basically put error verification together with line where error is returned,
for example:

ctx := stream.Context()
log := rpccontext.Logger(ctx)

cachedSelectors, err := s.isCallerAuthorized(ctx, log, nil)
if err != nil {
	return err
}

it is generally written this way to simplify reading

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 do pay little attention to this matter, it has been completed now.

managerErr error
expectTokenIDs []spiffeid.ID
}{
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a test case for invalid selectors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

@@ -441,6 +646,16 @@ func (m *FakeManager) SubscribeToCacheChanges(selectors cache.Selectors) cache.S
return newFakeSubscriber(m, m.updates)
}

func (m *FakeManager) FetchJWTSVID(ctx context.Context, spiffeID spiffeid.ID, audience []string) (*client.JWTSVID, error) {
svid := m.ca.CreateJWTSVID(spiffeID, audience)
if m.err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move error validation to the first line? (you are not validating generated SVID, if error 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.

done

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @loveyana!
This is looking great. Could you please update the dependency of spire-api-sdk to point to the latest commit of next branch? That should clean the PR of build errors.

pkg/agent/api/delegatedidentity/v1/service_test.go Outdated Show resolved Hide resolved
@amartinezfayo
Copy link
Member

Hi @loveyana, did you have a chance to look at the comments from @MarcosDY?

@azdagron azdagron modified the milestones: 1.2.2, 1.3.0 Mar 30, 2022
@loveyana
Copy link
Contributor Author

Hi @loveyana, did you have a chance to look at the comments from @MarcosDY?

Sorry for the late reply, I have been spending a lot of time on internal matters recently.

Copy link
Collaborator

@MarcosDY MarcosDY left a comment

Choose a reason for hiding this comment

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

LGTM!!!

Copy link
Member

@amartinezfayo amartinezfayo 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 @loveyana!

@amartinezfayo amartinezfayo merged commit e875c43 into spiffe:main Apr 5, 2022
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.

4 participants