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

OCPBUGS-39403: Fix parseIPList to Continue Processing After Invalid IPs and Return Valid IPs #621

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

mJace
Copy link
Contributor

@mJace mJace commented Aug 30, 2024

Summary

This PR updates the parseIPList function to handle IP lists containing invalid IPs or CIDRs more gracefully. Previously, the function would return an empty string as soon as it encountered an invalid IP or CIDR. This update ensures that the function will now continue processing the rest of the list and return a space-separated string of all valid IPs and CIDRs.

Changes

  • Modified parseIPList to:
    • Log all invalid entries for troubleshooting.
    • Return a string of valid IPs and CIDRs, or an empty string if none are valid.

Benefits

  • Improved Robustness: The function now handles mixed validity IP lists more gracefully, allowing valid entries to be processed even if there are some invalid entries.
  • Enhanced Debugging: Logging of invalid IPs or CIDRs provides better visibility into issues with input data.

Additional Notes

  • The function continues to trim and validate input while logging detailed information about invalid entries.
  • Ensure to review and test the function with various IP list scenarios to confirm the correctness of the changes.

@openshift-ci openshift-ci bot requested review from alebedev87 and gcs278 August 30, 2024 06:55
Copy link
Contributor

openshift-ci bot commented Aug 30, 2024

Hi @mJace. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions 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.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 30, 2024
@alebedev87
Copy link
Contributor

/assign

@mJace mJace changed the title Fix parseIPList to Continue Processing After Invalid IPs and Return Valid IPs OCPBUGS-39403 - Fix parseIPList to Continue Processing After Invalid IPs and Return Valid IPs Sep 3, 2024
@alebedev87
Copy link
Contributor

@mJace : would it be possible for you to provide some unit tests for this change?

@candita
Copy link
Contributor

candita commented Oct 2, 2024

/assign

@mJace mJace force-pushed the fix_whitelist_ip_parser branch from 80ce105 to 51aad66 Compare October 10, 2024 08:53
@mJace
Copy link
Contributor Author

mJace commented Oct 10, 2024

@alebedev87
I added more test case to function TestParseIPList in pkg/router/template/template_helper_test.go.

return list

if len(invalidIPs) > 0 {
log.V(7).Info("parseIPList found invalid IP/CIDR items", "invalidIPs", invalidIPs)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the log line up at line 391 where you find an invalid IP, e.g. log it for each invalid ip. Then you don't need the invalidIPs slice, nor to take a len later.

Copy link
Contributor Author

@mJace mJace Oct 24, 2024

Choose a reason for hiding this comment

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

Thank you for your advice.

@candita
Copy link
Contributor

candita commented Oct 23, 2024

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 23, 2024
@mJace mJace force-pushed the fix_whitelist_ip_parser branch from 51aad66 to 31fdfe8 Compare October 24, 2024 01:53
@mJace
Copy link
Contributor Author

mJace commented Oct 24, 2024

/retest-required

@mJace
Copy link
Contributor Author

mJace commented Oct 24, 2024

/retest

@mJace mJace requested a review from candita October 24, 2024 09:34
validIPs = append(validIPs, ip)
} else {
// Log invalid IP/CIDR
log.V(0).Info("parseIPList found invalid IP/CIDR", ip)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this changes behavior, we need to make sure this error is noticed, and indicate that the invalid IP is now ignored. Something like this:

Suggested change
log.V(0).Info("parseIPList found invalid IP/CIDR", ip)
log.Error("error parsing IP list, ignoring invalid IP/CIDR", ip)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a customErr for IP/CIDR since only net.parseCIDR returns err.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether this one should be an error, taking into account that now we don't stop the parsing and there can be some valid IPs still. I think that the error would make more sense down the code where we find that the list is empty. However in the similar conditions in the same function (when we return "") we use log.V(7).Info(). So it seems to be inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alebedev87 That’s why I use log.V(0).Info at the beginning.
I reviewed all scenarios that call log.Error() in template_helper.go, and they all return "" immediately.
Since, in this case, we will continue parsing the rest of the IP, is it okay to use log.Info but at a higher log level?
If yes, what level should I use here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The default log level is 2 so if we want this message to be visible it has to be <= 2. From what I can see in template_helper.go the log level 0 is what's used in similar cases (example) - when the user needs to be informed but the flow may continue. Similarly, looking at the other functions - failing the parsing with an error if the list of valid IPs/CIDRs is empty seems to be the way to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw the condition about the trimmer list being compared to the given list doesn't seem to use the right logging level:

	if trimmedList != list {
		log.V(7).Info("parseIPList leading/trailing spaces found")
		return ""
	}

I would prefer it to be a level 0 too as we want the user to see this.

@@ -1061,7 +1112,7 @@ func TestParseIPList(t *testing.T) {
}
return
}
if got != tc.input {
if got != tc.expectedReturn {
Copy link
Contributor

Choose a reason for hiding this comment

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

Followup to https://github.com/openshift/router/pull/621/files#r1815351390.

Suggested change
if got != tc.expectedReturn {
if expectedEmpty && got != "" || got != tc.expectedReturn {

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this was taken care of.

@@ -1061,7 +1112,7 @@ func TestParseIPList(t *testing.T) {
}
return
}
if got != tc.input {
if got != tc.expectedReturn {
t.Errorf("Failure: expected %q, got %q", tc.input, got)
Copy link
Contributor

@candita candita Oct 24, 2024

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Failure: expected %q, got %q", tc.input, got)
if expectedEmpty {
log.Errorf("Failure: expected none, got %q", got)
} else {
t.Errorf("Failure: expected %q, got %q", tc.expectedReturn, got)
}

@mJace mJace force-pushed the fix_whitelist_ip_parser branch 3 times, most recently from 09efe4a to aeb7e77 Compare October 24, 2024 23:01
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 21, 2025
@openshift-ci-robot
Copy link
Contributor

@mJace: This pull request references Jira Issue OCPBUGS-39403, which is invalid:

  • expected the bug to be open, but it isn't
  • expected the bug to target the "4.19.0" version, but no target version was set
  • expected the bug to be in one of the following states: NEW, ASSIGNED, POST, but it is Closed (Won't Do) instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Summary

This PR updates the parseIPList function to handle IP lists containing invalid IPs or CIDRs more gracefully. Previously, the function would return an empty string as soon as it encountered an invalid IP or CIDR. This update ensures that the function will now continue processing the rest of the list and return a space-separated string of all valid IPs and CIDRs.

Changes

  • Modified parseIPList to:
  • Log all invalid entries for troubleshooting.
  • Return a string of valid IPs and CIDRs, or an empty string if none are valid.

Benefits

  • Improved Robustness: The function now handles mixed validity IP lists more gracefully, allowing valid entries to be processed even if there are some invalid entries.
  • Enhanced Debugging: Logging of invalid IPs or CIDRs provides better visibility into issues with input data.

Additional Notes

  • The function continues to trim and validate input while logging detailed information about invalid entries.
  • Ensure to review and test the function with various IP list scenarios to confirm the correctness of the changes.

Instructions 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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Jan 21, 2025
@alebedev87
Copy link
Contributor

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jan 21, 2025
@openshift-ci-robot
Copy link
Contributor

@alebedev87: This pull request references Jira Issue OCPBUGS-39403, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.19.0) matches configured target version for branch (4.19.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @lihongan

In response to this:

/jira refresh

Instructions 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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from lihongan January 21, 2025 09:49
@mJace mJace force-pushed the fix_whitelist_ip_parser branch from 81ad24e to f0926cb Compare January 21, 2025 10:10
@alebedev87
Copy link
Contributor

/lgtm
/approve
/hold

Holding for @candita to have another look.

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Jan 21, 2025
Copy link
Contributor

openshift-ci bot commented Jan 21, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alebedev87

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 21, 2025
@alebedev87
Copy link
Contributor

/retest

1 similar comment
@mJace
Copy link
Contributor Author

mJace commented Jan 21, 2025

/retest

@alebedev87
Copy link
Contributor

openshift/origin#29466 should fix the image registry failure of e2e-aws-serial.

@gcs278
Copy link
Contributor

gcs278 commented Jan 23, 2025

openshift/origin#29466 is merged
/test e2e-aws-serial

@candita
Copy link
Contributor

candita commented Jan 24, 2025

/lgtm
/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 24, 2025
@rhamini3
Copy link

rhamini3 commented Feb 11, 2025

Pre-merge verified on cluster version: 4.18.0-0.ci.test-2025-02-12-162751-ci-ln-2i21xl2-latest

iamin@iamin-mac Downloads % oc get clusterversion 
NAME      VERSION                                                   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.18.0-0.ci.test-2025-02-12-162751-ci-ln-2i21xl2-latest   True        False         50m     Cluster version is 4.18.0-0.ci.test-2025-02-12-162751-ci-ln-2i21xl2-latest
  1. annotate the route with valid and invalid IPs
iamin@iamin-mac cluster-ingress-operator % oc annotate route edge-route --overwrite haproxy.router.openshift.io/ip_whitelist='0.0.0.0 192.abc.0.d 192.168.47.9'
route.route.openshift.io/edge-route annotated
  1. view the pod logs to see the invalid IP
iamin@iamin-mac Downloads % oc -n openshift-ingress logs router-default-5b7c764c88-kjvss | grep parseIPList

I0212 17:56:43.909529       1 template_helper.go:366] "msg"="parseIPList called" "logger"="template" "value"="0.0.0.0 192.abc.0.d 192.168.47.9"
I0212 17:56:43.909568       1 template_helper.go:392] "msg"="parseIPList found invalid IP/CIDR" "192.abc.0.d"="(MISSING)" "logger"="template"
I0212 17:56:43.909599       1 template_helper.go:402] "msg"="parseIPList parsed the list" "logger"="template" "validIPs"="0.0.0.0 192.168.47.9"

  1. check haProxy to make sure only valid logs are present and invalid logs aren't
iamin@iamin-mac cluster-ingress-operator % oc -n openshift-ingress rsh  router-default-5b7c764c88-kjvss
sh-5.1$ cat haproxy.config | grep edge-route
backend be_edge_http:default:edge-route
sh-5.1$ cat haproxy.config | grep edge-route -A25
backend be_edge_http:default:edge-route
  mode http
  option redispatch
  option forwardfor
  balance random
  acl allowlist src 0.0.0.0 192.168.47.9
  tcp-request content reject if !allowlist
  1. annotate route with all invalid IPs
iamin@iamin-mac cluster-ingress-operator % oc annotate route edge-route --overwrite haproxy.router.openshift.io/ip_whitelist='0.0.0.e 192.abc.0.d 192.168.47.'
route.route.openshift.io/edge-route annotated
  1. check logs to make sure all IPs are flagged as invalid
iamin@iamin-mac cluster-ingress-operator % oc -n openshift-ingress logs router-default-5b7c764c88-kjvss                                                     

I0212 18:01:24.498486       1 template_helper.go:366] "msg"="parseIPList called" "logger"="template" "value"="0.0.0.e 192.abc.0.d 192.168.47."
I0212 18:01:24.498498       1 template_helper.go:392] "msg"="parseIPList found invalid IP/CIDR" "0.0.0.e"="(MISSING)" "logger"="template"
I0212 18:01:24.498527       1 template_helper.go:392] "msg"="parseIPList found invalid IP/CIDR" "192.abc.0.d"="(MISSING)" "logger"="template"
I0212 18:01:24.498539       1 template_helper.go:392] "msg"="parseIPList found invalid IP/CIDR" "192.168.47."="(MISSING)" "logger"="template"
I0212 18:01:24.499173       1 template_helper.go:366] "msg"="parseIPList called" "logger"="template" "value"=""
I0212 18:01:24.499178       1 template_helper.go:370] "msg"="parseIPList empty list found" "logger"="template"
  1. haProxy should not contain any IPs
iamin@iamin-mac cluster-ingress-operator % oc -n openshift-ingress rsh  router-default-5b7c764c88-kjvss                                                       
sh-5.1$ cat haproxy.config | grep edge-route -A25
backend be_edge_http:default:edge-route
  mode http
  option redispatch
  option forwardfor
  balance random

marking bug as verified
/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Feb 11, 2025
@openshift-ci-robot
Copy link
Contributor

@mJace: This pull request references Jira Issue OCPBUGS-39403, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.19.0) matches configured target version for branch (4.19.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

No GitHub users were found matching the public email listed for the QA contact in Jira (iamin@redhat.com), skipping review request.

In response to this:

Summary

This PR updates the parseIPList function to handle IP lists containing invalid IPs or CIDRs more gracefully. Previously, the function would return an empty string as soon as it encountered an invalid IP or CIDR. This update ensures that the function will now continue processing the rest of the list and return a space-separated string of all valid IPs and CIDRs.

Changes

  • Modified parseIPList to:
  • Log all invalid entries for troubleshooting.
  • Return a string of valid IPs and CIDRs, or an empty string if none are valid.

Benefits

  • Improved Robustness: The function now handles mixed validity IP lists more gracefully, allowing valid entries to be processed even if there are some invalid entries.
  • Enhanced Debugging: Logging of invalid IPs or CIDRs provides better visibility into issues with input data.

Additional Notes

  • The function continues to trim and validate input while logging detailed information about invalid entries.
  • Ensure to review and test the function with various IP list scenarios to confirm the correctness of the changes.

Instructions 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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD b447c4d and 2 for PR HEAD f0926cb in total

Copy link
Contributor

openshift-ci bot commented Feb 20, 2025

@mJace: all tests passed!

Full PR test history. Your PR dashboard.

Instructions 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.

@openshift-merge-bot openshift-merge-bot bot merged commit ffb6637 into openshift:master Feb 20, 2025
9 checks passed
@openshift-ci-robot
Copy link
Contributor

@mJace: Jira Issue OCPBUGS-39403: All pull requests linked via external trackers have merged:

Jira Issue OCPBUGS-39403 has been moved to the MODIFIED state.

In response to this:

Summary

This PR updates the parseIPList function to handle IP lists containing invalid IPs or CIDRs more gracefully. Previously, the function would return an empty string as soon as it encountered an invalid IP or CIDR. This update ensures that the function will now continue processing the rest of the list and return a space-separated string of all valid IPs and CIDRs.

Changes

  • Modified parseIPList to:
  • Log all invalid entries for troubleshooting.
  • Return a string of valid IPs and CIDRs, or an empty string if none are valid.

Benefits

  • Improved Robustness: The function now handles mixed validity IP lists more gracefully, allowing valid entries to be processed even if there are some invalid entries.
  • Enhanced Debugging: Logging of invalid IPs or CIDRs provides better visibility into issues with input data.

Additional Notes

  • The function continues to trim and validate input while logging detailed information about invalid entries.
  • Ensure to review and test the function with various IP list scenarios to confirm the correctness of the changes.

Instructions 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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

Distgit: ose-haproxy-router-base
This PR has been included in build ose-haproxy-router-base-container-v4.19.0-202502200708.p0.gffb6637.assembly.stream.el9.
All builds following this will include this PR.

@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

Distgit: openshift-enterprise-haproxy-router
This PR has been included in build openshift-enterprise-haproxy-router-container-v4.19.0-202502200708.p0.gffb6637.assembly.stream.el9.
All builds following this will include this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants