Untrusted Jenkinsfiles and Supply Chain
Scenario: A fork changes the Jenkinsfile to exfiltrate environment variables during a privileged pull-request build.
Pipeline example
pipeline { agent { label 'untrusted-ephemeral' }; stages { stage('PR test') { steps { sh './test.sh' } } } }
Pull requests control executable inputs
A contribution can change shell scripts, tests, build files, and often its Jenkinsfile. On a privileged agent it can read environment variables, files, Docker sockets, cloud metadata, caches, nearby processes, and reachable internal services. Omitting withCredentials does not remove ambient agent authority. Treat fork and unreviewed branch content as hostile until a trusted policy transition.
Run untrusted validation on disposable agents without production credentials, with short-lived checkout identities, restricted egress, quotas, and no shared writable caches. Separate pull-request testing from post-merge publication. Some SCM plugins can load a trusted Jenkinsfile from the target branch while testing contribution source; document exactly which revision supplies orchestration and which supplies application files.
Defend the supply chain, not only secrets
An attacker may forge test XML, poison a dependency cache, publish under a trusted coordinate, exhaust executors, or substitute a package. Restrict signing, publication, and deployment to reviewed builds. Promote immutable digests created in trusted context. Sanitize artifact paths, cap runtime and fan-out, verify webhook signatures, and reject privileged parameter combinations from unauthorized causes.
Log masking reduces accidental disclosure after a mistake; it is not sandboxing. Validate the boundary by intentionally attempting metadata access, egress, cache modification, credential binding, and cross-workspace reads. The safe PR result is useful test evidence with no route to production authority.
Goal: Practice the concrete behavior in jenkins-credentials-binding. Learn sections have no Jenkins terminal; the Jenkins lab opens the real shared service in a new full-screen tab inside your private folder.