For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cicd-github-self-hosted-runner.md.
A documentation index is available at /llms.txt.
Self-hosted runners in public repositories are risky because they can retain state, files, or credentials between workflow runs. They also allow untrusted contributors (for example via pull requests) to access secrets or modify the runner environment.
Inspect the GitHub Actions workflow job runs-on setting. Any job whose runs-on value begins with the literal self-hosted, references a runner group, or uses expressions/matrix expansions that may evaluate to self-hosted should be reviewed or avoided in public repos.
Prefer explicit GitHub-hosted runner labels such as ubuntu-latest for public workflows. Expression-based or group-based runner selections are flagged because they may expand to self-hosted runners at runtime.
name:GitHub Hosted Runneron:pushjobs:# Should NOT trigger: GitHub-hosted runnertest_github_hosted:runs-on:ubuntu-lateststeps:- uses:actions/checkout@v4- run:npm test# Should NOT trigger: Array of GitHub-hosted runnerstest_github_hosted_array:runs-on:[ubuntu-latest, windows-latest]steps:- uses:actions/checkout@v4- run:npm test# Should NOT trigger: Matrix without self-hostedtest_matrix_no_self_hosted:strategy:matrix:runner:[ubuntu-latest, windows-latest, macos-latest]runs-on:${{ matrix.runner }}steps:- uses:actions/checkout@v4- run:npm test# Should NOT trigger: Expression that doesn't reference runnertest_expression_not_runner:runs-on:ubuntu-lateststeps:- name:Test with expressionrun:echo "${{ github.sha }}"
Non-Compliant Code Examples
name:Self Hosted Runneron:pushjobs:# Case 1: Literal self-hosted in arraytest:runs-on:[self-hosted, linux, x64]steps:- uses:actions/checkout@v4- run:npm test# Case 2a: Expression-based runner (string) - matrix with self-hostedtest_matrix_expression:strategy:matrix:runner:[self-hosted, ubuntu-latest]runs-on:${{ matrix.runner }}steps:- uses:actions/checkout@v4- run:npm test# Case 2b: Expression-based runner (array) - variable referencetest_expression_array:runs-on:["${{ inputs.runner }}"]steps:- uses:actions/checkout@v4- run:npm test# Case 2c: Expression-based runner (string) - simple expressiontest_expression_string:runs-on:${{ github.event.inputs.runner }}steps:- uses:actions/checkout@v4- run:npm test# Case 3: Runner group (implies self-hosted)test_runner_group:runs-on:group:my-runner-groupsteps:- uses:actions/checkout@v4- run:npm test
1
2
rulesets:- CICD / GitHub # Rules to enforce / GitHub.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.