Skip to content

Conversation

giorio94
Copy link
Member

@giorio94 giorio94 commented Jan 11, 2024

A few GHA workflows got recently modified to hardcode the repository and branch of the actions hosted locally (e.g., [1]). This was a security measure, as they are triggered after checking out the untrusted context (i.e., PR branch), and thus it would be possible for an external PR to inject malicious code.

Yet, at the same time, this change mostly defeats the smooth development process enabled by ariane (which automatically uses the workflow and context from the PR for trusted branches -- i.e., in cilium/cilium), requiring again to manually modify those references for testing purposes. Similarly, it also requires manual adaptations when changes are backported to stable branches, or to allow running them from forks, which are easy to overlook.

As an alternative solution, let's only check out the helm chart from the untrusted context in a separate directory, without overriding any of the trusted files (i.e., from the target branch) retrieved initially. This way, we are guaranteed that the local github actions are always trusted (as we are not overriding them, nor we are executing any script which could modify them), and can be invoked directly, without any additional constraint. A key aspect for this is that helm charts cannot execute arbitrary code in the client host.

Another difference, compared to the previous approach, is that now we also execute the ./contrib/scripts/kind.sh script from the trusted context (i.e., target branch) instead of the PR context. However, this file is effectively part of the workflow definition, and this change brings consistency with the rest of it. The same also applies for the Gateway API conformance tests.

As an additional security measure, let's also postpone the checkout of the context after the setup of the test environment.

[1]: 654d92f ("ci-e2e: Use lvh-kind in secure way")

Rework GHA workflows to checkout the untrusted context in a separate directory for increased separation

@giorio94 giorio94 added area/CI-improvement Topic or proposal to improve the Continuous Integration workflow release-note/ci This PR makes changes to the CI. labels Jan 11, 2024
@giorio94 giorio94 force-pushed the pr/giorio94/main/gha-dont-hardcode-actions-version branch from bafde25 to 5d4d7a1 Compare January 11, 2024 14:39
@giorio94 giorio94 changed the title gha: keep trusted and untrusted paths separate, and simplify actions ref gha: keep trusted and untrusted paths separate, and simplify actions reference Jan 11, 2024
@giorio94
Copy link
Member Author

/test

2 similar comments
@giorio94
Copy link
Member Author

/test

@giorio94
Copy link
Member Author

/test

@giorio94 giorio94 marked this pull request as ready for review January 12, 2024 07:52
@giorio94 giorio94 requested review from a team as code owners January 12, 2024 07:52
@giorio94 giorio94 added needs-backport/1.12 backport/author The backport will be carried out by the author of the PR. labels Jan 12, 2024
Copy link
Contributor

@thorn3r thorn3r left a comment

Choose a reason for hiding this comment

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

Nice work 👍

A few GHA workflows got recently modified to hardcode the repository and
branch of the actions hosted locally (e.g., [1]). This was a security
measure, as they are triggered after checking out the untrusted context
(i.e., PR branch), and thus it would be possible for an external PR to
inject malicious code.

Yet, at the same time, this change mostly defeats the smooth development
process enabled by ariane (which automatically uses the workflow and
context from the PR for trusted branches -- i.e., in cilium/cilium),
requiring again to manually modify those references for testing purposes.
Similarly, it also requires manual adaptations when changes are backported
to stable branches, or to allow running them from forks, which are easy
to overlook.

As an alternative solution, let's only check out the helm chart from the
untrusted context in a separate directory, without overriding any of
the trusted files (i.e., from the target branch) retrieved initially.
This way, we are guaranteed that the local github actions are always
trusted (as we are not overriding them, nor we are executing any script
which could modify them), and can be invoked directly, without any additional
constraint. A key aspect for this is that helm charts cannot execute
arbitrary code in the client host.

Another difference, compared to the previous approach, is that now we
also execute the `./contrib/scripts/kind.sh` script from the trusted
context (i.e., target branch) instead of the PR context. However, this
file is effectively part of the workflow definition, and this change
brings consistency with the rest of it. The same also applies for the
Gateway API conformance tests.

[1]: 654d92f ("ci-e2e: Use lvh-kind in secure way")

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
As an additional security measure, let's postpone the checkout of the
untrusted context after the setup of the test environment.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the pr/giorio94/main/gha-dont-hardcode-actions-version branch from 02cf32c to cd23fd5 Compare January 16, 2024 08:25
@giorio94
Copy link
Member Author

Rebased onto main to fix conflicts.

@giorio94
Copy link
Member Author

/test

@pchaigno pchaigno added this pull request to the merge queue Jan 16, 2024
Merged via the queue into main with commit 0c080f6 Jan 16, 2024
@pchaigno pchaigno deleted the pr/giorio94/main/gha-dont-hardcode-actions-version branch January 16, 2024 11:22
@giorio94 giorio94 removed the backport/author The backport will be carried out by the author of the PR. label Jan 22, 2024
@giorio94 giorio94 mentioned this pull request Jan 22, 2024
12 tasks
@giorio94 giorio94 added backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. and removed needs-backport/1.15 labels Jan 22, 2024
@giorio94 giorio94 mentioned this pull request Jan 22, 2024
11 tasks
@giorio94 giorio94 added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. and removed needs-backport/1.14 labels Jan 22, 2024
This was referenced Jan 22, 2024
@giorio94 giorio94 mentioned this pull request Jan 24, 2024
4 tasks
@github-actions github-actions bot added backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.12 The backport for Cilium 1.12.x for this PR is done. backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. and removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. backport-pending/1.12 labels Jan 25, 2024
@giorio94 giorio94 added backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. and removed backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. labels Jan 29, 2024
@@ -139,6 +139,7 @@ jobs:
uses: ./.github/actions/helm-default
with:
image-tag: ${{ inputs.SHA }}
chart-dir: ./untrusted/install/kubernetes/cilium
Copy link
Member

Choose a reason for hiding this comment

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

How does this pull from untrusted/ if the untrusted path is only checked out on line 224?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CI-improvement Topic or proposal to improve the Continuous Integration workflow backport-done/1.12 The backport for Cilium 1.12.x for this PR is done. backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.
Projects
No open projects
Status: Released
Status: Released
Status: Released
Development

Successfully merging this pull request may close these issues.

6 participants