Skip to main content

Secure CI/CD Policy

1. Objective​

This policy defines the security requirements applicable to the design, configuration and operation of continuous integration and delivery (CI/CD) pipelines for applications classified as L1, L2 or L3.

The CI/CD pipeline is a critical component of an organisation's security posture: it is the path by which code reaches production. A compromised, misconfigured pipeline, or one without adequate controls, is equivalent to a service door without a lock - it can be used to introduce malicious code, escalate privileges or exfiltrate secrets without the code review process being of any relevance.

The objective of this policy is to ensure that:

  • Pipelines are configured securely and versioned as code
  • Security gates are automated, with documented and blocking thresholds
  • The secrets used in the pipeline are managed centrally and never exposed in logs
  • Promotion between environments is controlled and requires approval proportional to the risk
  • The artefacts produced are signed and verified before any deploy

2. Scope​

This policy applies to all CI/CD pipelines that produce artefacts intended for test, acceptance or production environments, including build, test, analysis, packaging, containerisation and deploy pipelines.


3. Pipeline as versioned code​

The pipeline must be defined as code, versioned in the application's repository, subject to code review and with traceable changes:

RequirementL1L2L3
Pipeline defined as code (ci-pipeline.yml or equivalent)MandatoryMandatoryMandatory
Changes to the pipeline subject to code review and approvalRecommendedMandatoryMandatory + AppSec
Pipeline versioned in the same repository as the application (or a controlled monorepo)MandatoryMandatoryMandatory
No direct editing of the pipeline in the execution environment (no manual override)RecommendedMandatoryMandatory

4. Mandatory security gates​

The following gates must be configured in the pipeline, with documented thresholds and blocking behaviour according to the proportionality table:

4.1 Code and dependency analysis gates​

GateL1L2L3
Secret detection (TruffleHog, Gitleaks, detect-secrets)AlertBlocks any findingBlocks any finding
SAST (Semgrep, CodeQL, SonarQube, Bandit)AlertBlocks High/CriticalBlocks Medium+
Security linters per stackRecommendedMandatoryMandatory
SCA (Dependency-Check, Trivy, Grype)AlertBlocks High/CriticalBlocks Medium+
Licence validationRecommendedMandatoryMandatory

4.2 Build and artefact gates​

GateL1L2L3
SBOM generation per buildMandatory (basic)Mandatory (complete)Mandatory (complete + signed)
Artefact signing (Cosign or equivalent)RecommendedMandatoryMandatory
Signature verification before promotionNot applicableMandatoryMandatory
Vulnerability scan of container imagesRecommendedMandatoryMandatory

4.3 General gate rules​

  • Thresholds (minimum blocking severity) must be documented and versioned (gates-config.yaml or equivalent)
  • Changing a threshold requires approval from an AppSec Engineer
  • A gate that is disabled or whose threshold is temporarily lowered must be recorded as a formal exception
warning

Gates configured in "warn-only" mode (without blocking) at L2/L3 do not comply with this policy, except during a formally approved exception period with a defined expiry date.


5. Secrets management in the pipeline​

Secrets used in the pipeline (CI tokens, deploy keys, registry credentials, etc.) must be managed in accordance with the Secrets Management Policy. The specific principles for the pipeline context are:

  • Secrets injected through environment variables managed by the CI system, never hardcoded in the pipeline file
  • Secrets never printed in logs (masking configuration mandatory)
  • Access to production secrets restricted to jobs that genuinely need it (principle of least privilege)
  • Secrets rotated in accordance with policy; rotation verifiable without changing the pipeline
  • No secrets in build artefacts (images, JARs, packages)

6. Environment separation and controlled promotion​

The pipeline must implement physical or logical separation between environments (development, integration, staging, production), with controlled promotion:

RequirementL1L2L3
Separate environments with distinct credentialsRecommendedMandatoryMandatory
Promotion to staging requires green CI + gates OKRecommendedMandatoryMandatory
Promotion to production requires human approvalRecommendedMandatoryMandatory (dual approval)
Promotion to production uses the immutable build artefact (no rebuild)RecommendedMandatoryMandatory
Automatic rollback available in the event of a health check failureRecommendedMandatoryMandatory

The identity that performs the deploy to production must have minimum permissions - the pipeline must never have write access to development and production infrastructure simultaneously.


7. Pipeline identity and permissions​

The CI/CD system operates with its own identities (service accounts, CI tokens), which must follow the principle of least privilege:

  • Each pipeline has a dedicated identity; no use of developers' personal credentials
  • Pipeline permissions limited to what is necessary for each job (reading code, writing to the image registry, deploying to a specific environment)
  • CI tokens with a short TTL; automated rotation
  • Auditing of pipeline access active at L3
  • No PR approval permission for the pipeline identity (prevents automated self-merge)

8. Reproducibility and traceability​

Each pipeline execution must be traceable:

  • Execution logs retained in accordance with the Traceability Policy (minimum 90 days at L2, 1 year at L3)
  • Build artefacts associated with the commit SHA that originated them
  • SBOM associated with the artefact produced
  • Scanner results archived as artefacts of the execution
  • Promotion approvals recorded with the approver's identity, timestamp and a reference to the approved artefact

9. Pipeline integrity​

The pipeline itself is an attack vector - it must be treated with the same rigour as application code:

  • Pipeline dependencies (actions, plugins, external steps) pinned to specific versions with a hash (e.g. uses: actions/checkout@sha256:abc...)
  • No use of latest in pipeline steps at L2/L3
  • External actions or plugins assessed before adoption (origin, maintenance, permissions required)
  • The pipeline does not execute arbitrary code from the input of external PRs without an adequate sandbox

10. Expected artefacts​

ArtefactDescriptionRetention
ci-pipeline.ymlVersioned pipeline definitionVersion history
Execution logsComplete output of each run90 days (L2), 1 year (L3)
Scanner reports (SAST, SCA, secrets)Results per run, linked to the commit90 days (L2), 1 year (L3)
SBOM per buildSee SBOM PolicySee SBOM Policy
Promotion approval recordsIdentity, timestamp, approved artefact2 years (L2), 3 years (L3)
Gate/threshold configurationDocumented and versioned thresholdsVersion history

11. Responsibilities​

RoleResponsibility
DeveloperMaintain the pipeline as code; submit changes to the pipeline for review
DevOps / SREConfigure and operate the CI/CD platform; manage pipeline identities; configure environment separation
AppSec EngineerDefine gate thresholds; approve changes to the pipeline's security configurations; review the use of external actions
Tech LeadApprove promotions to production in accordance with the level's requirements
GRC / ComplianceAudit logs and approval records; verify compliance with the defined thresholds

12. Review and audit of this policy​

This policy must be reviewed annually or after any of the following events:

  • Incident originating in the pipeline (compromise, promotion of vulnerable code)
  • Adoption of a new CI/CD platform
  • Significant change in the integrated analysis tools

13. Normative and technical references​

ReferenceRelevance
SbD-ToE Ch. 07 - Secure CI/CDGates, scanners, artefacts, environment separation
SbD-ToE Ch. 05 - Dependencies, SBOM and SCASCA and SBOM in the pipeline
SbD-ToE Ch. 11 - Secure DeploymentPromotion approval gates
Secrets Management Policy (18_policy-gestao-segredos.md)Secrets in the pipeline
SBOM Policy (11_policy-sbom.md)Generation and archiving of SBOM per build
SLSA FrameworkPipeline supply chain integrity levels
OWASP CI/CD Security Top 10Security risks in CI/CD pipelines
CIS Software Supply Chain Security GuideReference controls for secure pipelines
NIST SP 800-218 (SSDF)PO.3, PW.8: secure infrastructure and protection of builds