Skip to content

[feat: gw api] Security Group discovery and management #4142

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

Merged
merged 11 commits into from
Apr 18, 2025

Conversation

zac-nixon
Copy link
Collaborator

Description

Adds logic to manage security groups, either via static IDs / names, or by controller managed SG. This logic combines the ingress and service paths to work for either nlb / alb.

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 k8s-ci-robot requested a review from M00nF1sh April 14, 2025 22:20
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 14, 2025
@k8s-ci-robot k8s-ci-robot requested a review from oliviassss April 14, 2025 22:20
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 14, 2025
Tags: tags,
}

if lbModelBuilder.loadBalancerType == elbv2model.LoadBalancerTypeNetwork {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have dedicated functions to build these LB type specific params? instead of big if blocks for better readability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

}

func (lbModelBuilder *loadBalancerBuilderImpl) translateSourcePrefixEnabled(b bool) elbv2model.EnablePrefixForIpv6SourceNat {
if b {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: Lets add proper variable name for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

func (lbModelBuilder *loadBalancerBuilderImpl) buildLoadBalancerName(lbConf *elbv2gw.LoadBalancerConfiguration, gw *gwv1.Gateway, scheme elbv2model.LoadBalancerScheme) (string, error) {
if lbConf.Spec.LoadBalancerName != nil {
name := *lbConf.Spec.LoadBalancerName
// The name of the loadbalancer can only have up to 32 characters
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i was just being defensive but yeah fair enough the whole point of using the CRD was to avoid having duplicate validations

@zac-nixon zac-nixon force-pushed the znixon/gw-sg-creation branch 2 times, most recently from 47f5eb6 to 1fcf866 Compare April 17, 2025 22:35
@wweiwei-li
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Apr 17, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@zac-nixon zac-nixon force-pushed the znixon/gw-sg-creation branch 2 times, most recently from c4a31e6 to 61c8da1 Compare April 18, 2025 19:09
Copy link
Collaborator

@shraddhabang shraddhabang 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

protocolSet = protocolSet.Insert(string(ec2types.ProtocolUdp))
break
default:
// Ignore? Throw error?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can ignore this one since the conversion would fail at the time of building RouteDescriptors.

// CIDR Loop
for _, cidr := range sourceRanges {
isIPv6 := isIPv6CIDR(cidr)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we simplify these nested ifs to something like this for better readability?

				if isIPv6 && includeIPv6 {
					permissions = append(permissions, ec2model.IPPermission{
						IPProtocol: protocol,
						FromPort:   awssdk.Int32(int32(port)),
						ToPort:     awssdk.Int32(int32(port)),
						IPv6Range: []ec2model.IPv6Range{
							{
								CIDRIPv6: cidr,
							},
						},
					})
				} else {
					permissions = append(permissions, ec2model.IPPermission{
						IPProtocol: protocol,
						FromPort:   awssdk.Int32(int32(port)),
						ToPort:     awssdk.Int32(int32(port)),
						IPRanges: []ec2model.IPRange{
							{
								CIDRIP: cidr,
							},
						},
					})
				}

				if enableICMP && isIPv6 && includeIPv6 {
					permissions = append(permissions, ec2model.IPPermission{
						IPProtocol: shared_constants.ICMPV6Protocol,
						FromPort:   awssdk.Int32(shared_constants.ICMPV6TypeForPathMtu),
						ToPort:     awssdk.Int32(shared_constants.ICMPV6CodeForPathMtu),
						IPv6Range: []ec2model.IPv6Range{
							{
								CIDRIPv6: cidr,
							},
						},
					})
				} else {
					permissions = append(permissions, ec2model.IPPermission{
						IPProtocol: shared_constants.ICMPV4Protocol,
						FromPort:   awssdk.Int32(shared_constants.ICMPV4TypeForPathMtu),
						ToPort:     awssdk.Int32(shared_constants.ICMPV4CodeForPathMtu),
						IPRanges: []ec2model.IPRange{
							{
								CIDRIP: cidr,
							},
						},
					})
				}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO, I don't think it's more readable. Also, it looks like there is a bug as it would always enable icmpv4 if icmp was not enabled.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shraddhabang, zac-nixon

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:
  • OWNERS [shraddhabang,zac-nixon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zac-nixon zac-nixon force-pushed the znixon/gw-sg-creation branch from 61c8da1 to 5c1f930 Compare April 18, 2025 19:16
@zac-nixon zac-nixon merged commit 685788c into kubernetes-sigs:main Apr 18, 2025
8 of 9 checks passed
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. 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