Skip to content
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

gha: keep trusted and untrusted paths separate, and simplify actions reference #30207

Merged
merged 2 commits into from
Jan 16, 2024

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 needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch needs-backport/1.14 This PR / issue needs backporting to the v1.14 branch needs-backport/1.15 This PR / issue needs backporting to the v1.15 branch labels Jan 12, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in v1.15.0-rc.1 Jan 12, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.14.6 Jan 12, 2024
@giorio94 giorio94 added the backport/author The backport will be carried out by the author of the PR. label Jan 12, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.13.11 Jan 12, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.12.18 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>
@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 This PR / issue needs backporting to the v1.15 branch labels Jan 22, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.15 in v1.15.0-rc.1 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 This PR / issue needs backporting to the v1.14 branch labels Jan 22, 2024
This was referenced Jan 22, 2024
@giorio94 giorio94 added backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. and removed needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch labels Jan 23, 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 backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. 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
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.15 to Backport done to v1.15 in v1.15.0-rc.1 Jan 29, 2024
@michi-covalent michi-covalent moved this from Needs backport from main to Backport done to v1.12 in 1.12.19 Feb 12, 2024
@michi-covalent michi-covalent moved this from Needs backport from main to Backport done to v1.13 in 1.13.12 Feb 13, 2024
@aanm aanm moved this from Needs backport from main to Backport done to v1.14 in 1.14.7 Apr 26, 2024
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
1.12.19
Backport done to v1.12
1.13.12
Backport done to v1.13
1.14.7
Backport done to v1.14
v1.15.0-rc.1
Backport done to v1.15
Development

Successfully merging this pull request may close these issues.

None yet

5 participants