Skip to content

Conversation

@kumvprat
Copy link
Contributor

Issue # (if applicable)

N/A - Enhancement and bug fixes for Security Guardian tool.

Reason for this change

Security guardian is first line of defense for scanning policy, roles and permissions vended by CDK for customers. This GH Action is critical to determine if a PR change is providing secure-by-default policies for any changes introduced in CDK.

The Security Guardian tool needed several critical improvements to function properly:

  1. CFN Intrinsic Resolution: Missing comprehensive support for CloudFormation intrinsic functions like Fn::Sub, Fn::Select, Fn::Contains, etc.
  2. Rule Coverage: Incomplete security rule coverage across AWS services
  3. Create noise: Current setup of security guardian does not provide benefit as it fails to exclude cases where the generic cfn-guard rule might not work. Like with KMS secrets or secret manager secrets

Description of changes

Added template preprocessing pipeline with intrinsic resolution and policy normalization, details can be found below

Major Enhancements:

  • Complete CFN Intrinsic Function Resolver: Added comprehensive support for all CloudFormation intrinsic functions including Fn::Sub with literal escaping, Fn::Select with bounds checking, Fn::Contains, Fn::Split, Fn::Cidr, Fn::Base64, and shorthand forms (!Ref, !GetAtt, etc.)
  • Cross-Stack Resolution: Implemented resource registry for resolving Fn::ImportValue and cross-template references
  • Policy Normalization: Added IAM policy normalizer to resolve intrinsics within policy documents before validation
  • Output presentation: Integrated JUnit XML output with GitHub Actions using pinned mikepenz/action-junit-report for rich PR feedback ( suggested by cfn-guard here)
  • Security report generation workflow : Separated out report generation into another workflow due to 2 reasons :
    • Gives us flexibility to change the trigger type for security-guardian to lower permissive trigger likepull_request or pull_request_review
    • Allows fork PRs to run : Fork PRs trigger workflow runs with read permissions, and the separate workflow can execute separate from the fork PR call chain with full permissions needed to update checks and annotation on the PR

Security Rule Expansion:

  • Added comprehensive guard rules for 13 AWS services: CodePipeline, DataTrace, DocumentDB, EC2, IAM, Kinesis, Neptune, Redshift, S3, SNS, SQS, and trust scope validation
  • Enhanced existing rules with better coverage for broad principals, wildcard actions, and cross-account access patterns

Describe any new or updated permissions being added

No new IAM permissions required. All changes are to the static analysis tool and GitHub Actions workflow.

Description of how you validated changes

Unit Testing: via

  • Guard Rule Syntax: All 13 guard rule files pass cfn-guard v3 parser validation
  • Cross-Stack Testing: Validated resolution of Fn::ImportValue and cross-template references
  • Example cases to test that the current set of rules PASS and FAIL for different scenarios

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…nsic scanner code to exempt some services from root principal check
…ner by default till it runs consistenly and changing workflow to run on pull_request_target
…summary and output as provided in the tool invocation arguments + Removed s3 bucket versioning requirement + data trace checks only have private key and aws access key id checks
…on : Not and contains with tests + made the resolution function modular
…being resolved by the custom resolver + removed malformed template checks as cdk should always produced a valid template + added policy resolution tests
…prehensive tests + Fix Fn::Sub literal escaping and parameter resolution + Add shorthand form support (etc.) + Improve Fn::Select bounds checking + Add comprehensive test coverage for guard rules and intrinsic functions
…results + changes in security guardian workflow to parse the junit files + removed test.sh + fix faulty guard rules + added action to consume and publish junit result
… fields in a policy are targeted for normalization
…it action report GH action looks for file attribute
…tead oif implementing a reversible function => Works for unresolved cfn temapates
… a PR rather than cehckout action based merge commit
…ecific object inside Properties and only triggers rule when the changes exists + test changes
…ecific object inside Properties and only triggers rule when the changes exists + test changes
…rent report generation workflow to add proper annotations
…l, the artifact carries the information wiht it
…l, the artifact carries the information wiht it
…l, the artifact carries the information wiht it => Pr info capture works with security guardian failure as well
@github-actions github-actions bot added the p2 label Nov 19, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 19, 2025 17:29
@kumvprat kumvprat changed the title Security guardian changes feat(ci): security guardian changes Nov 19, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 19, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter fails with the following errors:

❌ Features must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

@kumvprat
Copy link
Contributor Author

kumvprat commented Nov 19, 2025

This how a run would look like

image

This is how annotations look on the code

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants