-
Notifications
You must be signed in to change notification settings - Fork 4
use authorization.credentials instead of bearerToekn #45
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
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Long-lived SA token for Prometheus to authenticate to the WVA metrics endpoint. | ||
| # Required on OpenShift because user-workload-monitoring Prometheus rejects | ||
| # bearerTokenFile for security. The ServiceMonitor is patched (via | ||
| # monitor-auth-patch.yaml) to reference this Secret instead. | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: workload-variant-autoscaler-metrics-reader-token | ||
| annotations: | ||
| kubernetes.io/service-account.name: workload-variant-autoscaler-controller-manager | ||
| type: kubernetes.io/service-account-token | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Replace bearerTokenFile with authorization.credentials for OpenShift | ||
| # user-workload-monitoring compatibility. The user-workload Prometheus Operator | ||
| # rejects bearerTokenFile ("it accesses file system via bearer token file which | ||
| # Prometheus specification prohibits"). | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: ServiceMonitor | ||
| metadata: | ||
| name: controller-manager-metrics-monitor | ||
| spec: | ||
| endpoints: | ||
| - port: https | ||
| path: /metrics | ||
| interval: 10s | ||
| scheme: https | ||
| tlsConfig: | ||
| insecureSkipVerify: true | ||
|
Comment on lines
+15
to
+16
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.
Not a regression (base manifest has same setting), but this allows MITM attacks on metrics scraping traffic. If the controller-manager serves metrics over a cert signed by an in-cluster CA, consider configuring 🤖 Prompt for AI Agents
Member
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. Lacking full context, do we have to do this? |
||
| authorization: | ||
| credentials: | ||
| name: workload-variant-autoscaler-metrics-reader-token | ||
| key: token | ||
|
Comment on lines
+17
to
+20
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. 🧩 Analysis chain🌐 Web query:
💡 Result: The Prometheus Operator ServiceMonitor CRD includes an authorization field under spec.endpoints[] for configuring Authorization header credentials. This field uses a credentials object that functions as a SecretKeySelector. Key specification details: - Path: spec.endpoints[].authorization.credentials - Fields: - key (string, required): The key within the Secret containing the credentials. - name (string): Name of the Secret (in the same namespace as the ServiceMonitor). - optional (boolean): Whether the Secret or key must exist. The type field (string) under authorization sets the authentication type (defaults to "Bearer"; "Basic" causes an error). This cannot be used simultaneously with basicAuth or oauth2. The Secret must be accessible by the Prometheus Operator in the ServiceMonitor's namespace. Example YAML structure: spec: endpoints: - authorization: credentials: name: my-secret key: token type: Bearer port: metrics For basic authentication, use basicAuth instead, which has separate username and password SecretKeySelectors: basicAuth: username: name: auth-secret key: username password: name: auth-secret key: password Sources confirm this schema across Prometheus Operator v0.50+, OpenShift docs, and official CRD definitions. Citations:
🏁 Script executed: cat -n config/openshift/monitor-auth-patch.yamlRepository: opendatahub-io/workload-variant-autoscaler Length of output: 890 🏁 Script executed: # Search for the Secret resource
rg 'workload-variant-autoscaler-metrics-reader-token' --type yamlRepository: opendatahub-io/workload-variant-autoscaler Length of output: 289 🏁 Script executed: # Check for other insecureSkipVerify instances in ServiceMonitor configs
rg 'insecureSkipVerify' --type yaml -C 2Repository: opendatahub-io/workload-variant-autoscaler Length of output: 3740 Remove The 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Grant the OpenShift user-workload-monitoring Prometheus SA permission to | ||
| # authenticate to the WVA metrics endpoint (tokenreviews + subjectaccessreviews). | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: workload-variant-autoscaler-ocp-prometheus-metrics-auth | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: workload-variant-autoscaler-metrics-auth-role | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: prometheus-k8s | ||
| namespace: openshift-user-workload-monitoring |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: opendatahub-io/workload-variant-autoscaler
Length of output: 18253
🏁 Script executed:
Repository: opendatahub-io/workload-variant-autoscaler
Length of output: 1171
🏁 Script executed:
Repository: opendatahub-io/workload-variant-autoscaler
Length of output: 2191
Add ClusterRoleBinding for
metrics-readerrole to authorize controller-manager ServiceAccount.The
metrics-readerClusterRole exists (defined inconfig/rbac/metrics_reader_role.yamland included in the kustomize build), but there is no corresponding ClusterRoleBinding that grants this role to theworkload-variant-autoscaler-controller-managerServiceAccount. The token generated in this Secret will authenticate successfully but will receive HTTP 403 when Prometheus attempts to scrape/metricsdue to missing authorization.Add the following ClusterRoleBinding to
config/rbac/:metrics_reader_role_binding.yaml
Then reference it in
config/rbac/kustomization.yaml.🤖 Prompt for AI Agents