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

static auth changes for node-exporter #1393

Merged
merged 1 commit into from Sep 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/node-exporter/daemonset.yaml
Expand Up @@ -65,6 +65,7 @@ spec:
- --tls-cert-file=/etc/tls/private/tls.crt
- --tls-private-key-file=/etc/tls/private/tls.key
- --client-ca-file=/etc/tls/client/client-ca.crt
- --config-file=/etc/kube-rbac-policy/config.yaml
env:
- name: IP
valueFrom:
Expand Down Expand Up @@ -92,6 +93,9 @@ spec:
- mountPath: /etc/tls/client
name: metrics-client-ca
readOnly: false
- mountPath: /etc/kube-rbac-policy
name: node-exporter-kube-rbac-proxy-config
readOnly: true
hostNetwork: true
hostPID: true
initContainers:
Expand Down Expand Up @@ -147,6 +151,9 @@ spec:
- configMap:
name: metrics-client-ca
name: metrics-client-ca
- name: node-exporter-kube-rbac-proxy-config
secret:
secretName: node-exporter-kube-rbac-proxy-config
updateStrategy:
rollingUpdate:
maxUnavailable: 10%
Expand Down
18 changes: 18 additions & 0 deletions assets/node-exporter/kube-rbac-proxy-secret.yaml
@@ -0,0 +1,18 @@
apiVersion: v1
data: {}
kind: Secret
metadata:
labels:
app.kubernetes.io/part-of: openshift-monitoring
name: node-exporter-kube-rbac-proxy-config
namespace: openshift-monitoring
stringData:
config.yaml: |-
"authorization":
"static":
- "path": "/metrics"
"resourceRequest": false
"user":
"name": "system:serviceaccount:openshift-monitoring:prometheus-k8s"
"verb": "get"
type: Opaque
14 changes: 14 additions & 0 deletions jsonnet/components/node-exporter.libsonnet
Expand Up @@ -5,6 +5,7 @@ local wtmpPath = '/var/log/wtmp';
local wtmpVolumeName = 'node-exporter-wtmp';

local nodeExporter = import 'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus/components/node-exporter.libsonnet';
local generateSecret = import '../utils/generate-secret.libsonnet';

function(params)
local cfg = params;
Expand Down Expand Up @@ -126,6 +127,7 @@ function(params)
'--tls-cert-file=/etc/tls/private/tls.crt',
'--tls-private-key-file=/etc/tls/private/tls.key',
'--client-ca-file=/etc/tls/client/client-ca.crt',
'--config-file=/etc/kube-rbac-policy/config.yaml',
],
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts: [
Expand All @@ -139,6 +141,11 @@ function(params)
name: 'metrics-client-ca',
readOnly: false,
},
{
mountPath: '/etc/kube-rbac-policy',
name: 'node-exporter-kube-rbac-proxy-config',
readOnly: true,
},
],
resources: {
requests: {
Expand Down Expand Up @@ -206,6 +213,12 @@ function(params)
name: 'metrics-client-ca',
},
},
{
name: 'node-exporter-kube-rbac-proxy-config',
secret: {
secretName: 'node-exporter-kube-rbac-proxy-config',
},
},
],
securityContext: {},
priorityClassName: 'system-cluster-critical',
Expand All @@ -216,4 +229,5 @@ function(params)
},
},
},
kubeRbacProxySecret: generateSecret.staticAuthSecret(cfg.namespace, cfg.commonLabels, 'node-exporter-kube-rbac-proxy-config'),
}
12 changes: 12 additions & 0 deletions pkg/manifests/manifests.go
Expand Up @@ -91,6 +91,7 @@ var (
NodeExporterSecurityContextConstraints = "node-exporter/security-context-constraints.yaml"
NodeExporterServiceMonitor = "node-exporter/service-monitor.yaml"
NodeExporterPrometheusRule = "node-exporter/prometheus-rule.yaml"
NodeExporterKubeRbacProxySecret = "node-exporter/kube-rbac-proxy-secret.yaml"

PrometheusK8sClusterRoleBinding = "prometheus-k8s/cluster-role-binding.yaml"
PrometheusK8sRoleBindingConfig = "prometheus-k8s/role-binding-config.yaml"
Expand Down Expand Up @@ -774,6 +775,17 @@ func (f *Factory) NodeExporterPrometheusRule() (*monv1.PrometheusRule, error) {
return f.NewPrometheusRule(f.assets.MustNewAssetReader(NodeExporterPrometheusRule))
}

func (f *Factory) NodeExporterRBACProxySecret() (*v1.Secret, error) {
Copy link
Contributor

@arajkumar arajkumar Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this to TestUnconfiguredManifests test?

/hold

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

s, err := f.NewSecret(f.assets.MustNewAssetReader(NodeExporterKubeRbacProxySecret))
if err != nil {
return nil, err
}

s.Namespace = f.namespace

return s, nil
}

func (f *Factory) PrometheusK8sClusterRoleBinding() (*rbacv1.ClusterRoleBinding, error) {
crb, err := f.NewClusterRoleBinding(f.assets.MustNewAssetReader(PrometheusK8sClusterRoleBinding))
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/manifests/manifests_test.go
Expand Up @@ -703,6 +703,11 @@ func TestUnconfiguredManifests(t *testing.T) {
if err != nil {
t.Fatal(err)
}

_, err = f.NodeExporterRBACProxySecret()
if err != nil {
t.Fatal(err)
}
}

func TestSharingConfig(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/tasks/nodeexporter.go
Expand Up @@ -74,6 +74,15 @@ func (t *NodeExporterTask) Run(ctx context.Context) error {
return errors.Wrap(err, "reconciling node-exporter ClusterRoleBinding failed")
}

nes, err := t.factory.NodeExporterRBACProxySecret()
if err != nil {
return errors.Wrap(err, "intializing node-exporter rbac proxy secret failed")
}

err = t.client.CreateIfNotExistSecret(ctx, nes)
if err != nil {
return errors.Wrap(err, "creating node-exporter rbac proxy secret failed")
}
svc, err := t.factory.NodeExporterService()
if err != nil {
return errors.Wrap(err, "initializing node-exporter Service failed")
Expand Down