Skip to content

Commit 436be5c

Browse files
committed
Add implementation for technique to customize environmentCheck in actions queries
1 parent 9fc65df commit 436be5c

6 files changed

Lines changed: 58 additions & 1 deletion

File tree

actions/ql/lib/actions.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import codeql.actions.Ast
2+
3+
abstract class CustomEnvEnable extends Environment { }

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,19 @@ 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+
}
176+
177+
/**
178+
* `EnvironmentCheck` implementation model.
179+
*/
180+
predicate selectDeploymentEnvironmentDataModel(string selected) {
181+
Extensions::selectDeploymentEnvironmentDataModel(selected)
182+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,15 @@ 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 for a given repository.
94+
* Requires this to be externally supplied but once done can be used to
95+
* toggle precision of whether that suffices or not as a control check.
96+
*/
97+
extensible predicate enabledDeploymentEnvironmentDataModel(string name);
98+
99+
/**
100+
* Selects which deployment environments model to use to implement `EnvironmentCheck`.
101+
*/
102+
extensible predicate selectDeploymentEnvironmentDataModel(string mechanism);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,22 @@ abstract class LabelCheck extends ControlCheck {
277277
}
278278

279279
class EnvironmentCheck extends ControlCheck instanceof Environment {
280+
EnvironmentCheck() {
281+
exists(string selected |
282+
selectDeploymentEnvironmentDataModel(selected) and
283+
if selected = "EnvironmentCheckMaD"
284+
then enabledDeploymentEnvironmentDataModel(this.(Environment).getName())
285+
else
286+
if selected = "EnvironmentCheckCustomQL"
287+
then this instanceof CustomEnvEnable
288+
else this instanceof Environment
289+
)
290+
}
291+
280292
// Environment checks are not effective against any mutable attacks
281293
// they do actually protect against untrusted code execution (sha)
282294
override predicate protectsCategoryAndEvent(string category, string event) {
283-
event = actor_is_attacker_event() and category = any_category()
295+
event = actor_is_attacker_event() and category = toctou_category()
284296
or
285297
event = actor_not_attacker_event() and category = non_toctou_category()
286298
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/actions-all
4+
extensible: selectDeploymentEnvironmentDataModel
5+
data:
6+
# The possible values this can take are:
7+
# EnvironmentCheckCustomQL - for a custom QL implementation for the sufficient EnvironmentCheck.
8+
# EnvironmentCheckMaD - for a custom MaD list of deployment environments that are relevant to a database.
9+
- [""]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/actions-all
4+
extensible: enabledDeploymentEnvironmentDataModel
5+
data:
6+
- [""]

0 commit comments

Comments
 (0)