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

Node and Workload API support for federated bundles #583

Merged

Conversation

azdagron
Copy link
Member

@azdagron azdagron commented Sep 6, 2018

This PR updates the Node API to return bundles with x509 and JWT SVID updates. The agent has been updated to store all bundles returned from x509 SVID updates in its cache. JWT support in the agent has not been implemented and handling the bundles will be done at that time.

The workload API has been extended to return a map of bundles with updates as well as a list of bundle ids that each workload is associated with.

Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
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.

looks great, just some minor suggestions.

@@ -321,12 +321,21 @@ func (a *attestor) parseAttestationResponse(id string, r *node.AttestResponse) (
return nil, nil, fmt.Errorf("invalid svid: %v", err)
}

bundle, err := x509.ParseCertificates(r.SvidUpdate.Bundle)
if r.SvidUpdate.Bundles == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see no validations for r.SvidUpdate is it possible it can be nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is possible. I will add a check.

@@ -138,12 +143,14 @@ func (c *client) FetchUpdates(ctx context.Context, req *node.FetchX509SVIDReques
for spiffeid, svid := range resp.SvidUpdate.Svids {
svids[spiffeid] = svid
}
lastBundle = resp.SvidUpdate.Bundle
for spiffeid, bundle := range resp.SvidUpdate.Bundles {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible resp.SvidUpdate.Bundles to be nil here?

Copy link
Member Author

@azdagron azdagron Sep 6, 2018

Choose a reason for hiding this comment

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

Yes, but ranging over a nil map is not an error. It acts as if the map is empty.

return &Update{
Entries: regEntries,
SVIDs: svids,
Bundles: bundles,
Copy link
Collaborator

Choose a reason for hiding this comment

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

bundle is initialized before for so it will contains data from previous responses, andit can return error here with bundles from previous calls, is it expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. The old code returned aggregated update results and the error. However, the only consumer of the function does not use the returned update if there is an error. I'm not sure why the old code returned it. I think I'd rather return nil, err in this case.

@@ -35,17 +81,15 @@ type Cache interface {
DeleteEntry(regEntry *common.RegistrationEntry) bool
// Entries returns all the in force cached entries.
Entries() []*Entry
// IsEmpty returns true if this cache doesn't have any entry.
IsEmpty() bool
// Registers and returns a Subscriber, and then sends latest WorkloadUpdate on its channel
Subscribe(selectors Selectors) Subscriber
// Set the bundle
Copy link
Collaborator

Choose a reason for hiding this comment

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

Set the bundles

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

SetBundle([]*x509.Certificate)
// Retrieve the bundle
SetBundles(map[string][]*x509.Certificate)
// Retrieve the bundle for the trust domain
Bundle() []*x509.Certificate
// SubscribeToBundleChanges returns a new observer.Stream of []*x509.Certificate instances. Each
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment is no updated, it is no loger returning observer.Stream.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -39,7 +39,7 @@ type Manager interface {

// SubscribeToBundleChanges returns a new observer.Stream on which []*x509.Certificate instances are
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is no longer returning a observer.Stream

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -650,8 +671,18 @@ func getExpectedFetchX509SVID(data *fetchSVIDData) *node.X509SVIDUpdate {
caCert, _, _ := util.LoadCAFixture()
svidUpdate := &node.X509SVIDUpdate{
Svids: svids,
Bundle: caCert.Raw,
DEPRECATEDBundle: caCert.Raw,
Copy link
Collaborator

Choose a reason for hiding this comment

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

when we'll remove those deprecated fields? must we add some anotations/comments about a prossible version where we'll remove? or at leas when it was mark as deprecated? so we can track how long we have it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, i think that is a larger discussion to have about API deprecation paths. For now, is git history sufficient to know when it was deprecated?

@@ -26,12 +35,18 @@ message X509SVIDUpdate {
// keys. Map[SPIFFE_ID] => SVID.
map<string, X509SVID> svids = 1;

// Latest SPIRE Server bundle
bytes bundle = 2;
// DEPRECATED. Latest SPIRE Server bundle.
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 when it was deprecated (version)? to make it easier to track

Signed-off-by: Andrew Harding <azdagron@gmail.com>
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.

🥇

@azdagron azdagron merged commit 8927a86 into spiffe:master Sep 7, 2018
@azdagron azdagron deleted the node-workload-federated-bundle-support branch September 7, 2018 15:30
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.

3 participants