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

Support optimized security group rules for ALB #2205

Merged
merged 2 commits into from
Sep 20, 2021

Conversation

kishorj
Copy link
Collaborator

@kishorj kishorj commented Sep 1, 2021

Issue

Issue: #2118

Description

Add support for using shared backend security groups for ALB. This will result in using a constant number of SG rules per cluster for the purpose of allowing access to ALB traffic. Also enable management of security group rules for manually specified security groups. For details refer to issue #2118.

Tests

  • Backend SG feature get enabled by default, SG is auto-generated if needed, sg name is of the format k8s--traffic-<15 hex chars of sha256(clusterName + VPCID)>
  • backend SG is attached to the ALB
  • Ingress rule gets added to the instance security group to allow ALB traffic
  • Ingresses in the same cluster share the backend SG
  • backend SG gets deleted automatically if no longer needed
  • Ingresses with alb.ingress.kubernetes.io/security-groups annotation don't use the backend SG by default
  • When alb.ingress.kubernetes.io/manage-security-group-rules: "true" annotation is applied to ingress with manual SG configuration, the backend SG gets attached to the corresponding ALB, and the node SG gets updated to allow traffic
  • With manual security group configuration and manage rules set to true on an ingress, model builder returns error if backend security group feature is not enabled
  • When backend SG feature is disabled via the controller flag, the auto-generated SG gets used in the node SG rules as before
  • Backend SGs can be configured via command line flag --backend-security-groups in lieu of auto-generated ones

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 🌟

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 1, 2021
@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2021

Codecov Report

Merging #2205 (cf095ae) into main (7b3d25d) will increase coverage by 0.79%.
The diff coverage is 68.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2205      +/-   ##
==========================================
+ Coverage   52.39%   53.18%   +0.79%     
==========================================
  Files         133      135       +2     
  Lines        7257     7446     +189     
==========================================
+ Hits         3802     3960     +158     
- Misses       3158     3178      +20     
- Partials      297      308      +11     
Impacted Files Coverage Δ
pkg/config/controller_config.go 20.00% <0.00%> (-5.65%) ⬇️
pkg/ingress/model_build_managed_sg.go 66.66% <ø> (-0.65%) ⬇️
pkg/networking/backend_sg_provider_mocks.go 0.00% <0.00%> (ø)
pkg/ingress/model_builder.go 63.63% <57.14%> (+0.71%) ⬆️
pkg/ingress/model_build_load_balancer.go 61.86% <58.97%> (+9.90%) ⬆️
pkg/networking/backend_sg_provider.go 90.35% <90.35%> (ø)
pkg/ingress/model_build_target_group.go 73.74% <100.00%> (+0.77%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b3d25d...cf095ae. Read the comment docs.

@kishorj kishorj marked this pull request as ready for review September 1, 2021 20:14
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 1, 2021
@kishorj
Copy link
Collaborator Author

kishorj commented Sep 1, 2021

/retest

}

func (p *defaultBackendSGProvider) isBackendSGRequired(ctx context.Context) (bool, error) {
ingList := &networking.IngressList{}
Copy link
Collaborator

@M00nF1sh M00nF1sh Sep 16, 2021

Choose a reason for hiding this comment

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

personally i feel this depends on ingress implementation details too much.

also, seems the backendSG is not cleaned if there are some ingress in cluster even the left Ingresses don't need the backendSG.

shall we have a dedicated finalizer so that only ingresses/services needs backSG is added these finalizers?
if we have that, we can

call a dedicated function to test whether ingress/service needs backendSG, and then add this dedicated finalizer and invoke backendSGProvider.Get inside the group controller, and pass obtained backendSG into modelBuilder.
and then call backendSGProvider.Release if any group member have this finalizer, and remove the finalizer if it succeeds.

Or instead of add the finalizer in groupController, we have library some adds the finalizer before we create any cluster/controller-specific resources like backendSG, (e.g. make backendSGProvider.Get accepts a list of k8s resources as well).

i guess we could have a lot cluster/controller-specific resources like this backendSG in the future, e.g. a lambda function used to rewrite http requests for albs to do path rewrite)

@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 Sep 20, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 merged commit 4749148 into kubernetes-sigs:main Sep 20, 2021
@kishorj kishorj deleted the optimized-sg branch February 18, 2022 18:46
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.

4 participants