diff --git a/.gitea/workflows/ansible-ci.yml b/.gitea/workflows/ansible-ci.yml new file mode 100644 index 0000000..958a24c --- /dev/null +++ b/.gitea/workflows/ansible-ci.yml @@ -0,0 +1,191 @@ +name: OpenVPN Ansible + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + + ansible-lint: + name: Ansible Lint + runs-on: ubuntu-latest + + container: + image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup SSH + run: | + echo "Setting up SSH ..." + mkdir -p ~/.ssh + + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + + echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub + chmod 644 ~/.ssh/id_ed25519.pub + + - name: Run ansible-lint + run: ansible-lint + + + syntax-check: + name: Ansible Syntax Check + runs-on: ubuntu-latest + + container: + image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + + echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub + chmod 644 ~/.ssh/id_ed25519.pub + + - name: Syntax check + env: + ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg + run: | + ansible-playbook --syntax-check playbooks/openvpn.yml + + + deploy-prod: + name: Deploy OpenVPN + runs-on: ubuntu-latest + + needs: + - ansible-lint + - syntax-check + + container: + image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + + echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub + chmod 644 ~/.ssh/id_ed25519.pub + + - name: Deploy + env: + ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg + run: | + ansible-playbook playbooks/openvpn.yml + + + sbom: + name: Generate SBOM + runs-on: ubuntu-latest + + needs: + - deploy-prod + + container: + image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + + echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub + chmod 644 ~/.ssh/id_ed25519.pub + + - name: Generate SBOM + env: + ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg + run: | + ansible-playbook playbooks/sbom.yml + + - name: Upload SBOM + uses: actions/upload-artifact@v4 + with: + name: sbom + path: reports/sbom/ + retention-days: 365 + + + trivy-sbom: + name: Scan SBOM with Trivy + runs-on: ubuntu-latest + + needs: + - sbom + + container: + image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download SBOM + uses: actions/download-artifact@v4 + with: + name: sbom + path: reports/sbom/ + + - name: Scan SBOMs + run: | + ls -R reports || true + + mkdir -p reports/trivy + + if compgen -G "reports/sbom/*.json" > /dev/null; then + + for sbom in reports/sbom/*.json; do + filename=$(basename "$sbom" .json) + + echo "Scanning $sbom" + + trivy sbom \ + --format json \ + --output "reports/trivy/${filename}-trivy.json" \ + --exit-code 0 \ + "$sbom" + + trivy sbom \ + --format table \ + --output "reports/trivy/${filename}-trivy.txt" \ + --exit-code 0 \ + "$sbom" + done + + else + echo "No SBOM files found." + exit 1 + fi + + - name: Upload Trivy reports + uses: actions/upload-artifact@v4 + with: + name: trivy-reports + path: reports/trivy/ + retention-days: 365 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ae8cc3..8fcb61f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,6 +30,7 @@ deploy-prod: stage: deploy script: - ansible-playbook playbooks/openvpn.yml + when: manual sbom: stage: security