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

Security Group perms of FromPort 0 and ToPort -1 #223

Merged
merged 1 commit into from
Feb 29, 2016

Conversation

jacobo
Copy link
Contributor

@jacobo jacobo commented Feb 3, 2016

Security Group perms of FromPort 0 and ToPort -1

Fix generation of the FromPort and ToPort paramters when authorizing or revoking permissions on a security group.

Using min and max to get the parts of a range can somtimes return nil, using begin and end will always return the actual values the range was created with

Example: (0..-1).min is nil and (0..-1).max is also nil

Error message from AWS would be:

Invalid value 'Must specify both from and to ports with ICMP.' for portRange

@geemus
Copy link
Member

geemus commented Feb 5, 2016

I can see 0 as min, but why -1 as the default for max? Why not 0 for both? Or maybe even some other value? Sorry if I just lack context/understanding on this, haven't messed with this feature in ages.

@jacobo
Copy link
Contributor Author

jacobo commented Feb 8, 2016

because (0..0).max == 0 and (0..-1).max == nil ... really just workaround the shortcoming of ruby ranges...

an alternative might be something like (0..-1).to_s.split("..").map(&:to_i)

If we could go back in time and just accept 2 arguments instead of a range it would probably be cleaner..

Or maybe we need a new object PortRange...
class PortRange; def initialize(min,max) ...

@geemus
Copy link
Member

geemus commented Feb 8, 2016

Well, my question was maybe rather unclear. More directly, what is the context in which 0..-1 is the intended/desired value?

@jacobo
Copy link
Contributor Author

jacobo commented Feb 8, 2016

Apparently 0 to -1 is a valid ICMP port range... we were trying to delete a security group, and had to delete permissions, ran across a permission with port range 0 to -1 so generated a call to fog with (0..-1), which turned into an amazon call which was missing "FromPort" and "ToPort", because both the min and max of that range were nil and thus the call erred and failed. This patch "fixes" that problem.

@geemus
Copy link
Member

geemus commented Feb 9, 2016

Got it. How about we just allow you to pass from/to port options explicitly in the options hash to override the range values? Seems like that would be more explicit/less magical. I just worry that these defaults might work in the particular case you describe but cause unintended issues in other cases. What do you think?

Fix generation of the FromPort and ToPort paramters when authorizing or
revoking permissions on a security group.

Using `min` and `max` to get the parts of a range can somtimes return
nil, using `begin` and `end` will always return the actual values the
range was created with

Example: `(0..-1).min` is nil and `(0..-1).max` is also nil

Error message from AWS would be:

Invalid value 'Must specify both from and to ports with ICMP.' for
portRange
@jacobo jacobo force-pushed the security_group_port_range_bug branch from 93b7b87 to 4abac8e Compare February 9, 2016 20:26
@jacobo
Copy link
Contributor Author

jacobo commented Feb 9, 2016

Ok, sorry, I guess my initial "fix" was a bit hasty, here's a better one I think (It is a bit strange that the methods are called begin and end but they appear to work better than min and max)

@geemus
Copy link
Member

geemus commented Feb 10, 2016

@jacobo no worries, the quickest fix is usually the right one to reach for. I just was wary of side effects. I didn't even know about begin/end, sounds promising though.

@jacobo
Copy link
Contributor Author

jacobo commented Feb 29, 2016

soo... what's next, merge? do we need tests?

@geemus
Copy link
Member

geemus commented Feb 29, 2016

@jacobo yes. Sorry, I didn't realize the begin/end changes were already done. Thanks!

geemus added a commit that referenced this pull request Feb 29, 2016
Security Group perms of FromPort 0 and ToPort -1
@geemus geemus merged commit c5b14f9 into fog:master Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants