Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
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)
}
7 changes: 7 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,10 @@ 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 for a given repository.
* 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.
Comment thread
knewbury01 marked this conversation as resolved.
Outdated
*/
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
# realisitically would need to be manually/externally provided
Comment thread
knewbury01 marked this conversation as resolved.
Outdated
- ["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