-
Notifications
You must be signed in to change notification settings - Fork 565
Secure metrics endpoint with cntrlr-runtime metrics authz mechanics #3660
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,12 @@ GINKGO := $(TOOL_EXEC) github.com/onsi/ginkgo/v2/ginkgo | |
|
||
# Target environment and Dependencies # | ||
|
||
# Cert-manager version - update this for new releases | ||
CERT_MANAGER_VERSION ?= v1.18.2 | ||
|
||
# Cert-manager deployment timeout | ||
CERT_MANAGER_TIMEOUT ?= 120s | ||
|
||
# Minor Kubernetes version to build against derived from the client-go dependency version | ||
KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/') | ||
|
||
|
@@ -157,7 +163,29 @@ local-build: IMAGE_TAG = local | |
local-build: image | ||
|
||
.PHONY: run-local | ||
run-local: local-build kind-create deploy | ||
run-local: local-build kind-create cert-manager-install deploy | ||
|
||
.PHONY: cert-manager-install | ||
cert-manager-install: #HELP Install cert-manager $(CERT_MANAGER_VERSION) | ||
@echo "Installing cert-manager $(CERT_MANAGER_VERSION)" | ||
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml | ||
@echo "Waiting for cert-manager to be ready..." | ||
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager --timeout=$(CERT_MANAGER_TIMEOUT) | ||
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-cainjector --timeout=$(CERT_MANAGER_TIMEOUT) | ||
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=$(CERT_MANAGER_TIMEOUT) | ||
@echo "Waiting for cert-manager webhook to be ready..." | ||
kubectl wait --for=condition=Ready --namespace=cert-manager pod -l app=webhook --timeout=$(CERT_MANAGER_TIMEOUT) | ||
@echo "Waiting for cert-manager CRDs to be available..." | ||
kubectl wait --for condition=established --timeout=$(CERT_MANAGER_TIMEOUT) crd/certificates.cert-manager.io | ||
kubectl wait --for condition=established --timeout=$(CERT_MANAGER_TIMEOUT) crd/issuers.cert-manager.io | ||
@echo "cert-manager $(CERT_MANAGER_VERSION) installed successfully" | ||
|
||
.PHONY: cert-manager-uninstall | ||
cert-manager-uninstall: #HELP Uninstall cert-manager | ||
@echo "Uninstalling cert-manager..." | ||
kubectl delete -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml --ignore-not-found=true | ||
@echo "cert-manager uninstalled" | ||
|
||
|
||
.PHONY: clean | ||
clean: #HELP Clean up build artifacts | ||
|
@@ -231,6 +259,7 @@ deploy: $(KIND) $(HELM) #HELP Deploy OLM to kind cluster $KIND_CLUSTER_NAME (def | |
$(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME); \ | ||
$(HELM) upgrade --install olm deploy/chart \ | ||
--set debug=true \ | ||
--set certManager.enabled=true \ | ||
--set olm.image.ref=$(OLM_IMAGE) \ | ||
--set olm.image.pullPolicy=IfNotPresent \ | ||
--set catalog.image.ref=$(OLM_IMAGE) \ | ||
|
@@ -254,6 +283,9 @@ undeploy: $(KIND) $(HELM) #HELP Uninstall OLM from kind cluster $KIND_CLUSTER_NA | |
$(HELM) uninstall olm | ||
kubectl delete -f deploy/chart/crds | ||
|
||
# Uninstall cert-manager | ||
$(MAKE) cert-manager-uninstall | ||
|
||
#SECTION e2e | ||
|
||
# E2E test configuration | ||
|
@@ -269,7 +301,24 @@ e2e: #HELP Run e2e tests against a cluster running OLM (params: $E2E_TEST_NS (op | |
$(GO_TEST_ENV) $(GINKGO) -timeout $(E2E_TIMEOUT) $(GINKGO_OPTS) $(E2E_GINKGO_OPTS) ./test/e2e -- -namespace=$(E2E_TEST_NS) -olmNamespace=$(E2E_INSTALL_NS) -catalogNamespace=$(E2E_CATALOG_NS) $(E2E_OPTS) | ||
|
||
.PHONY: e2e-local | ||
e2e-local: e2e-build kind-create deploy e2e | ||
e2e-local: e2e-build kind-create e2e-local-deploy e2e | ||
|
||
.PHONY: e2e-local-deploy | ||
e2e-local-deploy: $(KIND) $(HELM) #HELP Deploy OLM for e2e testing (without cert-manager) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also had to make a new deploy target to deploy olm without cert-manager for e2e testing |
||
$(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME); \ | ||
$(HELM) upgrade --install olm deploy/chart \ | ||
--set debug=true \ | ||
--set certManager.enabled=false \ | ||
--set olm.image.ref=$(OLM_IMAGE) \ | ||
--set olm.image.pullPolicy=IfNotPresent \ | ||
--set catalog.image.ref=$(OLM_IMAGE) \ | ||
--set catalog.image.pullPolicy=IfNotPresent \ | ||
--set catalog.commandArgs=--configmapServerImage=$(CONFIGMAP_SERVER_IMAGE) \ | ||
--set catalog.opmImageArgs=--opmImage=$(OPERATOR_REGISTRY_IMAGE) \ | ||
--set package.image.ref=$(OLM_IMAGE) \ | ||
--set package.image.pullPolicy=IfNotPresent \ | ||
$(HELM_INSTALL_OPTS) \ | ||
--wait; | ||
|
||
#SECTION Code Generation | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{- if .Values.certManager.enabled }} | ||
--- | ||
apiVersion: cert-manager.io/v1 | ||
kind: Issuer | ||
metadata: | ||
name: {{ .Values.certManager.issuer.name }} | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
{{- if .Values.certManager.issuer.selfSigned }} | ||
selfSigned: {} | ||
{{- else if .Values.certManager.issuer.ca }} | ||
ca: | ||
secretName: {{ .Values.certManager.issuer.ca.secretName }} | ||
{{- end }} | ||
--- | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: {{ .Values.certManager.certificate.name }} | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
secretName: {{ .Values.certManager.certificate.secretName }} | ||
isCA: false | ||
usages: | ||
- server auth | ||
- client auth | ||
dnsNames: | ||
- localhost | ||
- catalog-operator.{{ .Values.namespace }}.svc | ||
- catalog-operator.{{ .Values.namespace }}.svc.cluster.local | ||
- olm-operator.{{ .Values.namespace }}.svc | ||
- olm-operator.{{ .Values.namespace }}.svc.cluster.local | ||
{{- range .Values.certManager.certificate.extraDnsNames }} | ||
- {{ . }} | ||
{{- end }} | ||
ipAddresses: | ||
- 127.0.0.1 | ||
{{- range .Values.certManager.certificate.extraIpAddresses }} | ||
- {{ . }} | ||
{{- end }} | ||
issuerRef: | ||
name: {{ .Values.certManager.issuer.name }} | ||
kind: Issuer | ||
group: cert-manager.io | ||
{{- end }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,16 +22,14 @@ spec: | |
seccompProfile: | ||
type: RuntimeDefault | ||
serviceAccountName: olm-operator-serviceaccount | ||
volumes: | ||
{{- if .Values.olm.tlsSecret }} | ||
volumes: | ||
{{- if .Values.certManager.enabled }} | ||
- name: srv-cert | ||
secret: | ||
secretName: {{ .Values.olm.tlsSecret }} | ||
{{- end }} | ||
{{- if .Values.olm.clientCASecret }} | ||
secretName: {{ .Values.certManager.certificate.secretName }} | ||
- name: profile-collector-cert | ||
secret: | ||
secretName: {{ .Values.olm.clientCASecret }} | ||
secretName: {{ .Values.certManager.certificate.secretName }} | ||
{{- end }} | ||
- name: tmpfs | ||
emptyDir: {} | ||
|
@@ -43,12 +41,10 @@ spec: | |
capabilities: | ||
drop: [ "ALL" ] | ||
volumeMounts: | ||
{{- if .Values.olm.tlsSecret }} | ||
{{- if .Values.certManager.enabled }} | ||
- name: srv-cert | ||
mountPath: "/srv-cert" | ||
readOnly: true | ||
{{- end }} | ||
{{- if .Values.olm.clientCASecret }} | ||
- name: profile-collector-cert | ||
mountPath: "/profile-collector-cert" | ||
readOnly: true | ||
|
@@ -78,31 +74,29 @@ spec: | |
- --writePackageServerStatusName | ||
- {{ .Values.writePackageServerStatusName }} | ||
{{- end }} | ||
{{- if .Values.olm.tlsSecret }} | ||
{{- if .Values.certManager.enabled }} | ||
- --tls-cert | ||
- /srv-cert/tls.crt | ||
- --tls-key | ||
- /srv-cert/tls.key | ||
{{- end }} | ||
{{- if .Values.olm.clientCASecret }} | ||
- --client-ca | ||
- /profile-collector-cert/tls.crt | ||
{{- end }} | ||
image: {{ .Values.olm.image.ref }} | ||
imagePullPolicy: {{ .Values.olm.image.pullPolicy }} | ||
ports: | ||
- containerPort: {{ .Values.olm.service.internalPort }} | ||
- containerPort: {{ if .Values.certManager.enabled }}{{ .Values.olm.service.internalPortHttps }}{{ else }}{{ .Values.olm.service.internalPort }}{{ end }} | ||
name: metrics | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: {{ .Values.olm.service.internalPort }} | ||
scheme: {{ if .Values.olm.tlsSecret }}HTTPS{{ else }}HTTP{{end}} | ||
port: {{ if .Values.certManager.enabled }}{{ .Values.olm.service.internalPortHttps }}{{ else }}{{ .Values.olm.service.internalPort }}{{ end }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which means the templates had to be updated to configure different endpoints based on the presence of the cert-manager |
||
scheme: {{ if .Values.certManager.enabled }}HTTPS{{ else }}HTTP{{ end }} | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: {{ .Values.olm.service.internalPort }} | ||
scheme: {{ if .Values.olm.tlsSecret }}HTTPS{{ else }}HTTP{{end}} | ||
port: {{ if .Values.certManager.enabled }}{{ .Values.olm.service.internalPortHttps }}{{ else }}{{ .Values.olm.service.internalPort }}{{ end }} | ||
scheme: {{ if .Values.certManager.enabled }}HTTPS{{ else }}HTTP{{ end }} | ||
terminationMessagePolicy: FallbackToLogsOnError | ||
env: | ||
- name: OPERATOR_NAMESPACE | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This presented itself as the easiest way to do all the tests we have for metrics (since these tests are about testing the metrics omitted, eg "creating a subscription emits these metrics", and not the security aspect of the endpoints).