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

SPIFFE Workload API support #238

Merged
merged 14 commits into from
Aug 4, 2019
Merged

SPIFFE Workload API support #238

merged 14 commits into from
Aug 4, 2019

Conversation

azdagron
Copy link
Contributor

This PR provides a TLS config source that obtains up-to-date certificates and trusted roots from the SPIFFE Workload API.

It leverages the go-spiffe Workload API library.

The PR adds the --use-workload-api CLI flag to enable the behavior. By default, the location of the SPIFFE Workload API socket is picked up from the SPIFFE_ENDPOINT_SOCKET environment variable. The --workload-api-addr flag can be used to explicitly set the address.

The functionality has been tested against SPIRE.

@azdagron
Copy link
Contributor Author

An open question is whether --workload-api-addr should imply --use-workload-api.... thoughts anybody?

@csstaub
Copy link
Member

csstaub commented Jul 17, 2019

Hi @azdagron, thank you for the pull request! This looks good at first glance, I'll have to give it a more in-depth reading when I get around to it. In the meantime, could you provide some examples on how to use this? I'd like to write an integration test to make sure we don't accidentally break with new changes.

@azdagron
Copy link
Contributor Author

Sure! Would you like those examples checked into the repository (and if so, where)?

@azdagron
Copy link
Contributor Author

And how much detail do you need? SPIRE server/agent configuration, etc? I have a whole demo folder I can dump somewhere if you'd like.

@csstaub
Copy link
Member

csstaub commented Jul 17, 2019

Ideally I'd like to have a page for this in the docs folder, and link it from the main README, plus an integration test that covers the scenario. That's what we've done for other "advanced" features like PKCS#11 or socket activation support.

@csstaub
Copy link
Member

csstaub commented Jul 17, 2019

Demo folder sounds good, that's something we could add in the docs folder as well.

@azdagron
Copy link
Contributor Author

Awesome, I'll get right on that.

@coveralls
Copy link

coveralls commented Jul 17, 2019

Coverage Status

Coverage decreased (-1.8%) to 89.579% when pulling 89ad942 on azdagron:spiffe-workload-api-support into dcd37be on square:master.

@azdagron
Copy link
Contributor Author

Sorry for all the commit churn. There is now a demo to use as a reference.


func (c *spiffeTLSConfig) GetClientConfig() *tls.Config {
config := c.base.Clone()
config.InsecureSkipVerify = true
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment explaining why this is safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

func (c *spiffeTLSConfig) GetServerConfig() *tls.Config {
config := c.base.Clone()
config.ClientAuth = tls.RequireAnyClientCert
config.InsecureSkipVerify = true
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, add comment here explaining why this is safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

type testLogger bytes.Buffer

func (l *testLogger) Printf(format string, args ...interface{}) {
fmt.Fprintf((*bytes.Buffer)(l), format, args...)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could map this to t.Logf from the testing package maybe, would produce slightly cleaner output I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, i idea here was to assert that certain things were logged but I forgot to implement the checks.

-------------------

The identity of the peer, i.e. the [SPIFFE ID](https://github.com/spiffe/spiffe/blob/master/standards/SPIFFE-ID.md), is embedded as a URI SAN on the
X509-SVID. Accordingly, the existing `--verify-uri-san` and `--allow-uri-san`
Copy link
Member

Choose a reason for hiding this comment

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

Nit: While the old flags still exist (and will continue to work as aliases), we actually renamed these to drop the -san suffix and expose them as "allow-uri" and "verify-uri" now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good to know!

@@ -0,0 +1,57 @@
SPIFFE Workload API Support
Copy link
Member

Choose a reason for hiding this comment

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

These docs are great, thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Also love the added demo

main.go Outdated
logger.Printf("error: unable to load certificates: %s\n", err)
return err
}
tlsConfigSource = certloader.TLSConfigSourceFromCertificate(cert)
Copy link
Member

Choose a reason for hiding this comment

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

Might be nice to factor this out into a function. I guess in general I should probably refactor main() a bit to make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@csstaub
Copy link
Member

csstaub commented Jul 18, 2019

Left some extra comments, but LGTM aside from some minor things.

@csstaub
Copy link
Member

csstaub commented Jul 18, 2019

Also re: "An open question is whether --workload-api-addr should imply --use-workload-api.... thoughts anybody?" I think probably yes, it would be good if it exited with an error if an addr is set without using the workload API. Not a big deal if it doesn't but kinda nice for people who are new and playing around with the flags.

@azdagron
Copy link
Contributor Author

I think I was more interested in knowing if it was a good idea to have --workload-api-addr imply --use-workload-api, so that you only needed to provide one or the other.... (and maybe rename --workload-api-addr to --use-workload-api-addr)

@azdagron
Copy link
Contributor Author

Hmm. The more I think about it, the more I'm personally in favor of specifying either --use-workload-api or --use-workload-api-addr ADDR, but not both.

@csstaub csstaub merged commit b3a7e8a into ghostunnel:master Aug 4, 2019
@csstaub
Copy link
Member

csstaub commented Aug 4, 2019

Thanks @azdagron! This marks the 200th pull request merged in Ghostunnel by the way 🎉 . I want to figure out what's causing #234 and do some more testing on the socket activation features I landed before making a release, but will tag this as 1.5.0-rc1 for testing.

@azdagron azdagron deleted the spiffe-workload-api-support branch August 4, 2019 15:11
@azdagron
Copy link
Contributor Author

azdagron commented Aug 4, 2019

Awesome, thanks @csstaub. And congrats on the PR 200 milestone!

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