Allow auto_auth with templates without specifying a sink#8812
Conversation
For situations where you want the Vault agent to handle one or more templates but do not require the acquired credentials elsewhere. Modify the logic in SyncServer so that if there are no sinks, ignore any new credentials. Since SyncServer is responsible for shutting down the agent, make sure it still properly shuts down in this new situation. Updated documentation. Solves hashicorp#7988
|
Hi @kula, Thanks for the PR! It's been a while since I dug into Agent - since before it supported templates in fact. You say " if there are no sinks, ignore any new credentials". Wouldn't that prevent re-rendering of templates post-reauth? |
|
When template support was added a template server (analogous to the sink server) was added, and I've been using this since shortly after I updated it to keep a token refreshed and using it to update templates with short lived IAM credentials and it's been working for me, at least. |
|
Thanks for clarifying. The change looks good but I'd like to see more tests. You could remove the sink from the config in TestAgent_Template_ExitCounter, since it's not using it anyway. For completeness I would also add a fixture-based test here since it's nice to have one place where we can look and see that that various supported configurations are validated. |
|
I think we can remove the sink config from all the |
They no longer need them, and they don't make use of them. Verified that all tests in command/agent_test.go still pass.
|
With this I've reverted the unnecessary documentation line break removal, as well as changed and added some tests. |
It's fine with me, I just picked an example of a test I found that seemed to be exercising the desired behaviour and that wouldn't suffer from removing sinks. The changes look good, please merge in master to resolve conflicts and I'll approve. |
|
I believe I've merged everything properly. Thanks! |
|
I have some test errors from the previous commit as well, I'm resolving those now. |
|
TestAgent_Template_Basic is now failing with timeout, it seems to block when we write to |
|
I did mess with the SinkServer, which is responsible for shutting down, I wonder if that had anything to do with it. Looking now. |
|
Okay, I think I have it narrowed down to two issues. The first is with the test framework. We start the tests in https://github.com/hashicorp/vault/blob/master/command/agent_test.go#L855-L863 by launching a goroutine to run the test. Then in https://github.com/hashicorp/vault/blob/master/command/agent_test.go#L874, if it is a test that didn't set However, if the test we started had errors starting (https://github.com/hashicorp/vault/blob/master/command/agent_test.go#L874) by the time we get down to line 874 there's nothing to receive the shutdown notification, and it will hang. I think we need a way for places that we do that to communicate back out that the routine has already gone away, don't try to send it a shutdown notification. The second part is two tests themselves, with a config of and with the config which makes sense, according to what we wanted to do in b08b137 --- an agent with no sinks, no templates and not using the token acquired to be a cache will just do nothing. It should error, and those two tests, given the context of these changes here, will never do anything and could be removed. However, I don't understand how those two tests ever passed. The check first removed in this PR, and which was then extended in b08b137, would error in the case |
|
Okay, now I'm confused, because current master branch of upstream Vault has a sink config at https://github.com/hashicorp/vault/blob/master/command/agent_test.go#L823-L827 --- did I just take that out for some reason when I merged back in master? I'm going to try to clean up things and try again. |
|
I did, in 1bc7575, because in testing templates we no longer need to make have a sink just to render a template. And, in that case, running a test to verify template output when you have no sinks, no templates and no cache using auto auth tokens doesn't make much sense, so the |
In 1bc7575 I removed the need for sinks in the template tests, since with related changes one can render templates without having to have sinks. With this change, however, an agent configuration with no sinks, no templates and no cache using an auto auth token is an invalid configuration --- it would simply do nothing but keep a token alive but not make it useful in any way. With that, however, the `zero` and `zero-with-exit` tests in TestAgent_Template_Basic will return errors. Remove these tests. Normally I'm leery of removing tests, however I feel that we have coverage elsewhere to verify that an agent config with no sinks, no templates and no cache using auto auth tokens will return an error.
ncabatoff
left a comment
There was a problem hiding this comment.
Looks good, thank you!
For situations where you want the Vault agent to handle one or more templates but do not require the acquired credentials elsewhere. Modify the logic in SyncServer so that if there are no sinks, ignore any new credentials. Since SyncServer is responsible for shutting down the agent, make sure it still properly shuts down in this new situation. Solves #7988
For situations where you want the Vault agent to handle one or
more templates but do not require the acquired credentials
elsewhere.
Modify the logic in SyncServer so that if there are no sinks,
ignore any new credentials. Since SyncServer is responsible
for shutting down the agent, make sure it still properly
shuts down in this new situation.
Updated documentation.
Solves #7988