Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.
9 changes: 9 additions & 0 deletions actions/ql/lib/codeql/actions/config/Config.qll
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ predicate untrustedGhCommandDataModel(string cmd_regex, string flag) {
predicate actionsPermissionsDataModel(string action, string permission) {
Extensions::actionsPermissionsDataModel(action, permission)
}

/**
* MaD models for deployment environments
* Fields:
* - name: deployment environment name, e.g. `Public CI`
*/
predicate enabledDeploymentEnvironmentDataModel(string name) {
Extensions::enabledDeploymentEnvironmentDataModel(name)
}
9 changes: 9 additions & 0 deletions actions/ql/lib/codeql/actions/config/ConfigExtensions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ extensible predicate untrustedGhCommandDataModel(string cmd_regex, string flag);
* - see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token for documentation of token permissions.
*/
extensible predicate actionsPermissionsDataModel(string action, string permission);

/**
* Holds for deployment environments that exist with `name` for a given repository.
* * - 'name' is the name of the environment defined.
* E.g. for the deployment environment `environment: EnvironmentInRepo`, `name` is `EnvironmentInRepo`.
* Requires this to be externally supplied but once done can be used to
* toggle precision of whether that suffices or not as a control check by contributing to `EnvironmentCheck`.
*/
extensible predicate enabledDeploymentEnvironmentDataModel(string name);
7 changes: 7 additions & 0 deletions actions/ql/lib/codeql/actions/security/ControlChecks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ abstract class LabelCheck extends ControlCheck {
}

class EnvironmentCheck extends ControlCheck instanceof Environment {
EnvironmentCheck() {
// if there are any custom tuples use those
if enabledDeploymentEnvironmentDataModel(_)
then enabledDeploymentEnvironmentDataModel(this.(Environment).getName())
else this instanceof Environment
}

// Environment checks are not effective against any mutable attacks
// they do actually protect against untrusted code execution (sha)
override predicate protectsCategoryAndEvent(string category, string event) {
Expand Down
5 changes: 5 additions & 0 deletions actions/ql/lib/ext/config/deployment_environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extensions:
- addsTo:
pack: codeql/actions-all
extensible: enabledDeploymentEnvironmentDataModel
data: []
Comment thread
knewbury01 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request_target:
types: [Created]
jobs:
test1:
environment: EnvironmentInRepo
runs-on: ubuntu-latest
steps:
- name: Test 1
run: echo "test1"
test2:
environment: EnvironmentNotInRepo
runs-on: ubuntu-latest
steps:
- name: Test 2
run: echo "test2"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| .github/workflows/controlcheck.yml:6:18:6:34 | EnvironmentInRepo |
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extensions:
- addsTo:
pack: codeql/actions-all
extensible: enabledDeploymentEnvironmentDataModel
data:
# assumed to exist in a repo where controlcheck.yml exists
# realistically would need to be manually/externally provided
- ["EnvironmentInRepo"]
5 changes: 5 additions & 0 deletions actions/ql/test/library-tests/basic/controlchecktest.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import actions
import codeql.actions.security.ControlChecks

from ControlCheck c
select c
Loading