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

Vault sidecar type annotation #496

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

liad5h
Copy link

@liad5h liad5h commented Jul 9, 2023

No description provided.

@hashicorp-cla
Copy link

hashicorp-cla commented Jul 9, 2023

CLA assistant check
All committers have signed the CLA.

@heatherezell heatherezell added enhancement New feature or request agent Area: Vault Agent (auth, templating, rendering, etc.) labels Jul 10, 2023
Copy link

@thyton thyton left a comment

Choose a reason for hiding this comment

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

@liad5h Thank you for taking this on and being patient! The PR is generally on a good path :). I have some change requests. I'm happy to sync up and help out with addressing them if you need.

Would you mind dropping a small description in the PR and something like below in CHANGELOG.md under Unreleased?

Improvements:
* Add support to configure sidecar type (proxy or agent) and proxy's auto auth token use through Pod Annotations [GH-496](https://github.com/hashicorp/vault-k8s/pull/496)

@@ -809,7 +809,7 @@ func TestConfigTelemetry(t *testing.T) {
"vault.hashicorp.com/agent-telemetry-stackdriver_location": "useast-1",
"vault.hashicorp.com/agent-telemetry-stackdriver_namespace": "foo",
"vault.hashicorp.com/agent-telemetry-stackdriver_debug_logs": "false",
"vault.hashicorp.com/agent-telemetry-prefix_filter": `["+vault.token", "-vault.expire", "+vault.expire.num_leases"]`,
"vault.hashicorp.com/agent-telemetry-prefix_filter": `["+vault.token", "-vault.expire", "+vault.expire.num_leases"]`,
Copy link

Choose a reason for hiding this comment

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

Could you revert the accidental space?

@@ -884,3 +894,24 @@ func (a *Agent) authConfig() map[string]interface{} {

return authConfig
}

func (a *Agent) sidecarType() string {
if a.SidecarType != "" && !(a.SidecarType == "agent" || a.SidecarType == "proxy") {
Copy link

Choose a reason for hiding this comment

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

Suggested change
if a.SidecarType != "" && !(a.SidecarType == "agent" || a.SidecarType == "proxy") {
if a.SidecarType != "" && (a.SidecarType == "agent" || a.SidecarType == "proxy") {

I think you meant if a.SidecarType is not empty, and a.SidecarType is "agent" or "proxy", then return a.SidecarType?

Comment on lines +288 to +290
arg := fmt.Sprintf(DefaultContainerArg, agent.SidecarType)
if container.Args[0] != arg {
t.Errorf("arg value wrong, should have been %s, got %s", arg, container.Args[0])
Copy link

Choose a reason for hiding this comment

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

Could we also add a similar assertion for agent.ProxyUseAutoAuthToken?

@@ -285,8 +285,9 @@ func TestContainerSidecar(t *testing.T) {
t.Errorf("wrong number of args, got %d, should have been %d", len(container.Args), 1)
}

if container.Args[0] != DefaultContainerArg {
t.Errorf("arg value wrong, should have been %s, got %s", DefaultContainerArg, container.Args[0])
arg := fmt.Sprintf(DefaultContainerArg, agent.SidecarType)
Copy link

Choose a reason for hiding this comment

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

Could you add different test cases under TestContainerSidecar() to test varying annotation sets containing 2 new annotations?

// AnnotationAgentSidecarType is the key of the annotation that controls whether
// a Vault agent or Vault proxy is injected into the pod
// Should be set to one of "agent" / "proxy", defaults to "agent".
AnnotationAgentSidecarType = "vault.hashicorp.com/sidecar-type"
// AnnotationAgentProxyUseAutoAuthToken is the key of the annotation that controls whether
// the auto auth token should be used in the vault proxy.
// configures the "use_auto_auth_token" key in the "api_proxy" stanza.
AnnotationAgentProxyUseAutoAuthToken = "vault.hashicorp.com/sidecar-proxy-use-auto-auth-token"

func TestContainerSidecar(t *testing.T) {
annotations := map[string]string{
AnnotationVaultRole: "foobar",
}
pod := testPod(annotations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent Area: Vault Agent (auth, templating, rendering, etc.) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants