Rules / GL094
GL094 SSH private key read and staged for exfiltration
Severity: error
OWASP: CICD-SEC-4 – Poisoned Pipeline Execution
CWE: CWE-522 – Insufficiently Protected Credentials
Risk
Reading an SSH private key (~/.ssh/id_rsa, id_ed25519, id_ecdsa, id_dsa) only to encode, archive, or copy it off is credential exfiltration: the key leaves the runner, encoded past a log masker, bundled into an artifact, or staged in a world-readable path for later pickup. A deploy key or a user's key lifted this way lets an attacker push code, reach production hosts, or impersonate the pipeline.
A bare read (cat ~/.ssh/id_rsa) is deliberately not flagged — it is low signal and often debugging. The tell is the read combined with a transform or a move: private key → encoder / archive / another location.
Trigger example
collect:
script:
- cat ~/.ssh/id_rsa | base64
Flagged shapes: a key piped into or passed to an encoder (cat id_rsa | base64, base64 id_rsa, xxd, od, hexdump, uuencode); the key or the whole .ssh directory archived (tar czf keys.tgz ~/.ssh, zip, gzip); and the key copied or moved to another path (cp ~/.ssh/id_rsa /tmp/exfil/, mv, install).
What is not flagged
- A bare read with no transform:
cat ~/.ssh/id_rsa. - Writing a key into place:
echo "$SSH_KEY" > ~/.ssh/id_rsa(that is GL032's side). - Using a key:
ssh-add ~/.ssh/id_rsa,chmod 600 ~/.ssh/id_rsa. - Generating a key:
ssh-keygen -t ed25519 -f ~/.ssh/id_rsa. - A public key:
cat ~/.ssh/id_rsa.pub | base64. - Copying a key into
~/.ssh(the destination, not the source):cp /tmp/key ~/.ssh/id_rsa.
Safe alternative
Let the CI platform inject the key and use it directly, without reading the file into another command:
deploy:
script:
- ssh-add ~/.ssh/id_rsa
- rsync -az ./build/ deploy@host:/srv/app/
Store the key in a masked, protected CI/CD variable or a secrets manager, write it only to ~/.ssh/ with chmod 600, and never encode, archive, or copy it elsewhere.
Notes
- Severity is
error. - Commands are read with shell parsing, so a key path inside a quoted string (
echo "cat ~/.ssh/id_rsa | base64") is text, not a command. - Script-line rule; assumes POSIX shell.
- Complements GL032 (key material written to a file or into a network pipe) and GL083 (reverse shell and network exfiltration).
- Suppress per-file with
.glsec-ignoreor inline# glsec:ignore GL094.
References
- GL032: SSH private key or credential written to a file or piped out
- GL083: reverse shell, backdoor or credential exfiltration in script
Documentation for glsec 1.29.0. Source of this page · Rule implementation