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

Fix setting single dst prefix for NSG rule #6258

Merged
merged 1 commit into from
May 23, 2024

Conversation

zarvd
Copy link
Contributor

@zarvd zarvd commented May 22, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

If you’ve got NSG rules set up like the one below, trying to apply a service will throw an error because you can’t set destinationAddressPrefixes to ["*"]. This PR fixes that by using destinationAddressPrefix when there’s just one destination prefix.

{
  "id": "/subscriptions/b48b8ebc-3e57-47ff-8603-408c05a7f2ba/resourceGroups/mc_e2erg-runner-pkqtqwafxgdpcaish_e2eaks-tgc_eastus/providers/Microsoft.Network/networkSecurityGroups/aks-agentpool-40253661-nsg/securityRules/NRMS-Rule-105",
  "name": "NRMS-Rule-105",
  "properties": {
    "access": "Deny",
    "description": "DO NOT DELETE - Will result in ICM Sev 2 - Azure Core Security, see aka.ms/cainsgpolicy",
    "destinationAddressPrefix": "*",
    "destinationPortRanges": [
      "1433",
      "1434",
      "3306",
      "4333",
      "5432",
      "6379",
      "7000",
      "7001",
      "7199",
      "9042",
      "9160",
      "9300",
      "16379",
      "26379",
      "27017"
    ],
    "direction": "Inbound",
    "priority": 105,
    "protocol": "*",
    "sourceAddressPrefix": "Internet",
    "sourceAddressPrefixes": [],
    "sourcePortRange": "*",
    "sourcePortRanges": []
  },
  "type": "Microsoft.Network/networkSecurityGroups/securityRules"
}

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix setting single dst prefix for NSG rule

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 22, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @zarvd. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot requested review from jwtty and nilo19 May 22, 2024 01:47
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 22, 2024
@zarvd zarvd force-pushed the fix/nsg/dst-prefix branch from 0215fd9 to 8f01d95 Compare May 22, 2024 01:59
@@ -379,41 +379,6 @@ func (helper *RuleHelper) removeDestinationFromRule(rule *network.SecurityRule,
return helper.addAllowRule(rule.Protocol, ipFamily, ListSourcePrefixes(rule), prefixes, expectedPorts)
}

// RemoveDestinationPrefixesFromRules removes the given destination addresses from all rules.
func (helper *RuleHelper) RemoveDestinationPrefixesFromRules(prefixes []string) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this function only used in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it has been replaced with RemoveDestinationFromRules in LC306

@jwtty
Copy link
Member

jwtty commented May 22, 2024

/approve
/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 May 22, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jwtty, zarvd

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2024
@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

/test

@k8s-ci-robot
Copy link
Contributor

@zarvd: The /test command needs one or more targets.
The following commands are available to trigger required jobs:

  • /test pull-cloud-provider-azure-check
  • /test pull-cloud-provider-azure-e2e-capz
  • /test pull-cloud-provider-azure-e2e-ccm-capz
  • /test pull-cloud-provider-azure-e2e-ccm-dualstack-capz
  • /test pull-cloud-provider-azure-e2e-ccm-dualstack-vmss-capz
  • /test pull-cloud-provider-azure-e2e-ccm-ipv6-capz
  • /test pull-cloud-provider-azure-e2e-ccm-ipv6-vmss-capz
  • /test pull-cloud-provider-azure-e2e-ccm-vmss-capz
  • /test pull-cloud-provider-azure-e2e-ccm-vmss-ip-lb-capz
  • /test pull-cloud-provider-azure-e2e-ccm-vmss-multi-slb-capz
  • /test pull-cloud-provider-azure-e2e-ccm-vmss-shared-probe-capz
  • /test pull-cloud-provider-azure-e2e-ccm-vmssflex-capz
  • /test pull-cloud-provider-azure-unit

Use /test all to run the following jobs that were automatically triggered:

  • pull-cloud-provider-azure-check
  • pull-cloud-provider-azure-e2e-capz
  • pull-cloud-provider-azure-e2e-ccm-capz
  • pull-cloud-provider-azure-e2e-ccm-vmss-capz
  • pull-cloud-provider-azure-e2e-ccm-vmss-ip-lb-capz
  • pull-cloud-provider-azure-e2e-ccm-vmss-multi-slb-capz
  • pull-cloud-provider-azure-e2e-ccm-vmss-shared-probe-capz
  • pull-cloud-provider-azure-e2e-ccm-vmssflex-capz
  • pull-cloud-provider-azure-unit

In response to this:

/test

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.

@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

/test pull-cloud-provider-azure-e2e-ccm-dualstack-capz
/test pull-cloud-provider-azure-e2e-ccm-dualstack-vmss-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-vmss-capz

@@ -107,6 +107,17 @@ func ListDestinationPrefixes(r *network.SecurityRule) []string {
return rv
}

func SetDestinationPrefixes(r *network.SecurityRule, prefixes []string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to the change but it should not be exported since there is no usage outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we fix these style issues in the other PRs later? It may also need a dedicated issue to discuss these best practices, including the package structure.

@nilo19
Copy link
Contributor

nilo19 commented May 22, 2024

Generally looks good. Is it worth an e2e test?

@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

Generally looks good. Is it worth an e2e test?

I think this case is quite tricky as listing all invalid inputs in an E2E test is hard. I prefer to use unit tests for this one. I am thinking of adding a NSG checker to simulate ARM validation in UT (maybe could also send the real ARM request to validate further for integration testing), hoping it could help us identify more issues and fix them sooner.

@zarvd zarvd force-pushed the fix/nsg/dst-prefix branch from 8f01d95 to 908724e Compare May 22, 2024 03:47
@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

/test pull-cloud-provider-azure-e2e-ccm-dualstack-capz
/test pull-cloud-provider-azure-e2e-ccm-dualstack-vmss-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-vmss-capz

Copy link
Member

@feiskyer feiskyer left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 22, 2024
@zarvd zarvd force-pushed the fix/nsg/dst-prefix branch from 908724e to ed945fd Compare May 22, 2024 10:31
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 22, 2024
@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

/test pull-cloud-provider-azure-e2e-ccm-dualstack-capz
/test pull-cloud-provider-azure-e2e-ccm-dualstack-vmss-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-capz
/test pull-cloud-provider-azure-e2e-ccm-ipv6-vmss-capz

@zarvd
Copy link
Contributor Author

zarvd commented May 22, 2024

/retest

@zarvd zarvd force-pushed the fix/nsg/dst-prefix branch from ed945fd to 9eb25ae Compare May 23, 2024 00:44
@MartinForReal
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2024
@zarvd zarvd force-pushed the fix/nsg/dst-prefix branch from 9eb25ae to 881d353 Compare May 23, 2024 03:17
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2024
@zarvd
Copy link
Contributor Author

zarvd commented May 23, 2024

rebased again...

@zarvd
Copy link
Contributor Author

zarvd commented May 23, 2024

/retest

@nilo19
Copy link
Contributor

nilo19 commented May 23, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2024
@k8s-ci-robot k8s-ci-robot merged commit d2e192c into kubernetes-sigs:master May 23, 2024
18 checks passed
@zarvd zarvd deleted the fix/nsg/dst-prefix branch May 23, 2024 08:35
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants