Skip to content

Commit 2f32a70

Browse files
authored
Merge pull request #22173 from knewbury01/knewbury01/customize-actions-sanitizers
Add way to customize environmentCheck Actions QL
2 parents 82bd4a3 + 72ad4e5 commit 2f32a70

11 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added an option to `EnvironmentCheck` to become specified by a MaD model, otherwise it will continue as the default it previously was. Without adding models to `actions/ql/lib/ext/config/deployment_environment.yml` the behavior of every query will be unchanged. When models are added queries using `ControlCheck` may find more results in cases where an enironment is no longer a sufficient sanitizer.

actions/ql/lib/codeql/actions/config/Config.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,12 @@ predicate untrustedGhCommandDataModel(string cmd_regex, string flag) {
164164
predicate actionsPermissionsDataModel(string action, string permission) {
165165
Extensions::actionsPermissionsDataModel(action, permission)
166166
}
167+
168+
/**
169+
* MaD models for deployment environments
170+
* Fields:
171+
* - name: deployment environment name, e.g. `Public CI`
172+
*/
173+
predicate enabledDeploymentEnvironmentDataModel(string name) {
174+
Extensions::enabledDeploymentEnvironmentDataModel(name)
175+
}

actions/ql/lib/codeql/actions/config/ConfigExtensions.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ extensible predicate untrustedGhCommandDataModel(string cmd_regex, string flag);
8888
* - see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token for documentation of token permissions.
8989
*/
9090
extensible predicate actionsPermissionsDataModel(string action, string permission);
91+
92+
/**
93+
* Holds for deployment environments that exist with `name` for a given repository.
94+
* * - 'name' is the name of the environment defined.
95+
* E.g. for the deployment environment `environment: EnvironmentInRepo`, `name` is `EnvironmentInRepo`.
96+
* Requires this to be externally supplied but once done can be used to
97+
* toggle precision of whether that suffices or not as a control check by contributing to `EnvironmentCheck`.
98+
*/
99+
extensible predicate enabledDeploymentEnvironmentDataModel(string name);

actions/ql/lib/codeql/actions/security/ControlChecks.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ abstract class LabelCheck extends ControlCheck {
277277
}
278278

279279
class EnvironmentCheck extends ControlCheck instanceof Environment {
280+
EnvironmentCheck() {
281+
// if there are any custom tuples use those
282+
if enabledDeploymentEnvironmentDataModel(_)
283+
then enabledDeploymentEnvironmentDataModel(this.(Environment).getName())
284+
else this instanceof Environment
285+
}
286+
280287
// Environment checks are not effective against any mutable attacks
281288
// they do actually protect against untrusted code execution (sha)
282289
override predicate protectsCategoryAndEvent(string category, string event) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/actions-all
4+
extensible: enabledDeploymentEnvironmentDataModel
5+
data: []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on:
2+
pull_request_target:
3+
types: [Created]
4+
jobs:
5+
test1:
6+
environment: EnvironmentInRepo
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Test 1
10+
run: echo "test1"
11+
test2:
12+
environment: EnvironmentNotInRepo
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Test 2
16+
run: echo "test2"

actions/ql/test/library-tests/basic/commands.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
| .github/workflows/commands.yml:28:9:31:2 | Run Step | wc -l |
1717
| .github/workflows/commands.yml:34:9:37:6 | Run Step | command1 |
1818
| .github/workflows/commands.yml:34:9:37:6 | Run Step | command2 |
19+
| .github/workflows/controlcheck.yml:9:9:11:2 | Run Step | echo "test1" |
20+
| .github/workflows/controlcheck.yml:15:9:16:25 | Run Step | echo "test2" |
1921
| .github/workflows/expression_nodes.yml:7:9:8:6 | Run Step | LINE 1echo '${{ github.event.comment.body }}' |
2022
| .github/workflows/expression_nodes.yml:8:9:10:6 | Run Step | LINE 1 echo '${{ github.event.comment.body }}' |
2123
| .github/workflows/expression_nodes.yml:10:9:13:6 | Run Step | LINE 1 echo '${{ github.event.comment.body }}' |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| .github/workflows/controlcheck.yml:6:18:6:34 | EnvironmentInRepo |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/actions-all
4+
extensible: enabledDeploymentEnvironmentDataModel
5+
data:
6+
# assumed to exist in a repo where controlcheck.yml exists
7+
# realistically would need to be manually/externally provided
8+
- ["EnvironmentInRepo"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import actions
2+
import codeql.actions.security.ControlChecks
3+
4+
from ControlCheck c
5+
select c

0 commit comments

Comments
 (0)