CI/CD Integration

Security-Checks automatisch bei jedem Deploy — GitHub Actions und GitLab CI.

Voraussetzung: Ein API-Zugang (Client-ID und Secret) und eine verifizierte Domain.

GitHub Actions

Legen Sie Client-ID und Secret Ihres API-Zugangs als Repository-Secrets ab (Settings → Secrets → UA_CLIENT_ID und UA_CLIENT_SECRET). Der Workflow holt zuerst einen kurzlebigen Access-Token:

name: Security Audit
on: [push]

jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - name: Run security scan
        run: |
          TOKEN=$(curl -sf __APP_DOMAIN__/oauth/token \
            -d grant_type=client_credentials \
            -d client_id="${{ secrets.UA_CLIENT_ID }}" \
            -d client_secret="${{ secrets.UA_CLIENT_SECRET }}" | jq -r .access_token)
          RESULT=$(curl -sf __APP_DOMAIN__/api/audit/short \
            -H "Authorization: Bearer $TOKEN" \
            -H "Content-Type: application/json" \
            -d '{"url":"https://ihre-domain.de"}')

          SCORE=$(echo $RESULT | jq '.score')
          echo "Security Score: $SCORE"

          if [ "$SCORE" -lt 60 ]; then
            echo "Score unter 60 — Build fehlgeschlagen"
            exit 1
          fi

Code-Audit-Ergebnisse in GitHub Code Scanning (SARIF)

Der Export GET /api/code/scans/:id/sarif liefert die Befunde eines Code-Audits im SARIF-Format. In GitHub Actions:

      - name: Code-Audit-Ergebnis als SARIF holen
        run: |
          curl -sf __APP_DOMAIN__/api/code/scans/$AUDIT_ID/sarif \
            -H "Authorization: Bearer $TOKEN" -o auditcollector.sarif
      - uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: auditcollector.sarif

GitLab CI

Variablen UA_CLIENT_ID und UA_CLIENT_SECRET (maskiert) unter Settings → CI/CD → Variables anlegen; der Token wird im Job geholt:

audit:
  stage: test
  script:
    - |
      TOKEN=$(curl -sf $AUDIT_URL/oauth/token -d grant_type=client_credentials \
        -d client_id="$UA_CLIENT_ID" -d client_secret="$UA_CLIENT_SECRET" | python3 -c \
        "import sys,json; print(json.load(sys.stdin)['access_token'])")
      RESULT=$(curl -sf $AUDIT_URL/api/audit/short \
        -H "Authorization: Bearer $TOKEN" \
        -H "Content-Type: application/json" \
        -d "{\"url\":\"$SITE_URL\"}")

      SCORE=$(echo $RESULT | python3 -c \
        "import sys,json; print(json.load(sys.stdin)['score'])")
      echo "Score: $SCORE"
      test $SCORE -ge 60

Große Sites: Background-Jobs pollen

Bei Scans über 50 Seiten gibt die API eine Job-ID zurück statt eines direkten Ergebnisses. Pollen Sie den Status:

JOB_ID=$(curl -sf __APP_DOMAIN__/api/audit/scan \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","options":{"maxPages":100}}' \
  | jq -r '.job_id')

while true; do
  STATUS=$(curl -sf __APP_DOMAIN__/api/jobs/$JOB_ID \
    -H "Authorization: Bearer $TOKEN" \
    | jq -r '.status')
  echo "Status: $STATUS"
  [ "$STATUS" = "completed" ] && break
  [ "$STATUS" = "failed" ] && exit 1
  sleep 10
done

Score-Schwellwerte

Empfohlene Schwellwerte für den Pipeline-Gate:

  • 90+ — Sehr gut, alles grün
  • 70–89 — Gut, kleinere Verbesserungen möglich
  • 60–69 — Akzeptabel, sollte verbessert werden
  • <60 — Kritisch, Deploy blockieren empfohlen
Tipp: Starten Sie mit einem niedrigen Schwellwert (z.B. 40) und erhöhen Sie ihn schrittweise, damit bestehende Projekte nicht sofort blockiert werden.