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

provider/aws: Remove default egress rule from Security Group on creation #1765

Merged
merged 8 commits into from
May 5, 2015

Conversation

catsby
Copy link
Contributor

@catsby catsby commented Apr 30, 2015

Security Groups in a VPC receive a default egress rule to permit all. This causes some issues though, as it's implicit, and causes errors if people try to add a duplicate rule. It also triggers a new plan if you do specify an egress rule, as we interpret that as needing to remove the old one.

This PR changes two things:

  • by default, if you specify an egress rule, we delete the default ALLOW ALL rule
  • you must now specify an egress rule when creating a Security Group inside a VPC reneged

Refs #1177
Fixes #1169, #1631
Probably fixes #1299

@@ -407,6 +411,23 @@ func resourceAwsSecurityGroupUpdateRules(
ns := n.(*schema.Set)

remove := expandIPPerms(group, os.Difference(ns).List())

if len(remove) == 0 && len(os.List()) == 0 && ruleset == "egress" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

len(remove) == 0 && len(os.List()) == 0 may be redundant, but I wasn't sure if len(os.List()) == 0 was enough. Should it be sufficient to check for nil here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably technically redundant, but I feel like it doesn't hurt to be extra explicit/conservative.

@catsby
Copy link
Contributor Author

catsby commented Apr 30, 2015

Note: some acceptance tests in SG now fail, but I can fix those if we think this is the right direction to take

},
},
IPProtocol: aws.String("-1"),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work if a user specifies the same egress rule in their config?

Probably an AccTest would answer one way or another.

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, it deletes the default, then immediately creates a new one

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, I forgot these lists end up getting executed serially, not in batches. Works for me!

@phinze
Copy link
Contributor

phinze commented Apr 30, 2015

I was picturing a wholly separate API request to specifically nuke the implicit rule, letting the remaining code do its thing unchanged, but if we can get this rule-list strategy tested and make it work I'm cool with it.

@catsby
Copy link
Contributor Author

catsby commented May 1, 2015

I've updated this, but am stuck on something.

The enforcement of an egress rule is, as it stands, only enforceable if the configuration of the Security Group (SG) sets the vpc_id attribute. If you do not, then the SG config has a nil value, and sent to AWS. If your AWS environment has a default VPC, the SG is created in that VPC, and gets the default egress rule applied.

We still revoke it just fine, but we failed to enforce the restriction. I can see confusion / problems from this, as users are probably used to but also maybe unaware of the default rule.

@ctiwald
Copy link
Contributor

ctiwald commented May 5, 2015

This is also contributing to the -1 protocol problem in #1177. Egress rules get the default, but local config doesn't have it, so there's always something found on plan.

@ctiwald
Copy link
Contributor

ctiwald commented May 5, 2015

Note this will also become a decision point for network ACLs, but the need isn't apparent because the read function for network ACLs is broken ( #1808 )

@catsby catsby force-pushed the f-aws-security-group-remove-default-egress branch from 2325c69 to e9b08cf Compare May 5, 2015 21:24

// TODO: We need to handle partial state better in the in-between
// TODO: We need to handle partial state better in the in-between
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace funkies here.

@phinze
Copy link
Contributor

phinze commented May 5, 2015

LGTM except for whitespace nits

@catsby
Copy link
Contributor Author

catsby commented May 5, 2015

@phinze ah, thanks; formatting issue after rebase ಠ_ಠ

Fixed, merging this

catsby added a commit that referenced this pull request May 5, 2015
…efault-egress

provider/aws: Remove default egress rule from Security Group on creation
@catsby catsby merged commit a400094 into master May 5, 2015
@catsby catsby deleted the f-aws-security-group-remove-default-egress branch May 5, 2015 21:47
@ghost
Copy link

ghost commented May 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants