-
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.
* feat: Add vault tests - Added vault deployment and bootstrap to Minikube - Added Vault private key test case - refactor tests - Increase coverage to 74%
- Loading branch information
1 parent
825bf06
commit 61d2603
Showing
7 changed files
with
166 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,27 @@ jobs: | |
# kustomize for each test but has no permission to do so | ||
- name: Remove pre-installed kustomize | ||
run: sudo rm -f /usr/local/bin/kustomize | ||
# Install vault to minikube cluster to test vault case with kubernetes auth | ||
- name: Install Vault | ||
env: | ||
GITHUB_PRIVATE_KEY: ${{ secrets.GH_TEST_APP_PK }} | ||
run: | | ||
cd scripts | ||
chmod +x install_and_setup_vault_k8s.sh | ||
./install_and_setup_vault_k8s.sh | ||
- name: Perform the test | ||
run: | | ||
export "GITHUB_PRIVATE_KEY=${{ secrets.GH_TEST_APP_PK }}" | ||
export "GH_APP_ID=${{ secrets.GH_APP_ID }}" | ||
export "GH_INSTALL_ID=${{ secrets.GH_INSTALL_ID }}" | ||
export "VAULT_ADDRESS=http://localhost:8200" | ||
export "VAULT_ROLE_AUDIENCE=githubapp" | ||
export "VAULT_ROLE=githubapp" | ||
# Run vault port forward in background | ||
kubectl port-forward vault-0 8200:8200 & | ||
# Run tests | ||
USE_EXISTING_CLUSTER=true make test | ||
- name: Report failure | ||
uses: nashmaniac/[email protected] | ||
|
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,6 @@ | ||
#!/bin/bash | ||
|
||
# Run this script to delete the vault setup in kubernetes | ||
|
||
helm delete vault | ||
kubectl delete pvc data-vault-0 |
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,19 @@ | ||
server: | ||
affinity: "" | ||
ha: | ||
enabled: false | ||
raft: | ||
enabled: true | ||
setNodeId: true | ||
config: | | ||
cluster_name = "vault-integrated-storage" | ||
storage "raft" { | ||
path = "/vault/data/" | ||
} | ||
listener "tcp" { | ||
address = "[::]:8200" | ||
cluster_address = "[::]:8201" | ||
tls_disable = "true" | ||
} | ||
service_registration "kubernetes" {} |
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,65 @@ | ||
#!/bin/bash | ||
|
||
# Run this script to setup vault on kubernetes with a simple role, policy and k8s auth | ||
# Export your github app private key then run the script | ||
# export GITHUB_PRIVATE_KEY=<YOUR GITHUB APP PRIVATE KEY> | ||
|
||
helm repo add hashicorp https://helm.releases.hashicorp.com | ||
helm repo update | ||
|
||
# install vault with single node | ||
helm install vault hashicorp/vault --values helm-vault-raft-values.yml | ||
kubectl get pods | ||
|
||
# wait for vault to run | ||
until kubectl get pod vault-0 -o=jsonpath='{.status.phase}' | grep -q "Running"; do sleep 5; done | ||
|
||
# get cluster keys | ||
kubectl exec vault-0 -- vault operator init \ | ||
-key-shares=1 \ | ||
-key-threshold=1 \ | ||
-format=json > cluster-keys.json | ||
|
||
# set unseal key | ||
VAULT_UNSEAL_KEY=$(jq -r ".unseal_keys_b64[]" cluster-keys.json) | ||
|
||
# unseal vault | ||
kubectl exec vault-0 -- vault operator unseal ${VAULT_UNSEAL_KEY} | ||
|
||
# wait for vault to be ready | ||
kubectl wait --for=condition=ready pod/vault-0 --timeout=300s | ||
|
||
# get root token | ||
VAULT_ROOT_TOKEN=$(jq -r ".root_token" cluster-keys.json) | ||
|
||
# login | ||
kubectl exec -i vault-0 -- vault login -non-interactive ${VAULT_ROOT_TOKEN} | ||
|
||
# enable kv-v2 | ||
kubectl exec -i vault-0 -- vault secrets enable -path=secret kv-v2 | ||
|
||
# write github app secret | ||
kubectl exec -i vault-0 -- vault kv put secret/githubapp/test privateKey="${GITHUB_PRIVATE_KEY}" | ||
|
||
# enable k8s auth | ||
kubectl exec -i vault-0 -- vault auth enable kubernetes | ||
|
||
# get k8s host | ||
KUBERNETES_HOST=$(kubectl exec -i vault-0 -- sh -c 'echo $KUBERNETES_SERVICE_HOST') | ||
|
||
# write k8s host | ||
kubectl exec -i vault-0 -- vault write auth/kubernetes/config kubernetes_host="https://$KUBERNETES_HOST:443" | ||
|
||
# write vault policy | ||
kubectl exec -i vault-0 -- sh -c 'vault policy write githubapp - <<EOF | ||
path "secret/data/githubapp/test" { | ||
capabilities = ["read"] | ||
} | ||
EOF' | ||
|
||
# write vault role | ||
kubectl exec -i vault-0 -- sh -c 'vault write auth/kubernetes/role/githubapp \ | ||
bound_service_account_names="default" \ | ||
bound_service_account_namespaces="namespace0" \ | ||
policies=githubapp \ | ||
ttl=24h' |