Skip to content

Add way to customize environmentCheck Actions QL#22173

Open
knewbury01 wants to merge 7 commits into
github:mainfrom
knewbury01:knewbury01/customize-actions-sanitizers
Open

Add way to customize environmentCheck Actions QL#22173
knewbury01 wants to merge 7 commits into
github:mainfrom
knewbury01:knewbury01/customize-actions-sanitizers

Conversation

@knewbury01

Copy link
Copy Markdown
Contributor

Add implementation for technique to customize EnvironmentCheck in actions queries

Currently there is no way to customize Actions query "sanitizers" ie ControlChecks. This PR adds a sample mechanism that uses 1) a specifier in MaD that designates which technique to use (the default is no customization) and 2) a mechanism that fills the definition of EnvironmentCheck with either i) a QL custom definition or ii) a MaD custom definition.

The purpose of this is to allow for checks to be selectively turned off or narrowed based on real info related to deployment environments in repos (this would need to be externally supplied) .

This PR is similar to and borrows ideas from this PR.

The intention of this work would be to potentially apply this style to any check type or other sanitizer types in other languages, if the mechanisms used here are found to be suitable.

One important consideration of this work is that for Actions there is currently no Customizations.qll file. Either this PR should also add one , or it should be carefully considered if the current actions.qll usage for a similar intended edit location is alright to do (probably the former would be more ideal).

@github-actions github-actions Bot added the Actions Analysis of GitHub Actions label Jul 10, 2026

@michaelnebel michaelnebel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for doing this! It is highly appreciated!

Would it be possible to add some tests as well?
Note, that for testing the Yaml alternative it is possible to add an .ext.yml file next to the .ql test file - it just needs to have the same base name as the test file. That is, if there is a test named test.ql then adding test.ext.yml makes it possible to add tuples to the extensible predicates that only applies for test.ql.

Comment thread actions/ql/lib/codeql/actions/security/ControlChecks.qll Outdated
Comment thread actions/ql/lib/ext/config/customize_checks.yml Outdated
Comment thread actions/ql/lib/ext/config/deployment_environment.yml Outdated
Comment thread actions/ql/lib/actions.qll Outdated
@knewbury01

knewbury01 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Thank you very much for doing this! It is highly appreciated!

Would it be possible to add some tests as well? Note, that for testing the Yaml alternative it is possible to add an .ext.yml file next to the .ql test file - it just needs to have the same base name as the test file. That is, if there is a test named test.ql then adding test.ext.yml makes it possible to add tuples to the extensible predicates that only applies for test.ql.

@michaelnebel thank you so much for the review! addressed most, except the testing request, which I agree with

but I am having a bit of trouble envisioning how to test this other than add a new test that just checks the enabled control checks... I dont see such a lib test currently. the reason it is a bit tough is bc I think we want the default behaviour to still be "add all envs as sanitizers" and the specific behaviour to be "enable just specific ones" which means all the security queries would still have the same result regardless of whether the mechanism is active or not... toggling it on and off wont affect the test result and therefore in my mind its a bit of a bad unit test ideology

I have added a library test for this. I think that makes the most sense, thanks for letting me know about how to enable MaD for just one test!

@knewbury01
knewbury01 requested a review from michaelnebel July 22, 2026 14:28
@knewbury01
knewbury01 marked this pull request as ready for review July 22, 2026 14:28
@knewbury01
knewbury01 requested a review from a team as a code owner July 22, 2026 14:28
Copilot AI review requested due to automatic review settings July 22, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds model-driven customization for which GitHub Actions deployment environments qualify as control checks.

Changes:

  • Defines a deployment-environment data extension.
  • Filters EnvironmentCheck using supplied environment names.
  • Adds coverage for listed and unlisted environments.
Show a summary per file
File Description
controlchecktest.ql Queries control checks.
controlchecktest.ext.yml Supplies a test environment model.
controlchecktest.expected Records the expected selected environment.
controlcheck.yml Provides listed and unlisted environments.
deployment_environment.yml Adds empty default extension data.
ControlChecks.qll Applies environment filtering.
ConfigExtensions.qll Declares the extensible predicate.
Config.qll Exposes the configuration predicate.

Review details

Comments suppressed due to low confidence (1)

actions/ql/lib/ext/config/deployment_environment.yml:5

  • The customization selector described by the PR is missing. With only this allowlist predicate, “customization disabled” is indistinguishable from an enabled customization that supplies zero environments; the latter therefore falls back to treating every referenced environment as a control check. Add a separate mode/technique predicate and gate allowlist filtering on it so an explicitly empty allowlist can disable all environment checks.
  - addsTo:
      pack: codeql/actions-all
      extensible: enabledDeploymentEnvironmentDataModel
    data: []
  • Files reviewed: 8/8 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment thread actions/ql/lib/ext/config/deployment_environment.yml
Comment thread actions/ql/test/library-tests/basic/controlchecktest.ext.yml Outdated
Comment thread actions/ql/lib/codeql/actions/config/ConfigExtensions.qll Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Actions Analysis of GitHub Actions documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants