Skip to content

Commit

Permalink
ci: standardize / clarify comments around privileged checkouts
Browse files Browse the repository at this point in the history
Workflows running on PRs and based on `pull_request_target` and
`workflow_dispatch` are executed in a privileged context (e.g. access to
repository secrets), hence we take extra care not to execute anything
coming from the PR directly in the context of the workflow steps, but
instead always in a sandboxed or controlled environment (e.g. a managed
Kubernetes cluster or LVH VMs).

This commit standardizes and adds some context around which checkouts
are trusted and which are not, and where to be start being careful with
what the workflow steps are doing.

Signed-off-by: Nicolas Busseneau <nicolas@isovalent.com>
  • Loading branch information
nbusseneau committed Aug 1, 2023
1 parent be2b725 commit 953f3ad
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 57 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-images-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
environment: release-base-images
runs-on: ubuntu-20.04
steps:
- name: Checkout main branch to access local actions
- name: Checkout default branch (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ github.event.repository.default_branch }}
Expand All @@ -46,7 +46,9 @@ jobs:
- name: Install Cosign
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1

- name: Checkout Source Code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
persist-credentials: false
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build-images-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
dockerfile: ./images/cilium-docker-plugin/Dockerfile

steps:
- name: Checkout main branch to access local actions
- name: Checkout default branch (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ github.event.repository.default_branch }}
Expand Down Expand Up @@ -94,7 +94,9 @@ jobs:
echo tag=${{ github.sha }} >> $GITHUB_OUTPUT
fi
- name: Checkout Source Code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
persist-credentials: false
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/conformance-aks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -220,8 +220,9 @@ jobs:
until docker manifest inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/$image:${{ steps.vars.outputs.sha }} &> /dev/null; do sleep 45s; done
done
# Checkout source code to install Cilium using local Helm chart.
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/conformance-aws-cni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -219,8 +219,9 @@ jobs:
until docker manifest inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/$image:${{ steps.vars.outputs.sha }} &> /dev/null; do sleep 45s; done
done
# Checkout source code to install Cilium using local Helm chart.
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/conformance-clustermesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:
cm-auth-mode-2: 'cluster'

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -355,13 +355,9 @@ jobs:
until docker manifest inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/$image:${{ steps.vars.outputs.sha }} &> /dev/null; do sleep 45s; done
done
# We need to checkout the SHA to retrieve the Helm chart
# Warning: since this is a privileged workflow, we should be careful NOT to
# use anything coming from an external contributor in a privileged
# environment. Here it's fine because we pass the Helm chart to be installed
# in a Kubernetes cluster, so it won't have access to the privileged
# environment from there.
- name: Checkout SHA
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/conformance-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:

timeout-minutes: 60
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -288,7 +288,9 @@ jobs:
echo junit_type="${JUNIT}" >> $GITHUB_OUTPUT
echo sha=${SHA} >> $GITHUB_OUTPUT
- name: Checkout pull request for Helm chart
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/conformance-eks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -212,8 +212,9 @@ jobs:
until docker manifest inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/$image:${{ steps.vars.outputs.sha }} &> /dev/null; do sleep 45s; done
done
# Checkout source code to install Cilium using local Helm chart.
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/conformance-externalworkloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -170,7 +170,9 @@ jobs:
echo sha=${SHA} >> $GITHUB_OUTPUT
echo owner=${OWNER} >> $GITHUB_OUTPUT
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/conformance-gateway-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- crd-channel: experimental
- crd-channel: standard
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -137,7 +137,9 @@ jobs:
echo skipped_tests=${SKIPPED_TESTS} >> $GITHUB_OUTPUT
echo supported_features=${SUPPORTED_FEATURES} >> $GITHUB_OUTPUT
- name: Checkout
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/conformance-ginkgo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ jobs:
# If any of these steps are modified, please update the copy of these
# steps further down under the 'setup-and-test' jobs.

- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.SHA || github.sha }}
Expand Down Expand Up @@ -150,7 +152,7 @@ jobs:
name: Build Ginkgo E2E
timeout-minutes: 30
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand All @@ -174,7 +176,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -234,7 +236,7 @@ jobs:
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand All @@ -243,7 +245,9 @@ jobs:
- name: Set Environment Variables
uses: ./.github/actions/set-env-variables

- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.SHA || github.sha }}
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/conformance-gke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -172,8 +172,9 @@ jobs:
echo sha=${SHA} >> $GITHUB_OUTPUT
echo owner=${OWNER} >> $GITHUB_OUTPUT
# Checkout source code to install Cilium using local Helm chart.
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/conformance-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
default-ingress-controller: true

steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -142,7 +142,9 @@ jobs:
--helm-set=extraConfig.bpf-lb-acceleration=${{ matrix.bpf-lb-acceleration }}"
echo cilium_install_defaults=${CILIUM_INSTALL_DEFAULTS} >> $GITHUB_OUTPUT
- name: Checkout
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/conformance-ipsec-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:

timeout-minutes: 60
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand Down Expand Up @@ -213,7 +213,9 @@ jobs:
echo junit_type="${JUNIT}" >> $GITHUB_OUTPUT
echo sha=${SHA} >> $GITHUB_OUTPUT
- name: Checkout pull request for Helm chart
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/conformance-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
runs-on: ubuntu-latest
name: Build Ginkgo Runtime
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand All @@ -88,8 +88,9 @@ jobs:
echo "sha=${SHA}" >> $GITHUB_OUTPUT
# Checkout source code to use the local `test` directory
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down Expand Up @@ -221,7 +222,7 @@ jobs:

timeout-minutes: 20
steps:
- name: Checkout context ref
- name: Checkout context ref (trusted)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ inputs.context-ref || github.sha }}
Expand All @@ -241,8 +242,9 @@ jobs:
echo "sha=${SHA}" >> $GITHUB_OUTPUT
# Checkout source code to use the local `test` directory
- name: Checkout code
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: ${{ steps.vars.outputs.sha }}
Expand Down

0 comments on commit 953f3ad

Please sign in to comment.