-
Notifications
You must be signed in to change notification settings - Fork 191
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 reading vault token from environment variables #693
Comments
Hello there.
I don't think there is an expectation that the token does not expire. If the sops decryption is not concluant, the reconciliation is stopped, and resume at next reconciliation interval. Sops accepts vault-token value from an environment variable, but we disabled it in Do you think it is feasible to use the Vault CSI Provider to sync your token to a kubernetes secret? You could then use that secret with your flux kustomization. |
Thanks for replying.
It's accurate that I don't think Vault CSI Provider would work here since that is used to sync Vault secrets not Vault token. The hard part is, how to detect the token is near expiry and automatically renew it, easily? What's more, the user is distributing their own token to another user to use even for a short period of time.
Good point. However storing that in a kubernetes secret which lives in etcd also bring security risks in a multi-tenant environment,: afaik etcd is encrypted using a global key. Once that key is compromised, unauthorized users may gain access to secrets of others. If flux doesn't enfore reading vault token from a kubernetes secret, a user can figure out how to minimize the attack surface and reduce risks in a multi-tenant environment. After all, users can always choose to provide it in a kubernetes secret. This proposal can work as a second option. But before I comment further, Could you elaborate a bit more on "any workload could be reconciled with that var"? I am really curious. |
when fetching the secret, The other way to rotate secret is to use a cronjob. Users do it for registry token rotation. the doc: https://fluxcd.io/docs/guides/cron-job-image-auth/#using-cronjob-to-sync-ecr-credentials-as-a-kubernetes-secret |
You mean, env var supplied to kustomize-controller pod can be read by any workload cluster wide? How that can be done? |
I see it the other way around. How to make sure that an env var provided to a controller that reconciles workloads cluster wide can be constrained to only specific workloads? A more viable way to go I think would be https://learn.hashicorp.com/tutorials/vault/approle |
see #695 |
Sorry, but I couldn't figure - What's the difference between reading from a kubernetes secret vs from a env var for this purpose? How does But despite the above, if we take a step back, this proposal won't let Flux lose anything, it just unlock a way for users to figure out a more secure, easier way that well integrates with existing infrastructure (vault and kubernetes) to decrypt secrets with Vault. Users are free to choose to supply the token from environment variables or kubernetes secrets.
I like this idea 😄 But I am not sure we want to go with this complex way. I don't know how long it takes to implement and this solution will need |
AppRole requires no outside tie in, it's a vault auth engine. Think of an AppRole as a service user that you assign policy to, You use the Role ID + Secret ID to authenticate and are given a short-lived token in return with the policies and parameters specified in the AppRole. in #695 i'm requesting Flux can be configured with an AppRole instead of Token, knowing it'll retrieve a token on demand. Reading this thread I think this is a good half-way house for me, thanks @souleb
|
For the implementation, I was talking about the time it takes before AppRole Auth can integrate with ks-controller.
I think it's a matter of time and effort. By allowing reading from env var, users can figure out the best way to retrieve and supply a token(e.g. make it in memory and only visible to the process which requests it), and do not require much effort from the Flux team. Another concern that makes me reluctant to use AppRole is, we are introducing new "identities" again... that are managed in different places. In this exmaple, https://learn.hashicorp.com/tutorials/vault/approle#step-2-create-a-role-with-policy-attached it creates a As a best practice, I would try to manage all identities in a single identity pool as much as I can. I would prefer utilizing the existing kubernetes RBAC which integrates well and sync with my IAM infrastructure which manages all identities and policies. Nevertheless, this proposal is about adding a new way to get tokens, not about preventing other ways. It's a addition. And I like the new AppRole idea. I would appreciate it if the Flux team could adopt the ‘batteries included but replaceable’ approach, and give users the freedom to choose whichever suits them the best. |
Let's make sure we understand the proposal the same way. The proposal is to enable the In this scenario, when declaring a
if we take the following examples:
We would expect user B's kustomization reconciliation to fail, but it would actually succeed because we don't have a way to constrain the env var. Now, this is partly implemented. When we cannot retrieve a secret containing a |
Correct.
Thanks for the example. I understood your concern now.
It will also succeed.
Specifically, the reason we lose that "isolation", is because we can only reference the same vault token for different apps. The core issue of "k8s secret and env var approach" is, when After understanding your concern, it seems |
on point 1. there is a hard enforcement at the namespace level. All workloads in the same namespace can use that secret, but not sure I understand point 2.
yes! And I imagine a token would have a single usage. |
https://github.com/banzaicloud/bank-vaults/blob/main/pkg/sdk/vault/client.go#L362 has a webhook that dynamically handles secrets on behalf of pods or by itself. It uses the kubernetes authentication method in vault. vaults trusts the respective (in our case flux's) cluster CA and the JWK token of the serviceaccount of the flux kustomize-controller pod. There should be a role that links to flux's serviceaccount and flux-system namespace to be assigned with a policy to use the transit engine. Flux should then be able to authenticate itself against vault and retrieve a token to contact the transit engine. |
Hi team, first of all, thanks for all your work!
Problem
This is originated from this discussion.
In short, currently the vault token that
kustomize-controller
reads is expected to not expire, and is the same that was used to encrypt the data key. This bring two concerns:vault login
is only attributed to that user. It shouldn't be used insidekustomize-controller
to decrypt against vault, representing a machine user. This violates the identity based authorization principle.Proposed Solution
By allowing kustomize-controller to read this sops
vault-token
value from a environment variable, we will unlock many potential ways to supply that token to kustomize-controller, e.g. There are various vault agent, injector, webhook that can work together to supply the vault token after authentication againt Vault using Kubernetes Auth, for example.After all, this will provide a more flexible way and allow customization on secret decryption.
The text was updated successfully, but these errors were encountered: