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

Get resolver based on attestation method #652

Merged

Conversation

marcosy
Copy link
Contributor

@marcosy marcosy commented Dec 10, 2018

Pull Request check list

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

Affected functionality
Node resolver selection (spire-server)

Description of change
Currently, spire-server selects the first configured node resolver when trying to discover additional node selectors. This PR introduces a change to make this selection based on attestation method.

Which issue this PR fixes
Fixes #555

Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

neat! a few comments...

selectors = append(selectors, resolved.Entries...)
if nodeResolver == nil {
// If not matching node resolver found, skip adding additional selectors
h.c.Log.Debug("could not find node resolver type %s", attestationType)
Copy link
Member

Choose a reason for hiding this comment

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

%q is a little nicer for logging arbitrary strings

@@ -38,12 +38,12 @@ func (c *Catalog) DataStores() []*catalog.ManagedDataStore {
return c.dataStores
}

func (c *Catalog) SetNodeAttestors(nodeAttestors ...nodeattestor.NodeAttestor) {
func (c *Catalog) SetNodeAttestors(baseName string, nodeAttestors ...nodeattestor.NodeAttestor) {
Copy link
Member

Choose a reason for hiding this comment

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

this feels a little clunky to me... i'd think i'd rather leave the Set methods as they are and instead introduce a new method (which the Set method could use):

func (c *Catalog) SetNodeAttestors(nodeAttestors ...nodeattestor.NodeAttestor) {
    c.nodeAttestors = nil
    for i, nodeAttestor := range nodeAttestors {
        c.AddNodeAttestorNamed(pluginName("nodeattestor", i), nodeAttestor)
    }
}

func (c *Catalog) AddNodeAttestorNamed(name string, nodeAttestor nodeattestor.NodeAttestor) {
    	c.nodeAttestors = append(c.nodeAttestors, catalog.NewManagedNodeAttestor(
			nodeAttestor, common.PluginConfig{
				PluginName: name,
			}))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, that looks better 👍

@@ -60,7 +60,7 @@ type HandlerTestSuite struct {
now time.Time
}

func SetupHandlerTest(t *testing.T) *HandlerTestSuite {
func SetupHandlerTest(t *testing.T, attestorBaseName, resolverBaseName string) *HandlerTestSuite {
Copy link
Member

Choose a reason for hiding this comment

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

rather than requiring each test to pass these values, i think it might be cleaner and clearer if SetupHandlerTest adds the node attestor using some default name, like "fake" or something, and then all of the other tests don't bother adding a resolver. Then there can be a test that adds a resolver under the right name, and one that adds a resolver under the wrong name (and depending on the rest of the tests, a test that has no resolver).

All of the above assumes you add a new field to the suite to hold onto the catalog...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I totally agree!

@marcosy marcosy merged commit cbbf489 into spiffe:master Jan 2, 2019
@evan2645 evan2645 mentioned this pull request Jan 22, 2019
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.

Support multiple node resolvers
2 participants