## Configuration Vault Agent Injector ### (Rancher RKE-based cluster) Configure an Authorized Cluster Endpoint - Create a unified domain that will direct queries to managing nodes of the cluster : 1. In Rancher, go to Cluster Management > ClusterName > Edit Config > Authorized Endpoint 2. Set domain name and add the certificate. ### Create Vault resources in kubernetes cluster - Create a serviceAccount with corresponding Secret, ClusterRoleBinding, Role and RoleBinding. ```bash cat < vault-values.yaml global: externalVaultAddr: https://vault.example.com csi: enabled: false injector: authPath: auth/testing/kubernetes replicas: 3 server: serviceAccount: create: false name: vault-auth priorityClassName: "system-cluster-critical" EOF helm repo add hashicorp https://helm.releases.hashicorp.com helm upgrade --install vault hashicorp/vault --version v0.28.1 -f vault-values.yaml ``` ### Upgrade Vault Agent Sidecar Injector - Get the last version number : [Github Vault Helm](https://github.com/hashicorp/vault-helm) - Create a vault-values.yaml file and upgrade helm release in the cluster ```bash cat < vault-values.yaml global: externalVaultAddr: https://vault.example.com csi: enabled: false injector: authPath: auth/testing/kubernetes replicas: 3 server: serviceAccount: create: false name: vault-auth priorityClassName: "system-cluster-critical" EOF helm upgrade -n vault --install vault hashicorp/vault --version v -f vault-values.yaml ``` ### Testing the setup ```bash # Testing directly the vault kubernetes auth methods : # Payload : {"role": "tests", "jwt": $TOKEN_REVIEW_JWT} curl -X POST https://vault.example.com/v1/auth/kubernetes/login -d @payload.json --header "Content-Type: application/json" # Testing via kubernetes API : # Ex : https://apik8s.tst.example.com/api/v1/namespaces/vault/serviceaccounts/default/token # Then : https://apik8s.tst.example.com/apis/authentication.k8s.io/v1/tokenreviews curl -X POST https://apik8s.tst.example.com/api/v1/namespaces/vault/serviceaccounts/default/token \ -H "Authorization: Bearer $TOKEN_REVIEW_JWT" \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{}' # payload : { # "apiVersion": "authentication.k8s.io/v1", # "kind": "TokenReview", # "spec": { # "token":"" # } #} curl -X POST https://apik8s.tst.example.com/apis/authentication.k8s.io/v1/tokenreviews \ -H "Authorization: Bearer $TOKEN_REVIEW_JWT" \ -H 'Content-Type: application/json; charset=utf-8' \ -d @payload.json