Skip to content

Commit

Permalink
Added operator metrics ssl and auth configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCazade committed Mar 13, 2023
1 parent 7213a26 commit fcc89e9
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
control-plane: controller-manager
name: netobserv-metrics-monitor
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
interval: 30s
path: /metrics
port: https
scheme: https
tlsConfig:
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
serverName: netobserv-metrics-service.netobserv.svc
selector:
matchLabels:
control-plane: controller-manager
2 changes: 2 additions & 0 deletions bundle/manifests/netobserv-metrics-service_v1_service.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.openshift.io/serving-cert-secret-name: manager-metrics-tls
creationTimestamp: null
labels:
control-plane: controller-manager
Expand Down
15 changes: 14 additions & 1 deletion bundle/manifests/netobserv-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ spec:
spec:
clusterPermissions:
- rules:
- nonResourceURLs:
- /metrics
verbs:
- get
- apiGroups:
- apiregistration.k8s.io
resources:
Expand Down Expand Up @@ -700,7 +704,8 @@ spec:
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=10
- --ignore-paths=/metrics
- --tls-cert-file=/etc/tls/private/tls.crt
- --tls-private-key-file=/etc/tls/private/tls.key
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
name: kube-rbac-proxy
ports:
Expand All @@ -714,6 +719,10 @@ spec:
requests:
cpu: 5m
memory: 64Mi
volumeMounts:
- mountPath: /etc/tls/private
name: manager-metric-tls
readOnly: true
securityContext:
runAsNonRoot: true
serviceAccountName: netobserv-controller-manager
Expand All @@ -723,6 +732,10 @@ spec:
secret:
defaultMode: 420
secretName: webhook-server-cert
- name: manager-metric-tls
secret:
defaultMode: 420
secretName: manager-metrics-tls
permissions:
- rules:
- apiGroups:
Expand Down
1 change: 0 additions & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ spec:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--ignore-paths=/metrics"
- "--v=10"
ports:
- containerPort: 8443
Expand Down
1 change: 0 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ spec:
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=10"
- "--ignore-paths=/metrics"
ports:
- containerPort: 8443
protocol: TCP
Expand Down
8 changes: 8 additions & 0 deletions config/openshift-olm/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace: netobserv
# field above.
namePrefix: netobserv-

resources:
- monitor.yaml

patches:
- path: ./monitoring-patch.yaml
target:
kind: Deployment
name: controller-manager
# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
Expand All @@ -9,11 +8,14 @@ metadata:
namespace: system
spec:
endpoints:
- path: /metrics
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
path: /metrics
interval: 30s
port: https
scheme: https
tlsConfig:
insecureSkipVerify: true
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
serverName: netobserv-metrics-service.netobserv.svc
selector:
matchLabels:
control-plane: controller-manager
27 changes: 27 additions & 0 deletions config/openshift-olm/monitoring-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Check that the 0 container is the expected one
- op: test
path: /spec/template/spec/containers/1/name
value: kube-rbac-proxy

- op: add
path: "/spec/template/spec/volumes/-"
value:
name: manager-metric-tls
secret:
secretName: manager-metrics-tls
defaultMode: 420

- op: add
path: "/spec/template/spec/containers/1/volumeMounts"
value:
- name: manager-metric-tls
readOnly: true
mountPath: /etc/tls/private

- op: add
path: "/spec/template/spec/containers/1/args/-"
value: '--tls-cert-file=/etc/tls/private/tls.crt'

- op: add
path: "/spec/template/spec/containers/1/args/-"
value: '--tls-private-key-file=/etc/tls/private/tls.key'
11 changes: 7 additions & 4 deletions config/openshift/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ namespace: netobserv
# field above.
namePrefix: netobserv-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
resources:
- monitor.yaml

patches:
- path: ./monitoring-patch.yaml
target:
kind: Deployment
name: controller-manager
bases:
- ../crd
- ../rbac
- ../manager
- ../webhook
- ../prometheus
- namespace.yaml
patchesStrategicMerge:
- patch.yaml
21 changes: 21 additions & 0 deletions config/openshift/monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
control-plane: controller-manager
name: metrics-monitor
namespace: system
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
path: /metrics
interval: 30s
port: https
scheme: https
tlsConfig:
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
serverName: netobserv-metrics-service.netobserv.svc
selector:
matchLabels:
control-plane: controller-manager
27 changes: 27 additions & 0 deletions config/openshift/monitoring-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Check that the 0 container is the expected one
- op: test
path: /spec/template/spec/containers/1/name
value: kube-rbac-proxy

- op: add
path: "/spec/template/spec/volumes/-"
value:
name: manager-metric-tls
secret:
secretName: manager-metrics-tls
defaultMode: 420

- op: add
path: "/spec/template/spec/containers/1/volumeMounts"
value:
- name: manager-metric-tls
readOnly: true
mountPath: /etc/tls/private

- op: add
path: "/spec/template/spec/containers/1/args/-"
value: '--tls-cert-file=/etc/tls/private/tls.crt'

- op: add
path: "/spec/template/spec/containers/1/args/-"
value: '--tls-private-key-file=/etc/tls/private/tls.key'
2 changes: 0 additions & 2 deletions config/prometheus/kustomization.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions config/rbac/auth_proxy_client_clusterrole.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: Service
metadata:
labels:
control-plane: controller-manager
annotations:
service.beta.openshift.io/serving-cert-secret-name: manager-metrics-tls
name: metrics-service
namespace: system
spec:
Expand Down
1 change: 0 additions & 1 deletion config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ resources:
- auth_proxy_service.yaml
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml
4 changes: 4 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
- apiGroups:
- apiregistration.k8s.io
resources:
Expand Down
1 change: 1 addition & 0 deletions controllers/flowcollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewFlowCollectorReconciler(client client.Client, scheme *runtime.Scheme, co
//+kubebuilder:rbac:groups=security.openshift.io,resources=securitycontextconstraints,verbs=list;create;update;watch
//+kubebuilder:rbac:groups=apiregistration.k8s.io,resources=apiservices,verbs=list;get;watch
//+kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;create;delete;update;patch;list;watch
//+kubebuilder:rbac:urls="/metrics",verbs=get

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
13 changes: 9 additions & 4 deletions controllers/flowcollector_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ func buildRoleMonitoringReader(ns string) *rbacv1.Role {
Name: constants.OperatorName + roleSuffix,
Namespace: ns,
},
Rules: []rbacv1.PolicyRule{{APIGroups: []string{""},
Verbs: []string{"get", "list", "watch"},
Resources: []string{"pods", "services", "endpoints"},
},
Rules: []rbacv1.PolicyRule{
{APIGroups: []string{""},
Verbs: []string{"get", "list", "watch"},
Resources: []string{"pods", "services", "endpoints"},
},
{
NonResourceURLs: []string{"/metrics"},
Verbs: []string{"get"},
},
},
}
return &cr
Expand Down
8 changes: 8 additions & 0 deletions monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-monitoring-config
namespace: openshift-monitoring
data:
config.yaml: |
enableUserWorkload: true

0 comments on commit fcc89e9

Please sign in to comment.