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

Refine LoadBalancer service access control and consolidating security-rules #5164

Conversation

zarvd
Copy link
Contributor

@zarvd zarvd commented Dec 14, 2023

What type of PR is this?

/cleanup

What this PR does / why we need it:

Purpose: create as few security rules as possible. (detail in #4713)
This PR has a ton of changes because we’ve completely changed the pattern for security rules.

Some screenshots:

Without allow list
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  type: LoadBalancer
  ipFamilyPolicy: PreferDualStack
  selector:
    app: foo
  ports:
    - name: port1
      protocol: TCP
      port: 30102
      targetPort: 30102
    - name: port2
      protocol: UDP
      port: 30102
      targetPort: 30102
    - name: port3
      protocol: TCP
      port: 30103
      targetPort: 30103

IPv4
image

IPv4 and IPv6
image

With additional public IPs
apiVersion: v1
kind: Service
metadata:
  name: foo
  annotations:
    service.beta.kubernetes.io/azure-additional-public-ips: "10.0.0.1,10.0.0.2"
spec:
  type: LoadBalancer
  ipFamilyPolicy: PreferDualStack
  selector:
    app: foo
  ports:
    - name: port1
      protocol: TCP
      port: 30102
      targetPort: 30102
    - name: port2
      protocol: UDP
      port: 30102
      targetPort: 30102
    - name: port3
      protocol: TCP
      port: 30103
      targetPort: 30103

image

Disable floating IP
apiVersion: v1
kind: Service
metadata:
  name: foo
  annotations:
    service.beta.kubernetes.io/azure-disable-load-balancer-floating-ip: "true"
spec:
  type: LoadBalancer
  ipFamilyPolicy: PreferDualStack
  selector:
    app: foo
  ports:
    - name: port1
      protocol: TCP
      port: 30102
      targetPort: 30102
    - name: port2
      protocol: UDP
      port: 30102
      targetPort: 30102
    - name: port3
      protocol: TCP
      port: 30103
      targetPort: 30103

NOTE: use backend pool nodes IPs as the destination addresses
image

With allow list
apiVersion: v1
kind: Service
metadata:
  name: foo
  annotations:
    service.beta.kubernetes.io/azure-allowed-service-tags: "AzureCloud,AzureDatabricks"
    service.beta.kubernetes.io/azure-allowed-ip-ranges: "10.10.10.10/32,10.10.10.11/32,2001:1234::/64"
spec:
  type: LoadBalancer
  ipFamilyPolicy: PreferDualStack
  selector:
    app: foo
  ports:
    - name: port1
      protocol: TCP
      port: 30102
      targetPort: 30102
    - name: port2
      protocol: UDP
      port: 30102
      targetPort: 30102
    - name: port3
      protocol: TCP
      port: 30103
      targetPort: 30103

image

Which issue(s) this PR fixes:

Fixes #4713
Fixes #4919

Special notes for your reviewer:

I’ve rewritten the logic that handles the configuration, but it should still behave the same way:

  • service.beta.kubernetes.io/azure-allowed-ip-ranges
  • service.beta.kubernetes.io/azure-allowed-service-tags
  • service.beta.kubernetes.io/azure-disable-load-balancer-floating-ip
  • service.beta.kubernetes.io/azure-additional-public-ips
  • and spec spec.LoadBalancerSourceRanges

The annotations would be deprecated after this change:

  • service.beta.kubernetes.io/azure-shared-securityrule now all the rules would be as shared.

code review guidance
This PR is pretty big, so I’ll break it down here to make it less of a headache. Sorry in advance!

The E2E tests aren’t finished yet (they still need some refactoring), but you can already start reviewing.

Does this PR introduce a user-facing change?

Refine consolidating security-rules for LoadBalancer service.
Deprecate service annotation `service.beta.kubernetes.io/azure-shared-securityrule`.

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


@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Dec 14, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 14, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @lodrem. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 14, 2023
@zarvd zarvd force-pushed the refactor-lb/consolidate-security-rules branch from dc95d8b to f4ce112 Compare December 14, 2023 11:17
@nilo19
Copy link
Contributor

nilo19 commented Dec 19, 2023

/kind feature

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 19, 2023
@nilo19
Copy link
Contributor

nilo19 commented Dec 19, 2023

/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 do-not-merge/needs-kind needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 19, 2023
@nilo19
Copy link
Contributor

nilo19 commented Dec 19, 2023

The IPV6 address in the last example does not appear in the source column of the screenshot. Is it expected?

@zarvd zarvd force-pushed the refactor-lb/consolidate-security-rules branch from f4ce112 to 00b55ba Compare December 20, 2023 06:01
@zarvd
Copy link
Contributor Author

zarvd commented Dec 20, 2023

The IPV6 address in the last example does not appear in the source column of the screenshot. Is it expected?

Yes because that cluster didn't enable IPv6.

If dual stack enabled, you would see something like:
allowlist-dualstack

@zarvd zarvd force-pushed the refactor-lb/consolidate-security-rules branch 6 times, most recently from 046915e to 7b157f3 Compare December 22, 2023 07:28
)

t.Run("internal Load Balancer", func(t *testing.T) {
t.Run("noop when no allow list specified", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

any tests when ILB services are annotated with allowded CIRDs and service tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Added a few more tests for ILB. They should cover its code path.

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.

Thank you for the excellent refactoring. The code is much clearer now. The changes LGTM in general, just added a few comments.

@feiskyer feiskyer added this to the v1.29 milestone Jan 3, 2024
@zarvd zarvd force-pushed the refactor-lb/consolidate-security-rules branch 3 times, most recently from 34422c6 to a7d613b Compare January 3, 2024 15:18
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
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feiskyer, lodrem

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 Jan 5, 2024
@zarvd zarvd force-pushed the refactor-lb/consolidate-security-rules branch from a7d613b to 87a5835 Compare January 5, 2024 02:22
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2024
@lzhecheng
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 Jan 5, 2024
@k8s-ci-robot k8s-ci-robot merged commit 1d8032f into kubernetes-sigs:master Jan 5, 2024
18 checks passed
@zarvd zarvd deleted the refactor-lb/consolidate-security-rules branch January 5, 2024 06:50
@phealy
Copy link

phealy commented Jan 5, 2024

Looks amazing - thank you for all the hard work and reviews, @lodrem , @nilo19 , @feiskyer, @lzhecheng, and anyone else I missed!

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/feature Categorizes issue or PR as related to a new feature. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
6 participants