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

Allow PrefixList for sshAccess and kubernetesApiAccess #13113

Merged
merged 1 commit into from Feb 15, 2022

Conversation

hierynomus
Copy link
Contributor

Signed-off-by: Jeroen van Erp jeroen@hierynomus.com

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 16, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @hierynomus. Thanks for your PR.

I'm waiting for a kubernetes 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 16, 2022
@k8s-ci-robot k8s-ci-robot added area/api area/provider/aws Issues or PRs related to aws provider do-not-merge/contains-merge-commits and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 16, 2022
@rifelpet
Copy link
Member

/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 Jan 16, 2022
@rifelpet
Copy link
Member

kops' cloudmock packages will need to be updated to recognize the new prefix list field. All of the changes needed should be in here

@hierynomus
Copy link
Contributor Author

Thanks for the pointer @rifelpet. Awaiting new build results now ;)

@@ -85,17 +85,23 @@ func validateClusterSpec(spec *kops.ClusterSpec, c *kops.Cluster, fieldPath *fie

// SSHAccess
for i, cidr := range spec.SSHAccess {
allErrs = append(allErrs, validateCIDR(cidr, fieldPath.Child("sshAccess").Index(i))...)
if !strings.HasPrefix(cidr, "pl-") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we (can we) add validation that the PrefixListID is actually valid by interrogating AWS, or don't we do that during validation?

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this only be allowed if the cloudprovider is AWS?

@hierynomus
Copy link
Contributor Author

@rifelpet Another question: Should we also add the PrefixList for the "ICMP for PMTU discovery" block? See:

// Allow ICMP traffic required for PMTU discovery
if utils.IsIPv6CIDR(cidr) {
c.AddTask(&awstasks.SecurityGroupRule{

If so, what should be the FromPort and ToPort?

@hierynomus
Copy link
Contributor Author

/retest

Copy link
Member

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

Perhaps modify one of the IPv6 e2e tests to use this?

@@ -85,17 +85,23 @@ func validateClusterSpec(spec *kops.ClusterSpec, c *kops.Cluster, fieldPath *fie

// SSHAccess
for i, cidr := range spec.SSHAccess {
allErrs = append(allErrs, validateCIDR(cidr, fieldPath.Child("sshAccess").Index(i))...)
if !strings.HasPrefix(cidr, "pl-") {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this only be allowed if the cloudprovider is AWS?

return strings.HasPrefix(id, "pl-")
}

func LimitIngress(t *awstasks.SecurityGroupRule, cidr string) *awstasks.SecurityGroupRule {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make this a receiver on awstasks.SecurityGroupRule? Perhaps call it SetPrefix()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added that as SetCidrOrPrefix, as I thought that SetPrefix wasn't fully covering the functionality.

Copy link
Member

Choose a reason for hiding this comment

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

My thinking was that a CIDR specifies a prefix. A "pl-" string is a prefix list. Both CIDR and PrefixList specify the subset of the address space that the SGR applies to.

I suppose "Prefix" is incorrectly singular when applied to prefix lists. I'm trying to find a good term to express the concept of the subset of address space.

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 agreed, basically either limit the ingress to certain address(blocks).

So that's why I initially chose LimitIngress

Copy link
Member

Choose a reason for hiding this comment

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

Except a security group rule can be for egress instead.

docs/cluster_spec.md Outdated Show resolved Hide resolved
docs/cluster_spec.md Outdated Show resolved Hide resolved
@johngmyers
Copy link
Member

As to ICMP/ICMPv6, you would need to query whether the prefix list in question contains IPv4 or IPv6 addresses, then add the appropriate rule. Per AWS documentation, a prefix list may contain only one address family.

@hierynomus
Copy link
Contributor Author

As to ICMP/ICMPv6, you would need to query whether the prefix list in question contains IPv4 or IPv6 addresses, then add the appropriate rule. Per AWS documentation, a prefix list may contain only one address family.

I've added this functionality, by passing the fi.Cloud.(awsup.AWSCloud) into the builder struct. Feel free to suggest a better way to obtain the AWS API.

I've kept the commit separate for now to ease the review process, I will squash it once you've OK'ed the implementation 😄

@hierynomus
Copy link
Contributor Author

Any ideas already @johngmyers on the naming of the method? Furthermore besides that, is there anything else needed? I've updated the complexe2e test to include 2 prefix lists (1 ipv4, 1 ipv6), which other e2e test needs something extra?

@johngmyers
Copy link
Member

Sorry, I haven't been able to get back to this due to the large review backlog.

@hierynomus
Copy link
Contributor Author

Hi @johngmyers Did you have any chance to come back to this PR again?

Copy link
Member

@hakman hakman left a comment

Choose a reason for hiding this comment

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

Hi @hierynomus. I did a first pass of the PR.
There are mostly small changes from my point of view, but would like to not do cloud calls in model.

pkg/apis/kops/validation/validation.go Show resolved Hide resolved
pkg/apis/kops/validation/validation.go Show resolved Hide resolved
pkg/apis/kops/validation/validation.go Show resolved Hide resolved
upup/pkg/fi/cloudup/awstasks/securitygrouprule.go Outdated Show resolved Hide resolved
Comment on lines 433 to 442
icmpIpv6 := false
if strings.HasPrefix(cidr, "pl-") {
b, err := b.IsIPv6PrefixList(cidr)
if err != nil {
return err
}
icmpIpv6 = b
} else {
icmpIpv6 = utils.IsIPv6CIDR(cidr)
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think model should check the kind of prefix with AWS. I would rather skip the ICMP rules for prefixes, for now.

As a curiosity, any idea what happens if you set IPv4 PrefixList to ICMPv6 protocol or IPV6 PrefixList to ICMPv4 protocol?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tried that out, AWS does allow to configure it like that, but not sure what the net effect is. I added a ICMPv4 inbound rule with an IPv6 type PrefixList, and the console accepted and created that.

Copy link
Member

Choose a reason for hiding this comment

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

So, let's skip this for now, to get it into 1.23 before the release. We can try later to add the ICMP rules and see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the effect would be of not rendering ICMP rules when a prefix list is in use? I took the approach of querying the AWS API from the IAM model, where that was already used, so I figured that was allowed ;).

Are you sure we can skip them?

Copy link
Member

Choose a reason for hiding this comment

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

It is required for Path MTU Discovery.
I am sure I don't want to call the cloud for this. 😄

docs/cluster_spec.md Outdated Show resolved Hide resolved
docs/cluster_spec.md Outdated Show resolved Hide resolved
pkg/model/awsmodel/api_loadbalancer.go Outdated Show resolved Hide resolved
cloudmock/aws/mockec2/prefixlists.go Outdated Show resolved Hide resolved
@hakman
Copy link
Member

hakman commented Feb 15, 2022

Great. Would you mind also squashing the commits before merging the PR?

@hierynomus
Copy link
Contributor Author

Great. Would you mind also squashing the commits before merging the PR?

Sure, will do that now!

Signed-off-by: Jeroen van Erp <jeroen@hierynomus.com>
Copy link
Member

@hakman hakman left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for taking the time to add this feature!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hakman

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 Feb 15, 2022
@k8s-ci-robot k8s-ci-robot merged commit bffc602 into kubernetes:master Feb 15, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 15, 2022
@hierynomus hierynomus deleted the issue-12925 branch February 15, 2022 15:27
k8s-ci-robot added a commit that referenced this pull request Feb 17, 2022
…-upstream-release-1.23

Automated cherry pick of #13113: Allow PrefixList for sshAccess and kubernetesApiAccess
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. area/api area/documentation area/provider/aws Issues or PRs related to aws provider 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants