-
Notifications
You must be signed in to change notification settings - Fork 173
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
Injector with external Vault server? #15
Comments
@smurfralf This scenario should work, provided pods can communicate with the external Vault cluster. You will need to set |
I'm struggling with using the deploy manifests from this repo, which i'm attempting to use because the helm charts are currently not working as intended with regards to global.enable variable, among other templating issues. FWIW - I was able to get it working by changing the following
I will report back here as I become less confused :) |
Hi @ls-brentsmith,
That RBAC is not needed by the injector. The injector doesn't actually communicate with Vault at all. The rbac you listed is what Vault uses when authenticating service accounts in Kubernetes.
This should really be the only thing you need to do.
The deploy examples in this repository use the vault namespace. You should only need to create a namespace kubectl create namespace vault
kubectl create -f ./deploy/injector-rbac.yaml --namespace=vault
kubectl create -f ./deploy/injector-service.yaml --namespace=vault
kubectl create -f ./deploy/injector-mutating-webhook.yaml --namespace=vault
kubectl create -f ./deploy/deployment.yaml --namespace=vault
kubectl get pods --namespace=vault |
@jasonodonnell thanks for the quick response. Follow up question, is it possible to inject a custom auth path for the vault-agents? |
@ls-brentsmith, there's no annotation currently that lets you alter the auth path, however, you can mount your own Vault Agent configuration files using a configmap. Here's an example: https://www.vaultproject.io/docs/platform/k8s/injector/examples.html#configmap-example. Mount path would go in the Hope that helps! |
Thank you for the quick response! |
Are there plans to add an annotation for custom auth paths? It'd be nice to have a choice between a configmap or just annotations. |
Yes, I'll be adding one @buckner! |
@jasonodonnell - back to the original topic of this issue... At any rate, solving that isn't my point. What I asked for in the description would be nice:
|
@smurfralf There are some dependencies in the Vault Helm project between the projects, so some stuff will need to change over there for installing the injector standalone. I'll document the process of configuring the injector with an external Vault service after the new year since HashiCorp is currently in a holiday shutdown. |
@jasonodonnell I have a setup of external vault server with consul backend and placed a load balancer in front of vault server in an EKS environment. Now m app has been deployed in separate EKS cluster where I mentioned AGENT_INJECT_VAULT_ADDR as the above mentioned ELB(Port 80). Now my app pod becomes not ready after I injected the init container . STATUS becomes 'Init:0/1' . I think it is something related to token initialization. How can I mention that token here and retrieve the secrets inside the Pod? |
@VinothChinnadurai Did you check the init container logs to see what's happening?
|
Yes @jasonodonnell . Please find it here
Not sure why it still hits some other service(vault.demo.svc) instead of ELB address |
@VinothChinnadurai Double check the env is set correctly because that looks like the default vault-k8s/deploy/injector-deployment.yaml Line 36 in 611492d
Next retrigger the injection by patching the pod. You'll need to set the status annotation to |
@jasonodonnell Happy New year! Thanks. It worked for me! But I find an issue with the syncing part where I have updated my secrets through vault API command Payload.json has Post then in the GET command of API, I can receive the updated secrets. |
@VinothChinnadurai Lower the TTL of your secret. Updates are based on TTL of the secret. |
@jasonodonnell does this also work with istio service mesh? |
@trx35479 We haven't done explicit testing with istio yet, so we can not verify if this will or will not work with it. If you happen to test this, please let us know what you find. |
========================================================== Init pod returns the following errors. how can it be fixed? Vault address has been changed to http://vlt.consulvault.172.31.101.63.xip.io Both the clusters are in the same network and curl command returns the response. I think I may have to pass the root token(or register secret with Vault) in order to authenticate. Thank you
|
@jasonodonnell @shlee322 I've noticed the code for setting a custom path for the Kubernetes Auth method has been committed to master. Any chance you guys are going to do a release of that soon? |
Hi @stevegore just released in |
Wrote this for myself and my team. It was pieced together using the awesome HashiCorp docs. All the examples follow what's in hashicorp/vault-guides repo and Learning modules on Hashi site. Hope one of you find this helpful. Injecting Secrets into Kubernetes Pods via VaultThere are two distinct parts of configuring auto-injection of secrets, Kubernetes & Vault. This will go through how-to configure both in order for auto-injection to work, as well as, a few custom options that should be considered as we deploy to production. This guide combines and refines two separate tutorials provided by Learn Vault for our specific use case. Kubernetes Auto-Injector Setup (Kubernetes)Service AccountsVault Agent Injector
Vault Auth
Cluster Role
Cluster Role BindingsVault Agent Injector
Vault Auth
Service
Mutating Webhook Configuration
As per Vault documentation, “By default, the Vault Agent Injector will process all namespaces in Kubernetes except the system namespaces kube-system and kube-public. To limit what namespaces the injector can work in a namespace selector can be defined to match labels attached to namespaces.” namespaceSelector is the selector for restricting the webhook to only specific namespaces. This should be set to a multiline string. For more information see https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-namespaceselector Deployment
Note the value for Kubernetes Auto-Injector Setup (Vault)Enable and Configure Kubernetes Auth Method
Couple things with noting.
Be aware that the vault-auth service account is associated with the authentication method. This is the service account created explicitly for the Kubernetes authentication. It is not to be associated with any other resource or action. As such, should be protected accordingly. If access to a Vault server is restricted by firewall rules and the Kubernetes cluster is not on the same internal network as the Vault server, it is critical a path is carved from the Kubernetes cluster to the Vault server, IE. whitelisting IP address of egress traffic from cluster in Vault’s firewall rule. Example Application Steps1. Enable KV (v2)
2. Store secret and password
3. Create Vault policy
4. Create Vault authentication role
5. Create Kubernetes service account
6. Create example application deployment (w/o annotations)
At this point the pod does not have access to the secret, as there are no Vault specific annotations within the deployment, yet. 7. Patch deployment
Now, there should be annotations associated with the pod. This will create the init and sidecar containers associated with the secret auto-injection. Secrets will be stored under /vault/secret. Worth noting, is the vault.hashicorp.com/agent-inject-secret-database-config.txt: "internal/data/database/config" annotation. The key dictates the name of the file to be database-config.txt with the value being the path within Vault’s KV store: internal/data/database/config. 8. Templatize secret output
There are multiple ways to configure how the secret is formatted, using the annotation template key vault.hashicorp.com/agent-inject-template-database-config.txt. For a complete list of annotation options, see the Vault Project links in the Attribution section below. 9. Create example application deployment (w/ annotations)
Other Things Worth NotingSecrets are bound to the service account. The service account for a deployment is specified in the spec.template.spec.serviceAccountName block. The corresponding Vault relation is specified in Vault’s authentication role Secrets are bound to the namespace. Similar to the service account, the corresponding Vault relation is specified in Vault’s authentication role. Errors for both service account and namespace will be manifest themselves as pods perpetually in the Init phase, never reaching ready. Errors are found within the vault-agent-init container logs, detailing the authentication error in clear English. The token, both init and sidecar containers use to communicate with Vault, lives locally within the container at the following path: /home/vault/.token. Unsurprisingly, the token is not mounted into the primary container within the pod, making direct communications between Vault and primary container difficult. |
Hi, I found an annotations option that help to custom the auth_path that easier than using config map.
Config annotation like that, the vault agent will call to endpoint: It's very useful when use have 1 vault cluster, and config authen with multiple k8s cluster. Hope this help! |
Thanks @dcatalano-figure for the write up with the demonstrable code. I recently delivered a HashiCorp Learn guide titled Integrate a Kubernetes Cluster with an External Vault.
|
Indeed, this is a new feature in 0.2.0 |
I see this issue is resolved but could someone guide me to the final documentation. We have an external vault gke cluster and multiple application gke clusters. I would like to see how we can use this tool to integrate our existing vault to inject secrets to all those clusters. |
@jasonodonnell , as per this documentation it is using a minikube and it is using http protocol to connect to the external vault sever. Mine is an external vault server with https protocol which uses a ca authorized certificate. in this case how to change the helm command to create injector pod with certificate options? Please help me. If i just replace http with https I am gtting below error. auth.handler: authenticating I have built my vault cluster using https://codelabs.developers.google.com/codelabs/vault-on-gke/index.html?index=..%2F..cloud#18 |
Hi @sandeepkatthi99, You need to create a Kube secret with the servers CA certificate (in the namespace with your app), then using annotations configure the Vault Agent to use it: vault.hashicorp.com/tls-secret: "<NAME OF KUBE SECRET>"
vault.hashicorp.com/ca-cert: "/vault/tls/ca.crt" |
This issue should be closed since the original description has been satisfied by vault-helm v0.4 with |
Thanaks @jasonodonnell jasonodonnell I will try the same. |
@burtlo Thanks for the learning guide. I just wanted to let you know that in the Configure Kubernetes authentication section, the |
There's a bug in the Vault website generator causing a bunch links to break and is something we're working on fixing. https://www.vaultproject.io/docs/auth/kubernetes/ will work and sorry for the inconvenience! |
@dcatalano-figure thanks for sharing your setup! I have a question though - I'm trying to go through with your setup however we have multiple clusters that would like to access vault secret. How do we go about that? |
@therealsamlin we're mounting the Kubernetes auth method at a different path for each cluster. Then set |
basically what @stevegore said. would like to add that auth path value must be prefixed with |
In my case, I have vault server running on GKE cluster A and I have installed Vault Agent Injector service on cluster B by passing externalVaultAddr which is exposed over http.
@jasonodonnell Any idea how to resolve this? |
Hi, I am also facing the same issue. (I have 2 gke cluster setup , Cluster A vault is installed with internal LB, cluster B for application Error writing data to auth/kubernetes/login: Error making API request. URL: PUT http://gke_internal_LB_IP:8200/v1/auth/kubernetes/login
and logs |
Hello, This question may have been answered earlier - not sure. While performing the setup on EKS side , after executing all the 4 yaml files under deploy folder, i am able to create the agent injector POD. However, when trying to perform the setup on the vault side, i am trying to obtain the JWT token as below , it complains of the missing secret token in secrets : export SERVICEACCOUNT_JWT_TOKEN=$(kubectl get secret -o jsonpath="{.data.token}" $(kubectl get serviceaccount vault-injector -n vault -o jsonpath="{.secrets[0].name}") | base64 -d) I verify that the secret does in exist with kubectl get secrets -n vault command Does the secret need to be created manually ? Is there a yaml to execute while deploying the agent injector itself ? Please let me know. |
Hello, @jasonodonnell please explain how to do it, I am new in Vault |
@asl-cloud99 We are also having the similar use case (I have 2 gke cluster setup with same VPC, Cluster A vault is installed with internal LB, cluster B for application). Are you able to make it to work? If so, can you please share the steps? |
I deployed the injector via the standard helm chart, with [centos@ip-10-5-58-194 (vaulttest) ~]$ kubectl logs vault-agent-injector-5657ff569b-kdn8n -c sidecar-injector
2021-06-15T19:35:24.646Z [INFO] handler: Starting handler..
Listening on ":8080"...
2021-06-15T19:35:24.654Z [INFO] handler.auto-tls: Generated CA
2021-06-15T19:35:24.655Z [INFO] handler.certwatcher: Updated certificate bundle received. Updating certs...
2021-06-16T17:11:24.000Z [INFO] handler.certwatcher: Updated certificate bundle received. Updating certs...
2021-06-17T14:47:24.000Z [INFO] handler.certwatcher: Updated certificate bundle received. Updating certs...
2021-06-18T12:23:24.000Z [INFO] handler.certwatcher: Updated certificate bundle received. Updating certs...
2021-06-18T15:11:36.470Z [ERROR] handler: http: TLS handshake error from 127.0.0.1:56344: EOF I've plenty of other TLS handshake issues reported with a bad certificate error but not this EOF variant. |
A colleague "changed service mesh mtls strict policy to permissive" and that got rid of the TLS handshake error but the injector still wasn't injecting the init/agent containers. Then she disabled the istio sidecar from the vault-agent-injector POD, and it started working. |
Hi Guys, I've tried all things shared here and still getting:
HELM: APP.YML:
VAULT_0 conf:
Would you please help me to spot what is wrong here? I'd really really appreciate some help ... |
Hi, However, I am facing authentication issue as shown below 2021-12-22T11:55:02.769Z [ERROR] auth.handler: error authenticating: I have enabled debug, here is the output of it 2021-12-22T11:08:10.887Z [DEBUG] (runner) final config: {"Consul":{"Address":"","Namespace":"","Auth":{"Enabled":false,"Username":"","Password":""},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000}},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000,"BlockQueryWaitTime":60000000000},"DefaultDelims":{"Left":null,"Right":null},"Exec":{"Command":"","Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"DEBUG","MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0","Name":"consul-template"},"Templates":[{"Backup":false,"Command":"","CommandTimeout":30000000000,"Contents":"{{ with secret "secret/data/devwebapp/config" }}{{ range $k, $v := .Data }}{{ $k }}: {{ $v }}\n{{ end }}{{ end }}","CreateDestDirs":true,"Destination":"/vault/secrets/credentials.txt","ErrMissingKey":false,"Exec":{"Command":"","Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":0,"Source":"","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"{{","RightDelim":"}}","FunctionDenylist":[],"SandboxPath":""}],"Vault":{"Address":"http://51.143.61.191:8200","Enabled":true,"Namespace":"","RenewToken":false,"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":false},"Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000},"UnwrapToken":false,"DefaultLeaseDuration":300000000000},"Wait":{"Enabled":false,"Min":0,"Max":0},"Once":false,"BlockQueryWaitTime":60000000000} Could someone please help in resolving this issue... |
Suggest you check the auth Method of the Cluster from where you are trying to retrieve secret. |
The scenario we want to support is to use a vault server which pre-exists the kubernetes cluster. We want the vault-k8s injector capability to talk to this vault server.
Is this scenario supported? I see that the injector command (vault-k8s/subcommand/injector/flags.go) takes a vault-address argument. And I see that deployment (vault-helm/templates/injector-deployment.yaml) sets the AGENT_INJECT_VAULT_ADDR env variable.
If the injector can be configured to use an external service, please document an example configuration that also disables installing vault as a service inside kubernetes.
The text was updated successfully, but these errors were encountered: