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

Switch off direct database access #449

Merged
merged 4 commits into from Aug 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions provider/azure/environ.go
Expand Up @@ -778,10 +778,6 @@ func (env *azureEnviron) newOSDisk(sourceImageName string) *gwacl.OSVirtualHardD
// getInitialEndpoints returns a slice of the endpoints every instance should have open
// (ssh port, etc).
func (env *azureEnviron) getInitialEndpoints(stateServer bool) []gwacl.InputEndpoint {
// TODO(axw) either proxy ssh traffic through one of the
// randomly chosen VMs to the internal address, or otherwise
// don't load balance SSH and provide a way of getting the
// local port.
cfg := env.Config()
endpoints := []gwacl.InputEndpoint{{
LocalPort: 22,
Expand All @@ -791,11 +787,6 @@ func (env *azureEnviron) getInitialEndpoints(stateServer bool) []gwacl.InputEndp
}}
if stateServer {
endpoints = append(endpoints, []gwacl.InputEndpoint{{
LocalPort: cfg.StatePort(),
Port: cfg.StatePort(),
Protocol: "tcp",
Name: "stateport",
}, {
LocalPort: cfg.APIPort(),
Port: cfg.APIPort(),
Protocol: "tcp",
Expand Down
15 changes: 2 additions & 13 deletions provider/azure/environ_test.go
Expand Up @@ -1158,11 +1158,6 @@ func (s *environSuite) TestInitialPorts(c *gc.C) {
// Only role2 should report opened state server ports via the Ports method.
dummyRole := *role1
configSetNetwork(&dummyRole).InputEndpoints = &[]gwacl.InputEndpoint{{
LocalPort: env.Config().StatePort(),
Protocol: "tcp",
Name: "stateserver",
Port: env.Config().StatePort(),
}, {
LocalPort: env.Config().APIPort(),
Protocol: "tcp",
Name: "apiserver",
Expand All @@ -1177,7 +1172,7 @@ func (s *environSuite) TestInitialPorts(c *gc.C) {
for _, port := range ports {
portmap[port.Number] = true
}
return portmap[env.Config().StatePort()] && portmap[env.Config().APIPort()]
return portmap[env.Config().APIPort()]
}
c.Check(inst1, gc.Not(jc.Satisfies), reportsStateServerPorts)
c.Check(inst2, jc.Satisfies, reportsStateServerPorts)
Expand Down Expand Up @@ -1247,13 +1242,7 @@ func (*environSuite) testNewRole(c *gc.C, stateServer bool) {
c.Check(sshEndpoint.Protocol, gc.Equals, "tcp")

if stateServer {
// There's also an endpoint for the state (mongodb) port.
stateEndpoint, ok := endpoints[env.Config().StatePort()]
c.Assert(ok, gc.Equals, true)
c.Check(stateEndpoint.LocalPort, gc.Equals, env.Config().StatePort())
c.Check(stateEndpoint.Protocol, gc.Equals, "tcp")

// And one for the API port.
// There should be an endpoint for the API port.
apiEndpoint, ok := endpoints[env.Config().APIPort()]
c.Assert(ok, gc.Equals, true)
c.Check(apiEndpoint.LocalPort, gc.Equals, env.Config().APIPort())
Expand Down
6 changes: 0 additions & 6 deletions provider/azure/instance_test.go
Expand Up @@ -353,11 +353,6 @@ func (s *instanceSuite) testPorts(c *gc.C, maskStateServerPorts bool) {
Protocol: "tcp",
Name: "test456",
Port: 4456,
}, {
LocalPort: s.env.Config().StatePort(),
Protocol: "tcp",
Name: "stateserver",
Port: s.env.Config().StatePort(),
}, {
LocalPort: s.env.Config().APIPort(),
Protocol: "tcp",
Expand All @@ -380,7 +375,6 @@ func (s *instanceSuite) testPorts(c *gc.C, maskStateServerPorts bool) {
{Number: 2123, Protocol: "udp"},
}
if !maskStateServerPorts {
expected = append(expected, network.Port{Number: s.env.Config().StatePort(), Protocol: "tcp"})
expected = append(expected, network.Port{Number: s.env.Config().APIPort(), Protocol: "tcp"})
network.SortPorts(expected)
}
Expand Down
10 changes: 2 additions & 8 deletions provider/ec2/ec2.go
Expand Up @@ -604,7 +604,7 @@ func (e *environ) StartInstance(args environs.StartInstanceParams) (instance.Ins
}
logger.Debugf("ec2 user data; %d bytes", len(userData))
cfg := e.Config()
groups, err := e.setUpGroups(args.MachineConfig.MachineId, cfg.StatePort(), cfg.APIPort())
groups, err := e.setUpGroups(args.MachineConfig.MachineId, cfg.APIPort())
if err != nil {
return nil, nil, nil, fmt.Errorf("cannot set up groups: %v", err)
}
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func (inst *ec2Instance) Ports(machineId string) ([]network.Port, error) {
// other instances that might be running on the same EC2 account. In
// addition, a specific machine security group is created for each
// machine, so that its firewall rules can be configured per machine.
func (e *environ) setUpGroups(machineId string, statePort, apiPort int) ([]ec2.SecurityGroup, error) {
func (e *environ) setUpGroups(machineId string, apiPort int) ([]ec2.SecurityGroup, error) {
jujuGroup, err := e.ensureGroup(e.jujuGroupName(),
[]ec2.IPPerm{
{
Expand All @@ -1088,12 +1088,6 @@ func (e *environ) setUpGroups(machineId string, statePort, apiPort int) ([]ec2.S
ToPort: 22,
SourceIPs: []string{"0.0.0.0/0"},
},
{
Protocol: "tcp",
FromPort: statePort,
ToPort: statePort,
SourceIPs: []string{"0.0.0.0/0"},
},
{
Protocol: "tcp",
FromPort: apiPort,
Expand Down
3 changes: 1 addition & 2 deletions provider/ec2/live_test.go
Expand Up @@ -224,9 +224,8 @@ func (t *LiveTests) TestInstanceGroups(c *gc.C) {
// that the unneeded permission that we added earlier
// has been deleted).
perms := info[0].IPPerms
c.Assert(perms, gc.HasLen, 6)
c.Assert(perms, gc.HasLen, 5)
checkPortAllowed(c, perms, 22) // SSH
checkPortAllowed(c, perms, coretesting.FakeConfig()["state-port"].(int))
checkPortAllowed(c, perms, coretesting.FakeConfig()["api-port"].(int))
checkSecurityGroupAllowed(c, perms, groups[0])

Expand Down
4 changes: 2 additions & 2 deletions provider/openstack/export_test.go
Expand Up @@ -296,8 +296,8 @@ func SetUseFloatingIP(e environs.Environ, val bool) {
env.ecfg().attrs["use-floating-ip"] = val
}

func SetUpGlobalGroup(e environs.Environ, name string, statePort, apiPort int) (nova.SecurityGroup, error) {
return e.(*environ).setUpGlobalGroup(name, statePort, apiPort)
func SetUpGlobalGroup(e environs.Environ, name string, apiPort int) (nova.SecurityGroup, error) {
return e.(*environ).setUpGlobalGroup(name, apiPort)
}

func EnsureGroup(e environs.Environ, name string, rules []nova.RuleInfo) (nova.SecurityGroup, error) {
Expand Down
13 changes: 5 additions & 8 deletions provider/openstack/live_test.go
Expand Up @@ -178,17 +178,15 @@ func (t *LiveTests) TestSetupGlobalGroupExposesCorrectPorts(c *gc.C) {
}
cleanup()
defer cleanup()
statePort := 12345 // Default 37017
apiPort := 34567 // Default 17070
group, err := openstack.SetUpGlobalGroup(t.Env, groupName, statePort, apiPort)
apiPort := 34567 // Default 17070
group, err := openstack.SetUpGlobalGroup(t.Env, groupName, apiPort)
c.Assert(err, gc.IsNil)
c.Assert(err, gc.IsNil)
// We default to exporting 22, statePort, apiPort, and icmp/udp/tcp on
// We default to exporting 22, apiPort, and icmp/udp/tcp on
// all ports to other machines inside the same group
// TODO(jam): 2013-09-18 http://pad.lv/1227142
// We shouldn't be exposing the API and State ports on all the machines
// that *aren't* hosting the state server. (And once we finish
// client-via-API we can disable the State port as well.)
// We shouldn't be exposing the API port on all the machines
// that *aren't* hosting the state server.
stringRules := make([]string, 0, len(group.Rules))
for _, rule := range group.Rules {
ruleStr := fmt.Sprintf("%s %d %d %q %q",
Expand All @@ -203,7 +201,6 @@ func (t *LiveTests) TestSetupGlobalGroupExposesCorrectPorts(c *gc.C) {
// We don't care about the ordering, so we sort the result, and compare it.
expectedRules := []string{
`tcp 22 22 "0.0.0.0/0" ""`,
fmt.Sprintf(`tcp %d %d "0.0.0.0/0" ""`, statePort, statePort),
fmt.Sprintf(`tcp %d %d "0.0.0.0/0" ""`, apiPort, apiPort),
fmt.Sprintf(`tcp 1 65535 "" "%s"`, groupName),
fmt.Sprintf(`udp 1 65535 "" "%s"`, groupName),
Expand Down
14 changes: 4 additions & 10 deletions provider/openstack/provider.go
Expand Up @@ -959,7 +959,7 @@ func (e *environ) StartInstance(args environs.StartInstanceParams) (instance.Ins
}
}
cfg := e.Config()
groups, err := e.setUpGroups(args.MachineConfig.MachineId, cfg.StatePort(), cfg.APIPort())
groups, err := e.setUpGroups(args.MachineConfig.MachineId, cfg.APIPort())
if err != nil {
return nil, nil, nil, fmt.Errorf("cannot set up groups: %v", err)
}
Expand Down Expand Up @@ -1296,7 +1296,7 @@ func (e *environ) Provider() environs.EnvironProvider {
return &providerInstance
}

func (e *environ) setUpGlobalGroup(groupName string, statePort, apiPort int) (nova.SecurityGroup, error) {
func (e *environ) setUpGlobalGroup(groupName string, apiPort int) (nova.SecurityGroup, error) {
return e.ensureGroup(groupName,
[]nova.RuleInfo{
{
Expand All @@ -1305,12 +1305,6 @@ func (e *environ) setUpGlobalGroup(groupName string, statePort, apiPort int) (no
ToPort: 22,
Cidr: "0.0.0.0/0",
},
{
IPProtocol: "tcp",
FromPort: statePort,
ToPort: statePort,
Cidr: "0.0.0.0/0",
},
{
IPProtocol: "tcp",
FromPort: apiPort,
Expand Down Expand Up @@ -1346,8 +1340,8 @@ func (e *environ) setUpGlobalGroup(groupName string, statePort, apiPort int) (no
// Note: ideally we'd have a better way to determine group membership so that 2
// people that happen to share an openstack account and name their environment
// "openstack" don't end up destroying each other's machines.
func (e *environ) setUpGroups(machineId string, statePort, apiPort int) ([]nova.SecurityGroup, error) {
jujuGroup, err := e.setUpGlobalGroup(e.jujuGroupName(), statePort, apiPort)
func (e *environ) setUpGroups(machineId string, apiPort int) ([]nova.SecurityGroup, error) {
jujuGroup, err := e.setUpGlobalGroup(e.jujuGroupName(), apiPort)
if err != nil {
return nil, err
}
Expand Down