Skip to main content

SKY-D338 · Security in code

Command reads host credentials or mounts the host root

CriticalCWE-200

A build or helper script should not need the machine's own credentials. SKY-D338 reports a command that reads a credential file (SSH keys, cloud and registry logins, .env files), writes into one, or starts a Docker container with the whole host filesystem mounted.

Languages
Shell, GitHub Actions, GitLab CI, Dockerfile, Python, TypeScript/JavaScript
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Catalog name
Sensitive host scope access
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

docker run -v /:/host gives the container every file on the host, including /root/.ssh and the CI runner's cached tokens, so one compromised image can read them all. A cat ~/.docker/config.json in a CI step prints registry passwords into a log that many people can read.

What Skylos flags

scripts/collect-logs.sh · ShellReported on line 5
#!/usr/bin/env bash# Gather host logs for the incident report.set -euo pipefail docker run --rm -v /:/host:ro ghcr.io/acme/log-collector:1.4 --root /hosttar -czf incident-logs.tgz ./collected

What Skylos leaves alone

scripts/collect-logs.sh · Shell
#!/usr/bin/env bash# Gather host logs for the incident report.set -euo pipefail docker run --rm -v /var/log:/host/var/log:ro ghcr.io/acme/log-collector:1.4 --root /hosttar -czf incident-logs.tgz ./collected

Why Skylos leaves it alone

The container gets only /var/log, read-only. Skylos reports a mount whose host side is / itself, not a mount of one folder.

More languages

YAML

Flagged

.github/workflows/build.yml · YAMLReported on line 15
name: Buildon: [push]permissions:  contents: readjobs:  build:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v4      - uses: docker/login-action@v3        with:          registry: ghcr.io          username: ${{ github.actor }}          password: ${{ secrets.GITHUB_TOKEN }}      - run: base64 -w0 ~/.docker/config.json > docker-auth.b64      - uses: actions/upload-artifact@v4        with:          name: docker-auth          path: docker-auth.b64

Not flagged

.github/workflows/deploy.yml · YAML
name: Deployon: [push]permissions:  contents: readjobs:  deploy:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v4      - name: Install deploy key        env:          DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}        run: mkdir -p ~/.ssh && echo "$DEPLOY_KEY" | base64 -d > ~/.ssh/id_ed25519      - run: ./scripts/deploy.sh

Why Skylos leaves it alone

Writing a key into ~/.ssh/id_* under the runner's own home folder is routine setup. In a GitHub Actions step where no env sets HOME and no run block reassigns it, Skylos does not report it. The same line in a shell script, GitLab job or Dockerfile is reported.

How Skylos decides

  1. Reads shell commands in .sh, .bash, .zsh, .ksh and .bats files, GitHub Actions run: steps, GitLab CI script items, Dockerfile RUN instructions, fixed command strings in Python os.system()-style calls or shell=True calls, and fixed strings passed to child_process.exec() in TypeScript and JavaScript.
  2. Splits each command at ;, &&, || and |, and parses redirects quote-aware (a quoted ">" is an argument). Reports when the command is a file reader (cat, grep, rg, head, tail, less, more, sed, awk, base64, tar, zip) and one of its arguments, or a file its output is redirected to, is a credential file.
  3. A credential file is .env and .env.*, *.env, .envrc, .netrc, .npmrc, .pypirc, .git-credentials, credentials, auth.json, config.json, id_rsa, id_ed25519, known_hosts, a .key, .pem, .p12 or .pfx file, or anything under .ssh/, .aws/, .azure/, .kube/, .claude/, .codex/, .config/gh/, .docker/config.json or /run/secrets/.
  4. Also reports docker run with a -v, --volume or --mount whose host side is the root (/:…, source=/, src=/).
  5. In GitHub Actions only, a reader writing ~/.ssh/known_hosts, ~/.ssh/id_*, ~/.netrc or ~/.pypirc is routine setup and not reported, when no workflow, job, container or step env sets HOME and no run block in the job assigns it. A reader writing a project-relative .env is not reported in a bash/sh step on a Linux or macOS runner that starts in the workspace and contains nothing that may change directory (cd, pushd, source, eval, function definitions and similar). Shell scripts, GitLab CI and Dockerfiles get neither exception.
  6. Targets with .., a glob, a variable other than a leading $HOME, and every other credential path stay reported. Every finding is CRITICAL.

How to fix it

Mount only the folders the container needs, read-only. Pass credentials to a job through the tool that consumes them (a login action, a secret mount, an environment variable scoped to one step) instead of reading or copying the credential file.

scripts/collect-logs.sh · Shell · the fix, against the flagged file
#!/usr/bin/env bash# Gather host logs for the incident report.set -euo pipefail Removed: docker run --rm -v /:/host:ro ghcr.io/acme/log-collector:1.4 --root /hostAdded: docker run --rm -v /var/log:/host/var/log:ro ghcr.io/acme/log-collector:1.4 --root /hosttar -czf incident-logs.tgz ./collected

When it can be wrong

  • Credential file names are matched without looking inside: reading config.json, .env.example, ~/.ssh/id_rsa.pub (a public key) or a test .pem fixture is reported as CRITICAL.
  • Writing ~/.npmrc or ~/.docker/config.json in a CI step with cat is reported even when it is ordinary login setup; only the routine files listed above are exempt, and only in GitHub Actions.
  • Missed: readers that are not on the list (jq, cp, python -c), a read inside $(…) as part of another command, ~/.ssh without a trailing slash, and in a GitHub Actions run: | block, or a multi-line GitLab item, a read on a later line, because the block is split only at ;, &&, || and |, not at line breaks.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • In a shell script, put the marker on the reported line as a real comment. In GitHub Actions, GitLab CI and Dockerfiles the marker may also sit on the line directly above, one rule per marker.

    Shell
    cat ./fixtures/test-server.pem  # skylos: ignore[SKY-D338] test fixture
  • [tool.skylos] ignore = ["SKY-D338"] turns the rule off for the whole project. Prefer a marker per reviewed line: this rule is CRITICAL and fails the gate on its own.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.