Skip to content

Commit a63b957

Browse files
authored
fix(deps): upgrade to operator-framework v1.39.2 and fix vulnerabilities (#63)
* fix(deps): update vulnerable packages * fix(deps): upgrade to operator-framework v1.39.2 Followed upgrade instructions on https://sdk.operatorframework.io/docs/upgrading-sdk-version/ from v1.37.0 to v1.39.2 Some notes: * The new operator introduces TLS endpoint for metrics endpoints, this is disable for now so we can spend time later on coming up with the right examples for our users on how to do this * Upgrade of kustomize was fixes with `kustomize edit fix --vars` command * Upgrade to go v1.23 was needed to fix vulnerabilities in x/net package Tested locally successfully. * chore(readme): update tested k8s version
1 parent d0d693e commit a63b957

31 files changed

Lines changed: 411 additions & 357 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 as builder
2+
FROM golang:1.23 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ endif
4949
# Image URL to use all building/pushing image targets
5050
IMG ?= ghcr.io/checkly/checkly-operator:${VERSION}
5151
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
52-
ENVTEST_K8S_VERSION = 1.29.0
52+
ENVTEST_K8S_VERSION = 1.31.0
5353

5454
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5555
ifeq (,$(shell go env GOBIN))
@@ -160,16 +160,16 @@ $(LOCALBIN):
160160

161161
## Tool Binaries
162162
KUBECTL ?= kubectl
163-
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
164-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
165-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
166-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
163+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
164+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
165+
ENVTEST ?= $(LOCALBIN)/setup-envtest
166+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
167167

168168
## Tool Versions
169-
KUSTOMIZE_VERSION ?= v5.3.0
170-
CONTROLLER_TOOLS_VERSION ?= v0.14.0
171-
ENVTEST_VERSION ?= release-0.17
172-
GOLANGCI_LINT_VERSION ?= v1.57.2
169+
KUSTOMIZE_VERSION ?= v5.4.3
170+
CONTROLLER_TOOLS_VERSION ?= v0.16.1
171+
ENVTEST_VERSION ?= release-0.19
172+
GOLANGCI_LINT_VERSION ?= v1.59.1
173173

174174
.PHONY: kustomize
175175
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -189,20 +189,22 @@ $(ENVTEST): $(LOCALBIN)
189189
.PHONY: golangci-lint
190190
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
191191
$(GOLANGCI_LINT): $(LOCALBIN)
192-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
192+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
193193

194194
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
195195
# $1 - target path with name of binary (ideally with version)
196196
# $2 - package url which can be installed
197197
# $3 - specific version of package
198198
define go-install-tool
199-
@[ -f $(1) ] || { \
199+
@[ -f "$(1)-$(3)" ] || { \
200200
set -e; \
201201
package=$(2)@$(3) ;\
202202
echo "Downloading $${package}" ;\
203+
rm -f $(1) || true ;\
203204
GOBIN=$(LOCALBIN) go install $${package} ;\
204-
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
205-
}
205+
mv $(1) $(1)-$(3) ;\
206+
} ;\
207+
ln -sf $(1)-$(3) $(1)
206208
endef
207209

208210
.PHONY: bundle

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Sources used for kick starting this project:
6666
### Versions
6767

6868
We're using the following versions of packages:
69-
* operator-sdk 1.37.0
70-
* golang 1.22
69+
* operator-sdk 1.39.2
70+
* golang 1.23
7171

72-
Tested with K8s `v1.29`.
72+
Tested with K8s `v1.31.2`.

cmd/main.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"crypto/tls"
2021
"errors"
2122
"flag"
2223
"os"
@@ -32,14 +33,15 @@ import (
3233
ctrl "sigs.k8s.io/controller-runtime"
3334
"sigs.k8s.io/controller-runtime/pkg/healthz"
3435
"sigs.k8s.io/controller-runtime/pkg/log/zap"
36+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3537
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3638

3739
"github.com/checkly/checkly-go-sdk"
3840

3941
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
4042
checklycontrollers "github.com/checkly/checkly-operator/internal/controller/checkly"
4143
networkingcontrollers "github.com/checkly/checkly-operator/internal/controller/networking"
42-
//+kubebuilder:scaffold:imports
44+
//kubebuilder:scaffold:imports
4345
)
4446

4547
var (
@@ -51,35 +53,63 @@ func init() {
5153
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5254

5355
utilruntime.Must(checklyv1alpha1.AddToScheme(scheme))
54-
//+kubebuilder:scaffold:scheme
56+
//kubebuilder:scaffold:scheme
5557
}
5658

5759
func main() {
5860
var metricsAddr string
5961
var enableLeaderElection bool
6062
var probeAddr string
63+
var secureMetrics bool
6164
var controllerDomain string
62-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
65+
var tlsOpts []func(*tls.Config)
66+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
67+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
6368
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6469
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6570
"Enable leader election for controller manager. "+
6671
"Enabling this will ensure there is only one active controller manager.")
72+
flag.BoolVar(&secureMetrics, "metrics-secure", true,
73+
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
6774
flag.StringVar(&controllerDomain, "controller-domain", "k8s.checklyhq.com", "Domain to use for annotations and finalizers.")
6875
opts := zap.Options{
6976
// Development: true,
7077
}
78+
7179
opts.BindFlags(flag.CommandLine)
7280
flag.Parse()
7381

82+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
83+
// More info:
84+
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/server
85+
// - https://book.kubebuilder.io/reference/metrics.html
86+
metricsServerOptions := metricsserver.Options{
87+
BindAddress: metricsAddr,
88+
SecureServing: secureMetrics,
89+
// TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
90+
// not provided, self-signed certificates will be generated by default. This option is not recommended for
91+
// production environments as self-signed certificates do not offer the same level of trust and security
92+
// as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
93+
// unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
94+
// to provide certificates, ensuring the server communicates using trusted and secure certificates.
95+
TLSOpts: tlsOpts,
96+
}
97+
98+
if secureMetrics {
99+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
100+
// These configurations ensure that only authorized users and service accounts
101+
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
102+
// https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/metrics/filters#WithAuthenticationAndAuthorization
103+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
104+
}
105+
74106
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
75107

76108
setupLog.Info("Controller domain setup", "value", controllerDomain)
77109

78110
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
79-
Scheme: scheme,
80-
Metrics: metricsserver.Options{
81-
BindAddress: metricsAddr,
82-
},
111+
Scheme: scheme,
112+
Metrics: metricsServerOptions,
83113
HealthProbeBindAddress: probeAddr,
84114
LeaderElection: enableLeaderElection,
85115
LeaderElectionID: "4e7eab13.checklyhq.com",
@@ -146,7 +176,7 @@ func main() {
146176
setupLog.Error(err, "unable to create controller", "controller", "AlertChannel")
147177
os.Exit(1)
148178
}
149-
//+kubebuilder:scaffold:builder
179+
//kubebuilder:scaffold:builder
150180

151181
setupLog.V(1).Info("starting health endpoint")
152182
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

config/crd/bases/k8s.checklyhq.com_alertchannels.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.14.0
6+
controller-gen.kubebuilder.io/version: v0.16.1
77
name: alertchannels.k8s.checklyhq.com
88
spec:
99
group: k8s.checklyhq.com
@@ -66,7 +66,6 @@ spec:
6666
the event) or if no container name is specified "spec.containers[2]" (container with
6767
index 2 in this pod). This syntax is chosen only to have some well-defined way of
6868
referencing a part of an object.
69-
TODO: this design is not final and this field is subject to change in the future.
7069
type: string
7170
kind:
7271
description: |-

config/crd/bases/k8s.checklyhq.com_apichecks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.14.0
6+
controller-gen.kubebuilder.io/version: v0.16.1
77
name: apichecks.k8s.checklyhq.com
88
spec:
99
group: k8s.checklyhq.com

config/crd/bases/k8s.checklyhq.com_groups.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.14.0
6+
controller-gen.kubebuilder.io/version: v0.16.1
77
name: groups.k8s.checklyhq.com
88
spec:
99
group: k8s.checklyhq.com

config/crd/kustomization.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This kustomization.yaml is not intended to be run by itself,
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
4-
resources:
54
# - bases/check.checklyhq.com_apis.yaml
5+
resources:
66
- bases/k8s.checklyhq.com_apichecks.yaml
77
- bases/k8s.checklyhq.com_groups.yaml
88
- bases/k8s.checklyhq.com_alertchannels.yaml
@@ -28,3 +28,5 @@ resources:
2828
# the following config is for teaching kustomize how to do kustomization for CRDs.
2929
configurations:
3030
- kustomizeconfig.yaml
31+
apiVersion: kustomize.config.k8s.io/v1beta1
32+
kind: Kustomization

config/default/kustomization.yaml

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@ namePrefix: checkly-operator-
1212
#commonLabels:
1313
# someName: someValue
1414

15-
bases:
16-
- ../crd
17-
- ../rbac
18-
- ../manager
1915
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2016
# crd/kustomization.yaml
2117
#- ../webhook
2218
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2319
#- ../certmanager
2420
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
25-
#- ../prometheus
26-
27-
patchesStrategicMerge:
28-
# Protect the /metrics endpoint by putting it behind auth.
29-
# If you want your controller-manager to expose the /metrics
30-
# endpoint w/o any authn/z, please comment the following line.
31-
- manager_auth_proxy_patch.yaml
21+
#- ../prometheus+ # [METRICS] Expose the controller manager metrics service.
22+
# - metrics_service.yaml
23+
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
24+
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
25+
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
26+
# be able to communicate with the Webhook Server.
27+
#- ../network-policy
28+
29+
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
30+
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
31+
# More info: https://book.kubebuilder.io/reference/metrics
32+
patches:
33+
- path: manager_metrics_patch.yaml
34+
target:
35+
kind: Deployment
3236

3337
# Mount the controller config file for loading manager configurations
3438
# through a ComponentConfig type
@@ -44,31 +48,9 @@ patchesStrategicMerge:
4448
#- webhookcainjection_patch.yaml
4549

4650
# the following config is for teaching kustomize how to do var substitution
47-
vars:
48-
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
49-
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
50-
# objref:
51-
# kind: Certificate
52-
# group: cert-manager.io
53-
# version: v1
54-
# name: serving-cert # this name should match the one in certificate.yaml
55-
# fieldref:
56-
# fieldpath: metadata.namespace
57-
#- name: CERTIFICATE_NAME
58-
# objref:
59-
# kind: Certificate
60-
# group: cert-manager.io
61-
# version: v1
62-
# name: serving-cert # this name should match the one in certificate.yaml
63-
#- name: SERVICE_NAMESPACE # namespace of the service
64-
# objref:
65-
# kind: Service
66-
# version: v1
67-
# name: webhook-service
68-
# fieldref:
69-
# fieldpath: metadata.namespace
70-
#- name: SERVICE_NAME
71-
# objref:
72-
# kind: Service
73-
# version: v1
74-
# name: webhook-service
51+
apiVersion: kustomize.config.k8s.io/v1beta1
52+
kind: Kustomization
53+
resources:
54+
- ../crd
55+
- ../rbac
56+
- ../manager

config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)