Zum Inhalt springen
uencoder

Wie in Bauen ein Sicher CI/CD Pipeline

Design ein CI/CD pipeline mit Sicherheit gates at jede Stufe: dependency scanning, SAST, DAST, secret detection, und artifact signing.

问题

Your CI/CD pipeline deploys Code ohne Sicherheit checks, allowing vulnerabilities, secrets, und malicious dependencies in reach production. You brauchen in integrate Sicherheit gates throughout der pipeline das Block insecure builds.

Voraussetzungen

  • Understanding of CI/CD concepts (build, test, deploy stages)
  • Familiarity with static and dynamic analysis tools
  • Knowledge of dependency management and supply chain risks

Schritte

  1. 1. Secure the source and dependencies

    Enforce branch protection: require PR reviews, signed commits, and status checks before merge. On every PR, scan dependencies for known vulnerabilities (CVE database) and license compliance. Use lockfiles (package-lock.json, pnpm-lock.yaml) to pin exact versions and detect supply chain attacks. Verify package signatures and provenance (SLSA levels). Fail the build if critical vulnerabilities are found. Use the config validator and file hash tools to verify integrity.

    Eingabe
    pull request with new dependency
    输出
    scan: 2 CVEs found (1 critical) | status: BLOCKED
  2. 2. Integrate static and dynamic analysis

    Run SAST (Static Application Security Testing) on every commit to detect code-level vulnerabilities: SQL injection, XSS, hardcoded secrets, insecure crypto. Run DAST (Dynamic Application Security Testing) against the staging deployment to find runtime vulnerabilities. Run SCA (Software Composition Analysis) for third-party dependencies. Configure tools to fail the build on critical/high findings. Use the JS linter, SQL validator, and regex tools for code quality checks.

    Eingabe
    source code commit
    输出
    SAST: 0 critical | DAST: 1 high (XSS in /search) | status: BLOCKED
  3. 3. Implement secret scanning and management

    Scan the repository for leaked secrets: API keys, passwords, private keys, tokens. Use pre-commit hooks to prevent secrets from being committed. Store secrets in a secrets manager (Vault, AWS Secrets Manager), injected as environment variables at build/runtime — never in the repo or CI config. Rotate secrets automatically. Use the env parser and hash-compare tools to manage and verify secrets. If a secret is detected, fail the build and alert the security team.

    Eingabe
    commit containing API key
    输出
    secret scan: 1 secret detected (AWS key) | status: BLOCKED | alert sent
  4. 4. Sign artifacts and enforce deployment gates

    Sign build artifacts (containers, binaries) with a build-system signing key (Sigstore/cosign, GPG). Generate SBOM (Software Bill of Materials) for each build. Enforce deployment gates: only signed artifacts from the main branch, passing all security checks, can deploy to production. Use progressive deployment (canary) with automated rollback on error rate spikes. Audit all pipeline steps immutably. Use the file hash and timestamp tools for artifact verification.

    Eingabe
    build artifact: app-v1.2.3.tar
    输出
    signature: cosign sign | SBOM: generated | gate: PASS -> deploy

Erwartetes Ergebnis

Ein CI/CD pipeline wo jede bauen ist scanned für vulnerabilities, secrets, und dependency risks, mit signed artifacts und deployment gates das prevent insecure Code von reaching production.

Häufige Fehler

Security scans that don't fail the build
Configure scanners to exit non-zero on critical/high findings. A scan that only reports but doesn't block is ineffective. Use quality gates with thresholds.
Storing secrets in CI environment variables or repo
Use a secrets manager (Vault, AWS SM) with short-lived credentials injected at runtime. CI env vars are often visible in logs and to anyone with repo access.
Skipping security scans for speed
Run fast checks (SAST, secret scan) on every PR, slower checks (DAST, full dependency scan) on merge to main or nightly. Never skip for speed — optimize the tools instead.

Troubleshooting指引

  • If SAST produces too many false positives, tune the rules and establish a baseline of accepted findings, then fail only on new issues.
  • If dependency scanning is slow, use incremental scanning (only changed dependencies) and cache the vulnerability database.
  • For monorepos, run pipeline stages only for affected packages to balance security coverage with build speed.

Sicherheitsgrenzen

  • CI/CD security gates reduce but do not eliminate risk — zero-days and novel attack vectors may bypass known-pattern scanners.
  • All secret management happens in the secrets manager; the pipeline never logs or stores secrets in plaintext.
  • The pipeline itself is a high-value target — secure the CI system with MFA, least privilege, and audit logging.

Verwandte Tools

Konfigurations-Validator
Config Validate — reines Client-seitiges Tool. Datenschutz zuerst, kein Server-Roundtrip.
WERKZEUG
Konfigurations-Vergleich
Config Diff — reines Client-seitiges Tool. Datenschutz zuerst, kein Server-Roundtrip.
WERKZEUG
ENV-Parser
Parst KEY=VALUE-Zeilen im .env-Stil zu JSON. Leerzeilen und #-Kommentare werden übersprungen. Weitere dotenv-Konventionen sind nicht implementiert: Ein „export “-Präfix bleibt im Schlüssel stehen (export PORT=3000 → „export PORT“), und Anführungszeichen um Werte bleiben unverändert erhalten.
WERKZEUG
ENV zu JSON
Env To Json — reines Client-seitiges Tool. Datenschutz zuerst, kein Server-Roundtrip.
WERKZEUG
Datei-Hash
Einfachen Hash des Dateiinhalts berechnen.
WERKZEUG
Datei-Info
Dateiinhalt-Info abrufen: Größe, Zeilen, Wörter.
WERKZEUG
Datei-Diff
Zeilenweiser Diff von zwei Dateien.
WERKZEUG
JS-Lint
JavaScript auf häufige Probleme linten.
WERKZEUG
JS-Validator
Eine Klammerbilanz-Prüfung für JavaScript: Runde, eckige und geschweifte Klammern müssen paarweise auftreten. Die Prüfung ist heuristisch — Regex-Literale mit Klammern (z. B. /\(/) können ein falsches UNCLOSED auslösen; kein vollständiger Parser.
WERKZEUG
SQL-Validator
Eine leichte SQL-Plausibilitätsprüfung: Die Anweisung muss mit einem SQL-Schlüsselwort beginnen, und die Klammern müssen ausgeglichen sein. Mit einer Klammer beginnende Anweisungen wie (SELECT 1) UNION (SELECT 2) werden abgelehnt — kein echter SQL-Parser.
WERKZEUG
JSON-Validator
Validate JSON and pinpoint syntax errors by line and column. Kostenlos, privat und 100% clientseitig.
WERKZEUG
YAML-Parser
YAML Parser — reines Client-seitiges Tool. Datenschutz zuerst, kein Server-Roundtrip.
WERKZEUG
Regex-Tester
Test regular expressions with match highlighting, capture groups, and replace preview. Kostenlos, privat und 100% clientseitig.
WERKZEUG
Hash-Vergleich
Compare MD5, SHA-1, SHA-256, SHA-384, SHA-512 of the same input. Kostenlos, privat, 100% clientseitig.
WERKZEUG
Zeitstempel-Konverter
Convert between Unix timestamps and human-readable dates with UTC and local time. Kostenlos, privat und 100% clientseitig.
WERKZEUG

Verwandte Begriffe

参考链接