Using Vault with Kubernetes Auth Backend

1,950 views
Skip to first unread message

Mic-Le

unread,
Mar 28, 2018, 10:10:24 AM3/28/18
to Vault
Greetings!

I am trying to use Vault with a Kubernetes auth backend as described here .
I got to the point where Vault is configured to use Kubernetes backend and role for default service account is created.

The confusion part is coming on the client side (inside the kubernetes pod) - while client interacts with Vault, which client token should it use in HTTP request header?

I tried to use a token from Kubernetes default account secret, but got "permission denied" error:

$ curl -XPOST -H "X-Vault-Token: xxxxx...." --data '{"pw": "demo"}' http://vault:8200/v1/secret

please advise.

Thank you!

Brian Kassouf

unread,
Mar 28, 2018, 12:10:42 PM3/28/18
to vault...@googlegroups.com
Hi!

You'll need to use the login
(https://www.vaultproject.io/docs/auth/kubernetes.html#via-the-api)
endpoint to trade the kuberentes service account token for a vault
token. The Vault token is what you pass into the header for future
requests.

Best,
Brian
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/vault/issues
> IRC: #vault-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vault" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vault-tool+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vault-tool/058bc5ee-72b6-492f-bb51-306b90d878de%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mic-Le

unread,
Mar 28, 2018, 2:09:03 PM3/28/18
to Vault
Thank you, Brian!

Following your advise, I am trying to authenticate by running the following commands from inside the POD:

$ KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)
$ curl -XPOST --data '{"role": "demo", "jwt": "'$KUBE_TOKEN'"}' http://vault:8200/v1/auth/kubernetes/login

{"errors":["Post kubernetes:8443/apis/authentication.k8s.io/v1/tokenreviews: unsupported protocol scheme \"kubernetes\""]}

Can you please point out what did I miss?

Thanks again!

Brian Kassouf

unread,
Mar 28, 2018, 2:19:02 PM3/28/18
to vault...@googlegroups.com
I believe you're not correctly concatenating the data string. try something like

curl -sb \
--request POST \
--data "{\"role\": \"demo\", \"jwt\": \"${KUBE_TOKEN}\"}" \
"http://vault:8200/v1/auth/kubernetes/login"
> https://groups.google.com/d/msgid/vault-tool/a945764c-20e3-4131-a290-04c54001ffe7%40googlegroups.com.

Mic-Le

unread,
Mar 28, 2018, 2:23:18 PM3/28/18
to Vault
Brian, 

I got the same error using your proposed command..

What else can I check?

Brian Kassouf

unread,
Mar 28, 2018, 2:51:00 PM3/28/18
to vault...@googlegroups.com
Can you show how you configured your kubernetes backend in Vault? And
verify the "kubernets_host" has http:// or https:// before the
hostname?
> https://groups.google.com/d/msgid/vault-tool/fbb5448a-2ae3-4803-bb07-0be7e962e4b9%40googlegroups.com.

Mic-Le

unread,
Mar 28, 2018, 3:46:47 PM3/28/18
to Vault
Brian,

I have installed Vault in Kubernetes (minikube) using the Helm chart .

Since I am new to Vault, I am not sure how to pull out the backend configuration.

Here are the commands I used to get the info about auth backends:


$ vault read sys/auth

Key            Value
---            -----
kubernetes/    map[local:false seal_wrap:false type:kubernetes accessor:auth_kubernetes_124131ec config:map[default_lease_ttl:0 max_lease_ttl:0] description:]
token/         map[local:false seal_wrap:false type:token accessor:auth_token_7d996f06 config:map[default_lease_ttl:0 max_lease_ttl:0] description:token based credentials]


$ vault auth list

Path           Type          Description
----           ----          -----------
kubernetes/    kubernetes    n/a
token/         token         token based credentials

I did not specifically configure kubernetes auth backend.

Brian Kassouf

unread,
Mar 28, 2018, 4:20:56 PM3/28/18
to vault...@googlegroups.com

Mic-Le

unread,
Mar 28, 2018, 5:29:39 PM3/28/18
to Vault
Thank you, Brian.

Seems like this one was miss-configured. 

Appreciate your help!

Pal D

unread,
Jun 20, 2018, 7:01:17 AM6/20/18
to Vault


Hi Mic-Le,Brian,

I am also trying to setup kubernetes auth backend with vault.


when I am trying to authenticate using API from curl or from my application I am getting "invalid header error.  key Authorization"

a complete snippet from that is as below:

{"errors":["Post https://testaks-testgroup-123d48-v6923444.hcp.westeurope.azmk8s.io:443/apis/authentication.k8s.io/v1/tokenreviews: net/http: invalid header field value \"Bearer eyJhbG.........qm515tt8\\n\" for key Authorization"]}


can you please help me in resolving this.

Your help will be appriciated here.!
Thanks,

Vasilev Vjacheslav

unread,
Jul 2, 2018, 5:02:11 AM7/2/18
to Vault
Hi Pal D,

Were you able to solve this issue or at least find some clues to root cause?

среда, 20 июня 2018 г., 14:01:17 UTC+3 пользователь Pal D написал:

Vasilev Vjacheslav

unread,
Jul 2, 2018, 5:11:45 AM7/2/18
to Vault
I see that the problem not related to Vault, but how K8s side processes Bearer token
Reply all
Reply to author
Forward
0 new messages