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 support for vault kubernetes authentication #274

Closed
justinas-b opened this issue Jan 24, 2022 · 18 comments
Closed

Add support for vault kubernetes authentication #274

justinas-b opened this issue Jan 24, 2022 · 18 comments
Milestone

Comments

@justinas-b
Copy link

Hey! For the workloads running in kubernetes, usually kubernetes authentication method is used on a Vault, through it would be awesome to have this supported on envconsul also.

This would eliminate need of managing all the tokens for authentication with vault.

More about authentication method here: https://www.vaultproject.io/docs/auth/kubernetes

@justinas-b
Copy link
Author

In some sort, related to #252

@yellowmegaman
Copy link

Having this implemented will enable really great level of security.
If only envconsul could get secrets only via k8s auth:

  • we could inject secrets for pid 1, not leaving the file with secrets on disk (as with Vault injector)
  • with proper user in container, kubectl exec won't be able to read /proc/1/environ
  • we could also add a bit of RBAC and policies (e.g. gatekeeper) on top of that - and no one will be able to run workload with ServiceAccount that has access to those secrets.

So if I understood correctly, it's a killer feature, much better than vault injector or Vault CSI in current state.

@Kryvchun
Copy link
Contributor

@eikenb Hi. I am going to implement this, and as I see, I will need to:

  1. support k8s auth method in consul-template:
    a. Add new fields to CreateConsulClientInput:
    K8SAuthRoleName            string
    K8SServiceAccountMountPath string
    K8SServiceAccountToken     string
    b. If a token is unset in the function CreateVaultClient, then execute client.Auth().Login(...) with vault.auth.KubernetesAuth auth method, and set the token.
  2. add config flags to envconsul.

Am I right about the idea of implementation?

I found only one mention about implementing other auth methods in the comment of consul-template:
hashicorp/consul-template#744 (comment)

@justinas-b
Copy link
Author

Would it make sense to include vault namespace also?

@yellowmegaman
Copy link

Would it make sense to include vault namespace also?

Correct me if I'm wrong, it's already supported.

@yellowmegaman
Copy link

@eikenb John can you please take a look at @Kryvchun plan?

@eikenb
Copy link
Contributor

eikenb commented May 9, 2022

Hey @Kryvchun, @yellowmegaman, @justinas-b...

Sorry for the silence. I've been busy trying to get up to speed on consul-esm to fix an important bug there and have been ignoring my inbox.

I haven't worked on the Auth portions of consul-template yet but will happily work through the PRs there. With a quick skim it seems like you're on the right path. The hardest part will probably be figuring out how to test it as consul-template relies heavily on integration tests which won't work here. But that would be part of the consul-template PR and we can figure that out there.

I'm not actively working on consul-template right now but try to spend time every Monday on community feedback for all the projects. I am planning on working on Envconsul soon-ish (next after the consul-esm 0.6.1 bugfix release I'm working on now) and we might be able to squeeze all this in at that point.

@gauravkr19
Copy link

gauravkr19 commented Jul 13, 2022

Can anyone please share the documentation on using envconsul with Kubernetes workload.

@Kryvchun
Copy link
Contributor

@gauravkr19
Copy link

Thanks @Kryvchun for the quick response. Is this part of the latest release ?
Do we have an example of its usage with Kubernetes?

@eikenb
Copy link
Contributor

eikenb commented Jul 13, 2022

If anyone would like to write up a quick example to include in the README or, if better, another file I'd be happy to include it. Thanks.

@gauravkr19
Copy link

gauravkr19 commented Jul 14, 2022

Hi John & Maksym,
I have been trying to place secrets with period in its Key, like “com.tibco.resource.password"=2323 from Vault to Pod's environment variable.
However, it errors out when exporting this as env variable, Error: "Bad identifier".

Can envconsul solve this. Can it export the variable with dot into container's shell.

@eikenb
Copy link
Contributor

eikenb commented Jul 14, 2022

That should work with envconsul.

$ consul kv put foo/bar.zed.wha 1234
Success! Data written to: foo/bar.zed.wha
$ envconsul -pristine -prefix foo -once bash
jae@hidoshi:/home/jae/projects/envconsul$ env
bar.zed.wha=1234
[...]

I used consul as it was handy (testing stuff like this right now) but should work the same either way.

@gauravkr19
Copy link

gauravkr19 commented Jul 15, 2022

thanks John for confirming this, I tested this with Vault and can use non-standard identifiars as secret keys.
Now, need to implement the same in openshift with K8s auth method. Any idea when this feature of K8s authentication will be released, did not find it in latest vers 0.12.1.

@eikenb eikenb added this to the v0.13.0 milestone Jul 15, 2022
@eikenb
Copy link
Contributor

eikenb commented Jul 15, 2022

Sorry @gauravkr19, my k8s knowledge is very limited. You might want to try asking in hashicorp's discuss forums, maybe the vault-k8s one will be able to help.

https://discuss.hashicorp.com/tags/c/vault/30/k8s

@eikenb
Copy link
Contributor

eikenb commented Jul 15, 2022

Just realized this ticket is still open and I've merged this already. IE. it didn't auto-close.

This support was merged in with #281

@eikenb eikenb closed this as completed Jul 15, 2022
@yellowmegaman
Copy link

@eikenb Great! Thank you. Can we have new release with it?

@eikenb
Copy link
Contributor

eikenb commented Jul 18, 2022

@yellowmegaman.. I have 1 last bug to finish fixing then will be putting out a new release. Should be this week as I have a PR already up to fix the bug (upstream in consul-template) and am just waiting on a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants