Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: new tool to run cfn-guard to detect inline broad scoped permissions #34115

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

QuantumNeuralCoder
Copy link
Contributor

@QuantumNeuralCoder QuantumNeuralCoder commented Apr 11, 2025

Issue # (if applicable)

None

Closes #.
None

Reason for this change

  • Adds a new tool to run cfn-guard
  • Enhances PR linter to find added or updated snapshot templates and run cfn-guard through them for detecting inline broad trust policy

Description of changes

Refer README.md
Also refer the pr-linter change here. This will be opened once current PR is merged.

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Tested on personal fork. Refer QuantumNeuralCoder#6
PR Linter output shows test results.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team April 11, 2025 20:06
@github-actions github-actions bot added the p2 label Apr 11, 2025
@QuantumNeuralCoder QuantumNeuralCoder added pr/do-not-merge This PR should not be merged at this time. and removed p2 labels Apr 11, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 11, 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.

(This review is outdated)

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (74cbe27) to head (62b80d8).
Report is 30 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #34115   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         120      120           
  Lines        6976     6976           
  Branches     1178     1178           
=======================================
  Hits         5859     5859           
  Misses       1005     1005           
  Partials      112      112           
Flag Coverage Δ
suite.unit 83.98% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 83.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumNeuralCoder QuantumNeuralCoder changed the title feat(cfn-guard-action): Adding cfn guard run to pr linter feat(cfn-guard-action): new tool to run cfn-guard to detect inline broad scoped permissions Apr 11, 2025
@github-actions github-actions bot added the p2 label Apr 11, 2025
@QuantumNeuralCoder
Copy link
Contributor Author

Exemption Request since github workflow separately tested on personal fork.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Apr 11, 2025
@QuantumNeuralCoder QuantumNeuralCoder removed the pr/do-not-merge This PR should not be merged at this time. label Apr 11, 2025
@QuantumNeuralCoder QuantumNeuralCoder changed the title feat(cfn-guard-action): new tool to run cfn-guard to detect inline broad scoped permissions chore: new tool to run cfn-guard to detect inline broad scoped permissions Apr 11, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 11, 2025 22:58

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

required: false
default: "single-line-summary"

runs:
Copy link
Contributor

Choose a reason for hiding this comment

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

since cfn-guard is required, I believe it worth adding a step to install cfn-guard, so we do not need every time we use this GH action to add a step to install it

@@ -0,0 +1,30 @@
name: 'cfn-guard-custom-rules-tool'
description: 'CFN Guard for custom or granular guard rules'
author: QuantumNeuralCoder
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove the author :)

Comment on lines 41 to 45
if (!rulePathToUse && ruleSetUrl) {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rules-'));
rulePathToUse = path.join(tempDir, 'rules.guard');
await downloadFile(ruleSetUrl, rulePathToUse);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the rules set file will be always a local file in the repo, why shall we download it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed all in latest commit

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 11, 2025
Comment on lines +10 to +14
# Triggered from a separate job when a review is added
workflow_run:
workflows: [PR Linter Trigger]
types:
- completed
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the PR Linter trigger will trigger this workflow along with PR Linter.

Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to link it to PR Linter ?

echo "pr_number=$(cat pr/pr_number)" >> "$GITHUB_OUTPUT"
echo "pr_sha=$(cat pr/pr_sha)" >> "$GITHUB_OUTPUT"

validate-pr:
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this step ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shas are referred in the next step. i have renamed the validate-pr step

Comment on lines +24 to +54
download-if-workflow-run:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.pr_output.outputs.pr_number }}
pr_sha: ${{ steps.pr_output.outputs.pr_sha }}
# if conditions on all individual steps because subsequent jobs depend on this job
# and we cannot skip it entirely
steps:
- name: 'Download workflow_run artifact'
if: github.event_name == 'workflow_run'
uses: dawidd6/action-download-artifact@v9
with:
run_id: ${{ github.event.workflow_run.id }}
name: pr_info
path: pr/
search_artifacts: true

- name: 'Determine PR info'
# PR info comes from the artifact if downloaded, or GitHub context if not.
if: github.event_name == 'workflow_run'
id: 'pr_output'
run: |
if [[ ! -f pr/pr_number ]]; then
echo "${{ github.event.pull_request.number }}" > pr/pr_number
fi
if [[ ! -f pr/pr_sha ]]; then
echo "${{ github.event.pull_request.head.sha }}" > pr/pr_sha
fi
cat pr/*
echo "pr_number=$(cat pr/pr_number)" >> "$GITHUB_OUTPUT"
echo "pr_sha=$(cat pr/pr_sha)" >> "$GITHUB_OUTPUT"
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the value of these steps ?

Comment on lines +58 to +63
permissions:
contents: read
pull-requests: write
statuses: read
issues: read
checks: read
Copy link
Contributor

Choose a reason for hiding this comment

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

do not think we need these permissions, we will not update the PR

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 62b80d8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

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 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants