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

chore(deps): update dependency go to v1.23.0 #353

Merged
merged 16 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "1.21"
go-version: "1.23"
- run: make unit-tests
- name: Upload unit-tests coverage to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
Expand All @@ -35,8 +35,8 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "1.21"
go-version: "1.23"
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: v1.59.1
version: v1.60.1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Golang
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "1.21"
go-version: "1.23"

- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand Down
27 changes: 14 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 3m

build-tags:
- testing

# This file contains only configs which differ from defaults.
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
Expand Down Expand Up @@ -166,7 +167,7 @@ linters-settings:
nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [ funlen, gocognit, lll ]
allow-no-explanation: [funlen, gocognit, lll]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
Expand Down Expand Up @@ -209,7 +210,6 @@ linters-settings:
# Default: false
all: true


linters:
disable-all: true
enable:
Expand All @@ -234,7 +234,6 @@ linters:
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
jvanz marked this conversation as resolved.
Show resolved Hide resolved
- fatcontext # detects nested contexts in loops
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
Expand Down Expand Up @@ -323,26 +322,26 @@ linters:
#- tagliatelle # checks the struct tags
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines

############################################################################
# Kubewarden linter customization
# The following linters are disabled because they does not make sense for
# the Kubewarden
# the Kubewarden
############################################################################

# We disable the testpackage linter because we have tests which is not
# black boxed and that will not cause issues for us for now.
# - testpackage # makes you use a separate _test package

# We disable the lll linter because we have long lines in many places and splitting them
# will not make the code more readable.
# - lll
# - lll

# We use replace directives in go.mod to replace some dependencies. Dependabot updates it over time.
# - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
# Init functions are used in many places in the project. For instance, to registry types in the
# scheme. This is a common usage in kubebuilder projects

# Init functions are used in many places in the project. For instance, to registry types in the
# scheme. This is a common usage in kubebuilder projects
# - gochecknoinits # checks that no init functions are present in Go code

issues:
Expand All @@ -353,9 +352,11 @@ issues:

exclude-rules:
- source: "(noinspection|TODO)"
linters: [ godot ]
linters: [godot]
- source: "//noinspection"
linters: [ gocritic ]
linters: [gocritic]
- text: 'shadow: declaration of "(err|ctx)" shadows declaration at'
linters: [govet]
- path: "_test\\.go"
linters:
- bodyclose
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the audit-scanner binary
FROM golang:1.22 as builder
FROM golang:1.23 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(abspath $(ROOT_DIR)/bin)
IMG ?= audit-scanner:latest

GOLANGCI_LINT_VER := v1.59.1
GOLANGCI_LINT_VER := v1.60.1
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(BIN_DIR)/$(GOLANGCI_LINT_BIN)

Expand Down
214 changes: 104 additions & 110 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,109 +27,120 @@
defaultPageSize = 100
)

// log level
var level logconfig.Level

// print result of scan as JSON to stdout
var outputScan bool

// list of namespaces to be skipped from scan
var skippedNs []string

// skip SSL cert validation when connecting to PolicyServers endpoints
var insecureSSL bool

// disable storing the results in the k8s cluster
var disableStore bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "audit-scanner",
Short: "Reports evaluation of existing Kubernetes resources with your already deployed Kubewarden policies",
Long: `Scans resources in your kubernetes cluster with your already deployed Kubewarden policies.
//nolint:gocognit
func NewRootCommand() *cobra.Command {
var (
level logconfig.Level // log level.
outputScan bool // print result of scan as JSON to stdout.
skippedNs []string // list of namespaces to be skipped from scan.
insecureSSL bool // skip SSL cert validation when connecting to PolicyServers endpoints.
disableStore bool // disable storing the results in the k8s cluster.
)

Check warning on line 38 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L31-L38

Added lines #L31 - L38 were not covered by tests

// rootCmd represents the base command when called without any subcommands.
rootCmd := &cobra.Command{
Use: "audit-scanner",
Short: "Reports evaluation of existing Kubernetes resources with your already deployed Kubewarden policies",
Long: `Scans resources in your kubernetes cluster with your already deployed Kubewarden policies.

Check warning on line 44 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L41-L44

Added lines #L41 - L44 were not covered by tests
Each namespace will have a PolicyReport with the outcome of the scan for resources within this namespace.
There will be a ClusterPolicyReport with results for cluster-wide resources.`,

RunE: func(cmd *cobra.Command, _ []string) error {
level.SetZeroLogLevel()
namespace, err := cmd.Flags().GetString("namespace")
if err != nil {
return err
}
kubewardenNamespace, err := cmd.Flags().GetString("kubewarden-namespace")
if err != nil {
return err
}
clusterWide, err := cmd.Flags().GetBool("cluster")
if err != nil {
return err
}
policyServerURL, err := cmd.Flags().GetString("policy-server-url")
if err != nil {
return err
}
caCertFile, err := cmd.Flags().GetString("extra-ca")
if err != nil {
return err
}
parallelNamespacesAudits, err := cmd.Flags().GetInt("parallel-namespaces")
if err != nil {
return err
}
parallelResourcesAudits, err := cmd.Flags().GetInt("parallel-resources")
if err != nil {
return err
}
parallelPoliciesAudit, err := cmd.Flags().GetInt("parallel-policies")
if err != nil {
return err
}
pageSize, err := cmd.Flags().GetInt("page-size")
if err != nil {
return err
}

config := ctrl.GetConfigOrDie()
dynamicClient := dynamic.NewForConfigOrDie(config)
clientset := kubernetes.NewForConfigOrDie(config)
RunE: func(cmd *cobra.Command, _ []string) error {
level.SetZeroLogLevel()
namespace, err := cmd.Flags().GetString("namespace")
if err != nil {
return err

Check warning on line 52 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L48-L52

Added lines #L48 - L52 were not covered by tests
}
kubewardenNamespace, err := cmd.Flags().GetString("kubewarden-namespace")
if err != nil {
return err

Check warning on line 56 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L54-L56

Added lines #L54 - L56 were not covered by tests
}
clusterWide, err := cmd.Flags().GetBool("cluster")
if err != nil {
return err

Check warning on line 60 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L58-L60

Added lines #L58 - L60 were not covered by tests
}
policyServerURL, err := cmd.Flags().GetString("policy-server-url")
if err != nil {
return err

Check warning on line 64 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L62-L64

Added lines #L62 - L64 were not covered by tests
}
caCertFile, err := cmd.Flags().GetString("extra-ca")
if err != nil {
return err

Check warning on line 68 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L66-L68

Added lines #L66 - L68 were not covered by tests
}
parallelNamespacesAudits, err := cmd.Flags().GetInt("parallel-namespaces")
if err != nil {
return err

Check warning on line 72 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L70-L72

Added lines #L70 - L72 were not covered by tests
}
parallelResourcesAudits, err := cmd.Flags().GetInt("parallel-resources")
if err != nil {
return err

Check warning on line 76 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L74-L76

Added lines #L74 - L76 were not covered by tests
}
parallelPoliciesAudit, err := cmd.Flags().GetInt("parallel-policies")
if err != nil {
return err

Check warning on line 80 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L78-L80

Added lines #L78 - L80 were not covered by tests
}
pageSize, err := cmd.Flags().GetInt("page-size")
if err != nil {
return err

Check warning on line 84 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L82-L84

Added lines #L82 - L84 were not covered by tests
}

config := ctrl.GetConfigOrDie()
dynamicClient := dynamic.NewForConfigOrDie(config)
clientset := kubernetes.NewForConfigOrDie(config)

Check warning on line 89 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L87-L89

Added lines #L87 - L89 were not covered by tests

auditScheme, err := scheme.NewScheme()
if err != nil {
return err

Check warning on line 93 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L91-L93

Added lines #L91 - L93 were not covered by tests
}
client, err := client.New(config, client.Options{Scheme: auditScheme})
if err != nil {
return err

Check warning on line 97 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L95-L97

Added lines #L95 - L97 were not covered by tests
}
policiesClient, err := policies.NewClient(client, kubewardenNamespace, policyServerURL)
if err != nil {
return err

Check warning on line 101 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L99-L101

Added lines #L99 - L101 were not covered by tests
}
k8sClient, err := k8s.NewClient(dynamicClient, clientset, kubewardenNamespace, skippedNs, int64(pageSize))
if err != nil {
return err

Check warning on line 105 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L103-L105

Added lines #L103 - L105 were not covered by tests
}
policyReportStore := report.NewPolicyReportStore(client)
scanner, err := scanner.NewScanner(policiesClient, k8sClient, policyReportStore, outputScan, disableStore, insecureSSL, caCertFile,
parallelNamespacesAudits,
parallelResourcesAudits,
parallelPoliciesAudit)
if err != nil {
return err

Check warning on line 113 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L107-L113

Added lines #L107 - L113 were not covered by tests
}
return startScanner(namespace, clusterWide, scanner)

Check warning on line 115 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L115

Added line #L115 was not covered by tests
},
}

auditScheme, err := scheme.NewScheme()
if err != nil {
return err
}
client, err := client.New(config, client.Options{Scheme: auditScheme})
if err != nil {
return err
}
policiesClient, err := policies.NewClient(client, kubewardenNamespace, policyServerURL)
if err != nil {
return err
}
k8sClient, err := k8s.NewClient(dynamicClient, clientset, kubewardenNamespace, skippedNs, int64(pageSize))
if err != nil {
return err
}
policyReportStore := report.NewPolicyReportStore(client)
// make sure we always get json formatted errors, even for flag errors
rootCmd.SilenceErrors = true
rootCmd.SilenceUsage = true

Check warning on line 121 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L120-L121

Added lines #L120 - L121 were not covered by tests

scanner, err := scanner.NewScanner(policiesClient, k8sClient, policyReportStore, outputScan, disableStore, insecureSSL, caCertFile,
parallelNamespacesAudits,
parallelResourcesAudits,
parallelPoliciesAudit)
if err != nil {
return err
}
rootCmd.Flags().StringP("namespace", "n", "", "namespace to be evaluated")
rootCmd.Flags().BoolP("cluster", "c", false, "scan cluster wide resources")
rootCmd.Flags().StringP("kubewarden-namespace", "k", defaultKubewardenNamespace, "namespace where the Kubewarden components (e.g. PolicyServer) are installed (required)")
rootCmd.Flags().StringP("policy-server-url", "u", "", "URI to the PolicyServers the Audit Scanner will query. Example: https://localhost:3000. Useful for out-of-cluster debugging")
rootCmd.Flags().VarP(&level, "loglevel", "l", fmt.Sprintf("level of the logs. Supported values are: %v", logconfig.GetSupportedValues()))
rootCmd.Flags().BoolVarP(&outputScan, "output-scan", "o", false, "print result of scan in JSON to stdout")
rootCmd.Flags().StringSliceVarP(&skippedNs, "ignore-namespaces", "i", nil, "comma separated list of namespace names to be skipped from scan. This flag can be repeated")
rootCmd.Flags().BoolVar(&insecureSSL, "insecure-ssl", false, "skip SSL cert validation when connecting to PolicyServers endpoints. Useful for development")
rootCmd.Flags().StringP("extra-ca", "f", "", "File path to CA cert in PEM format of PolicyServer endpoints")
rootCmd.Flags().BoolVar(&disableStore, "disable-store", false, "disable storing the results in the k8s cluster")
rootCmd.Flags().IntP("parallel-namespaces", "", defaultParallelNamespaces, "number of Namespaces to scan in parallel")
rootCmd.Flags().IntP("parallel-resources", "", defaultParallelResources, "number of resources to scan in parallel")
rootCmd.Flags().IntP("parallel-policies", "", defaultParallelPolicies, "number of policies to evaluate for a given resource in parallel")
rootCmd.Flags().IntP("page-size", "", defaultPageSize, "number of resources to fetch from the Kubernetes API server when paginating")

Check warning on line 136 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L123-L136

Added lines #L123 - L136 were not covered by tests

return startScanner(namespace, clusterWide, scanner)
},
return rootCmd

Check warning on line 138 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L138

Added line #L138 was not covered by tests
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
// make sure we always get json formatted errors, even for flag errors
rootCmd.SilenceErrors = true
rootCmd.SilenceUsage = true

func Execute(rootCmd *cobra.Command) {

Check warning on line 143 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L143

Added line #L143 was not covered by tests
if err := rootCmd.Execute(); err != nil {
log.Fatal().Err(err).Msg("Error on cmd.Execute()")
}
Expand Down Expand Up @@ -158,20 +169,3 @@
}
return scanner.ScanAllNamespaces(ctx, runUID)
}

func init() {
rootCmd.Flags().StringP("namespace", "n", "", "namespace to be evaluated")
rootCmd.Flags().BoolP("cluster", "c", false, "scan cluster wide resources")
rootCmd.Flags().StringP("kubewarden-namespace", "k", defaultKubewardenNamespace, "namespace where the Kubewarden components (e.g. PolicyServer) are installed (required)")
rootCmd.Flags().StringP("policy-server-url", "u", "", "URI to the PolicyServers the Audit Scanner will query. Example: https://localhost:3000. Useful for out-of-cluster debugging")
rootCmd.Flags().VarP(&level, "loglevel", "l", fmt.Sprintf("level of the logs. Supported values are: %v", logconfig.SupportedValues))
rootCmd.Flags().BoolVarP(&outputScan, "output-scan", "o", false, "print result of scan in JSON to stdout")
rootCmd.Flags().StringSliceVarP(&skippedNs, "ignore-namespaces", "i", nil, "comma separated list of namespace names to be skipped from scan. This flag can be repeated")
rootCmd.Flags().BoolVar(&insecureSSL, "insecure-ssl", false, "skip SSL cert validation when connecting to PolicyServers endpoints. Useful for development")
rootCmd.Flags().StringP("extra-ca", "f", "", "File path to CA cert in PEM format of PolicyServer endpoints")
rootCmd.Flags().BoolVar(&disableStore, "disable-store", false, "disable storing the results in the k8s cluster")
rootCmd.Flags().IntP("parallel-namespaces", "", defaultParallelNamespaces, "number of Namespaces to scan in parallel")
rootCmd.Flags().IntP("parallel-resources", "", defaultParallelResources, "number of resources to scan in parallel")
rootCmd.Flags().IntP("parallel-policies", "", defaultParallelPolicies, "number of policies to evaluate for a given resource in parallel")
rootCmd.Flags().IntP("page-size", "", defaultPageSize, "number of resources to fetch from the Kubernetes API server when paginating")
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/kubewarden/audit-scanner

go 1.22.0

toolchain go1.22.6
go 1.23.0

require (
github.com/google/uuid v1.6.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,6 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0=
sigs.k8s.io/controller-runtime v0.6.3/go.mod h1:WlZNXcM0++oyaQt4B7C2lEE5JYRs8vJUzRP4N4JpdAY=
sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw=
sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg=
sigs.k8s.io/controller-runtime v0.18.5 h1:nTHio/W+Q4aBlQMgbnC5hZb4IjIidyrizMai9P6n4Rk=
sigs.k8s.io/controller-runtime v0.18.5/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down
2 changes: 1 addition & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const (
AuditScannerRunUIDLabel = "kubewarden.io/audit-scanner-run-uid"
)

// ErrResourceNotFound is an error used to tell that the required resource is not found
// ErrResourceNotFound is an error used to tell that the required resource is not found.
var ErrResourceNotFound = errors.New("resource not found")
Loading
Loading