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 using existing/shared Security Groups #5744

Merged
merged 3 commits into from
Oct 2, 2018

Conversation

rdrgmnzs
Copy link
Contributor

@rdrgmnzs rdrgmnzs commented Sep 3, 2018

This PR implements the ability to use an existing Security Groups for Instance Groups and Load Balancer on AWS.

This PR pulls in most of the work in #3562 #3595 #3625 while fixing a few issues. Credit for those goes to @justinsb and @chrislovecnm.

/assign @justinsb @geojaz @mikesplain

@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 Sep 3, 2018
@rdrgmnzs rdrgmnzs force-pushed the security_groups branch 3 times, most recently from f3914d8 to 8a404d8 Compare September 4, 2018 02:15
@chrisz100
Copy link
Contributor

What a huge thing... from going through it two times I'd say looks good, but second and third opinion YES PLEASE!
Thanks @rdrgmnzs !

/lgtm

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

@geojaz geojaz left a comment

Choose a reason for hiding this comment

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

the PR works and lgtm technically, but I'd like to get some more ideas about how we structure this in the cluster spec.

just in case my excitement about getting this feature done wasn't apparent, I want this feature so bad and have been waiting for a long time. Let's get the details worked out and get it into 1.11 alpha

docs/security_groups.md Show resolved Hide resolved
docs/security_groups.md Show resolved Hide resolved
// IdleTimeoutSeconds sets the timeout of the api loadbalancer.
IdleTimeoutSeconds *int64 `json:"idleTimeoutSeconds,omitempty"`
// SecurityGroup is the id of the security group to be use by the load balancer.
SecurityGroup *string `json:"securityGroup,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

I need to think about the representation of this data a bit- I think we need to figure out how to have one field in these structs for SG. I wish we hadn't called the field AdditionalSecurityGroups to start with, but this is the hand we are dealt.

My suggestion is to have one field to manage all of the SG parameters that we'll end up needing. Below are just some thoughts that can definitely use some iteration/smart ideas. Please jump in and help us sort this out. any ideas @justinsb?

Would a data structure like this get us anything?

type SecurityGroupSpec struct {
	AdoptDefaultSG bool`json:"adoptDefaultSG,true"`
	AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
}

// LoadBalancerAccessSpec provides configuration details related to API LoadBalancer and its access
type LoadBalancerAccessSpec struct {
	// Type of load balancer to create may Public or Internal.
	Type LoadBalancerType `json:"type,omitempty"`
	// IdleTimeoutSeconds sets the timeout of the api loadbalancer.
	IdleTimeoutSeconds *int64 `json:"idleTimeoutSeconds,omitempty"`
	SecurityGroupSpec SecurityGroupSpec 
        // Deprecation in lieu of SecurirtGroupSPec to come. for now let's just copy the slice
        AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
	// UseForInternalApi indicates wether the LB should be used by the kubelet
	UseForInternalApi bool `json:"useForInternalApi,omitempty"`
	// SSLCertificate allows you to specify the ACM cert to be used the the LB
	SSLCertificate string `json:"sslCertificate,omitempty"`
}

Does that make life better, worse, or equivalent to a PR that's already done and works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@geojaz as per the last Office Hour we decided to keep this as SecurityGroup correct?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 27, 2018
@geojaz
Copy link
Member

geojaz commented Sep 28, 2018 via email

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 29, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 1, 2018
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 1, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 2, 2018
Verbosely log when a user overwrites LB or IG security groups

Change SecurityGroup to SecurityGroupOverride

Allow using existing/shared Security Groups

Update tests
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 2, 2018
@rdrgmnzs
Copy link
Contributor Author

rdrgmnzs commented Oct 2, 2018

@geojaz SecurityGroupOverride it is!

Copy link
Member

@justinsb justinsb left a comment

Choose a reason for hiding this comment

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

One blocker I think - the cilium removal, but otherwise looks good to me - I'm going to do a pass with some of my "I wonder if this would be cleaner" thoughts, but we can do those in follow-on PRs if they work.

pkg/model/awsmodel/api_loadbalancer.go Outdated Show resolved Hide resolved
pkg/model/firewall.go Outdated Show resolved Hide resolved
Lifecycle: b.Lifecycle,
SecurityGroup: b.LinkToSecurityGroup(kops.InstanceGroupRoleNode),
SourceGroup: b.LinkToSecurityGroup(kops.InstanceGroupRoleMaster),
if len(groups) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is right - what if there was one node IG using the standard SG and another node IG using an override?

Copy link
Member

Choose a reason for hiding this comment

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

Tackled in #5862

name := "masters." + b.ClusterName()
baseGroup = &awstasks.SecurityGroup{
Name: s(name),
Lifecycle: lifecycle,
VPC: b.LinkToVPC(),
Description: s("Security group for masters"),
RemoveExtraRules: []string{
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: It's odd that RemoveExtraRules are here but not in the override...

Copy link
Member

Choose a reason for hiding this comment

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

I think I convinced myself in #5862 that it doesn't make a ton of sense for a shared (unmanaged) security group...

# Security Groups

## Use existing AWS Security Groups
**Note: Use this at your own risk, when existing SGs are used Kops will NOT ensure they are properly configured.**
Copy link
Member

Choose a reason for hiding this comment

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

I do hope we can relax this (ExistsAndWarnIfChanges should warn!), but we'll see :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this already happens. The issue is that this displays a compressed object on the terminal and unless you are looking for it, it can be easy to miss. Hence the note here, however I'm fine with removing the note as well.

sgLink = &awstasks.SecurityGroup{
Name: lbSpec.SecurityGroupOverride,
ID: lbSpec.SecurityGroupOverride,
Shared: fi.Bool(true),
Copy link
Member

Choose a reason for hiding this comment

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

I would have thought it should suffice to build it using LinkToELBSecurityGroup, but just create it with a specified ID and Shared=true. I'll take a look though...

Copy link
Member

@justinsb justinsb Oct 2, 2018

Choose a reason for hiding this comment

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

Tackled in #5863

lbSG.Tags = b.CloudTags(*lbSG.Name, false)

if lbSpec.SecurityGroupOverride != nil {
lbSG.Name = fi.String(*lbSpec.SecurityGroupOverride)
Copy link
Member

Choose a reason for hiding this comment

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

Ah maybe this is it, because the name is significant after all

Copy link
Member

@justinsb justinsb Oct 2, 2018

Choose a reason for hiding this comment

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

Tackled in #5863

@@ -208,19 +229,28 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
}
}

masterGroups, err := b.GetSecurityGroups(kops.InstanceGroupRoleMaster)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should make GetSecurityGroups return a richer data structure, like

type SecurityGroupMapping struct {
ID string
Suffix string
Groups []*InstanceGroup
}

func GetSecurityGroups() ([]SecurityGroupMapping, error) ...

Again ... thoughts for future refactoring though :-)

Copy link
Member

Choose a reason for hiding this comment

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

Tackled in #5862

FromPort: i64(443),
ToPort: i64(443),
CIDR: s(apiAccess),
for masterGroupName, masterGroup := range masterGroups {
Copy link
Member

Choose a reason for hiding this comment

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

Note to self for future refactoring - I'm wondering if we could have a helper function that did a security-group for each group, instead of doing a loop every time

Copy link
Member

Choose a reason for hiding this comment

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

This was not really any clearer, because we have to map the group into SecurityGroup or Source. It might be a little simpler, but not a huge win

t := &awstasks.SecurityGroupRule{
Name: s(fmt.Sprintf("all-nodes-to-master%s", suffix)),
Lifecycle: b.Lifecycle,
SecurityGroup: b.LinkToSecurityGroup(kops.InstanceGroupRoleMaster),
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to expand out the groups here. We can do that as a follow-on, I think

Copy link
Member

Choose a reason for hiding this comment

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

Tackled in #5862

@justinsb
Copy link
Member

justinsb commented Oct 2, 2018

Looking good! I have a follow-on for some of the edge-cases here (mixing security groups in a role, mixing override and default in a role) but I'll send a separate PR for those!

/approve
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrisz100, justinsb, rdrgmnzs

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 Oct 2, 2018
@k8s-ci-robot k8s-ci-robot merged commit c97ad57 into kubernetes:master Oct 2, 2018
k8s-ci-robot added a commit that referenced this pull request Oct 3, 2018
@machbio
Copy link

machbio commented Oct 3, 2018

Thanks @justinsb , @chrislovecnm and @rdrgmnzs for the feature - what is the milestone release version for this feature ?

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

7 participants