Skip to content

feat(queries): new queries "Instance Uses Metadata Service IMDSv1" for Terraform/aws, Ansible/aws and CloudFormation/AWS#7624

Merged
cx-artur-ribeiro merged 18 commits into
masterfrom
AST-40699
Aug 14, 2025
Merged

feat(queries): new queries "Instance Uses Metadata Service IMDSv1" for Terraform/aws, Ansible/aws and CloudFormation/AWS#7624
cx-artur-ribeiro merged 18 commits into
masterfrom
AST-40699

Conversation

@cx-ricardo-jesus

Copy link
Copy Markdown
Contributor

Closes #

Reason for Proposed Changes

  • Currently we have no support for the verification of the IMDS version in place.

Proposed Changes

  • I followed a similar approach regarding the implementation of the query for the platforms Ansible and Terraform. On both of them, I only used a single policy.
  • In this policy is used two helper functions, the first one called is_metadata_service_enabled check's if the metadata service is enabled, i.e., when the field http_endpoint is set to enabled or it's not defined at all, which is the same as having the value enabled set (default's to enabled).
  • The verification described above is necessary because if the metadata service is not enabled there is no point in checking the http_tokens field.
  • After using the first helper function, it's used the other one, that is called http_tokens_undefined_or_not_required that as the name says, checks if the field http_tokens is not defined or is defined as required. The field http_tokens defines if whether or not the metadata service requires IMDSv2.
  • On the implementation for the CloudFormation platform, I made the verifications on the field's for two types of resources AWS::EC2::Instance and AWS:EC2::LaunchTemplate.
  • I made the same verifications as the queries implemented for the Ansible and Terraform platforms, but for this case the MetadataOptions block is inside the LaunchTemplateData for the resource of type AWS::EC2::LaunchTemplate.
  • For all the queries I provided seven different samples, two negative samples and five positive samples.
  • The negative samples, the first one hast the metadata_options block defined with both http_endpoint and http_tokens field's defined with enabled and required repectively.
  • The positive samples, have all the variations regarding the values that should return a vulnerable result on http_tokens and http_endpoint fields.

I submit this contribution under the Apache-2.0 license.

@cx-ricardo-jesus cx-ricardo-jesus requested a review from a team as a code owner August 4, 2025 10:44
@github-actions github-actions Bot added feature New feature query New query feature ansible Ansible query cloudformation CloudFormation query terraform Terraform query aws PR related with AWS Cloud labels Aug 4, 2025
@github-actions

github-actions Bot commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.11

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@Checkmarx Checkmarx deleted a comment from gitguardian Bot Aug 4, 2025
@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as draft August 4, 2025 11:06
@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as ready for review August 4, 2025 13:53
@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as draft August 5, 2025 09:12
@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as ready for review August 5, 2025 13:58
@Checkmarx Checkmarx deleted a comment from gitguardian Bot Aug 6, 2025

@cx-artur-ribeiro cx-artur-ribeiro 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.

Hey Ricardo, everything looks good besides the typos 😄.

Comment thread assets/queries/ansible/aws/instance_uses_metadata_service_IMDSv1/query.rego Outdated
Comment thread assets/queries/ansible/aws/instance_uses_metadata_service_IMDSv1/query.rego Outdated
@gitguardian

gitguardian Bot commented Aug 7, 2025

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
19562607 Triggered Generic Password f354763 assets/queries/common/passwords_and_secrets/test/positive53.json View secret
4266022 Triggered Generic Password 1117a2d assets/queries/cloudFormation/aws/amplify_app_basic_auth_config_password_exposed/test/negative7.yaml View secret
9419039 Triggered Username Password 1117a2d assets/queries/cloudFormation/aws/amplify_app_basic_auth_config_password_exposed/test/positive6.json View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. 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


🦉 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.

@cx-artur-ribeiro cx-artur-ribeiro 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.

LGTM, nice job.

@cx-artur-ribeiro cx-artur-ribeiro merged commit 3af270d into master Aug 14, 2025
30 checks passed
@cx-artur-ribeiro cx-artur-ribeiro deleted the AST-40699 branch August 14, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ansible Ansible query aws PR related with AWS Cloud cloudformation CloudFormation query feature New feature query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants