fix(query): fn for API Gateway With CloudWatch Logging Disabled - terraform/aws#7694
Merged
cx-ricardo-jesus merged 9 commits intoSep 25, 2025
Conversation
…n field), added searchLine, fixed typo in key values, fixed logic error that caused query to not flag when scaning complete test folder)
Contributor
…udwatch_Logging_Disabled-terraform/aws
…udwatch_Logging_Disabled-terraform/aws
…udwatch_Logging_Disabled-terraform/aws
cx-artur-ribeiro
suggested changes
Sep 17, 2025
cx-artur-ribeiro
left a comment
Contributor
There was a problem hiding this comment.
Just a quick fix to the message but apart from that everything looks good :)
…ng_disabled/query.rego Co-authored-by: Artur Ribeiro <153724638+cx-artur-ribeiro@users.noreply.github.com>
…udwatch_Logging_Disabled-terraform/aws
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 20838717 | Triggered | Generic Password | a12d5a1 | assets/queries/azureResourceManager/sql_server_database_with_alerts_disabled/test/negative7.bicep | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
…udwatch_Logging_Disabled-terraform/aws
…udwatch_Logging_Disabled-terraform/aws
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Reason for Proposed Changes
Currently the API Gateway With CloudWatch Logging Disabled terraform query does not account for the
access_log_settings.destination_arnfield of the aws_api_gateway_stage resource.This query is meant to flag whenever "CloudWatch Logs" are not enabled for a
aws_api_gateway_stageresource; currently it only checks for aaws_cloudwatch_log_groupresource that has a "name" field that references the relevantaws_api_gateway_stage'sstage_name. To do this thehaveLogsfunction checks for a specific regex match where given astage_namelike "example" the "name" of theaws_cloudwatch_log_groupcould be :name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.example.id}/${example}"This is shown in the negative1 test with "var.stage_name" as the stage_name. The "name" also references an
aws_api_gateway_rest_apiresource but that is irrelevant for the purposes of this query.The missing case is associated with the
access_log_settings.destination_arnfield from theaws_api_gateway_stagesince this field's purpose is to define where to send access logs as per the documentation. This is a glaring flaw and the field must be accounted for.Proposed Changes
Fixed a typo in the original message, and altered said message to be more informative (original message stated "not undefined" when it should say "undefined").
Fixed a logic error unrelated to the False Positive that caused the scan of a folder to not give results that scanning an individual file would, this was due to the fact that the auxiliary function was scanning through all "documents" in the generated payload.
Added new helper functions and a "master" helper function
get_resultsthat will define the flagging order. I decided that, in case a sample does not have a valid "stage_name" or a valid "destination_arn", it is the "destination_arn" that will be flagged since it is a resource that exists solely to properly reference aaws_cloudwatch_log_group, while the stage_name will flag simply because noaws_cloudwatch_log_groupresource properly referenced it and not because it is totally invalid.Added 2 different
resultvalues depending on the reason for the query flagging. This results are given by thedoes_not_have_valid_stage_namepolicy that is very much alike the original query logic and the newdoes_not_have_valid_destination_arnfor the missing case. Note that the "destination_arn" must also respect a specific regex pattern as such :regexPattern := sprintf("aws_cloudwatch_log_group.%s.arn", [name])Where the "name" is the literal name of the
aws_cloudwatch_log_groupnot its "name" field.Added tests for the new case :
destination_arndestination_arnbut a validstage_namedestination_arnandstage_namedestination_arnandstage_namedestination_arnandstage_nameaccess_log_settingsfield and an invalidstage_name.A test case for the
access_log_settingsfield without thedestination_arnwas not added since thedestination_arnis a required for said field.Note : From my research modules cannot replace this resource since even using modules that can provide similar functions like api-gateway, they cannot define the
aws_api_gateway_stagetoaws_cloudwatch_log_groupinteraction that causes this query to flag by themselves.I submit this contribution under the Apache-2.0 license.