diff --git a/.github/renovate.json b/.github/renovate.json index 941e06b6..156955ec 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,27 +1,148 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["config:recommended"], + "extends": [ + "config:best-practices", + ":gitSignOff", + ":rebaseStalePrs", + "docker:disableMajor", + "default:pinDigestsDisabled", + "helpers:pinGitHubActionDigests" + ], + "labels": [ + "kind/dependency upgrade" + ], "baseBranchPatterns": ["main", "/^release-.*/"], + "constraints": { + "go": "1.26" + }, + "postUpdateOptions": [ + "gomodTidy" + ], "packageRules": [ { - "description": "Disable all updates on release branches by default", + "description": "Disable major updates on release branches", "matchBaseBranches": ["/^release-.*/"], + "matchUpdateTypes": ["major"], "enabled": false }, { - "description": "Re-enable only patch updates on release branches", - "matchBaseBranches": ["/^release-.*/"], - "matchUpdateTypes": ["patch"], - "enabled": true + "enabled": false, + "groupName": "all minor dependencies", + "groupSlug": "all-minor", + "matchPackageNames": [ + "*" + ], + "matchUpdateTypes": [ + "minor" + ] }, { - "description": "Re-enable digest updates for container images on release branches", - "matchBaseBranches": ["/^release-.*/"], - "matchManagers": ["dockerfile"], - "matchUpdateTypes": ["digest"], - "enabled": true + "groupName": "all patch dependencies", + "groupSlug": "all-patch", + "matchPackageNames": [ + "*" + ], + "matchUpdateTypes": [ + "patch" + ] + }, + { + "description": "Do NOT generate PRs to pin or apply digests to dockerfiles", + "enabled": false, + "matchDatasources": [ + "docker" + ], + "matchUpdateTypes": [ + "pin", + "pinDigest", + "digest" + ], + "automerge": false + }, + { + "description": "Do generate PRs for minor dockerfile updates", + "enabled": true, + "matchDatasources": [ + "docker" + ], + "matchUpdateTypes": [ + "minor" + ], + "matchBaseBranches": [ + "main", + "/^release-\\d+\\..*/" + ], + "automerge": false + }, + { + "description": "Do automerge patch updates to dockerfiles", + "enabled": true, + "matchDatasources": [ + "docker" + ], + "matchUpdateTypes": [ + "patch" + ], + "additionalBranchPrefix": "dockerfile ", + "groupName": "All dockerfile images", + "automerge": true, + "pinDigests": false + }, + { + "description": "Do NOT generate PRs for major go dependency updates", + "enabled": false, + "matchDatasources": [ + "go" + ], + "matchUpdateTypes": [ + "major" + ], + "automerge": false + }, + { + "description": "Do automerge go dependency patch updates, except for versions starting with 0", + "enabled": true, + "matchDatasources": [ + "go" + ], + "matchUpdateTypes": [ + "patch" + ], + "matchCurrentVersion": "!/^0/", + "automerge": true + }, + { + "description": "Do generate PRs for golang version patch bumps, keeping x.yy version the same", + "enabled": true, + "matchDatasources": [ + "golang-version" + ], + "matchUpdateTypes": [ + "patch" + ], + "automerge": false + }, + { + "description": "Do automerge and pin actions in GH workflows, except for versions starting with 0", + "enabled": true, + "matchDatasources": [ + "github-runners" + ], + "matchUpdateTypes": [ + "minor", + "patch" + ], + "matchCurrentVersion": "!/^0/", + "automerge": true } ], + "vulnerabilityAlerts": { + "enabled": true, + "addLabels": [ + "kind/security" + ] + }, + "osvVulnerabilityAlerts": true, "customManagers": [ { "customType": "regex", diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 14fe7a96..14334261 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -66,6 +66,12 @@ jobs: with: version: v2.14.0 + - name: Run Gosec Security Scanner + if: steps.changed-files.outputs.any_changed == 'true' + run: make gosec + # Gosec results are available in workflow logs + # SonarCloud provides Code Scanning integration in the Security tab + e2e-tests: name: E2E Tests runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 641c2afd..6e158eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ rhdh-must-gather-output.tar.gz *.test cover.out +# Security scanning reports +gosec.sarif + diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 00000000..2dce3c3c --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1,14 @@ +# add test files to analysis scope +sonar.sources = . +sonar.tests= . + +# Include test subdirectories in test scope +sonar.test.inclusions = tests/**/*, **/*_test.go + +# Exclude test subdirectories from source scope. +# Also drop Dockerfiles: docker:S8431 flags FROM image:tag@sha256:... +# which is the pinDigest form Konflux and "Validate Image Digests" require. +# Dockerfile parsers reject NOSONAR, and sonar.issue.ignore.multicriteria is +# ignored by SonarCloud Automatic Analysis. +# sonar.exclusions is honoured. Hadolint still lints these files. +sonar.exclusions = tests/**/*, **/*_test.go, Containerfile, .rhdh/docker/Containerfile diff --git a/Makefile b/Makefile index d10dcbdc..56616c36 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,17 @@ BUILD_ARGS ?= LABELS ?= BASE_COLLECTION_PATH ?= ./out +# Tool Binaries +LOCALBIN ?= $(shell pwd)/bin +GOSEC ?= $(LOCALBIN)/gosec + +# Tool Versions +GOSEC_VERSION ?= v2.29.0 + +# Gosec options - default format is sarif so we can integrate with Github code scanning +GOSEC_FMT ?= sarif # for other options, see https://github.com/securego/gosec#output-formats +GOSEC_OUTPUT_FILE ?= gosec.sarif + # Go configuration GO ?= go GO_MODULE := github.com/redhat-developer/rhdh-must-gather @@ -86,6 +97,11 @@ test: ## Run unit tests lint: ## Run linter (golangci-lint) golangci-lint run ./... +.PHONY: gosec +gosec: addgosec ## Run the gosec scanner for non-test files in this repo + # we let the report content trigger a failure using the GitHub Security features. + $(GOSEC) -no-fail -exclude-generated -fmt $(GOSEC_FMT) -out $(GOSEC_OUTPUT_FILE) ./... + ##@ Build .PHONY: image-build @@ -147,6 +163,32 @@ clean: clean-out ## Remove built images, binary, and test output -rm -rf "$(TEST_RESULTS_DIR)" @echo "Cleanup complete" +##@ Dependencies + +.PHONY: addgosec +addgosec: $(GOSEC) ## Download gosec locally if necessary. +$(GOSEC): $(LOCALBIN) + $(call go-install-tool,$(GOSEC),github.com/securego/gosec/v2/cmd/gosec,$(GOSEC_VERSION)) + +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist +# $1 - target path with name of binary (ideally with version) +# $2 - package url which can be installed +# $3 - specific version of package +define go-install-tool +@[ -f "$(1)-$(3)" ] || { \ +set -e; \ +package=$(2)@$(3) ;\ +echo "Downloading $${package}" ;\ +rm -f $(1) || true ;\ +GOBIN=$(LOCALBIN) go install $${package} ;\ +mv $(1) $(1)-$(3) ;\ +} ;\ +ln -sf $(1)-$(3) $(1) +endef + ##@ General .PHONY: help