Make WordPress Core


Ignore:
Timestamp:
01/22/2025 03:13:21 PM (21 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Improve the security and correctness of the GitHub Actions workflows files.

This includes removing use of dangerous inline GitHub Actions expressions, preventing word splitting, further tightening permissions, and generally improving many aspects of the workflows.

This also introduces a new workflow that runs Actionlint to detect incorrect and insecure code and configuration in workflow files.

Props johnbillion, swissspidy, flixos90, desrosj.

See #62221

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/slack-notifications.yml

    r59519 r59679  
    5555    if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event.workflow_run.event != 'pull_request' }}
    5656    outputs:
    57       previous_conclusion: ${{ steps.previous-conclusion.outputs.previous_conclusion }}
     57      previous_conclusion: ${{ steps.previous-attempt-result.outputs.result }}
    5858      payload: ${{ steps.create-payload.outputs.payload }}
    5959
    … …  
    6969              owner: context.repo.owner,
    7070              repo: context.repo.repo,
    71               run_id: ${{ github.run_id }},
     71              run_id: context.runId,
    7272            });
    7373
    74             if ( '${{ inputs.calling_status }}' == 'failure' && workflow_run.data.run_attempt == 1 ) {
     74            if ( process.env.CALLING_STATUS == 'failure' && workflow_run.data.run_attempt == 1 ) {
    7575              return 'first-failure';
    7676            }
    … …  
    8383                owner: context.repo.owner,
    8484                repo: context.repo.repo,
    85                 run_id: ${{ github.run_id }},
     85                run_id: context.runId,
    8686                attempt_number: workflow_run.data.run_attempt - 1
    8787              });
    … …  
    9595              repo: context.repo.repo,
    9696              workflow_id: workflow_run.data.workflow_id,
    97               branch: '${{ env.CURRENT_BRANCH }}',
     97              branch: process.env.CURRENT_BRANCH,
    9898              exclude_pull_requests: true,
    9999            });
    … …  
    125125            // Can't determine previous workflow conclusion.
    126126            return 'unknown';
    127 
    128       - name: Store previous conclusion as an output
    129         id: previous-conclusion
    130         run: echo "previous_conclusion=${{ steps.previous-attempt-result.outputs.result }}" >> $GITHUB_OUTPUT
     127        env:
     128          CALLING_STATUS: ${{ inputs.calling_status }}
    131129
    132130      - name: Get the commit message
    … …  
    141139              owner: context.repo.owner,
    142140              repo: context.repo.repo,
    143               ref: '${{ github.sha }}'
     141              ref: context.sha,
    144142            });
    145143            return commit_details.data.commit.message;
    … …  
    148146        id: commit-message
    149147        run: |
    150           COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g'
    151           ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || github.event.head_commit.message }}
    152           EOF
    153           )
    154           echo "commit_message_escaped=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
     148          # shellcheck disable=SC2016
     149          COMMIT_MESSAGE="$(echo "${COMMIT_MSG_RAW}" | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g')"
     150          echo "commit_message_escaped=${COMMIT_MESSAGE}" >> "$GITHUB_OUTPUT"
     151        env:
     152          COMMIT_MSG_RAW: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || github.event.head_commit.message }}
    155153
    156154      - name: Construct payload and store as an output
    157155        id: create-payload
    158         run: echo "payload={\"workflow_name\":\"${{ github.workflow }}\",\"ref_name\":\"${{ env.CURRENT_BRANCH }}\",\"run_url\":\"https://github.com/WordPress/wordpress-develop/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}" >> $GITHUB_OUTPUT
     156        run: |
     157          PAYLOAD="$( jq \
     158            -n \
     159            --arg workflow_name "${GITHUB_WORKFLOW}" \
     160            --arg ref_name "${CURRENT_BRANCH}" \
     161            --arg run_url "https://github.com/WordPress/wordpress-develop/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}" \
     162            --arg commit_message "${COMMIT_MSG}" \
     163            '{workflow_name: $workflow_name, ref_name: $ref_name, run_url: $run_url, commit_message: $commit_message}'
     164          )"
     165          echo "payload=$PAYLOAD" >> "$GITHUB_OUTPUT"
     166        env:
     167          COMMIT_MSG: ${{ steps.commit-message.outputs.commit_message_escaped }}
    159168
    160169  # Posts notifications when a workflow fails.
    161170  failure:
    162171    name: Failure notifications
     172    permissions: {}
    163173    runs-on: ubuntu-latest
    164174    timeout-minutes: 10
    … …  
    177187  fixed:
    178188    name: Fixed notifications
     189    permissions: {}
    179190    runs-on: ubuntu-latest
    180191    timeout-minutes: 10
    … …  
    193204  success:
    194205    name: Success notifications
     206    permissions: {}
    195207    runs-on: ubuntu-latest
    196208    timeout-minutes: 10
    … …  
    209221  cancelled:
    210222    name: Cancelled notifications
     223    permissions: {}
    211224    runs-on: ubuntu-latest
    212225    timeout-minutes: 10
Note: See TracChangeset for help on using the changeset viewer.