rancher: Vault Sidecar Injector error with k8s installed by rancher 2.5
What kind of request is this (question/bug/enhancement/feature request): Bug
Steps to reproduce (least amount of steps as possible):
- Create a k8s on-premise cluster from rancher 2.5 and Kubernetes version 1.19.4-rancher1-2. Network provider: Canel
- Install vault server cluster external and base https://xxxx.com (Certificate issued by AlphaSSL - trusted)
- Setup vault sidecar injector by the steps below (The step verified and work well by many k8s clusters installed by kuberspray):
export VAULT_TOKEN=XXXX
export VAULT_ADDR=https://xxxx.com
kubectl apply -f sa.yaml -n production
vault auth enable -path="rndvault" kubernetes
TOKEN_REVIEW_JWT=$(kubectl get secret vault-auth -n production -o go-template='{{ .data.token }}' | base64 --decode)
KUBE_CA_CERT=$(kubectl config view -n production --raw --minify --flatten -o jsonpath='{.clusters[].cluster.certificate-authority-data}' | base64 --decode)
KUBE_HOST=$(kubectl config view -n production --raw --minify --flatten -o jsonpath='{.clusters[].cluster.server}')
vault write auth/rndvault/config \
token_reviewer_jwt="$TOKEN_REVIEW_JWT" \
kubernetes_host="$KUBE_HOST" \
kubernetes_ca_cert="$KUBE_CA_CERT"
vault write auth/rndvault/role/internal-app \
bound_service_account_names=internal-app \
bound_service_account_namespaces=production \
policies=internal-app \
ttl=24h
helm install vault --set "injector.externalVaultAddr=https://xxxx.com" https://github.com/hashicorp/vault-helm/archive/v0.6.0.tar.gz -n production
=> finished without errors.
- sa.yaml:
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: internal-app
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: vault-auth
---
apiVersion: v1
kind: Secret
metadata:
name: vault-auth
annotations:
kubernetes.io/service-account.name: vault-auth
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: role-tokenreview-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: vault-auth
namespace: production
- kind: ServiceAccount
name: vault-auth
namespace: production
Result:
2020-12-10T12:29:43.868Z [INFO] auth.handler: authenticating
2020-12-10T12:29:43.944Z [ERROR] auth.handler: error authenticating: error="Error making API request.
URL: PUT https://https://xxxx.com/v1/auth/rndvault/login
Code: 403. Errors:
* permission denied" backoff=1.80540266
2020-12-10T12:29:45.749Z [INFO] auth.handler: authenticating
Other details that may be helpful:
- The script to deploy is finsihed and worked well with k8s installed by kuberspray. It just didn’t work with k8s cluster installed by rancher.
Environment information
- Rancher version (
rancher/rancher/rancher/serverimage tag or shown bottom left in the UI): - Installation option (single install/HA):
Cluster information
- Cluster type (Hosted/Infrastructure Provider/Custom/Imported): Hosted
- Machine type (cloud/VM/metal) and specifications (CPU/memory): VM 32vCPU/32GB Memory * 6 nodes.
- Kubernetes version (use
kubectl version):
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T11:56:40Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:09:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}```
- Docker version (use `docker version`):
Client: Docker Engine - Community Version: 19.03.6 API version: 1.40 Go version: go1.12.16 Git commit: 369ce74a3c Built: Thu Feb 13 01:27:49 2020 OS/Arch: linux/amd64 Experimental: false
Server: Docker Engine - Community Engine: Version: 19.03.6 API version: 1.40 (minimum version 1.12) Go version: go1.12.16 Git commit: 369ce74a3c Built: Thu Feb 13 01:26:21 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683
gz#14314
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 16
Got a toy Vault sidecar injector working - here’s what it took for an RKE cluster launched through the Rancher server.
Create and configure the cluster
When creating the RKE-based cluster in Rancher (Custom or node driver), ensure the following:
rancher_kubernetes_engine_config.authentication.sansmust be an array containing the FQDN. In my case, it looks like the following:Optional: create a development Vault server
I used a development Vault server at
nikkelma-vault.fe.rancher.spacewhen doing my testing. I ran the following:Configure Vault for Kubernetes, install Injector
I developed the following script to configure Vault, install the Vault Injector, and deploy a test application to confirm correct behavior.
NOTES:
KUBE_HOSTuses port 6443 because my ACE FQDN was simply a DNS entry pointing to my cluster’s control plane. Use the correct port for your configuration, possibly leaving off the port if using the HTTPS default of 443.VAULT_ADDRto point to your Vault cluster - I used a local development server here.File contents reference
sa.yaml: NOTE: edited from source issue to grant only vault-auth service account access thesystem:auth-delegatorroleinternal-app-policy.hcl:deploy.yaml:@bienkma the difference is the activation of Authorized Cluster Endpoint (ACE) to be able to use internal Kube JWT token instead of rancher tokens.
using kubespray is not an option in my case since we’re using vsphere to automatically provide de cluster. got some workarounds going on, if any fits i will post it here. thanks