Ontwerp GitLab CI Pipelines voor Geautomatiseerde Beveiligings- en Compliancehandhaving
description
Met deze prompt ontwikkel je GitLab CI pipelines die geautomatiseerde beveiligings- en compliancehandhaving integreren, waardoor handmatige inspanning en risico's op niet-naleving verminderen. Het waarborgt continue naleving van beveiligingsnormen door je CI/CD workflows, wat de veiligheid en auditgereedheid van je pipeline verbetert, essentieel voor gereguleerde omgevingen of projecten met hoge beveiligingseisen.
prompt
Help me een GitLab CI pipelineconfiguratie te maken die automatisch beveiligings- en compliancebeleid afdwingt tijdens builds en deployments. Mijn huidige GitLab CI YAML-configuratie: <voer je GitLab CI YAML-configuratie in>. Specifieke compliance-standaarden of beleidsregels om af te dwingen: <noem de beveiligingsnormen of ...
try_prompt
generate_helper
disclaimerOnPageApi
tags
ai_answers
provider: openai
model: gpt-4.1-nano
Hier is een uitgebreide GitLab CI/CD-configuratie die automatische beveiligings- en compliance-analyses integreert tijdens builds en deployments. Deze configuratie bevat:
- Integratie van OWASP Top 10 beveiligingsscans
- Geheimen-scanning met GitLab Secret Detection
- Gebruik van Trivy voor container vulnerabilities
- Rapportage via e-mail en Slack bij fouten
- Bescherming van staging en productieomgevingen
```yaml
stages:
- build
- test
- scan_security
- deploy
variables:
# Slack webhook URL voor meldingen (stel deze in onder CI/CD > Variables)
SLACK_WEBHOOK_URL: "https://hooks.slack.com/services/xxx/yyy/zzz"
# E-mail adres voor compliance rapporten
COMPLIANCE_REPORT_EMAIL: "securityteam@voorbeeld.com"
build_job:
stage: build
image: docker:latest
services:
- docker:dind
script:
- echo "Project bouwen"
- docker build -t mijnapp:latest .
test_job:
stage: test
image: docker:latest
script:
- echo "Tests uitvoeren"
- # Voeg hier je testcommando's toe
# OWASP Top 10 Security Scan (bijvoorbeeld met OWASP Dependency-Check of Snyk)
scan_security_owasp:
stage: scan_security
image: owasp/dependency-check:latest
script:
- dependency-check --project mijnapp --scan ./app --out ./reports/dependency-check
artifacts:
paths:
- reports/dependency-check
reports:
dependency_scanning: ./reports/dependency-check/dependency-check-report.json
only:
- master
- main
allow_failure: false
# Geheimen scanning met GitLab Secret Detection
secret_detection:
stage: scan_security
image: gitlab/gitlab-secret-detection:latest
variables:
SECRET_DETECTION_SCAN: "true"
script:
- /analyzer
artifacts:
reports:
secret_detection: gl-secret-detection-report.json
only:
- master
- main
allow_failure: false
# Trivy container vulnerability scan
trivy_scan:
stage: scan_security
image: aquasec/trivy:latest
script:
- trivy image --exit-code 1 --format json --output trivy-report.json mijnapp:latest
artifacts:
paths:
- trivy-report.json
allow_failure: false
only:
- master
- main
# Deployment naar staging
deploy_staging:
stage: deploy
environment:
name: staging
url: https://staging.voorbeeld.com
script:
- echo "Deploy naar staging"
- # Deployment commando's
only:
- develop
# Deployment naar productie (beveiligd, vereist handmatige bevestiging)
deploy_production:
stage: deploy
environment:
name: productie
url: https://www.voorbeeld.com
script:
- echo "Deploy naar productie"
- # Deployment commando's
when: manual
only:
- main
# Automatisch rapporteren en notificaties bij fouten
after_script:
- |
if [ "$CI_JOB_STATUS" != "success" ]; then
# Slack melding
curl -X POST -H 'Content-type: application/json' --data '{"text":"🚨 Fout in pipeline: '$CI_JOB_NAME' - '$CI_PROJECT_NAME' - '$CI_PIPELINE_URL'"}' $SLACK_WEBHOOK_URL
# E-mail rapport (voorbeeld met sendmail of andere tool)
echo "Fout in pipeline: $CI_JOB_NAME" | mail -s "Pipeline Fout: $CI_PROJECT_NAME" $COMPLIANCE_REPORT_EMAIL
fi
```
**Toelichting:**
- **Security Scans:** Er worden verschillende scans uitgevoerd na de build en test fase, inclusief OWASP dependency check, secret detection en Trivy voor container vulnerabilities.
- **Rapportages:** Bij fouten worden automatische meldingen gestuurd naar Slack en een e-mail naar het securityteam.
- **Deployments:** De staging-omgeving wordt automatisch ingezet bij commits op develop, terwijl productie handmatig wordt bevestigd.
- **Beveiliging:** Alleen op `master`/`main` worden kritieke scans en deploys uitgevoerd, en de productie deployment is expliciet handmatig.
Zorg dat je de variabelen `SLACK_WEBHOOK_URL` en `COMPLIANCE_REPORT_EMAIL` aanpast aan jouw situatie. Ook kun je aanvullende scans of policies toevoegen afhankelijk van je organisatie.
Heeft u nog verdere wensen of vragen?
provider: deepseek
model: deepseek-chat
Hier is een verbeterde GitLab CI-configuratie met geïntegreerde beveiligings- en compliance-controles:
```yaml
stages:
- build
- test
- security_scan
- deploy
variables:
SECURITY_SCANS_DIR: "${CI_PROJECT_DIR}/security-reports"
# Cache voor betere prestaties bij security scans
cache:
paths:
- vendor/
- node_modules/
- .cache/
build_job:
stage: build
script:
- echo "Project bouwen"
artifacts:
paths:
- build/
expire_in: 1 hour
test_job:
stage: test
script:
- echo "Tests uitvoeren"
dependencies:
- build_job
# Security Scanning Stage
secret_detection:
stage: security_scan
image:
name: aquasec/trivy:latest
script:
- mkdir -p ${SECURITY_SCANS_DIR}
- |
trivy filesystem . \
--security-checks secret \
--format template \
--template "@contrib/gitlab.tpl" \
--output "${SECURITY_SCANS_DIR}/secret-detection-report.json"
artifacts:
paths:
- ${SECURITY_SCANS_DIR}/
reports:
secret_detection: ${SECURITY_SCANS_DIR}/secret-detection-report.json
expire_in: 1 week
allow_failure: false
dependency_scan:
stage: security_scan
image:
name: aquasec/trivy:latest
script:
- mkdir -p ${SECURITY_SCANS_DIR}
- |
trivy filesystem . \
--security-checks vuln \
--format template \
--template "@contrib/gitlab.tpl" \
--output "${SECURITY_SCANS_DIR}/dependency-scan-report.json"
artifacts:
paths:
- ${SECURITY_SCANS_DIR}/
reports:
dependency_scanning: ${SECURITY_SCANS_DIR}/dependency-scan-report.json
expire_in: 1 week
allow_failure: false
sast_scan:
stage: security_scan
image:
name: aquasec/trivy:latest
script:
- mkdir -p ${SECURITY_SCANS_DIR}
- |
trivy filesystem . \
--security-checks config \
--format template \
--template "@contrib/gitlab.tpl" \
--output "${SECURITY_SCANS_DIR}/sast-report.json"
artifacts:
paths:
- ${SECURITY_SCANS_DIR}/
reports:
sast: ${SECURITY_SCANS_DIR}/sast-report.json
expire_in: 1 week
allow_failure: false
# Compliance Gate
compliance_check:
stage: security_scan
image: alpine:latest
script:
- |
echo "Compliance checks uitvoeren..."
# Controleer of security scans zijn geslaagd
if [ -f "${SECURITY_SCANS_DIR}/secret-detection-report.json" ] &&
[ -f "${SECURITY_SCANS_DIR}/dependency-scan-report.json" ] &&
[ -f "${SECURITY_SCANS_DIR}/sast-report.json" ]; then
echo "✓ Alle security scans voltooid"
else
echo "✗ Een of meer security scans ontbreken"
exit 1
fi
dependencies:
- secret_detection
- dependency_scan
- sast_scan
needs: ["secret_detection", "dependency_scan", "sast_scan"]
allow_failure: false
# Notificaties
notify_security_team:
stage: security_scan
image: curlimages/curl:latest
script:
- |
# E-mail rapport naar security team
echo "Security scan rapporten worden gegenereerd voor ${CI_PROJECT_NAME}" | \
curl -X POST -H "Content-Type: application/json" \
-d '{"text":"Security scans voltooid voor '"${CI_PROJECT_NAME}"'. Rapport beschikbaar in GitLab."}' \
${SLACK_WEBHOOK_URL}
when: on_success
dependencies:
- compliance_check
notify_failure:
stage: security_scan
image: curlimages/curl:latest
script:
- |
# Slack melding bij falen
curl -X POST -H "Content-Type: application/json" \
-d '{"text":"🚨 SECURITY CHECK GEFAALD voor '"${CI_PROJECT_NAME}"'. Pipeline geblokkeerd."}' \
${SLACK_WEBHOOK_URL}
when: on_failure
# Gecontroleerde deployments
deploy_staging:
stage: deploy
script:
- echo "Deploy naar staging omgeving"
- |
# Alleen doorgaan als security checks geslaagd zijn
echo "Security compliance geverifieerd - deploying naar staging"
environment:
name: staging
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
needs: ["compliance_check"]
deploy_production:
stage: deploy
script:
- echo "Deploy naar productie omgeving"
- |
# Extra checks voor productie
echo "Productie deployment - extra compliance verificatie"
environment:
name: production
rules:
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
when: manual
needs: ["compliance_check"]
# Wekelijkse compliance rapportage
compliance_report:
stage: security_scan
image: alpine:latest
script:
- |
echo "Genereren wekelijks compliance rapport..."
# Genereer samenvattend rapport
echo "Compliance Rapport - ${CI_PROJECT_NAME}" > compliance-summary.txt
echo "Datum: $(date)" >> compliance-summary.txt
echo "OWASP Top 10 Scan: VOLTOOID" >> compliance-summary.txt
echo "Secret Detection: VOLTOOID" >> compliance-summary.txt
echo "Dependency Scan: VOLTOOID" >> compliance-summary.txt
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
artifacts:
paths:
- compliance-summary.txt
expire_in: 1 month
```
**Belangrijke kenmerken van deze configuratie:**
1. **OWASP Top 10 afdwinging** via Trivy SAST, dependency scanning en secret detection
2. **Geheim detectie** met Trivy's secret scanning
3. **Compliance gates** die deployments blokkeren bij security issues
4. **Slack notificaties** voor zowel success als failures
5. **Beveiligde deployments** naar staging en productie
6. **Wekelijkse rapportage** voor compliance tracking
**Vereiste omgevingsvariabelen in GitLab:**
- `SLACK_WEBHOOK_URL` voor notificaties
**Aanvullende aanbevelingen:**
- Configureer branch protection rules in GitLab
- Stel merge request approvals in voor security team
- Voeg kwaliteitsscores toe voor compliance meting
- Integreer met externe security tools indien nodig
Deze configuratie zorgt ervoor dat geen enkel build naar staging of productie kan worden gedeployed zonder dat alle security checks zijn geslaagd.