Skip to content

Commit 200d467

Browse files
authored
Merge pull request #912 from sozercan/secure-repo
[StepSecurity] Apply security best practices
2 parents 3173ed1 + 19c6f4d commit 200d467

9 files changed

+278
-16
lines changed

Diff for: .github/dependabot.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
groups:
8+
actions-all:
9+
patterns:
10+
- "*"
11+
12+
- package-ecosystem: docker
13+
directory: /
14+
schedule:
15+
interval: weekly
16+
17+
- package-ecosystem: gomod
18+
directory: /
19+
schedule:
20+
interval: weekly
21+
ignore:
22+
- dependency-name: "*"
23+
update-types:
24+
- "version-update:semver-major"
25+
- "version-update:semver-minor"
26+
groups:
27+
k8s:
28+
patterns:
29+
- "k8s.io/*"
30+
- "sigs.k8s.io/*"
31+
32+
- package-ecosystem: docker
33+
directory: /pkg/util/nethealth
34+
schedule:
35+
interval: weekly
36+
37+
- package-ecosystem: gomod
38+
directory: /test
39+
schedule:
40+
interval: weekly
41+
ignore:
42+
- dependency-name: "*"
43+
update-types:
44+
- "version-update:semver-major"
45+
- "version-update:semver-minor"
46+
groups:
47+
k8s:
48+
patterns:
49+
- "k8s.io/*"
50+
- "sigs.k8s.io/*"
51+
52+
- package-ecosystem: docker
53+
directory: /test/kernel_log_generator
54+
schedule:
55+
interval: weekly

Diff for: .github/workflows/codeql.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: ["master"]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: ["master"]
20+
schedule:
21+
- cron: "0 0 * * 1"
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
analyze:
28+
name: Analyze
29+
runs-on: ubuntu-latest
30+
permissions:
31+
actions: read
32+
contents: read
33+
security-events: write
34+
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
language: ["go"]
39+
# CodeQL supports [ $supported-codeql-languages ]
40+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41+
42+
steps:
43+
- name: Harden Runner
44+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
45+
with:
46+
egress-policy: audit
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@d05fceb0450a68babd9a7597626abef20f03dad6 # v2.25.5
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
60+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
61+
# If this step fails, then you should remove it and run the build manually (see below)
62+
- name: Autobuild
63+
uses: github/codeql-action/autobuild@d05fceb0450a68babd9a7597626abef20f03dad6 # v2.25.5
64+
65+
# ℹ️ Command-line programs to run using the OS shell.
66+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67+
68+
# If the Autobuild fails above, remove it and uncomment the following three lines.
69+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70+
71+
# - run: |
72+
# echo "Run, Build Application using script"
73+
# ./location_of_script_within_repo/buildscript.sh
74+
75+
- name: Perform CodeQL Analysis
76+
uses: github/codeql-action/analyze@d05fceb0450a68babd9a7597626abef20f03dad6 # v2.25.5
77+
with:
78+
category: "/language:${{matrix.language}}"

Diff for: .github/workflows/dependency-review.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required,
6+
# PRs introducing known-vulnerable packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
name: 'Dependency Review'
10+
on: [pull_request]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
dependency-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Harden Runner
20+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
21+
with:
22+
egress-policy: audit
23+
24+
- name: 'Checkout Repository'
25+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
26+
- name: 'Dependency Review'
27+
uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2.5.1

Diff for: .github/workflows/scorecards.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This workflow uses actions that are not certified by GitHub. They are provided
2+
# by a third-party and are governed by separate terms of service, privacy
3+
# policy, and support documentation.
4+
5+
name: Scorecard supply-chain security
6+
on:
7+
# For Branch-Protection check. Only the default branch is supported. See
8+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
9+
branch_protection_rule:
10+
# To guarantee Maintained check is occasionally updated. See
11+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
12+
schedule:
13+
- cron: '20 7 * * 2'
14+
push:
15+
branches: ["master"]
16+
17+
# Declare default permissions as read only.
18+
permissions: read-all
19+
20+
jobs:
21+
analysis:
22+
name: Scorecard analysis
23+
runs-on: ubuntu-latest
24+
permissions:
25+
# Needed to upload the results to code-scanning dashboard.
26+
security-events: write
27+
# Needed to publish results and get a badge (see publish_results below).
28+
id-token: write
29+
contents: read
30+
actions: read
31+
32+
steps:
33+
- name: Harden Runner
34+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
35+
with:
36+
egress-policy: audit
37+
38+
- name: "Checkout code"
39+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
40+
with:
41+
persist-credentials: false
42+
43+
- name: "Run analysis"
44+
uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6
45+
with:
46+
results_file: results.sarif
47+
results_format: sarif
48+
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
49+
# - you want to enable the Branch-Protection check on a *public* repository, or
50+
# - you are installing Scorecards on a *private* repository
51+
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
52+
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
53+
54+
# Public repositories:
55+
# - Publish results to OpenSSF REST API for easy access by consumers
56+
# - Allows the repository to include the Scorecard badge.
57+
# - See https://github.com/ossf/scorecard-action#publishing-results.
58+
# For private repositories:
59+
# - `publish_results` will always be set to `false`, regardless
60+
# of the value entered here.
61+
publish_results: true
62+
63+
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
64+
# format to the repository Actions tab.
65+
- name: "Upload artifact"
66+
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
67+
with:
68+
name: SARIF file
69+
path: results.sarif
70+
retention-days: 5
71+
72+
# Upload the results to GitHub's code scanning dashboard.
73+
- name: "Upload to code-scanning"
74+
uses: github/codeql-action/upload-sarif@d05fceb0450a68babd9a7597626abef20f03dad6 # v2.25.5
75+
with:
76+
sarif_file: results.sarif

Diff for: .github/workflows/tag-release.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ on:
77
paths:
88
- version.txt
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
tag:
1215
if: ${{ github.repository == 'kubernetes/node-problem-detector' }}
1316
runs-on: ubuntu-latest
1417
permissions:
1518
contents: write
1619
steps:
17-
- uses: actions/checkout@v4
20+
- name: Harden Runner
21+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
22+
with:
23+
egress-policy: audit
24+
25+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
1826
with:
1927
fetch-depth: 0
2028
- run: /usr/bin/git config --global user.email [email protected]

Diff for: .github/workflows/update-deps.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ jobs:
1717
if: ${{ github.repository == 'kubernetes/node-problem-detector' }}
1818
runs-on: ubuntu-22.04
1919
steps:
20-
- uses: actions/setup-go@v5
20+
- name: Harden Runner
21+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
22+
with:
23+
egress-policy: audit
24+
25+
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
2126
with:
2227
go-version: '1.22.3'
23-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
2429
- name: Update Dependencies
2530
id: update_deps
2631
run: |
@@ -30,7 +35,7 @@ jobs:
3035
echo 'EOF' >> $GITHUB_OUTPUT
3136
- name: Create PR
3237
if: ${{ steps.update_deps.outputs.changes != '' }}
33-
uses: peter-evans/create-pull-request@v6
38+
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5
3439
with:
3540
title: 'Update dependencies'
3641
commit-message: Update dependencies

Diff for: .pre-commit-config.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/gitleaks/gitleaks
3+
rev: v8.16.3
4+
hooks:
5+
- id: gitleaks
6+
- repo: https://github.com/golangci/golangci-lint
7+
rev: v1.52.2
8+
hooks:
9+
- id: golangci-lint
10+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
11+
rev: 3.0.0
12+
hooks:
13+
- id: shellcheck
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v4.4.0
16+
hooks:
17+
- id: end-of-file-fixer
18+
- id: trailing-whitespace

Diff for: Dockerfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
ARG BASEIMAGE
1514

1615
# "builder-base" can be overriden using dockerb buildx's --build-context flag,
17-
# by users who want to use a different images for the builder. E.g. if you need to use an older OS
16+
# by users who want to use a different images for the builder. E.g. if you need to use an older OS
1817
# to avoid dependencies on very recent glibc versions.
1918
# E.g. of the param: --build-context builder-base=docker-image://golang:<something>@sha256:<something>
2019
# Must override builder-base, not builder, since the latter is referred to later in the file and so must not be
21-
# directly replaced. See here, and note that "stage" parameter mentioned there has been renamed to
20+
# directly replaced. See here, and note that "stage" parameter mentioned there has been renamed to
2221
# "build-context": https://github.com/docker/buildx/pull/904#issuecomment-1005871838
23-
FROM golang:1.22.3-bookworm as builder-base
22+
FROM golang:1.22-bookworm@sha256:5c56bd47228dd572d8a82971cf1f946cd8bb1862a8ec6dc9f3d387cc94136976 as builder-base
2423
FROM builder-base as builder
2524
LABEL maintainer="Andy Xie <[email protected]>"
2625

@@ -36,8 +35,7 @@ COPY . /gopath/src/k8s.io/node-problem-detector/
3635
WORKDIR /gopath/src/k8s.io/node-problem-detector
3736
RUN GOARCH=${TARGETARCH} make bin/node-problem-detector bin/health-checker bin/log-counter
3837

39-
ARG BASEIMAGE
40-
FROM --platform=${TARGETPLATFORM} ${BASEIMAGE}
38+
FROM --platform=${TARGETPLATFORM} registry.k8s.io/build-image/debian-base:bookworm-v1.0.4@sha256:b30608f5a81f8ba99b287322d0bfb77ec506adcce396147aa4a59699d69be3e0 as base
4139

4240
LABEL maintainer="Random Liu <[email protected]>"
4341

Diff for: Makefile

+3-6
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ else ifeq ($(shell go env GOHOSTOS), windows)
7373
ENABLE_JOURNALD=0
7474
endif
7575

76-
# Set default base image to Debian 12 (Bookworm)
77-
BASEIMAGE:=registry.k8s.io/build-image/debian-base:bookworm-v1.0.3
78-
7976
# Disable cgo by default to make the binary statically linked.
8077
CGO_ENABLED:=0
8178

@@ -239,7 +236,7 @@ build-binaries: $(ALL_BINARIES)
239236

240237
build-container: clean Dockerfile
241238
docker buildx create --platform $(DOCKER_PLATFORMS) --use
242-
docker buildx build --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
239+
docker buildx build --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
243240

244241
$(TARBALL): ./bin/node-problem-detector ./bin/log-counter ./bin/health-checker ./test/bin/problem-maker
245242
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
@@ -251,7 +248,7 @@ build-tar: $(TARBALL) $(ALL_TARBALLS)
251248
build: build-container build-tar
252249

253250
docker-builder:
254-
docker build -t npd-builder . --target=builder --build-arg BASEIMAGE=$(BASEIMAGE)
251+
docker build -t npd-builder . --target=builder
255252

256253
build-in-docker: clean docker-builder
257254
docker run \
@@ -264,7 +261,7 @@ ifneq (,$(findstring gcr.io,$(REGISTRY)))
264261
gcloud auth configure-docker
265262
endif
266263
# Build should be cached from build-container
267-
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
264+
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
268265

269266
push-tar: build-tar
270267
gsutil cp $(TARBALL) $(UPLOAD_PATH)/node-problem-detector/

0 commit comments

Comments
 (0)