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

ConfigMap with missing vault section should default to env vars #353

Merged
merged 1 commit into from
May 25, 2022

Conversation

swenson
Copy link

@swenson swenson commented May 23, 2022

When using a ConfigMap to hold the agent config, it is natural to omit
the vault section, since the config may be hard-coded and won't know
necessarily know the correct address for the Vault server.

In that case, we should set any known information about the Vault server
(address, cert, etc.) in environment variables passed to the agent so
that it can connect to the correct Vault server.

Fixes #300

When using a ConfigMap to hold the agent config, it is natural to omit
the `vault` section, since the config may be hard-coded and won't know
necessarily know the correct address for the Vault server.

In that case, we should set any known information about the Vault server
(address, cert, etc.) in environment variables passed to the agent so
that it can connect to the correct Vault server.

Fixes #300
@swenson swenson requested a review from a team May 23, 2022 23:53
Name: "VAULT_TLS_SERVER_NAME",
Value: a.Vault.TLSServerName,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also include VAULT_NAMESPACE?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. Namespace isn't part of the vault config block, only auto_auth. And if we set VAULT_NAMESPACE, it could end up overriding a namespace the user sets in their auto_auth config: https://github.com/hashicorp/vault/blob/9334ae5f338c90f9a6d65e749794593e50acd48d/command/agent.go#L367-L369. However, if they've explicitly set the namespace annotation, it does seem like a reasonable thing to add. Overall it's a difficult one to call, but it maybe feels safer to exclude it for now, to maintain the current behaviour?

Copy link
Author

Choose a reason for hiding this comment

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

Exactly. I only targeted the things that are in the vault config block.

Comment on lines +70 to +75
if a.Vault.Address != "" {
envs = append(envs, corev1.EnvVar{
Name: "VAULT_ADDR",
Value: a.Vault.Address,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

(Just making sure I understand) It looks like all these can be overridden by the user with annotations from https://www.vaultproject.io/docs/platform/k8s/injector/annotations#vault-annotations? So like for the vault address, the order of precedence would be:

  • vault stanza in configmap
  • This setting of VAULT_ADDR
  • The value of vault.hashicorp.com/service

We may want to add a note about this new behavior in or adjacent to https://www.vaultproject.io/docs/platform/k8s/injector/examples

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I believe that is correct. I'll double-check it before merging, and add a ticket to update those docs.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I confirmed that vault.hashicorp.com/service will override the agent container VAULT_ADDR settings.

@swenson
Copy link
Author

swenson commented May 25, 2022

I noticed this also fixes another use case: even with a helm-deployed Vault, this will now set the VAULT_ADDR as expected if the vault {} section is missing from the config; before the agent pod would just hang forever not knowing where to connect to Vault.

@swenson
Copy link
Author

swenson commented May 25, 2022

Thanks!

@swenson swenson merged commit aefb6ea into main May 25, 2022
@swenson swenson deleted the vault-3701/configmap-no-vault branch May 25, 2022 17:55
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.

Injector don't set external vault address when using ConfigMap
4 participants