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

Allow overriding of volume mount path and added a flag to preserve case sensitivity of secrets #71

Merged

Conversation

smitthakkar96
Copy link
Contributor

@smitthakkar96 smitthakkar96 commented Feb 6, 2020

This PR adds two new annotations:

  • vault.hashicorp.com/secret-volume-path
  • vault.hashicorp.com/preserve-secret-case
  • Fixes broken test (it was always passing): TestSecretAnnotations

Why?

  • Currently vault-injector doesn't allow overriding the path where it mounts the secrets. In our case our base image expects the secrets to be present in a particular directory so it gets picked up as env vars when the container starts.

  • Currently vault-injector assumes that the case of the secret name doesn't matter well in our case it is very important, so to not break backwards compatibility and also fullfil the need I added vault.hashicorp.com/preserve-secret-case

@hashicorp-cla
Copy link

hashicorp-cla commented Feb 6, 2020

CLA assistant check
All committers have signed the CLA.

@smitthakkar96 smitthakkar96 requested review from jasonodonnell and catsby and removed request for jasonodonnell February 6, 2020 13:57
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 @smitthakkar96,

Added some inline comments about things that need to be fixed. Additionally these annotations will require tests. Case sensitivity can be added here, secret path can be added here and a new test case to verify the mount path can be added here.

Thanks!

agent-inject/agent/container_volume.go Show resolved Hide resolved
agent-inject/agent/annotations.go Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
agent-inject/agent/annotations.go Outdated Show resolved Hide resolved
agent-inject/agent/annotations.go Outdated Show resolved Hide resolved
agent-inject/agent/annotations.go Outdated Show resolved Hide resolved
@jasonodonnell jasonodonnell removed the request for review from catsby February 6, 2020 14:36
@smitthakkar96
Copy link
Contributor Author

Thanks @jasonodonnell will address the comments

@smitthakkar96
Copy link
Contributor Author

@jasonodonnell I addressed the comments

@smitthakkar96
Copy link
Contributor Author

@jasonodonnell any updates?

@ShabihZaidi
Copy link

any update, I want this feature too

@jasonodonnell
Copy link
Contributor

Hi @smitthakkar96, sorry for the delay, but I'm ready to review this now! When you get a chance can you resolve the conflicts? Thanks!

@smitthakkar96 smitthakkar96 force-pushed the smit/allow_override_behaviour branch from 5cb4371 to a8dc585 Compare February 19, 2020 16:43
@smitthakkar96
Copy link
Contributor Author

@jasonodonnell resolved

}

func TestSecretAnnotationsWithPreserveCaseSensitivityFlagOn(t *testing.T) {
tests := []struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasonodonnell this is not dry but making it dry would make tests a bit complicated so I duplicated the code

@smitthakkar96
Copy link
Contributor Author

ping!

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 @smitthakkar96, I finally got some time to review this!

I like what this PR is trying to do and it's a much needed feature. I do think that the path and preserve case should be configurable per secret and not global.

For example I think this would be more useful if the following were possible:

vault.hashicorp.com/agent-inject-secret-db-creds: "database/creds/db-app"
vault.hashicorp.com/agent-inject-template-db-creds: |
    {{- with secret "database/creds/db-app" -}}
     postgres://{{ .Data.username }}:{{ .Data.password }}@postgres.postgres.svc:5432/wizard?sslmode=disable
    {{- end }}
vault.hashicorp.com/agent-inject-path-db-creds: "/etc/db"
vault.hashicorp.com/agent-inject-preserve-case-db-creds: "true"

Admittedly this does complicate things because we'll now need to iterate over any custom paths and create/mount volumes for those.

Thoughts?

@smitthakkar96
Copy link
Contributor Author

@jasonodonnell isn't it better to still keep it global and allow overriding at secret level if needed? I am happy to update the code to allow overriding the path and case sensitivity flag at secret level if we agree

@saurav-k
Copy link

@smitthakkar96 @jasonodonnell Your comments make more sense to have path configurable per secret. Specially with pattern you suggested .

@smitthakkar96
Copy link
Contributor Author

@saurav-k I still think having a global flag makes it easy for people to configure incase if you want to override the path for all secrets you are fetching. Incase of if you want to override per secret you can still do if we implement what @jasonodonnell is suggesting

@saurav-k
Copy link

@smitthakkar96 Makes sense to have a global flag in case you want to mount all secret at same path and this PR can be scoped to global flag and another PR can be created for the feature suggested by @jasonodonnell , My thoughts on suggested feature. I have seen apps need files from different mount location as secret . and in that case suggested feature will be very useful. Let's wait for @jasonodonnell to give his view on scope of this PR.

@jasonodonnell
Copy link
Contributor

@smitthakkar96 I agree the global flag is also valuable because in some situations it would eliminate a lot of annotations. It would likely be that secret specific configurations override the globals.

@smitthakkar96
Copy link
Contributor Author

smitthakkar96 commented Feb 25, 2020 via email

@smitthakkar96
Copy link
Contributor Author

@jasonodonnell I made the changes, please have a look when you get chance

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.

Thanks for your patience @smitthakkar96, this looks great!

@jasonodonnell jasonodonnell merged commit 15cdb01 into hashicorp:master Mar 2, 2020
@smitthakkar96
Copy link
Contributor Author

@jasonodonnell thanks for merging it :)

RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
…se sensitivity of secrets (hashicorp#71)

* Allow overriding of volume mount path and also the case sensitivity

* Addressed CR comments and fix broken test

* cleanup

* allow paths to be configurable at secret level

* added tests

* run go fmt
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.

5 participants