|
| 1 | +--- |
| 2 | +name: Tests |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + paths: |
| 7 | + - 'charts/**' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - 'charts/**' |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + name: Test Helm charts |
| 18 | + runs-on: ubuntu-22.04 |
| 19 | + steps: |
| 20 | + - name: Checkout repo |
| 21 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Set up Helm |
| 26 | + uses: Azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 |
| 27 | + with: |
| 28 | + version: 'v3.13.1' |
| 29 | + |
| 30 | + - name: Set up lynx |
| 31 | + run: sudo apt install lynx |
| 32 | + |
| 33 | + - name: Set up Python |
| 34 | + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1 |
| 35 | + with: |
| 36 | + python-version: '3.12' |
| 37 | + check-latest: true |
| 38 | + |
| 39 | + - name: Set up chart-testing |
| 40 | + uses: helm/chart-testing-action@b43128a8b25298e1e7b043b78ea6613844e079b1 # v2.6.0 |
| 41 | + |
| 42 | + - name: Run chart-testing (list-changed) |
| 43 | + id: list-changed |
| 44 | + run: | |
| 45 | + CHANGED=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) |
| 46 | + if [[ -n "$CHANGED" ]]; then |
| 47 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Create kind cluster |
| 51 | + if: steps.list-changed.outputs.changed == 'true' |
| 52 | + uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0 |
| 53 | + with: |
| 54 | + config: .github/workflows/config/cluster.yaml |
| 55 | + |
| 56 | + - name: Set up cluster |
| 57 | + if: steps.list-changed.outputs.changed == 'true' |
| 58 | + run: | |
| 59 | + installation_id=$(uuidgen) |
| 60 | + echo $installation_id |
| 61 | + installation_key=$(openssl rand -base64 12) |
| 62 | + sa_password=$(openssl rand -base64 12) |
| 63 | + cert_pass=$(openssl rand -base64 12) |
| 64 | +
|
| 65 | + #TLS setup |
| 66 | + echo "Creating root CA cert" |
| 67 | + openssl req -x509 -sha256 -days 1 -newkey rsa:2048 -keyout rootCA.key -out rootCA.crt -subj "/CN=Bitwarden Ingress" --passout pass:$cert_pass |
| 68 | + echo "Generating TLS key" |
| 69 | + openssl genrsa -out bitwarden.localhost.key 2048 |
| 70 | + echo "Generating TLS cert" |
| 71 | + openssl req -key bitwarden.localhost.key -new -out bitwarden.localhost.csr --passin pass:$cert_pass -subj "/CN=bitwarden.localhost" |
| 72 | +
|
| 73 | + echo "Signing TLS cert" |
| 74 | + cat > bitwarden.localhost.ext << EOF |
| 75 | + authorityKeyIdentifier=keyid,issuer |
| 76 | + basicConstraints=CA:FALSE |
| 77 | + subjectAltName = @alt_names |
| 78 | + [alt_names] |
| 79 | + DNS.1 = bitwarden.localhost |
| 80 | + EOF |
| 81 | +
|
| 82 | + openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in bitwarden.localhost.csr -out bitwarden.localhost.crt -days 1 -CAcreateserial -extfile bitwarden.localhost.ext --passin pass:$cert_pass |
| 83 | +
|
| 84 | + echo "Exporting TLS certs to PEM" |
| 85 | + openssl x509 -in bitwarden.localhost.crt -out bitwarden.localhost.pem --passin pass:$cert_pass |
| 86 | + openssl x509 -in rootCA.crt -out rootCA.pem --passin pass:$cert_pass |
| 87 | +
|
| 88 | + #Ingress |
| 89 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml |
| 90 | + kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission |
| 91 | + sudo echo "127.0.0.1 bitwarden.localhost" | sudo tee -a /etc/hosts |
| 92 | +
|
| 93 | + #Namespace |
| 94 | + kubectl create ns bitwarden |
| 95 | +
|
| 96 | + kubectl config set-context --current --namespace=bitwarden |
| 97 | +
|
| 98 | + #Secrets |
| 99 | + kubectl create secret generic custom-secret \ |
| 100 | + --from-literal=globalSettings__installation__id=$installation_id \ |
| 101 | + --from-literal=globalSettings__installation__key=$installation_key \ |
| 102 | + --from-literal=globalSettings__mail__smtp__username="REPLACE" \ |
| 103 | + --from-literal=globalSettings__mail__smtp__password="REPLACE" \ |
| 104 | + --from-literal=globalSettings__yubico__clientId="REPLACE" \ |
| 105 | + --from-literal=globalSettings__yubico__key="REPLACE" \ |
| 106 | + --from-literal=SA_PASSWORD=$sa_password |
| 107 | +
|
| 108 | + kubectl create secret tls tls-secret --cert=bitwarden.localhost.pem --key=bitwarden.localhost.key |
| 109 | +
|
| 110 | + - name: Run chart-testing (install) |
| 111 | + if: steps.list-changed.outputs.changed == 'true' |
| 112 | + run: ct install --target-branch ${{ github.event.repository.default_branch }} --skip-clean-up --namespace bitwarden |
| 113 | + |
| 114 | + - name: Test install |
| 115 | + if: steps.list-changed.outputs.changed == 'true' |
| 116 | + run: | |
| 117 | + #For review purposes |
| 118 | + echo "*****DEPLOYMENTS*****" |
| 119 | + kubectl get deployments |
| 120 | + echo "*****PODS*****" |
| 121 | + kubectl get pods |
| 122 | + echo "*****SERVICES*****" |
| 123 | + kubectl get svc |
| 124 | + echo "*****JOBS*****" |
| 125 | + kubectl get jobs |
| 126 | + echo "*****INGRESS*****" |
| 127 | + kubectl describe ingress |
| 128 | +
|
| 129 | + echo "*****HOME*****" |
| 130 | + home=$(curl -Ls https://bitwarden.localhost -w httpcode=%{http_code} --cacert rootCA.pem) |
| 131 | + echo $home | lynx -stdin -dump -width=100 |
| 132 | + httpCode=$(echo "${home}" | grep -Po 'httpcode=\K(\d\d\d)') |
| 133 | + bodyCheck=$(echo "${home}" | grep -Po 'Bitwarden Web Vault') |
| 134 | + if [[ ${httpCode} -ne 200 ]]; then |
| 135 | + echo "::error::ERROR: Home page failed to load. HTTP code was $httpCode" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | + if [[ "$bodyCheck" != "Bitwarden Web Vault" ]]; then |
| 139 | + echo "::error::ERROR: Home page failed to load. Please check body output above." |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | +
|
| 143 | + echo "Home OK." |
| 144 | +
|
| 145 | + echo "*****API/CONFIG*****" |
| 146 | + config=$(curl -Ls https://bitwarden.localhost/api/config -w httpcode=%{http_code} --cacert rootCA.pem) |
| 147 | + echo $config | lynx -stdin -dump -width=100 |
| 148 | + httpCode=$(echo "${config}" | grep -Po 'httpcode=\K(\d\d\d)') |
| 149 | + bodyCheck=$(echo "${config}" | grep -Po '\"vault\":\"https://bitwarden\.localhost\"') |
| 150 | + if [[ ${httpCode} -ne 200 ]]; then |
| 151 | + echo "::error::ERROR: Home page failed to load. HTTP code was $httpCode" |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | + if [[ "$bodyCheck" != '"vault":"https://bitwarden.localhost"' ]]; then |
| 155 | + echo "::error::ERROR: API/Config page failed to load. Please check body output above." |
| 156 | + exit 1 |
| 157 | + fi |
| 158 | +
|
| 159 | + echo "API/Config OK." |
| 160 | +
|
| 161 | + echo "*****ADMIN*****" |
| 162 | + admin=$(curl -Ls https://bitwarden.localhost/admin -w httpcode=%{http_code} --cacert rootCA.pem) |
| 163 | + echo $admin | lynx -stdin -dump -width=100 |
| 164 | +
|
| 165 | + httpCode=$(echo "${admin}" | grep -Po 'httpcode=\K(\d\d\d)') |
| 166 | + bodyCheck=$(echo "${admin}" | grep -Po "We'll email you a secure login link") |
| 167 | + if [[ ${httpCode} -ne 200 ]]; then |
| 168 | + echo "::error::ERROR: Home page failed to load. HTTP code was $httpCode" |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | + if [[ "$bodyCheck" != "We'll email you a secure login link" ]]; then |
| 172 | + echo "::error::ERROR: Admin page failed to load. Please check body output above." |
| 173 | + exit 1 |
| 174 | + fi |
| 175 | +
|
| 176 | + echo "Admin OK." |
| 177 | +
|
| 178 | + - name: Clean-up |
| 179 | + if: steps.list-changed.outputs.changed == 'true' |
| 180 | + run: | |
| 181 | + helm ls --all --short | xargs -L1 helm delete |
| 182 | + kubectl delete ns bitwarden |
| 183 | + kind delete cluster |
0 commit comments