Build yaml misconfiguration

From RedHatProductSecurity/prodsec-skills · View interactive version

Build yaml misconfiguration is an AI agent skill from the GitHub repository RedHatProductSecurity/prodsec-skills. Apply when reviewing or writing GitLab CI (.gitlab-ci.yml), Tekton pipeline/task YAML, or Containerfiles/Dockerfiles used in CI builds. Detects common misconfigurations that expose secrets, weaken isolation, skip security gates, grant excessive privileges, or produce insecure container images.

How to use this skill

Skill file

Build YAML Misconfiguration

Detect and prevent security misconfigurations in GitLab CI and Tekton pipeline definitions. Misconfigured build YAML is a common source of secret leakage, privilege escalation, and supply chain compromise.

GitLab CI (.gitlab-ci.yml)

Secret Exposure

# BAD -- secret visible in logs and available on all branches
variables:
  DB_PASSWORD: "hunter2"

# GOOD -- use CI/CD protected variable (set in GitLab UI)
# Reference as $DB_PASSWORD in scripts; set masked + protected in settings

Runner and Execution Isolation

# BAD -- no runner restriction, runs on any available shared runner
deploy-production:
  script:
    - ./deploy.sh

# GOOD -- pinned to a dedicated runner
deploy-production:
  tags:
    - production-deploy
    - privileged-denied
  script:
    - ./deploy.sh

Pipeline Permissions and Trust

# BAD -- security scan can fail silently
sast:
  allow_failure: true
  script:
    - run-sast-scanner

# GOOD -- security scan blocks pipeline on failure
sast:
  allow_failure: false
  script:
    - run-sast-scanner
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

Container Image Builds in CI

# BAD -- privileged DinD with mutable tag
build-image:
  image: docker:latest
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375
  script:
    - docker build -t myapp .

# GOOD -- unprivileged build with pinned image
build-image:
  image: quay.io/buildah/stable@sha256:<digest>
  script:
    - buildah bud --layers -t myapp .
    - buildah push myapp $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

Include and Extends Risks

# RISKY -- remote include with no version pinning
include:
  - remote: 'https://example.com/ci-templates/build.yml'

# BETTER -- pinned project include
include:
  - project: 'my-group/ci-templates'
    ref: 'v2.1.0'
    file: '/templates/build.yml'

Tekton Pipelines

Secret Exposure

# BAD -- secret hardcoded in task
steps:
  - name: deploy
    image: registry.redhat.io/ubi9/ubi-minimal
    script: |
      curl -H "Authorization: Bearer my-secret-token" https://api.example.com

# GOOD -- secret from Kubernetes Secret
steps:
  - name: deploy
    image: registry.redhat.io/ubi9/ubi-minimal
    env:
      - name: API_TOKEN
        valueFrom:
          secretKeyRef:
            name: deploy-creds
            key: token
    script: |
      curl -H "Authorization: Bearer $API_TOKEN" https://api.example.com

Step Image Security

# BAD -- mutable tag from public registry
steps:
  - name: build
    image: ubuntu:latest

# GOOD -- pinned digest from trusted registry
steps:
  - name: build
    image: registry.redhat.io/ubi9/ubi-minimal@sha256:<digest>

Task and Pipeline Permissions

# BAD -- running as root with no restrictions
steps:
  - name: build
    image: registry.redhat.io/ubi9/ubi-minimal
    script: |
      make build

# GOOD -- non-root with dropped capabilities
steps:
  - name: build
    image: registry.redhat.io/ubi9/ubi-minimal
    securityContext:
      runAsNonRoot: true
      runAsUser: 1001
      capabilities:
        drop: ["ALL"]
    script: |
      make build

Pipeline Structure Risks

# BAD -- unpinned external task bundle
taskRef:
  resolver: bundles
  params:
    - name: bundle
      value: quay.io/someone/my-task:latest

# GOOD -- pinned by digest
taskRef:
  resolver: bundles
  params:
    - name: bundle
      value: quay.io/myorg/my-task@sha256:<digest>

Tekton Chains and Provenance


Containerfile / Dockerfile Hardening

Container image definitions are typically referenced or inlined in CI YAML. Misconfigurations here produce insecure images that run in production.

Run as Non-Root

# BAD -- runs as root by default
FROM registry.redhat.io/ubi9/ubi-minimal
COPY app /app
CMD ["/app/server"]

# GOOD -- explicit non-root user
FROM registry.redhat.io/ubi9/ubi-minimal
RUN microdnf install -y shadow-utils && \
    useradd -r -u 1001 appuser && \
    microdnf clean all
COPY --chown=appuser:appuser app /app
USER appuser
CMD ["/app/server"]

Secrets in Image Layers

# BAD -- secret baked into image layer
COPY .env /app/.env
ENV API_KEY=sk-secret-value

# GOOD -- BuildKit secret mount (not persisted in layer)
RUN --mount=type=secret,id=api_key \
    export API_KEY=$(cat /run/secrets/api_key) && \
    ./configure --with-key="$API_KEY"

Base Image Hygiene

# BAD -- mutable tag, full OS image
FROM ubuntu:latest

# GOOD -- pinned digest, minimal trusted image
FROM registry.redhat.io/ubi9/ubi-minimal@sha256:<digest>

Multi-Stage Builds

# GOOD -- multi-stage: build tools stay in builder stage
FROM registry.redhat.io/ubi9/ubi:latest AS builder
RUN dnf install -y gcc make && dnf clean all
COPY . /src
RUN cd /src && make

FROM registry.redhat.io/ubi9/ubi-minimal@sha256:<digest>
COPY --from=builder /src/bin/app /app/server
USER 1001
CMD ["/app/server"]

Build Context Leakage

# .dockerignore
.git
.env
*.pem
*.key
credentials/
node_modules/

Unnecessary Capabilities and Ports

# GOOD -- only expose what's needed, add healthcheck
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s \
  CMD curl -f http://localhost:8080/healthz || exit 1

Read-Only and Immutability

Common Containerfile Misconfigurations

| Misconfiguration | Risk | Fix |

|-----------------|------|-----|

| No USER directive | Container runs as root | Add USER <non-root> before CMD |

| COPY .env or COPY *.key | Secrets baked into extractable layers | Use BuildKit --mount=type=secret |

| ENV SECRET_KEY=value | Secret visible in docker inspect | Pass at runtime via orchestrator |

| FROM image:latest | Mutable tag; supply chain risk | Pin by @sha256:<digest> |

| No .dockerignore | .git, credentials sent to build context | Create .dockerignore with exclusions |

| Single-stage with build tools | Compilers, test deps ship to production | Use multi-stage builds |

| RUN chmod 777 | World-writable files in image | Use specific permissions (chmod 755) |

| No HEALTHCHECK | Orchestrator cannot detect unhealthy state | Add HEALTHCHECK instruction |

| sudo or setuid binaries installed | Privilege escalation path | Remove from final image |


Common Misconfigurations (Both Platforms)

| Misconfiguration | Risk | Fix |

|-----------------|------|-----|

| Hardcoded secrets in YAML | Credential leakage via repo access or logs | Use vault/CI variables/K8s Secrets |

| allow_failure: true on security jobs | Security findings silently ignored | Set allow_failure: false |

| Mutable image tags (:latest) | Supply chain compromise via tag poisoning | Pin by digest |

| Privileged containers/runners | Container escape to host | Use unprivileged builds (Buildah/Kaniko) |

| Unscoped variables/secrets | Secrets available to untrusted branches/jobs | Scope to protected branches/environments |

| Debug output (set -x, printenv) | Secrets printed to job logs | Remove debug flags; use masked variables |

| Unpinned remote includes/task refs | External changes alter your pipeline | Pin to version/commit/digest |

| Missing security scan gates | Vulnerable code reaches production | Add SAST/SCA/image scanning as blocking steps |

| Auto-deploy to production | No human review before deploy | Require manual approval gate |

| Shell executor (GitLab) | Job-to-job state leakage on shared host | Use Docker/Kubernetes executor |

| No USER in Containerfile | Container runs as root in production | Add non-root USER directive |

| Secrets in image layers | Credentials extractable from image | Use BuildKit secret mounts |

| No .dockerignore | Sensitive files leak into build context | Create .dockerignore with exclusions |

| Single-stage build | Build tools ship to production | Use multi-stage builds |

Implementation Checklist

Test Plan

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.