Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Add Spire trustsource#14

Open
pawalt wants to merge 14 commits into
developfrom
pawalt/add-spire-trustsource
Open

Add Spire trustsource#14
pawalt wants to merge 14 commits into
developfrom
pawalt/add-spire-trustsource

Conversation

@pawalt
Copy link
Copy Markdown

@pawalt pawalt commented Jan 2, 2020

This resolves #2

Describe your changes
This PR adds support for using Spire servers as a trust source.

Testing performed
Unit tests have been written in spiretrustsource_test.go

Additional context
I moved the file trust source and this one to using afero to ease testing.
I'm not particularly happy with how much code is repeated between tests, so I'm looking to refactor them with the suite package.
EDIT: I refactored some code, and I think this is fine without using suite.

@pawalt pawalt requested review from dennisgove and twexler January 2, 2020 19:53
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch 4 times, most recently from dc80a6a to daa224c Compare January 3, 2020 02:14
@pawalt pawalt mentioned this pull request Jan 3, 2020
Comment thread cmd/plugin/vault-auth-spire.go Outdated
Comment thread cmd/plugin/vault-auth-spire.go Outdated
Comment thread internal/common/settings.go Outdated
@pawalt pawalt requested a review from dennisgove January 3, 2020 16:48
Comment thread internal/common/settings.go Outdated
Comment thread internal/common/settings.go Outdated
Comment thread internal/common/spiffetrustsource_test.go
Comment thread internal/common/spiffetrustsource_test.go
Comment thread internal/common/spiffetrustsource_test.go
Comment thread internal/common/spiffetrustsource_test.go Outdated
Comment thread internal/common/spiretrustsource.go Outdated
Comment thread internal/common/spiretrustsource.go Outdated
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch 2 times, most recently from c14eb3e to 38c8248 Compare January 3, 2020 21:22
@pawalt pawalt requested a review from twexler January 3, 2020 21:22
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch 3 times, most recently from 08d783a to 1759f4e Compare January 7, 2020 20:15
Peyton Walters and others added 12 commits January 8, 2020 17:54
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch from 7d546c6 to 105f661 Compare January 8, 2020 22:54
Comment thread internal/common/spiretrustsource_test.go Outdated
Comment thread internal/common/spiretrustsource_test.go
Comment thread internal/common/spiretrustsource.go Outdated
Comment thread internal/common/spiretrustsource.go Outdated
Comment on lines +158 to +161
select {
case w.source.updateChan <- struct{}{}:
case <-time.After(w.source.updateTimeout):
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary to write the backup to disk before making the certs available for use? I think it might be better to make them available for other threads, then write to disk. This makes the disk write a non-blocking call for cert usage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I need this blocking so that I can make sure the write completed before reading a file in my tests. I'm not too worried about extra blocking in tests. However, I only need it in tests, so I've added a testing flag. Let me know what you think.

Comment thread internal/common/spiretrustsource.go
Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
Comment thread internal/common/spiretrustsource.go Outdated
Comment on lines +114 to +123
// NewSpireTestSource creates a new spire trust source with the test flag on.
func NewSpireTestSource(spireEndpointURLs map[string]string, localBackupDir string) (*SpireTrustSource, error) {
ts, err := NewSpireTrustSource(spireEndpointURLs, localBackupDir)
if err != nil {
return nil, err
}
ts.testing = true
return ts, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't love this. I'm going to give some thought to a better way to accomplish what's needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

OK. I would love to use method overriding to add an optional testing flag, but Go doesn't have overriding.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Another common pattern is to pass in a config struct that can take on default values instead of using individual parameters.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could also pass an optional configuration function ala https://godoc.org/github.com/pkg/term#CBreakMode

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@dennisgove seemed to have the main problem of "we don't want to have test flags in prod code", so I don't think extra configuration functions would fix that problem. I'm really not sure how to fix that problem other than making a whole new type of watcher for testing purposes, but I feel like that defeats the purpose of the tests.

Signed-off-by: Peyton Walters <pwalters18@bloomberg.net>
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch from b758d1e to 2ed1e29 Compare January 25, 2020 23:31
@pawalt
Copy link
Copy Markdown
Author

pawalt commented Jan 25, 2020

I've added a second struct. Let me know what you think.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Spire as a TrustSource

3 participants