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

Harden CI #385

Merged
merged 22 commits into from
May 21, 2024
Merged

Harden CI #385

merged 22 commits into from
May 21, 2024

Conversation

louiseschmidtgen
Copy link
Contributor

@louiseschmidtgen louiseschmidtgen commented Apr 29, 2024

Description

This PR hardens CI by:

Note: I've also verified our chron-jobs work with my adjustemnts in this commit.

@louiseschmidtgen louiseschmidtgen changed the title WIP harden CI Harden CI Apr 29, 2024
@louiseschmidtgen louiseschmidtgen marked this pull request as ready for review April 29, 2024 13:51
@louiseschmidtgen louiseschmidtgen requested a review from a team as a code owner April 29, 2024 13:51
@bschimke95
Copy link
Contributor

I think the integration tests fail because of the limited permissions you give in the GH workflow (the tests pass locally). Try to give more permissions to the integration-tests workflow.

@louiseschmidtgen louiseschmidtgen marked this pull request as draft May 16, 2024 12:08
@louiseschmidtgen
Copy link
Contributor Author

Looks like there is a limitation of the step-security Harden Runner: Harden-Runner is not supported when job is run in a container as it needs sudo access on the Ubuntu VM to run. It can be used to monitor jobs that use containers to run steps. See here
Hence the error on Command here: '['lxc', 'shell', 'k8s-integration-be904b-11', '--', 'bash', '-c', 'k8s kubectl exec busybox -- nslookup kubernetes.default']'

@louiseschmidtgen
Copy link
Contributor Author

louiseschmidtgen commented May 16, 2024

Another note: the step-security Harden Runner only works for ubuntu. If we have tests on other OS we will run into trouble.

@louiseschmidtgen louiseschmidtgen marked this pull request as ready for review May 18, 2024 13:15
@louiseschmidtgen louiseschmidtgen requested a review from addyess May 18, 2024 13:22
Copy link
Contributor

@eaudetcobello eaudetcobello 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, couple of comments

.github/workflows/scorecard.yaml Outdated Show resolved Hide resolved
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Copy link
Contributor

@eaudetcobello eaudetcobello May 18, 2024

Choose a reason for hiding this comment

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

We use checkout@v4 (tag pinning) elsewhere, we should do the same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, just have to silence it too 👍🏼

runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
@@ -14,6 +20,10 @@
- { branch: main }

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
@@ -77,6 +90,10 @@
# Add branches to test here

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
name: Unit Tests & Code Quality
runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
@@ -86,6 +96,10 @@
runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/[email protected]

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: GitHub-owned GitHubAction not pinned by hash Click Remediation section below to solve this issue
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
uses: ossf/[email protected]

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: third-party GitHubAction not pinned by hash Click Remediation section below to solve this issue
- name: "Upload artifact"
uses: actions/upload-artifact@97a0fba1372883ab732affbe8f94b823f91727db # v3.pre.node20
uses: actions/upload-artifact@v3

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: GitHub-owned GitHubAction not pinned by hash Click Remediation section below to solve this issue
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
uses: github/codeql-action/[email protected]

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 0: GitHub-owned GitHubAction not pinned by hash Click Remediation section below to solve this issue
@@ -28,6 +31,8 @@
echo "strict=" >> $GITHUB_OUTPUT
fi
update:
permissions:
contents: write # for Git to git push

Check failure

Code scanning / Scorecard

Token-Permissions

score is 0: jobLevel 'contents' permission set to 'write' Remediation tip: Verify which permissions are needed and consider whether you can reduce them. Click Remediation section below for further remediation help
Copy link
Contributor

Package Line Rate
github.com/canonical/k8s/api/v1 35%
github.com/canonical/k8s/cmd/k8s-apiserver-proxy 0%
github.com/canonical/k8s/cmd/k8s 37%
github.com/canonical/k8s/cmd/k8sd 0%
github.com/canonical/k8s/cmd 0%
github.com/canonical/k8s/cmd/util 15%
github.com/canonical/k8s/pkg/client/dqlite 48%
github.com/canonical/k8s/pkg/client/helm 5%
github.com/canonical/k8s/pkg/client/helm/mock 100%
github.com/canonical/k8s/pkg/client/kubernetes 69%
github.com/canonical/k8s/pkg/k8s/client 0%
github.com/canonical/k8s/pkg/k8s/client/mock 8%
github.com/canonical/k8s/pkg/k8sd/api 14%
github.com/canonical/k8s/pkg/k8sd/api/impl 0%
github.com/canonical/k8s/pkg/k8sd/app 11%
github.com/canonical/k8s/pkg/k8sd/controllers 45%
github.com/canonical/k8s/pkg/k8sd/database 48%
github.com/canonical/k8s/pkg/k8sd/database/util 0%
github.com/canonical/k8s/pkg/k8sd/features/cilium 0%
github.com/canonical/k8s/pkg/k8sd/features/coredns 0%
github.com/canonical/k8s/pkg/k8sd/features 0%
github.com/canonical/k8s/pkg/k8sd/features/localpv 0%
github.com/canonical/k8s/pkg/k8sd/features/metrics-server 100%
github.com/canonical/k8s/pkg/k8sd/pki 52%
github.com/canonical/k8s/pkg/k8sd/setup 77%
github.com/canonical/k8s/pkg/k8sd/types 78%
github.com/canonical/k8s/pkg/proxy 6%
github.com/canonical/k8s/pkg/snap/mock 85%
github.com/canonical/k8s/pkg/snap 17%
github.com/canonical/k8s/pkg/snap/util 90%
github.com/canonical/k8s/pkg/utils 60%
github.com/canonical/k8s/pkg/utils/control 100%
github.com/canonical/k8s/pkg/utils/errors 100%
github.com/canonical/k8s/pkg/utils/experimental/snapdconfig 12%
github.com/canonical/k8s/pkg/utils/node 0%
github.com/canonical/k8s/pkg/utils/shims 0%
Summary 37% (2551 / 6900)

Copy link
Contributor

@bschimke95 bschimke95 left a comment

Choose a reason for hiding this comment

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

LGTM

@louiseschmidtgen louiseschmidtgen merged commit 52c2dbb into main May 21, 2024
13 checks passed
@louiseschmidtgen louiseschmidtgen deleted the KU-629/harden-CI branch May 21, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants