-
Notifications
You must be signed in to change notification settings - Fork 121
Testscript #777
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
Closed
Closed
Testscript #777
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c980589
add test workflow
arthurclares d93cc14
Test
arthurclares 4fe23e5
include hash test
arthurclares d88699b
update test yml
arthurclares 5a81275
update to yaml
arthurclares 563e32d
check hash
arthurclares bd89032
update files
arthurclares 6dd3092
hardenedPR2
arthurclares cd32c7c
test hash
arthurclares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,120 @@ | ||||||||||||||||||||||||||||||||||||||||||
| name: Test Hardened PR Workflow | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||
| workflow_dispatch: | ||||||||||||||||||||||||||||||||||||||||||
| inputs: | ||||||||||||||||||||||||||||||||||||||||||
| simulate_pr_number: | ||||||||||||||||||||||||||||||||||||||||||
| description: "PR number to simulate (for logs only)" | ||||||||||||||||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||||||||||||||||
| default: "123" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||
| pull-requests: read | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||
| test-hardened: | ||||||||||||||||||||||||||||||||||||||||||
| name: Validate Hardened Workflow Logic | ||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||
| # 1) Harden Runner (AUDIT mode for testing – no blocks yet) | ||||||||||||||||||||||||||||||||||||||||||
| - name: Harden Runner (audit mode) | ||||||||||||||||||||||||||||||||||||||||||
| uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | ||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||
| egress-policy: audit | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # 2) Checkout THIS repository/branch so files are available in the workspace | ||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout repository | ||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||
| ref: main | ||||||||||||||||||||||||||||||||||||||||||
| fetch-depth: 1 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # 3) Simulate PR metadata (purely informational) | ||||||||||||||||||||||||||||||||||||||||||
| - name: Simulate PR Context | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| echo "Simulating PR #${{ github.event.inputs.simulate_pr_number }}" | ||||||||||||||||||||||||||||||||||||||||||
| echo "Base branch: main" | ||||||||||||||||||||||||||||||||||||||||||
| echo "PR branch : (simulated)" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # 4) Show what is actually in .github/scripts to debug paths quickly | ||||||||||||||||||||||||||||||||||||||||||
| - name: List .github/scripts (if present) | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| echo "Listing .github/scripts..." | ||||||||||||||||||||||||||||||||||||||||||
| ls -la .github/scripts || echo "::warning::.github/scripts not found in this repo/branch" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # 5) Integrity Check (guarded): compute hash only if the file exists | ||||||||||||||||||||||||||||||||||||||||||
| - name: Integrity Check (Hash Compare) | ||||||||||||||||||||||||||||||||||||||||||
| id: integrity | ||||||||||||||||||||||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||
| FILE_PATH: ".github/scripts/validate-kql-comments.ps1" | ||||||||||||||||||||||||||||||||||||||||||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||||||||||||||||||||||||||||||||||||||||||
| SIMULATE_PR_NUMBER: ${{ github.event.inputs.simulate_pr_number }} | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||
| echo "Running integrity check for $FILE_PATH" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Ensure we have the latest main ref available | ||||||||||||||||||||||||||||||||||||||||||
| git fetch --no-tags origin main || true | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Compute base hash from the file as it exists on the main branch (trusted source) | ||||||||||||||||||||||||||||||||||||||||||
| if ! git show "origin/main:${FILE_PATH}" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "Error: ${FILE_PATH} not found on origin/main" | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| base_hash=$(git show "origin/main:${FILE_PATH}" | sha256sum | cut -d ' ' -f1) | ||||||||||||||||||||||||||||||||||||||||||
| echo "Base hash (origin/main): $base_hash" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # If this run was triggered by a pull_request, fetch the PR head and compute its file hash | ||||||||||||||||||||||||||||||||||||||||||
| if [ -n "${PR_NUMBER:-}" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "Detected PR run for PR #${PR_NUMBER}. Fetching PR head..." | ||||||||||||||||||||||||||||||||||||||||||
| git fetch origin "refs/pull/${PR_NUMBER}/head:refs/remotes/origin/pr/${PR_NUMBER}" || true | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if ! git show "refs/remotes/origin/pr/${PR_NUMBER}:${FILE_PATH}" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "Error: $FILE_PATH not found in PR #${PR_NUMBER}" | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| pr_hash=$(git show "refs/remotes/origin/pr/${PR_NUMBER}:${FILE_PATH}" | sha256sum | cut -d ' ' -f1) | ||||||||||||||||||||||||||||||||||||||||||
| echo "PR hash (PR #${PR_NUMBER}): $pr_hash" | ||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||
| # Manual run: fall back to workspace file (but still trust main as the baseline) | ||||||||||||||||||||||||||||||||||||||||||
| if [ -f "$FILE_PATH" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| pr_hash=$(sha256sum "$FILE_PATH" | cut -d ' ' -f1) | ||||||||||||||||||||||||||||||||||||||||||
| echo "Manual run: PR hash computed from workspace file: $pr_hash" | ||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||
| echo "Error: no PR context and workspace file $FILE_PATH not found" | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ "$base_hash" != "$pr_hash" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "Integrity check failed! File on PR does not match trusted version on main." | ||||||||||||||||||||||||||||||||||||||||||
| echo "Base (main): $base_hash" | ||||||||||||||||||||||||||||||||||||||||||
| echo "PR/head: $pr_hash" | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| echo "Integrity check passed." | ||||||||||||||||||||||||||||||||||||||||||
| # 6) Conditional Execution Simulation (purely illustrative) | ||||||||||||||||||||||||||||||||||||||||||
| - name: Check Approval Condition (simulated) | ||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||
| echo "Simulating reviewDecision = APPROVED" | ||||||||||||||||||||||||||||||||||||||||||
| echo "PR approved" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
+106
|
||||||||||||||||||||||||||||||||||||||||||
| # 6) Conditional Execution Simulation (purely illustrative) | |
| - name: Check Approval Condition (simulated) | |
| run: | | |
| echo "Simulating reviewDecision = APPROVED" | |
| echo "PR approved" | |
| # 6) Check PR Approval Status (actual validation) | |
| - name: Check PR Approval Status | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUMBER: ${{ github.event.inputs.simulate_pr_number }} | |
| run: | | |
| echo "Checking approval status for PR #$PR_NUMBER" | |
| APPROVAL_COUNT=$(gh pr reviews $PR_NUMBER --json state --jq '[.[] | select(.state=="APPROVED")] | length') | |
| if [ "$APPROVAL_COUNT" -eq 0 ]; then | |
| echo "PR is NOT approved. Failing workflow." | |
| exit 1 | |
| else | |
| echo "PR is approved." | |
| fi |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded branch reference 'main' should be made configurable or use a dynamic reference like
${{ github.event.repository.default_branch }}to support repositories with different default branch names.