Merge lp://staging/~jameinel/juju-core/security-group-group-id-1226996 into lp://staging/juju-core/1.14

Proposed by John A Meinel
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 1750
Proposed branch: lp://staging/~jameinel/juju-core/security-group-group-id-1226996
Merge into: lp://staging/juju-core/1.14
Diff against target: 238 lines (+144/-9)
4 files modified
environs/jujutest/livetests.go (+4/-0)
provider/openstack/export_test.go (+24/-0)
provider/openstack/live_test.go (+86/-0)
provider/openstack/provider.go (+30/-9)
To merge this branch: bzr merge lp://staging/~jameinel/juju-core/security-group-group-id-1226996
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+186321@code.staging.launchpad.net

Commit message

provider/openstack: bug #1226996 SecurityGroup

We intended to allow access to any port for any instance in the
default security group. However, we didn't specify a CIDR and we
didn't reference the Source Group Id. Which meant we actually were
exposing *all* ports to *all* machines.

https://codereview.appspot.com/13562045/
R=fwereade, rogpeppe

Description of the change

provider/openstack: bug #1226996 SecurityGroup

We intended to allow access to any port for any instance in the
default security group. However, we didn't specify a CIDR and we
didn't reference the Source Group Id. Which meant we actually were
exposing *all* ports to *all* machines.

I do have some tests that the security group we get back from
EnsureGroup has the right bits set. I was hoping for a slightly better
cross-provider test that actually runs a service on a random port and
ensures that we are unable to actually connect to that port.

However, I think this is a nice small fix for 1.14 which is worthy of
landing.

https://codereview.appspot.com/13562045/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :
Download full text (5.3 KiB)

Reviewers: mp+186321_code.launchpad.net,

Message:
Please take a look.

Description:
provider/openstack: bug #1226996 SecurityGroup

We intended to allow access to any port for any instance in the
default security group. However, we didn't specify a CIDR and we
didn't reference the Source Group Id. Which meant we actually were
exposing *all* ports to *all* machines.

I do have some tests that the security group we get back from
EnsureGroup has the right bits set. I was hoping for a slightly better
cross-provider test that actually runs a service on a random port and
ensures that we are unable to actually connect to that port.

However, I think this is a nice small fix for 1.14 which is worthy of
landing.

https://code.launchpad.net/~jameinel/juju-core/security-group-group-id-1226996/+merge/186321

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13562045/

Affected files (+71, -0 lines):
   A [revision details]
   M provider/openstack/export_test.go
   M provider/openstack/live_test.go
   M provider/openstack/provider.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130917234003-54re4ia2qmlq7xt3
+New revision: <email address hidden>

Index: provider/openstack/export_test.go
=== modified file 'provider/openstack/export_test.go'
--- provider/openstack/export_test.go 2013-08-21 01:31:34 +0000
+++ provider/openstack/export_test.go 2013-09-18 10:25:42 +0000
@@ -9,6 +9,7 @@
   "strings"
   "text/template"

+ "launchpad.net/goose/errors"
   "launchpad.net/goose/identity"
   "launchpad.net/goose/nova"
   "launchpad.net/goose/swift"
@@ -235,6 +236,25 @@
   WritablePublicStorage(e).Remove(productMetadatafile)
  }

+// DiscardSecurityGroup cleans up a security group, it is not an error to
+// delete something that doesn't exist.
+func DiscardSecurityGroup(e environs.Environ, name string) error {
+ env := e.(*environ)
+ novaClient := env.nova()
+ group, err := novaClient.SecurityGroupByName(name)
+ if err != nil {
+ if errors.IsNotFound(err) {
+ // Group already deleted, done
+ return nil
+ }
+ }
+ err = novaClient.DeleteSecurityGroup(group.Id)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
  func FindInstanceSpec(e environs.Environ, series, arch, cons string) (spec
*instances.InstanceSpec, err error) {
   env := e.(*environ)
   spec, err = findInstanceSpec(env, &instances.InstanceConstraint{

Index: provider/openstack/live_test.go
=== modified file 'provider/openstack/live_test.go'
--- provider/openstack/live_test.go 2013-08-21 18:38:22 +0000
+++ provider/openstack/live_test.go 2013-09-18 10:25:42 +0000
@@ -7,9 +7,12 @@
   "crypto/rand"
   "fmt"
   "io"
+
   gc "launchpad.net/gocheck"
   "launchpad.net/goose/client"
   "launchpad.net/goose/identity"
+ "launchpad.net/goose/nova"
+
   "launchpad.net/juju-core/environs"
   "launchpad.net/juju-core/environs/jujutest"
   envtesting "launchpad.net/juju-core/environs/testing"
@@ -127,3 +130,42 @@
   t.LiveTests.TearDownTest(c)
   t.LoggingSuite.TearDownTest...

Read more...

Revision history for this message
John A Meinel (jameinel) wrote :

This might actually break the openstack live tests. I'm trying to go between trunk and this branch to figure out what is going on. I *think* in the live tests we actually start the server on a random port (as though we were launching it locally).

In "-gocheck.vv" here I see:

"dialing wss://15.185.89.136:177777/"

Which, AIUI isn't actually exposed by default. If I look at the secgroup, I see that we *do* expose 19034 which is where Mongo is running, but we *aren't* exposing the API port.

So this might break some juju commands (juju get) which want to connect direct to the API. It seems we are missing a test that the API port is by default exposed to the world after bootstrap.

Revision history for this message
John A Meinel (jameinel) wrote :

So I won't land this as is, but I'm still interested in getting feedback if it is a sane direction.

Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :

On 2013/09/19 10:53:03, jameinel wrote:
> Please take a look.

This should now properly bootstrap on Openstack. I'm still testing and
https://bugs.launchpad.net/bugs/1227533 got a bit in the way of manual
testing, but these security groups should be sane.

https://codereview.appspot.com/13562045/

Revision history for this message
Roger Peppe (rogpeppe) wrote :

LGTM with some minor suggestions below.

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go
File provider/openstack/export_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go#newcode241
provider/openstack/export_test.go:241: func DiscardSecurityGroup(e
environs.Environ, name string) error {
This is more involved logic than I'd usually expect to see in
export_test.go.
Perhaps define as discardSecurityGroup inside the implementation
and "var DiscardSecurityGroup = discardSecurityGroup" here?

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go
File provider/openstack/live_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go#newcode188
provider/openstack/live_test.go:188: defer cleanup()
again?

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go
File provider/openstack/provider.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go#newcode964
provider/openstack/provider.go:964: return e.ensureGroup(groupName,
why not use e.jujuGroupName as before?

https://codereview.appspot.com/13562045/

Revision history for this message
William Reade (fwereade) wrote :

LGTM

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go
File provider/openstack/export_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go#newcode241
provider/openstack/export_test.go:241: func DiscardSecurityGroup(e
environs.Environ, name string) error {
On 2013/09/19 13:00:21, rog wrote:
> This is more involved logic than I'd usually expect to see in
export_test.go.
> Perhaps define as discardSecurityGroup inside the implementation
> and "var DiscardSecurityGroup = discardSecurityGroup" here?

I think it's reasonable, though -- if it's useful for testing, but not
"real" functionality it's perfectly proper to put it here rather than
clutter up the package when built not as a test.

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go
File provider/openstack/live_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go#newcode194
provider/openstack/live_test.go:194: // client-via-API we can disable
the State port as well.)
aside: this is exactly what the firewaller does, and is another reason
to keep self-hosted juju in mind.

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go
File provider/openstack/provider.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go#newcode1006
provider/openstack/provider.go:1006: // other instances that might be
running on the same OpenStack account.
This does assume no two people will share both an account and an env
name; this has bitten people in practice, IIRC. Maybe worth pointing
that out explicitly here?

https://codereview.appspot.com/13562045/

Revision history for this message
Roger Peppe (rogpeppe) wrote :

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go
File provider/openstack/export_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go#newcode241
provider/openstack/export_test.go:241: func DiscardSecurityGroup(e
environs.Environ, name string) error {
On 2013/09/19 13:09:11, fwereade wrote:
> On 2013/09/19 13:00:21, rog wrote:
> > This is more involved logic than I'd usually expect to see in
export_test.go.
> > Perhaps define as discardSecurityGroup inside the implementation
> > and "var DiscardSecurityGroup = discardSecurityGroup" here?

> I think it's reasonable, though -- if it's useful for testing, but not
"real"
> functionality it's perfectly proper to put it here rather than clutter
up the
> package when built not as a test.

As an alternative, how about exporting only that functionality that
needs to be exported.

func NovaClient(e environs.Environ) *nova.Client {
     return e.(*environ).nova()
}

Then we can move DiscardSecurityGroup near the place it's used.

https://codereview.appspot.com/13562045/

Revision history for this message
John A Meinel (jameinel) wrote :

Please take a look.

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go
File provider/openstack/export_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/export_test.go#newcode241
provider/openstack/export_test.go:241: func DiscardSecurityGroup(e
environs.Environ, name string) error {
On 2013/09/19 13:00:21, rog wrote:
> This is more involved logic than I'd usually expect to see in
export_test.go.
> Perhaps define as discardSecurityGroup inside the implementation
> and "var DiscardSecurityGroup = discardSecurityGroup" here?

Well, it is deleting security groups which is something we *don't* ever
do in live code. So I'm hesitant to put something in there just to
expose it for tests.

If we fix bugs like: https://bugs.launchpad.net/bugs/1227574 then I
think it is reasonable to share the implementation.

So I could move it, but I'd rather wait until we are actually going to
be calling it from there.

both provider/ec2/export_test.go and provider/openstack/export_test.go
have a fair amount of test-specific logic in them, so it doesn't seem
unprecedented. state/export_test.go also has AddCustomCharm with lots of
logic. It even has a private helper function for two of the other
exported functions. :)

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go
File provider/openstack/live_test.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/live_test.go#newcode188
provider/openstack/live_test.go:188: defer cleanup()
On 2013/09/19 13:00:21, rog wrote:
> again?

no, the third time should be removed :)

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go
File provider/openstack/provider.go (right):

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go#newcode964
provider/openstack/provider.go:964: return e.ensureGroup(groupName,
On 2013/09/19 13:00:21, rog wrote:
> why not use e.jujuGroupName as before?

for testability. jujuGroupName isn't exposed, but I can expose just this
function and then pass whatever name I want from the test suite.

It means I can test setting security groups in a "live" fashion without
having to actually start a machine.

https://codereview.appspot.com/13562045/diff/4001/provider/openstack/provider.go#newcode1006
provider/openstack/provider.go:1006: // other instances that might be
running on the same OpenStack account.
On 2013/09/19 13:09:11, fwereade wrote:
> This does assume no two people will share both an account and an env
name; this
> has bitten people in practice, IIRC. Maybe worth pointing that out
explicitly
> here?

This is just looking like a move because of how the diff was generated,
but I can try to update this per your request.

https://codereview.appspot.com/13562045/

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (18.6 KiB)

The attempt to merge lp:~jameinel/juju-core/security-group-group-id-1226996 into lp:juju-core/1.14 failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 0.773s
ok launchpad.net/juju-core/agent/tools 0.228s
ok launchpad.net/juju-core/bzr 7.378s
ok launchpad.net/juju-core/cert 1.948s
ok launchpad.net/juju-core/charm 0.929s
? launchpad.net/juju-core/charm/hooks [no test files]
ok launchpad.net/juju-core/cloudinit 0.021s
ok launchpad.net/juju-core/cmd 0.247s
? launchpad.net/juju-core/cmd/builddb [no test files]
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 117.015s

----------------------------------------------------------------------
FAIL: machine_test.go:377: MachineSuite.TestManageStateServesAPI

[LOG] 20.92653 INFO juju environs/testing: uploading FAKE tools 1.14.1-precise-amd64
[LOG] 20.94392 INFO juju.environs.boostrap bootstrapping environment "dummyenv"
[LOG] 20.94395 INFO juju.environs.tools reading tools with major version 1
[LOG] 20.94397 INFO juju.environs.tools filtering tools by version: 1.14.1
[LOG] 20.94398 INFO juju.environs.tools filtering tools by series: precise
[LOG] 20.94400 DEBUG juju.environs.tools reading v1.* tools
[LOG] 20.94401 INFO juju.environs.tools falling back to public bucket
[LOG] 20.94402 DEBUG juju.environs.tools reading v1.* tools
[LOG] 20.94405 DEBUG juju.environs.tools found 1.14.1-precise-amd64
[LOG] 20.94409 INFO juju environs/dummy: would pick tools from 1.14.1-precise-amd64
[LOG] 20.96770 INFO juju.state opening state; mongo addresses: ["localhost:49608"]; entity ""
[LOG] 20.97791 INFO juju.state connection established
[LOG] 20.99485 INFO juju.state initializing environment
[LOG] 21.01528 INFO juju state/api: listening on "127.0.0.1:40611"
[LOG] 21.03274 INFO juju.state opening state; mongo addresses: ["localhost:49608"]; entity ""
[LOG] 21.03661 INFO juju.state connection established
[LOG] 21.05528 INFO juju juju: authorization error while connecting to state server; retrying
[LOG] 21.05539 INFO juju.state opening state; mongo addresses: ["localhost:49608"]; entity ""
[LOG] 21.06091 INFO juju.state connection established
[LOG] 21.09123 INFO juju state/api: dialing "wss://127.0.0.1:40611/"
[LOG] 21.09442 INFO juju state/api: connection established
[LOG] 21.09456 DEBUG juju rpc/jsoncodec: <- {"RequestId":1,"Type":"Admin","Request":"Login","Params":{"AuthTag":"user-admin","Password":"dummy-secret","Nonce":""}}
[LOG] 21.09492 DEBUG juju rpc/jsoncodec: -> {"RequestId":1,"Response":{}}
[LOG] 21.09516 INFO juju.container.lxc lxcObjectFactory replaced with mock lxc factory
[LOG] 21.09628 DEBUG juju rpc/jsoncodec: <- {"RequestId":2,"Type":"Pinger","Request":"Ping","Params":{}}
[LOG] 21.09638 DEBUG juju rpc/jsoncodec: -> {"RequestId":2,"Response":{}}
[LOG] 21.16556 INFO juju machine agent machine-0 start
[LOG] 21.17998 INFO juju Starting StateWorker for machine-0
[LOG] 21.18003 INFO juju worker: start "state"
[LOG] 21.18006 INFO juju.state opening state; mongo addresses: ["localhost:49608"]; entity "machine-0"
[LOG] 21.18031 INFO juju worker: start "api"
[...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: