SKY-D338 · Security in code
Command reads host credentials or mounts the host root
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
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
#!/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 ./collectedWhat Skylos leaves alone
#!/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 ./collectedWhy 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
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.b64Not flagged
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.shWhy 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
- Reads shell commands in
.sh,.bash,.zsh,.kshand.batsfiles, GitHub Actionsrun:steps, GitLab CI script items, DockerfileRUNinstructions, fixed command strings in Pythonos.system()-style calls orshell=Truecalls, and fixed strings passed tochild_process.exec()in TypeScript and JavaScript. - 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. - A credential file is
.envand.env.*,*.env,.envrc,.netrc,.npmrc,.pypirc,.git-credentials,credentials,auth.json,config.json,id_rsa,id_ed25519,known_hosts, a.key,.pem,.p12or.pfxfile, or anything under.ssh/,.aws/,.azure/,.kube/,.claude/,.codex/,.config/gh/,.docker/config.jsonor/run/secrets/. - Also reports
docker runwith a-v,--volumeor--mountwhose host side is the root (/:…,source=/,src=/). - In GitHub Actions only, a reader writing
~/.ssh/known_hosts,~/.ssh/id_*,~/.netrcor~/.pypircis routine setup and not reported, when no workflow, job, container or stepenvsetsHOMEand no run block in the job assigns it. A reader writing a project-relative.envis 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. - 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.
#!/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 ./collectedWhen 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.pemfixture is reported as CRITICAL. - Writing
~/.npmrcor~/.docker/config.jsonin a CI step withcatis 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,~/.sshwithout a trailing slash, and in a GitHub Actionsrun: |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.