forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kelseyhightower#623 from stepanstipl/kubernetes-auth
Add Kubernetes auth for Vault backend
- Loading branch information
Showing
6 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ type Config struct { | |
RoleID string | ||
SecretID string | ||
YAMLFile string | ||
Role string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
These are steps to get vault with Kubernetes auth working on minikube. | ||
|
||
*Do not use default service account in prod instead create dedicated acount for Vault auth.* | ||
|
||
- Deploy Helm | ||
``` | ||
# Install Helm - on macOS | ||
brew install kubernetes-helm | ||
# Deploy tiller into the cluster | ||
helm init | ||
- Install Vault in dev mode | ||
``` | ||
# Add Vault chart | ||
helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator | ||
# Install Vault | ||
# Currently the chart has Vault 0.8.2 and we need 0.8.3 (but PR is pending) | ||
helm install incubator/vault --name vault --set vault.dev=true --set image.tag="0.8.3" | ||
``` | ||
- Enable Kubernetes backend | ||
``` | ||
# Get Vault pod name | ||
export POD_NAME=$(kubectl get pods --namespace default -l "app=vault" -o jsonpath="{.items[0].metadata.name}") | ||
# Get inside pod | ||
kubectl exec -i -t ${POD_NAME} sh | ||
# Set env vars for Vault client | ||
export VAULT_TOKEN=$(cat /root/.vault-token) | ||
# Enable Kube auth backend | ||
vault auth-enable kubernetes | ||
# Configure Kube auth bacckend | ||
vault write auth/kubernetes/config \ | ||
kubernetes_host=https://kubernetes \ | ||
kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt | ||
# Create Vault policy for testing | ||
vault write sys/policy/test \ | ||
rules='path "secret/*" { capabilities = ["create", "read"] }' | ||
# Cretate role for confd | ||
vault write auth/kubernetes/role/confd \ | ||
bound_service_account_names=vault-auth \ | ||
bound_service_account_namespaces=default \ | ||
policies=test \ | ||
ttl=1h | ||
# Write test secret | ||
vault write secret/foo value=bar | ||
``` | ||
- Create RBAC (if used) rule to allow acccess to TokenReview API | ||
``` | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: role-tokenreview-binding | ||
namespace: default | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:auth-delegator | ||
subjects: | ||
- kind: ServiceAccount | ||
name: vault-auth | ||
namespace: default | ||
``` | ||
- Start a pod with confd and get a secret | ||
``` | ||
kubectl run test -i -t --image=quay.io/stepanstipl/test:confd-v7 \ | ||
--restart=Never -- sh | ||
# Inside the pod | ||
# Create confd config | ||
mkdir -p /etc/confd/conf.d /etc/confd/templates | ||
echo '[template] | ||
src = "test.conf.tmpl" | ||
dest = "/tmp/test.conf" | ||
keys = [ | ||
"/secret/foo", | ||
]' > /etc/confd/conf.d/test.toml | ||
# And template | ||
echo '{{getv "/secret/foo"}}' > /etc/confd/templates/test.conf.tmpl | ||
# and finally run confd | ||
confd -onetime -backend vault -auth-type kubernetes -role-id confd -node http://unrealistic-sabertooth-vault:8200 -log-level debug | ||
``` | ||
- Check `/tmp/test.conf`, it should contain your secret | ||
``` | ||
cat /tmp/test.conf | ||
``` |