Secrets management
Store secrets in a secret manager, not in code. Inject them at runtime. Rotate them often.
Automated scans
Add a scanner for vulnerabilities and secrets. Run it on every push so bad code never ships.
Pipelines can leak secrets or ship vulnerable code. Learn to add security checks and protect credentials.
About 1 min of reading
Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.
A pipeline can leak secrets or ship vulnerable code, so security is layered into it. Secrets are injected from a vault and never appear in a log, actions are pinned to exact commit SHAs so they cannot drift, and scanners block the build on findings.
I scan a workflow source for a leaked secret and print that the build is clean, then print that real secrets come from a vault rather than the code.
Before you run it, say out loud what it will print. Then open the answer.
I pin an action to a full commit SHA so it cannot drift when a new release is published, and print that a read-only token cannot push or delete even if the workflow is compromised.
Before you run it, say out loud what it will print. Then open the answer.
Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.
Read the first example one line at a time. A line that prints shows what appears on screen; the rest set things up quietly.
Store secrets in a secret manager, not in code. Inject them at runtime. Rotate them often.
Add a scanner for vulnerabilities and secrets. Run it on every push so bad code never ships.
- name: Scan secrets
run: gitleaks detect --source .
Store real passwords as encrypted secrets in your repo settings. Never hardcode them in the workflow. A leaked secret is worse than a bug.
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.CI_READ_ONLY }}
Use a token with the least access the job needs. A read-only token means a compromised workflow cannot push or delete by accident. Principle of least privilege.
- uses: actions/checkout@8ade135...
Tagging an action by version tag can drift when the maintainer publishes a new release. Pinning to a full commit SHA freezes the exact code that runs. It is the strongest defense against a supply-chain surprise.
Each one is defined here on this site. Open the entry for the full definition and the other words it points at.