Saltar al contenido
uencoder

Cómo a Construir un Seguro CI/CD Pipeline

Design un CI/CD pipeline con seguridad gates at cada etapa: dependency scanning, SAST, DAST, secret detection, y artifact signing.

问题

Your CI/CD pipeline deploys código sin seguridad checks, allowing vulnerabilities, secrets, y malicious dependencies a reach production. You necesitar a integrate seguridad gates throughout el pipeline ese bloque insecure builds.

Requisitos previos

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

Pasos

  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.

    entrada
    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.

    entrada
    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.

    entrada
    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.

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

Resultado esperado

Un CI/CD pipeline donde cada construir es scanned para vulnerabilities, secrets, y dependency risks, con signed artifacts y deployment gates ese prevent insecure código de reaching production.

Errores comunes

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.

Solución de problemas指引

  • 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.

Límites de seguridad

  • 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.

Herramientas relacionadas

Validador de configuraciones
Config Validate — herramienta 100% del lado del cliente. Privacidad primero, sin round-trip al servidor.
HERRAMIENTA
Comparador de configuraciones
Config Diff — herramienta 100% del lado del cliente. Privacidad primero, sin round-trip al servidor.
HERRAMIENTA
Analizador de ENV
Analiza líneas KEY=VALUE estilo .env a JSON. Se omiten las líneas vacías y los comentarios con #. Las convenciones de dotenv más allá de eso no están implementadas: un prefijo "export " se mantiene en la clave (export PORT=3000 → "export PORT") y las comillas alrededor de los valores se conservan tal cual.
HERRAMIENTA
De ENV a JSON
Env To Json — herramienta 100% del lado del cliente. Privacidad primero, sin round-trip al servidor.
HERRAMIENTA
Hash de archivo
Calcular un hash simple del contenido del archivo.
HERRAMIENTA
Información de archivo
Obtener información del contenido del archivo: tamaño, líneas, palabras.
HERRAMIENTA
Diferencias entre archivos
Diff línea por línea de dos archivos.
HERRAMIENTA
Lint JS
Analizar JavaScript en busca de problemas comunes.
HERRAMIENTA
Validador JS
Una comprobación de equilibrio de delimitadores para JavaScript: paréntesis, corchetes y llaves deben emparejarse. Es heurística — los literales de regex que contengan corchetes (p. ej. /\(/) pueden provocar un falso UNCLOSED; no es un analizador completo.
HERRAMIENTA
Validador SQL
Una comprobación ligera de SQL: la sentencia debe empezar con una palabra clave SQL y los paréntesis deben equilibrarse. Las sentencias que empiezan con paréntesis, como (SELECT 1) UNION (SELECT 2), se rechazan — no es un analizador SQL real.
HERRAMIENTA
Validador JSON
Validate JSON and pinpoint syntax errors by line and column. Gratis, privado y 100% del lado del cliente.
HERRAMIENTA
Analizador de YAML
YAML Parser — herramienta 100% del lado del cliente. Privacidad primero, sin round-trip al servidor.
HERRAMIENTA
Probador de regex
Test regular expressions with match highlighting, capture groups, and replace preview. Gratis, privado y 100% del lado del cliente.
HERRAMIENTA
Comparador de hashes
Compare MD5, SHA-1, SHA-256, SHA-384, SHA-512 of the same input. Gratis, privado, 100% del lado del cliente.
HERRAMIENTA
Convertidor de marcas de tiempo
Convert between Unix timestamps and human-readable dates with UTC and local time. Gratis, privado y 100% del lado del cliente.
HERRAMIENTA

Términos relacionados

参考链接