Skip to content

Add InfraScan audit workflow for security scanning#240

Open
igor-soldev wants to merge 1 commit into
mosip:masterfrom
igor-soldev:master
Open

Add InfraScan audit workflow for security scanning#240
igor-soldev wants to merge 1 commit into
mosip:masterfrom
igor-soldev:master

Conversation

@igor-soldev

@igor-soldev igor-soldev commented May 27, 2026

Copy link
Copy Markdown

Description

This PR introduces an automated InfraScan GitHub Actions workflow to the mosip/infra repository in order to continuously scan infrastructure-as-code configurations for security vulnerabilities and cost optimization opportunities.

The workflow runs on every push and pull_request event and executes a comprehensive InfraScan analysis of Terraform definitions. It generates an HTML report and uploads it as a GitHub Actions artifact for further inspection.

This change is a follow-up to the InfraScan analysis and findings shared in the: #200

The referenced analysis identified multiple areas for improvement across the infrastructure codebase, including:

  • encryption and data protection gaps (e.g. EBS encryption settings),
  • missing observability controls (e.g. VPC Flow Logs),
  • IAM policy hardening opportunities,
  • cost optimization improvements (e.g. NAT Gateway usage, missing budget alerts, and spot instance adoption).

The full InfraScan report used for validation is available here:
https://infrascan.soldevelo.com/?scan_id=6bf4a14c-ed6b-45f0-8e23-a381845bfaab

By introducing this workflow, the repository gains continuous infrastructure security validation directly in CI/CD, ensuring that similar misconfigurations are detected early in future changes and before reaching production environments.

Summary by CodeRabbit

  • Chores
    • Added automated infrastructure scanning to validate code quality and security on every push and pull request with reports available for review.

Review Change Stack

Signed-off-by: Igor <iolszewski@soldevelo.com>
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

A new GitHub Actions workflow is added to run infrastructure security scans automatically on every push and pull request. The workflow checks out the repository, executes an InfraScan action to generate a comprehensive HTML report, and uploads it as a build artifact with 14-day retention, ensuring the report is captured even if the scan step fails.

Changes

InfraScan Audit Workflow

Layer / File(s) Summary
Workflow triggers and job initialization
.github/workflows/infrascan.yml
Workflow named "InfraScan Audit" triggers on push and pull_request events; a job (infrascan) is configured to run on ubuntu-latest.
Environment preparation and InfraScan execution
.github/workflows/infrascan.yml
Repository is checked out, infrascan-reports directory is created with full permissions (chmod 777), and the soldevelo/infrascan@v1.0.6 action executes a comprehensive scan with output saved to infrascan-reports/report.html.
Report artifact upload and retention
.github/workflows/infrascan.yml
Generated report is uploaded as a build artifact using if: always() to ensure upload on scan failure; artifact retention is set to 14 days.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🐰 A workflow hops to life, with scans so bright,
Infrastructure audited left and right!
Reports stored safely, fourteen days preserved,
Security insights that are well deserved. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a GitHub Actions InfraScan workflow for security scanning of infrastructure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
.github/workflows/infrascan.yml (2)

14-17: ⚡ Quick win

Reduce directory permissions for least privilege.

chmod 777 is overly permissive and unnecessary in the GitHub Actions runner environment. Use chmod 755 or remove the chmod command entirely.

🔐 Proposed fix to use appropriate permissions
       - name: Create Reports Directory
         run: |
           mkdir -p infrascan-reports
-          chmod 777 infrascan-reports
+          chmod 755 infrascan-reports

Or simply remove the chmod line since default permissions are sufficient for this use case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/infrascan.yml around lines 14 - 17, The workflow step
"Create Reports Directory" currently sets overly permissive permissions with the
line `chmod 777 infrascan-reports`; change this to `chmod 755 infrascan-reports`
or remove the `chmod` command entirely (keeping `mkdir -p infrascan-reports`) so
the directory uses least-privilege/default permissions in the GitHub Actions
runner.

3-5: ⚡ Quick win

Consider filtering workflow triggers to specific branches.

The workflow runs on all push and pull_request events across all branches, which may generate unnecessary workflow runs and increase CI costs. Consider filtering to key branches like master or specific release branches.

⚙️ Proposed configuration to limit triggers
 on:
   push:
+    branches:
+      - master
   pull_request:
+    branches:
+      - master
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/infrascan.yml around lines 3 - 5, The workflow currently
triggers on all push and pull_request events (the top-level keys "on", "push",
and "pull_request"); narrow the triggers to only target important branches by
replacing those keys with branch filters (e.g., push: branches: [main, master,
release/*] and pull_request: branches: [main, master, release/*]) so CI only
runs for key branches or release branches; update the "on" section accordingly
to include the branch arrays and any exceptions (paths or tags) as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/infrascan.yml:
- Line 12: Replace mutable action tags with immutable commit SHAs for each
GitHub Action usage (e.g., the checkout action reference "actions/checkout@v4",
the infrascan action "soldevelo/infrascan@v1.0.6", and the upload artifact
action "actions/upload-artifact@v4"); find the uses: lines and change them to
their corresponding full commit SHA pins while leaving a trailing comment with
the human-friendly version (e.g., "// actions/checkout@v4") for maintainability
so the workflow uses pinned SHAs and retains version context.
- Around line 11-12: The GitHub Actions checkout step using actions/checkout@v4
is leaving credentials persisted; update that step by adding the option
persist-credentials: false to the checkout action (i.e., modify the Checkout
code block for uses: actions/checkout@v4 to include persist-credentials: false)
so credentials are not kept and cannot be leaked via uploaded artifacts.

---

Nitpick comments:
In @.github/workflows/infrascan.yml:
- Around line 14-17: The workflow step "Create Reports Directory" currently sets
overly permissive permissions with the line `chmod 777 infrascan-reports`;
change this to `chmod 755 infrascan-reports` or remove the `chmod` command
entirely (keeping `mkdir -p infrascan-reports`) so the directory uses
least-privilege/default permissions in the GitHub Actions runner.
- Around line 3-5: The workflow currently triggers on all push and pull_request
events (the top-level keys "on", "push", and "pull_request"); narrow the
triggers to only target important branches by replacing those keys with branch
filters (e.g., push: branches: [main, master, release/*] and pull_request:
branches: [main, master, release/*]) so CI only runs for key branches or release
branches; update the "on" section accordingly to include the branch arrays and
any exceptions (paths or tags) as needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5e3bd675-4152-4ecd-8c3c-aafa0aa8f6bb

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf6f86 and 904f338.

📒 Files selected for processing (1)
  • .github/workflows/infrascan.yml

Comment on lines +11 to +12
- name: Checkout code
uses: actions/checkout@v4

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Set persist-credentials: false to prevent credential leakage.

The checkout action persists credentials by default, which could be exposed through uploaded artifacts. Since this workflow uploads artifacts, explicitly disable credential persistence.

🔒 Proposed fix to disable credential persistence
       - name: Checkout code
         uses: actions/checkout@v4
+        with:
+          persist-credentials: false

As per static analysis hint: "credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false"

🧰 Tools
🪛 zizmor (1.25.2)

[warning] 11-12: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 12-12: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/infrascan.yml around lines 11 - 12, The GitHub Actions
checkout step using actions/checkout@v4 is leaving credentials persisted; update
that step by adding the option persist-credentials: false to the checkout action
(i.e., modify the Checkout code block for uses: actions/checkout@v4 to include
persist-credentials: false) so credentials are not kept and cannot be leaked via
uploaded artifacts.

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

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.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Pin actions to full commit SHAs for supply chain security.

All three actions use tag references which are mutable and can be rewritten by attackers. Pin to full commit SHAs to protect against supply chain attacks.

🔐 Example fix for SHA pinning
       - name: Checkout code
-        uses: actions/checkout@v4
+        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Apply similar pinning for soldevelo/infrascan@v1.0.6 and actions/upload-artifact@v4. Use full commit SHAs with version comments for maintainability.

As per static analysis hint: "unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)"

Also applies to: 20-20, 27-27

🧰 Tools
🪛 zizmor (1.25.2)

[warning] 11-12: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 12-12: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/infrascan.yml at line 12, Replace mutable action tags with
immutable commit SHAs for each GitHub Action usage (e.g., the checkout action
reference "actions/checkout@v4", the infrascan action
"soldevelo/infrascan@v1.0.6", and the upload artifact action
"actions/upload-artifact@v4"); find the uses: lines and change them to their
corresponding full commit SHA pins while leaving a trailing comment with the
human-friendly version (e.g., "// actions/checkout@v4") for maintainability so
the workflow uses pinned SHAs and retains version context.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant