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

Add support for NLB security group #3329

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

oliviassss
Copy link
Collaborator

@oliviassss oliviassss commented Aug 10, 2023

Issue

Description

Added support of Security Groups for NLB. With the security group support, it is feasible to forward the NLB traffic to the EC2 instances without having to open up the instances for global access. For backwards compatibility, NLBs created without the security groups or the existing NLBs will continue to provide the legacy behavior. Similar to ALB, there are two sets of SGs for NLB - frontend and backend SGs:

  • The controller will automatically create and attach the frontend SG to the NLB provisioned, and add rules for inbound-cidrs and listen-ports. If the users want to attach existing frontend SG to the NLB, they can explicitly specify via annotation service.beta.kubernetes.io/aws-load-balancer-security-groups
  • The Backend SG controls the traffic between the NLB and the EC2 instances/ENIs, and it gets attached to the NLB similar to the frontend SG. In case of auto-generated frontend SG, the controller automatically adds Node/ENI SG rules to allow egress traffic from the NLB. The rule management is disabled by default if the frontend SG is specified via annotation. We provide an annotation to configure controller’s management on backend SG rules regardless of the frontend SG type service.beta.kubernetes.io/aws-load-balancer-manage-backend-security-group-rules: true/false

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

sg rules restriction on NLB
remove discovery from default code path, not needed for NLB with SG
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 10, 2023
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 93.77% and project coverage change: +0.90% 🎉

Comparison is base (05e6f58) 54.71% compared to head (09b6030) 55.61%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3329      +/-   ##
==========================================
+ Coverage   54.71%   55.61%   +0.90%     
==========================================
  Files         148      149       +1     
  Lines        8626     8819     +193     
==========================================
+ Hits         4720     4905     +185     
- Misses       3574     3577       +3     
- Partials      332      337       +5     
Files Changed Coverage Δ
pkg/config/feature_gates.go 0.00% <0.00%> (ø)
pkg/networking/backend_sg_provider.go 92.45% <78.57%> (-1.39%) ⬇️
pkg/service/model_build_load_balancer.go 84.22% <85.07%> (+2.07%) ⬆️
pkg/service/model_build_managed_sg.go 94.11% <94.11%> (ø)
pkg/service/model_build_target_group.go 87.58% <100.00%> (+1.90%) ⬆️
pkg/service/model_builder.go 91.34% <100.00%> (+3.04%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@M00nF1sh
Copy link
Collaborator

/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 Aug 10, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: M00nF1sh, oliviassss

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 Aug 10, 2023
@k8s-ci-robot k8s-ci-robot merged commit b805cc2 into kubernetes-sigs:main Aug 10, 2023
7 checks passed
@oliviassss oliviassss deleted the nlb-sg branch August 10, 2023 16:17
}
if !t.featureGates.Enabled(config.NLBSecurityGroup) {
if existingLB != nil && len(existingLB.LoadBalancer.SecurityGroups) != 0 {
return nil, errors.New("conflicting security groups configuration")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a terribly helpful error message, as it gives no clue as to what is conflicting. Better to say something like "existing NLB has security groups attached, but NLBSecurityGroup feature gate is disabled"

func (t *defaultModelBuildTask) buildLoadBalancerSecurityGroups(ctx context.Context, existingLB *elbv2deploy.LoadBalancerWithTags,
ipAddressType elbv2model.IPAddressType) ([]core.StringToken, error) {
if existingLB != nil && len(existingLB.LoadBalancer.SecurityGroups) == 0 {
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it not be possible to add a SG to an existing NLB by explicitly setting the relevant annotation?

ctx := context.Background()
stack, _, err := builder.Build(ctx, tt.svc)
stack, _, _, err := builder.Build(ctx, tt.svc)
if tt.wantError {
Copy link
Contributor

Choose a reason for hiding this comment

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

wantError should be more specific: it should be a string and should assert.EqualError()

ctx := context.Background()
stack, _, err := builder.Build(ctx, tt.svc)
stack, _, _, err := builder.Build(ctx, tt.svc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be doing asserts on the returned value of backendSGRequired

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants