glsec

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

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

References

Documentation for glsec 1.29.0. Source of this page · Rule implementation