TROUBLESHOOTING HASHICORP VAULT KUBERNETES AUTH ERROR
We were trying to integrate Spring Cloud Gateway (SCG) on Kubernetes with HashiCorp. We followed the steps mentioned in vault documentation. We were able to bring up vault and vault injector but SCG pods were stuck in init state. Found following error in SCG application pod vault-agent-init container logs:
NAME READY STATUS RESTARTS AGE
scg-0 0/2 Init:0/1 0 9h
vault-0 1/1 Running 0 10h
vault-agent-injector-5c89c7dfc5-n2v6v 1/1 Running 0 20h
Cgo: disabled
Log Level: info
Version: Vault v1.8.4
Version Sha: 925bc650ad1d997e84fbb832f302a6bfe0105bbb
2022-09-30T16:24:28.007Z [INFO] sink.server: starting sink server
2022-09-30T16:24:28.007Z INFO creating watcher
2022-09-30T16:25:28.008Z [ERROR] auth.handler: error authenticating: error="context deadline exceeded" backoff=1sTo verify that vault injector was connecting to right vault instance, we verified init agent config using below kubectl command:
kubectl exec -it scg-0 -c vault-agent-init cat /home/vault/config.json
Config was pointing to a different vault than what we created. As we are using shared Kubernetes cluster, we checked with our cluster admin if there was any other vault injector running in the cluster. They confirmed that there was another one running. As the old was not in use, we requested to delete it. Post that vault init container was connecting to correct vault but still the error was not gone.
We tried few things but could not find out the issue. Finally, vault troubleshooting guide came to our rescue. We have enabled audit raw logs as mentioned in the document. Regular audit logs write hashed strings so we couldn’t see what tokens and roles are sent from our application. But after enabling raw logs, we could see the actual token being passed as part of the authentication process.
vault audit enable -path=file_raw file file_path=/vault/audit-raw.log log_raw=true
After inspecting decrypted jwt token (There are lot of online tools to decrypt), we found that token we used in creating auth/kubernetes/config and auth/kubernetes/role were different than what SCG application uses. SCG uses by default service-account-scg service account to authenticate to vault. After making corrections to Kubernetes authentication method and application role, SCG application pod came up and was in ready state.
Comments
Post a Comment