The Dangerous pull_request_target Pattern
billing-service is public. To comment test coverage on pull requests from forks, someone wrote .github/workflows/coverage.yml (in /home/student/repos/billing-service) with the pull_request_target trigger, which runs with a write token and the repository's secrets, and then checks out the fork's code and runs its tests. Any fork can change the test script and steal the secrets.
Split the work into two workflows:
coverage.yml: triggered by pull_request (not pull_request_target), with permissions contents: read only. It checks out the PR as usual, runs npm ci and npm test -- --coverage, and uploads coverage/summary.txt as an artifact named coverage. It uses no secrets.coverage-comment.yml: triggered by workflow_run when the workflow Coverage completes. It needs pull-requests: write and actions: read, runs only when the triggering run succeeded, downloads the coverage artifact from that run, and posts the comment with ./scripts/comment.sh coverage/summary.txt. It must not check out or run any code from the pull request: only the default branch's code.About this machine
Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.
Part of CI/CD Pipelines in Practice. Next step: Applying a Saved Plan Fails
Teaching or writing about this? Embed this lab on your page
Your machine is ready to start
A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.
No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.