Authentication for metrics and version endpoint#1607
Authentication for metrics and version endpoint#1607naveenpaul1 merged 1 commit intonoobaa:masterfrom
Conversation
0788a0f to
1286643
Compare
1286643 to
3523050
Compare
3523050 to
7c92b87
Compare
7c92b87 to
d286e70
Compare
d286e70 to
d49700f
Compare
WalkthroughThis change adds two new environment variables for metrics and version authorization to the core StatefulSet and endpoint Deployment. It introduces a new Kubernetes secret for metrics authorization, updates the reconciler to create and manage this secret, and configures Prometheus ServiceMonitors to use the secret for bearer token authentication. Changes
Sequence Diagram(s)sequenceDiagram
participant Operator
participant Reconciler
participant KubernetesAPI
participant NBClient
participant Prometheus
Operator->>Reconciler: Start reconciliation
Reconciler->>KubernetesAPI: Ensure SecretMetricsAuth exists
alt Secret does not exist
Reconciler->>NBClient: CreateAuthAPI(metrics role)
NBClient-->>Reconciler: Return metrics token
Reconciler->>KubernetesAPI: Create Secret with metrics token
end
Reconciler->>KubernetesAPI: Patch StatefulSet and Deployment with METRICS_AUTH_ENABLED and VERSION_AUTH_ENABLED
Reconciler->>KubernetesAPI: Patch ServiceMonitors with Bearer token referencing SecretMetricsAuth
Prometheus->>KubernetesAPI: Scrape endpoints using Bearer token
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (6)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (5)
⏰ Context from checks skipped due to timeout of 90000ms (13)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
pkg/system/phase4_configuring.go (1)
1672-1684: Nil-slice guard & namespace explicitness
endpointsmay be nil if a user prunes endpoints from the CRD; add a quick nil-check to avoid panic.- You rely on defaulting to the ServiceMonitor’s namespace. Being explicit increases readability and avoids surprises if cross-namespace ServiceMonitor support lands.
func (r *Reconciler) setServiceMonitorAuthorization(endpoints []monitoringv1.Endpoint) { - for i := range endpoints { + if endpoints == nil { + return + } + for i := range endpoints { endpoints[i].Authorization = &monitoringv1.SafeAuthorization{ Type: "Bearer", Credentials: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ - Name: r.SecretMetricsAuth.Name, + Name: r.SecretMetricsAuth.Name, + Namespace: r.SecretMetricsAuth.Namespace, // be explicit }, Key: metricsAuthKey, }, } } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
deploy/internal/statefulset-core.yaml(1 hunks)pkg/bundle/deploy.go(2 hunks)pkg/system/phase2_creating.go(1 hunks)pkg/system/phase4_configuring.go(3 hunks)pkg/system/reconciler.go(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
pkg/system/reconciler.go (3)
pkg/util/util.go (1)
KubeObject(276-286)pkg/bundle/deploy.go (1)
File_deploy_internal_secret_empty_yaml(4858-4865)pkg/options/options.go (1)
Namespace(60-60)
pkg/system/phase4_configuring.go (4)
pkg/system/reconciler.go (1)
Reconciler(59-133)pkg/util/util.go (1)
SecretResetStringDataFromData(958-968)pkg/nb/types.go (1)
CreateAuthParams(320-325)pkg/options/options.go (1)
OperatorAccountEmail(47-47)
⏰ Context from checks skipped due to timeout of 90000ms (13)
- GitHub Check: run-kms-key-rotate-test
- GitHub Check: cnpg-deployment-test
- GitHub Check: run-kms-tls-sa-test
- GitHub Check: run-core-config-map-tests
- GitHub Check: run-kms-kmip-test
- GitHub Check: run-kms-tls-token-test
- GitHub Check: run-azure-vault-test
- GitHub Check: run-kms-dev-test
- GitHub Check: golangci-lint
- GitHub Check: run-cli-tests
- GitHub Check: run-admission-test
- GitHub Check: run-hac-test
- GitHub Check: run-operator-tests
🔇 Additional comments (4)
pkg/system/phase2_creating.go (1)
1420-1422: Set default auth flags for metrics and version endpoints
EnsuresMETRICS_AUTH_ENABLEDandVERSION_AUTH_ENABLEDdefault to"true"in the core ConfigMap, matching the new StatefulSet environment variables.deploy/internal/statefulset-core.yaml (1)
104-113: Enable runtime auth flags for metrics and version endpoints
AddedMETRICS_AUTH_ENABLEDandVERSION_AUTH_ENABLEDenv vars sourced from thenoobaa-configConfigMap. This aligns with the reconciler defaults and allows toggling endpoint auth without redeploying the pod.pkg/bundle/deploy.go (1)
5047-5047:Details
✅ Verification successful
Verify updated SHA256 checksum
The checksum constant was bumped after adding environment variables to the core StatefulSet manifest. Please confirm that this value exactly matches the SHA256 ofdeploy/internal/statefulset-core.yamlto avoid bundle mismatches.
🏁 Script executed:
#!/bin/bash # Verify the Sha256_deploy_internal_statefulset_core_yaml matches the file content. expected="94af9a850a7bf063f236f7ff3c8a23630a882329137bd854e33b040cec52de44" actual=$(sha256sum deploy/internal/statefulset-core.yaml | awk '{print $1}') if [ "$expected" != "$actual" ]; then echo "❌ SHA mismatch: expected $expected, got $actual" exit 1 fi echo "✅ SHA matches"Length of output: 549
🏁 Script executed:
#!/bin/bash # Re-verify the SHA256 checksum using shasum since sha256sum is unavailable. expected="94af9a850a7bf063f236f7ff3c8a23630a882329137bd854e33b040cec52de44" actual=$(shasum -a 256 deploy/internal/statefulset-core.yaml | awk '{print $1}') if [ "$expected" != "$actual" ]; then echo "❌ SHA mismatch: expected $expected, got $actual" exit 1 fi echo "✅ SHA matches"Length of output: 550
🏁 Script executed:
#!/usr/bin/env bash # Use Python to compute SHA256 since sha256sum and shasum are unavailable. expected="94af9a850a7bf063f236f7ff3c8a23630a882329137bd854e33b040cec52de44" actual=$(python3 - << 'EOF' import hashlib, sys try: data = open('deploy/internal/statefulset-core.yaml', 'rb').read() print(hashlib.sha256(data).hexdigest()) except Exception as e: sys.exit(1) EOF ) if [ -z "$actual" ]; then echo "❌ Failed to compute SHA256. Please verify manually. " exit 1 fi if [ "$expected" != "$actual" ]; then echo "❌ SHA mismatch: expected $expected, got $actual" exit 1 fi echo "✅ SHA matches"Length of output: 422
Checksum Verified for StatefulSet Manifest
The SHA256 constant inpkg/bundle/deploy.go(line 5047) matches the computed SHA256 ofdeploy/internal/statefulset-core.yaml(94af9a850a7bf063f236f7ff3c8a23630a882329137bd854e33b040cec52de44). No further action is needed.pkg/system/phase4_configuring.go (1)
49-50: 👍 Dedicated key constantUsing a single, file-local
metricsAuthKeyconstant prevents typos in multiple call-sites.
d49700f to
9c2144c
Compare
9c2144c to
e4c340c
Compare
e4c340c to
d92013c
Compare
tangledbytes
left a comment
There was a problem hiding this comment.
LGTM. Just some minor comments.
Signed-off-by: naveenpaul1 <napaul@redhat.com>
d92013c to
0674d87
Compare
Explain the changes
metricsto get the JWT token in the configuration phase, And the response token will be saved as secret(metrics-auth-secret)Issues: Fixed #xxx / Gap #xxx
DFBUGS-1802
Testing Instructions:
containerized deployment
metrics-auth-secret, secret can be used for accessing noobaa management and endpoint metrics/version.Design doc : https://ibm.ent.box.com/notes/1853310270159
Summary by CodeRabbit
Summary by CodeRabbit