fix(networkpolicy): allow DNS and KubeAPI egress for AllowIngressMetrics to enable secure metrics token validation#3343
Conversation
…ics to enable secure metrics token validation
📝 WalkthroughWalkthroughThis PR changes how the AllowIngressMetrics network policy rule set handles egress: instead of denying all egress traffic, it now restricts egress to DNS and Kubernetes API server communication. A new ChangesAllowIngressMetrics egress behavior change
Estimated code review effort: 2 (Simple) | ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
PR Summary by QodoAllow DNS and KubeAPI egress for AllowIngressMetrics NetworkPolicy
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Clee2691, jcantrill The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
Code Review by Qodo
Context used✅ Compliance rules (platform):
9 rules 1. Unrestricted egress destinations
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/metrics/logfilemetricexporter/metric_exporter_test.go (1)
235-246: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting a shared egress-port matcher.
The same KubeAPI-TCP + DNS-UDP
ConsistOfblock is duplicated here and ininternal/network/network_policy_test.go(and reportedly ininternal/factory/network_policy_test.goper the stack). A small shared helper (e.g., returning the two expectednetworkingv1.NetworkPolicyPortmatchers) would reduce duplication and keep future port changes in sync across suites.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/metrics/logfilemetricexporter/metric_exporter_test.go` around lines 235 - 246, The egress-port assertion in the metrics exporter test duplicates the same KubeAPI-TCP plus DNS-UDP matcher used elsewhere, so extract a shared helper for the expected ports. Add a reusable function or test helper around the existing `ConsistOf`/`networkingv1.NetworkPolicyPort` setup, then update this `metric_exporter_test.go` check and the matching assertions in `internal/network/network_policy_test.go` and `internal/factory/network_policy_test.go` to use it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/metrics/logfilemetricexporter/metric_exporter_test.go`:
- Around line 235-246: The egress-port assertion in the metrics exporter test
duplicates the same KubeAPI-TCP plus DNS-UDP matcher used elsewhere, so extract
a shared helper for the expected ports. Add a reusable function or test helper
around the existing `ConsistOf`/`networkingv1.NetworkPolicyPort` setup, then
update this `metric_exporter_test.go` check and the matching assertions in
`internal/network/network_policy_test.go` and
`internal/factory/network_policy_test.go` to use it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fceab307-480b-4170-ae8a-0781d1ca2724
📒 Files selected for processing (5)
api/logging/v1alpha1/log_file_metrics_exporter_types.gointernal/factory/network_policy.gointernal/factory/network_policy_test.gointernal/metrics/logfilemetricexporter/metric_exporter_test.gointernal/network/network_policy_test.go
|
@Clee2691: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
8907da0
into
openshift:master
Description
This PR adds
DNSandKubeAPIserver ports to the egress allow list for theAllowIngressMetricsnetwork policy ruleset, enabling secure metrics token validation/cc @vparfonov
/assign @jcantrill
Summary by CodeRabbit