feat(k8s-test): Try login and obtain API token #1
Workflow file for this run
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
name: k8s Deployment | ||
on: | ||
workflow_call: | ||
env: | ||
DD_HOSTNAME: defectdojo.default.minikube.local | ||
HELM_RABBIT_BROKER_SETTINGS: " \ | ||
--set redis.enabled=false \ | ||
--set rabbitmq.enabled=true \ | ||
--set celery.broker=rabbitmq \ | ||
--set createRabbitMqSecret=true \ | ||
" | ||
HELM_REDIS_BROKER_SETTINGS: " \ | ||
--set redis.enabled=true \ | ||
--set rabbitmq.enabled=false \ | ||
--set celery.broker=redis \ | ||
--set createRedisSecret=true \ | ||
" | ||
HELM_MYSQL_DATABASE_SETTINGS: " \ | ||
--set database=mysql \ | ||
--set postgresql.enabled=false \ | ||
--set mysql.enabled=true \ | ||
--set createMysqlSecret=true \ | ||
" | ||
HELM_PG_DATABASE_SETTINGS: " \ | ||
--set database=postgresql \ | ||
--set postgresql.enabled=true \ | ||
--set mysql.enabled=false \ | ||
--set createPostgresqlSecret=true \ | ||
" | ||
jobs: | ||
setting_minikube_cluster: | ||
name: Kubernetes Deployment | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
# databases, broker and k8s are independent, so we don't need to test each combination | ||
# lastest k8s version (https://kubernetes.io/releases/) and oldest supported version from aws | ||
# are tested (https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html#available-versions) | ||
- databases: pgsql | ||
brokers: redis | ||
k8s: 'v1.26.11' | ||
os: debian | ||
- databases: mysql | ||
brokers: rabbit | ||
k8s: 'v1.26.11' | ||
os: debian | ||
- databases: pgsql | ||
brokers: rabbit | ||
k8s: 'v1.29.2' | ||
os: debian | ||
- databases: mysql | ||
brokers: redis | ||
k8s: 'v1.29.2' | ||
os: debian | ||
- databases: pgsql | ||
brokers: rabbit | ||
k8s: 'v1.29.2' | ||
os: alpine | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Minikube | ||
uses: manusa/[email protected] | ||
with: | ||
minikube version: 'v1.31.2' | ||
kubernetes version: ${{ matrix.k8s }} | ||
driver: docker | ||
start args: '--addons=ingress --cni calico' | ||
github token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Status of minikube | ||
run: |- | ||
minikube status | ||
- name: Load images from artifacts | ||
uses: actions/download-artifact@v3 | ||
- name: Load docker images | ||
timeout-minutes: 10 | ||
run: |- | ||
eval $(minikube docker-env) | ||
docker load -i nginx/nginx-${{ matrix.os }}_img | ||
docker load -i django/django-${{ matrix.os }}_img | ||
docker images | ||
- name: Configure HELM repos | ||
run: |- | ||
helm repo add bitnami https://charts.bitnami.com/bitnami | ||
helm dependency list ./helm/defectdojo | ||
helm dependency update ./helm/defectdojo | ||
- name: Set confings into Outputs | ||
id: set | ||
run: |- | ||
echo "pgsql=${{ env.HELM_PG_DATABASE_SETTINGS }}" >> $GITHUB_ENV | ||
echo "mysql=${{ env.HELM_MYSQL_DATABASE_SETTINGS }}" >> $GITHUB_ENV | ||
echo "redis=${{ env.HELM_REDIS_BROKER_SETTINGS }}" >> $GITHUB_ENV | ||
echo "rabbit=${{ env.HELM_RABBIT_BROKER_SETTINGS }}" >> $GITHUB_ENV | ||
- name: Deploying Djano application with ${{ matrix.databases }} ${{ matrix.brokers }} | ||
timeout-minutes: 10 | ||
run: |- | ||
helm install \ | ||
--timeout 800s \ | ||
defectdojo \ | ||
./helm/defectdojo \ | ||
--set django.ingress.enabled=true \ | ||
--set imagePullPolicy=Never \ | ||
${{ env[matrix.databases] }} \ | ||
${{ env[matrix.brokers] }} \ | ||
--set createSecret=true \ | ||
--set tag=${{ matrix.os }} \ | ||
# --set imagePullSecrets=defectdojoregistrykey | ||
- name: Check deployment status | ||
run: |- | ||
kubectl get pods | ||
kubectl get ingress | ||
kubectl get services | ||
- name: Check Application | ||
timeout-minutes: 10 | ||
run: |- | ||
to_complete () { | ||
kubectl wait --for=$1 $2 --timeout=500s --selector=$3 2>/tmp/test || true | ||
if [[ -s /tmp/test ]]; then | ||
echo "ERROR: $2" | ||
cat /tmp/test | ||
echo "INFO: status:" | ||
kubectl get pods | ||
echo "INFO: logs:" | ||
kubectl logs --selector=$3 --all-containers=true | ||
exit 1 | ||
fi | ||
return ${?} | ||
} | ||
echo "Waiting for init job..." | ||
to_complete "condition=Complete" job "defectdojo.org/component=initializer" | ||
echo "Waiting for celery pods..." | ||
to_complete "condition=ready" pod "defectdojo.org/component=celery" | ||
echo "Waiting for django pod..." | ||
to_complete "condition=ready" pod "defectdojo.org/component=django" | ||
echo "Pods up and ready to rumbole" | ||
kubectl get pods | ||
RETRY=0 | ||
while : | ||
do | ||
OUT=$(kubectl run curl --quiet=true --image=curlimages/curl:7.73.0 \ | ||
--overrides='{ "apiVersion": "v1" }' \ | ||
--restart=Never -i --rm -- -s -m 20 -I --header "Host: $DD_HOSTNAME" http://`kubectl get service defectdojo-django -o json \ | ||
| jq -r '.spec.clusterIP'`/login?next=/) | ||
echo $OUT | ||
CR=`echo $OUT | egrep "^HTTP" | cut -d' ' -f2` | ||
echo $CR | ||
if [[ $CR -ne 200 ]]; then | ||
echo $RETRY | ||
if [[ $RETRY -gt 2 ]]; then | ||
kubectl get pods | ||
echo `kubectl logs --tail=30 -l defectdojo.org/component=django -c uwsgi` | ||
echo "ERROR: cannot display login screen; got HTTP code $CR" | ||
exit 1 | ||
else | ||
((RETRY++)) | ||
echo "Attempt $RETRY to get login page" | ||
sleep 5 | ||
fi | ||
else | ||
echo "Result received" | ||
break | ||
fi | ||
done | ||
ADMIN_PASS=$(kubectl get secret/defectdojo -o json | jq -r '.data.DD_ADMIN_PASSWORD' | base64 -d) | ||
echo "Simple Login check" | ||
OUT=$(kubectl run curl --quiet=true --image=curlimages/curl:7.73.0 \ | ||
--overrides='{ "apiVersion": "v1" }' \ | ||
--restart=Never -i --rm -- -s -m 20 -I --header "Host: $DD_HOSTNAME" http://`kubectl get service defectdojo-django -o json \ | ||
| jq -r '.spec.clusterIP'`/login?next=/ --data-raw "username=admin&password=$ADMIN_PASS") | ||
echo $OUT | ||
CR=`echo $OUT | egrep "^HTTP" | cut -d' ' -f2` | ||
echo $CR | ||
if [[ $CR -ne 200 ]]; then | ||
echo "ERROR: login is not possible; got HTTP code $CR" | ||
exit 1 | ||
else | ||
echo "Result received" | ||
fi | ||
echo "Simple API check" | ||
OUT=$(kubectl run curl --quiet=true --image=curlimages/curl:7.73.0 \ | ||
--overrides='{ "apiVersion": "v1" }' \ | ||
--restart=Never -i --rm -- -s -m 20 -I --header "Host: $DD_HOSTNAME" http://`kubectl get service defectdojo-django -o json \ | ||
| jq -r '.spec.clusterIP'`/api/v2/api-token-auth/ --data-raw "username=admin&password=$ADMIN_PASS") | ||
echo $OUT | ||
CR=`echo $OUT | egrep "^HTTP" | cut -d' ' -f2` | ||
echo $CR | ||
if [[ $CR -ne 200 ]]; then | ||
echo "ERROR: login is not possible; got HTTP code $CR" | ||
exit 1 | ||
else | ||
echo "Result received" | ||
fi | ||
echo "Final Check of components" | ||
errors=`kubectl get pods | grep Error | awk '{print $1}'` | ||
if [[ ! -z $errors ]]; then | ||
echo "Few pods with errors" | ||
for line in $errors; do | ||
echo "Dumping log from $line" | ||
kubectl logs --tail 50 $line | ||
done | ||
exit 1 | ||
else | ||
echo "DD K8S successfully deployed" | ||
fi | ||
curl 'http://localhost:8080/login?next=/' \ | ||
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8' \ | ||
-H 'Accept-Language: en-GB,en' \ | ||
-H 'Cache-Control: no-cache' \ | ||
-H 'Connection: keep-alive' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-H 'Cookie: firefly_session=eyJpdiI6IlNrTjZoTThFQWwvVlgrQjN0ZUd1dVE9PSIsInZhbHVlIjoiZk55Mm85VTFhU0ZpZndjM3F0d3d1T3FNUWMxRmNVT0krS0JremsxTDBLdWJlbF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YTg2N2NjODMwNWI1M2YyMDJiZGY1M2VkMzciLCJ0YWciOiIifQ%3D%3D; flow=eyJpdiI6IkN5OTdJYWI1REFrWThQQnFGTVA1L3c9PSIsInZhbHVlIjoibnNNbExHa2JoNXphWldESkJaQ2dnR1R3SS9TazY2R0tncmFlYkJ0OC9LYzc1Ym93OXRzcFFtTjkrUTZ4aGxMWCIsIm1hYyI6ImFhMzUwOTY2OGZhOWRhYjQ5YWEwYjNmYWMzOTU5OGVmYTE4NzkyZjNjNzJiN2RlZDMyYjcwOTAwYjUyMjViMWMiLCJ0YWciOiIifQ%3D%3D; csrftoken=HGbxIy9Yy0PMTPBXePHxsM6x6ZaWl832' \ | ||
-H 'Origin: http://localhost:8080' \ | ||
-H 'Pragma: no-cache' \ | ||
-H 'Referer: http://localhost:8080/login?next=/' \ | ||
-H 'Sec-Fetch-Dest: document' \ | ||
-H 'Sec-Fetch-Mode: navigate' \ | ||
-H 'Sec-Fetch-Site: same-origin' \ | ||
-H 'Sec-Fetch-User: ?1' \ | ||
-H 'Sec-GPC: 1' \ | ||
-H 'Upgrade-Insecure-Requests: 1' \ | ||
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' \ | ||
-H 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Brave";v="126"' \ | ||
-H 'sec-ch-ua-mobile: ?0' \ | ||
-H 'sec-ch-ua-platform: "macOS"' \ | ||
--data-raw 'csrfmiddlewaretoken=uMiPBTX9Ue7LmofKGBjWruu3seKEheQC1ijc9hWXi4Mn53GxKgQjJ6qqo3KqscJu&username=admin&password=admin' |