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 Spire trustsource #14

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open

Add Spire trustsource #14

wants to merge 14 commits into from

Conversation

pawalt
Copy link

@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
cmd/plugin/vault-auth-spire.go Outdated Show resolved Hide resolved
cmd/plugin/vault-auth-spire.go Outdated Show resolved Hide resolved
internal/common/settings.go Outdated Show resolved Hide resolved
@pawalt pawalt requested a review from dennisgove January 3, 2020 16:48
internal/common/settings.go Outdated Show resolved Hide resolved
internal/common/settings.go Outdated Show resolved Hide resolved
internal/common/spiffetrustsource_test.go Outdated Show resolved Hide resolved
internal/common/spiffetrustsource_test.go Outdated Show resolved Hide resolved
internal/common/spiffetrustsource_test.go Outdated Show resolved Hide resolved
internal/common/spiffetrustsource_test.go Outdated Show resolved Hide resolved
internal/common/spiretrustsource.go Outdated Show resolved Hide resolved
internal/common/spiretrustsource.go Outdated Show resolved Hide resolved
@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 <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
Signed-off-by: Peyton Walters <[email protected]>
@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch from 7d546c6 to 105f661 Compare January 8, 2020 22:54
internal/common/spiretrustsource_test.go Outdated Show resolved Hide resolved
internal/common/spiretrustsource_test.go Show resolved Hide resolved
internal/common/spiretrustsource.go Outdated Show resolved Hide resolved
internal/common/spiretrustsource.go Outdated Show resolved Hide resolved
Comment on lines 158 to 161
select {
case w.source.updateChan <- struct{}{}:
case <-time.After(w.source.updateTimeout):
}
Copy link
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
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.

internal/common/spiretrustsource.go Outdated Show resolved Hide resolved
Signed-off-by: Peyton Walters <[email protected]>
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
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
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
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

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
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.

@pawalt pawalt force-pushed the pawalt/add-spire-trustsource branch from b758d1e to 2ed1e29 Compare January 25, 2020 23:31
@pawalt
Copy link
Author

pawalt commented Jan 25, 2020

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

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 Spire as a TrustSource
3 participants