Skip to content

Conversation

@ck319
Copy link
Contributor

@ck319 ck319 commented Dec 29, 2022

Reason for Change:

This fixes an issue where unsupported IPV6 addresses were not being validated at the translate step, causing an error when attempting to add them to the dataplane.

Issue Fixed:

Requirements:

Notes:
Add check for valid IPV4 addresses in the translate policy step

@ck319 ck319 requested a review from a team as a code owner December 29, 2022 19:11
@ck319 ck319 requested review from vakalapa and removed request for a team December 29, 2022 19:11
@ck319 ck319 added the npm Related to NPM. label Dec 29, 2022
Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

left some comments. Could you also add a short description of the current issue and how your PR fixes it?

klog.Errorf("Failed to translate podSelector in NetworkPolicy %s in namespace %s: %s", netPolObj.ObjectMeta.Name, netPolObj.ObjectMeta.Namespace, err.Error())
// The exec time isn't relevant here, so consider a no-op.
return metrics.NoOp, errNetPolTranslationFailure
return metrics.NoOp, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment why we return nil here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

npmNetPol := policies.NewNPMNetworkPolicy(netPolName, npObj.Namespace)

// check if IPs are valid IPV4 addresses
for _, egress := range npObj.Spec.Egress {
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, we perform all error checking in translateRule(), with one exception below in the ad-hoc validation on the final NPMNetworkPolicy. See #1717 for an example of erroring through translateRule().

In general, I feel it's best to keep code consistent so long as it doesn't add complexity. In this situation, it seems there could be a small, clean solution through translateRule().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

// ErrUnsupportedSCTP is returned when SCTP protocol is used in windows.
ErrUnsupportedSCTP = errors.New("unsupported SCTP protocol used on windows")
ErrUnsupportedSCTP = errors.New("unsupported SCTP protocol used on windows")
ErrInvalidIPV6Address = errors.New("invalid IPV6 address")
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: seems this error will be thrown for any IPv6 or for an invalid IPv4. Maybe "unsupported" is a better word for IPv6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

huntergregory
huntergregory previously approved these changes Jan 5, 2023
@ck319 ck319 merged commit 04a3d29 into master Feb 8, 2023
@ck319 ck319 deleted the ckovacs_ipv6check branch February 8, 2023 04:55
rjdenney pushed a commit that referenced this pull request Mar 13, 2023
* add check for ipv6 addresses in translatePolicy

* fix static error lint issue

* updated static error name and moved IPV4 logic

* moved check to ipBlockRule

* updated UT

---------

Co-authored-by: Hunter Gregory <42728408+huntergregory@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Related to NPM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants