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 annotation to copy volume mounts from existing container #212

Merged
merged 2 commits into from
Jan 26, 2021
Merged

Add annotation to copy volume mounts from existing container #212

merged 2 commits into from
Jan 26, 2021

Conversation

pbar1
Copy link
Contributor

@pbar1 pbar1 commented Jan 16, 2021

This PR introduces the following annotation: vault.hashicorp.com/agent-copy-volume-mounts, whose value is expected to be the name of container (or init container) in the original pod spec whose volume mounts are to be copied into the Vault Agent init/sidecar containers. Volume mounts whose paths include the string serviceaccount are ignored so we don't end up copying K8s service account token mounts (ie, /var/run/secrets/kubernetes.io/serviceaccount).

The reasoning behind this feature: We inject all pods with X.509 certs via SPIFFE at runtime that end up in emptyDir volumes. We'd like to use the Vault Agent Auto-Auth Cert Method with these certs; our Vaults already require mTLS and use the TLS Certificates Auth Method against this PKI, so having these volumes mounted to the Vault Agent's init and sidecar containers is required.

Regarding Auto-Auth via the Cert Method - I've got a separate branch that generalizes the injector to support all Auth Methods (#213). We're currently successfully running a build of the injector with these features in our dev environment.

Let me know how I can help to get this merged. Thanks! ☄️

@hashicorp-cla
Copy link

hashicorp-cla commented Jan 16, 2021

CLA assistant check
All committers have signed the CLA.

Add test

Add copy volume mount test

Extract copyVolumeMount logic

Signed-off-by: Pierce Bartine <piercebartine@gmail.com>
Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

Hi @pbar1, thanks for the contribution, this looks great! I took it for a spin and it works as described and have no comments on the implementation.

One thing I would ask before merging, I think we'll need a handler test case for this. The side effect of this annotation on the agents should result in volume JSON patches, so we'll want to test that is the case. Take a look at the handler test cases and let me know if you have any questions.

@pbar1
Copy link
Contributor Author

pbar1 commented Jan 26, 2021

Sure, I've just added another test case for the handler, in which the CopyVolumeMounts annotation is specified.

@jasonodonnell jasonodonnell self-requested a review January 26, 2021 20:25
Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jasonodonnell jasonodonnell merged commit f01385e into hashicorp:master Jan 26, 2021
@pbar1
Copy link
Contributor Author

pbar1 commented Jan 26, 2021

Thank you!

@pbar1 pbar1 deleted the copy-volmounts branch January 26, 2021 21:55
@irsl
Copy link

irsl commented Feb 3, 2021

Guys, this is awesome and perfect timing; I just realized I need this for a use case and it was just released yesterday! :)

jfroche added a commit to jfroche/vault-k8s that referenced this pull request Feb 15, 2021
We currently have two options to define vault agent templates:
either define the template configuration as an inline template in the
annotation or configure the vault agent directly. The former is really
not handy when template is getting complex, the latter forces us to
manage the whole vault agent configuration.

We add a new annotation that enables the vault agent to inject secrets
from a template file on the container disk. Since
hashicorp#212, this template can be
present in volume defined on the container.

Annotation example:

```yaml
vault.hashicorp.com/agent-inject-secret-foo: 'database/roles/app'
vault.hashicorp.com/agent-inject-template-source-foo: '/etc/my-app/config.toml.tmpl'
vault.hashicorp.com/agent-inject-file-foo: '/etc/my-app/config.toml',
vault.hashicorp.com/agent-copy-volume-mounts: 'MyContainerNameWithVolumes'
```

If a template content is also defined in annotation (using
`vault.hashicorp.com/agent-inject-template`, the template on disk won't be used.

refs hashicorp#84
jfroche added a commit to jfroche/vault-k8s that referenced this pull request Mar 30, 2021
We currently have two options to define vault agent templates:
either define the template configuration as an inline template in the
annotation or configure the vault agent directly. The former is really
not handy when template is getting complex, the latter forces us to
manage the whole vault agent configuration.

We add a new annotation that enables the vault agent to inject secrets
from a template file on the container disk. Since
hashicorp#212, this template can be
present in volume defined on the container.

Annotation example:

```yaml
vault.hashicorp.com/agent-inject-secret-foo: 'database/roles/app'
vault.hashicorp.com/agent-inject-template-file-foo: '/etc/my-app/config.toml.tmpl'
vault.hashicorp.com/agent-inject-file-foo: '/etc/my-app/config.toml',
vault.hashicorp.com/agent-copy-volume-mounts: 'MyContainerNameWithVolumes'
```

If a template content is also defined in annotation (using
`vault.hashicorp.com/agent-inject-template`, the template on disk won't be used.

refs hashicorp#84
jfroche added a commit to jfroche/vault-k8s that referenced this pull request Mar 30, 2021
We currently have two options to define vault agent templates:
either define the template configuration as an inline template in the
annotation or configure the vault agent directly. The former is really
not handy when template is getting complex, the latter forces us to
manage the whole vault agent configuration.

We add a new annotation that enables the vault agent to inject secrets
from a template file on the container disk. Since
hashicorp#212, this template can be
present in volume defined on the container.

Annotation example:

```yaml
vault.hashicorp.com/agent-inject-secret-foo: 'database/roles/app'
vault.hashicorp.com/agent-inject-template-file-foo: '/etc/my-app/config.toml.tmpl'
vault.hashicorp.com/agent-inject-file-foo: '/etc/my-app/config.toml',
vault.hashicorp.com/agent-copy-volume-mounts: 'MyContainerNameWithVolumes'
```

If a template content is also defined in annotation (using
`vault.hashicorp.com/agent-inject-template`, the template on disk won't be used.

refs hashicorp#84
jasonodonnell pushed a commit that referenced this pull request Apr 5, 2021
We currently have two options to define vault agent templates:
either define the template configuration as an inline template in the
annotation or configure the vault agent directly. The former is really
not handy when template is getting complex, the latter forces us to
manage the whole vault agent configuration.

We add a new annotation that enables the vault agent to inject secrets
from a template file on the container disk. Since
#212, this template can be
present in volume defined on the container.

Annotation example:

```yaml
vault.hashicorp.com/agent-inject-secret-foo: 'database/roles/app'
vault.hashicorp.com/agent-inject-template-file-foo: '/etc/my-app/config.toml.tmpl'
vault.hashicorp.com/agent-inject-file-foo: '/etc/my-app/config.toml',
vault.hashicorp.com/agent-copy-volume-mounts: 'MyContainerNameWithVolumes'
```

If a template content is also defined in annotation (using
`vault.hashicorp.com/agent-inject-template`, the template on disk won't be used.

refs #84
RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
…rp#212)

* Add annotation to copy volumeMounts from container

Add test

Add copy volume mount test

Extract copyVolumeMount logic

Signed-off-by: Pierce Bartine <piercebartine@gmail.com>

* Add handler test for CopyVolumeMounts
RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
We currently have two options to define vault agent templates:
either define the template configuration as an inline template in the
annotation or configure the vault agent directly. The former is really
not handy when template is getting complex, the latter forces us to
manage the whole vault agent configuration.

We add a new annotation that enables the vault agent to inject secrets
from a template file on the container disk. Since
hashicorp#212, this template can be
present in volume defined on the container.

Annotation example:

```yaml
vault.hashicorp.com/agent-inject-secret-foo: 'database/roles/app'
vault.hashicorp.com/agent-inject-template-file-foo: '/etc/my-app/config.toml.tmpl'
vault.hashicorp.com/agent-inject-file-foo: '/etc/my-app/config.toml',
vault.hashicorp.com/agent-copy-volume-mounts: 'MyContainerNameWithVolumes'
```

If a template content is also defined in annotation (using
`vault.hashicorp.com/agent-inject-template`, the template on disk won't be used.

refs hashicorp#84
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.

4 participants