+ // RootCertPEM holds the x509 certificate of the root CA
+ // that signed the state server certificate, in PEM format.
+ RootCertPEM []byte
+
// StateServerPEM holds the state server certificate and private
// key in PEM format; it is required when StateServer is set,
// and ignored otherwise.
@@ -85,7 +89,10 @@
return base64.StdEncoding.EncodeToString(data)
}
Reviewers: mp+134498_ code.launchpad. net,
Message:
Please take a look.
Description:
environs/cloudinit: add RootCertPEM
Instances need to know the root CA certificate
so that they can verify the server they're talking to.
https:/ /code.launchpad .net/~rogpeppe/ juju-core/ 151-cloudinit- root-cert/ +merge/ 134498
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6854054/
Affected files: cloudinit/ cloudinit. go cloudinit/ cloudinit_ test.go
A [revision details]
M environs/
M environs/
M environs/ec2/ec2.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: <email address hidden>
+New revision: <email address hidden>
Index: environs/ cloudinit/ cloudinit. go cloudinit/ cloudinit. go' cloudinit/ cloudinit. go 2012-11-14 14:09:56 +0000 cloudinit/ cloudinit. go 2012-11-15 16:11:30 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -29,6 +29,10 @@
// or MongoDB instance.
StateServer bool
+ // RootCertPEM holds the x509 certificate of the root CA StdEncoding. EncodeToString( data)
+ // that signed the state server certificate, in PEM format.
+ RootCertPEM []byte
+
// StateServerPEM holds the state server certificate and private
// key in PEM format; it is required when StateServer is set,
// and ignored otherwise.
@@ -85,7 +89,10 @@
return base64.
}
-const serverPEMPath = "/var/lib/ juju/server. pem" juju/server. pem" juju/root. pem"
+const (
+ serverPEMPath = "/var/lib/
+ rootCertPEMPath = "/var/lib/
+)
func New(cfg *MachineConfig) (*cloudinit.Config, error) {
if err := verifyConfig(cfg); err != nil {
@@ -115,6 +122,10 @@
debugFlag = " --debug"
}
+ addScripts(c, string( cfg.RootCertPEM )), Sprintf( "echo %s > %s", RootCertPEM) == 0 { ccessor == "" {
+ fmt.Sprintf("echo %s > %s", shquote(
rootCertPEMPath),
+ )
+
if cfg.StateServer {
addScripts(c,
fmt.
@@ -280,6 +291,9 @@
if cfg.StateInfo == nil {
return fmt.Errorf("missing state info")
}
+ if len(cfg.
+ return fmt.Errorf("missing root CA certificate PEM")
+ }
if cfg.StateServer {
if cfg.InstanceIdA
return fmt.Errorf("missing instance id accessor")
Index: environs/ cloudinit/ cloudinit_ test.go cloudinit/ cloudinit_ test.go' cloudinit/ cloudinit_ test.go 2012-11-14 14:09:56 +0000 cloudinit/ cloudinit_ test.go 2012-11-15 16:11:30 +0000 "1.2.3- linux-amd64" ), "1.2.3- linux-amd64" ), "state- addr.example. com"}, MachineConfig) { StateServerPEM = []byte{} MachineConfig) { MachineConfig) { MachineConfig) { MachineConfig{ ccessor: "$instance_id", HZgxpwqIA1fHVuY JY9GMPG1LnTnZ9I Ng= IBAgIBADALBgkqh kiG9w0BAQUwJjEN MAsGA1UEChMEanV qdTEV VqdSB0ZXN0aW5nM B4XDTEyMTExNTE1 NDAyMFoXDTIyMTE xNTE1 sGA1UEChMEanVqd TEVMBMGA1UEAxMM anVqdSB0ZXN0aW5 nMFow EBA0sAMEgCQQCQG R9Sj2dsNuBF5R7g xcg28EJu0yqxrqI LAYkH Q7O1RddW4pdCAv8 Qj3bsRvaxwoxwmc AnD9AgMBAAGjYzB hMA4G wQEAwIABDAPBgNV HRMBAf8EBTADAgE BMB0GA1UdDgQWBB T5jDkLWX0S yMMTAfBgNVHSMEG DAWgBT5jDkLWX0S xPRuee2ULoDrfiy MMTAL UDQQAEpl0ITRktd 6uNklg9KduXQqwG /WQ6NVbK48UMkoK HnNya 81a6efihNr93uVJ qf+NbX0+ bO/
=== modified file 'environs/
--- environs/
+++ environs/
@@ -44,6 +44,7 @@
Tools: newSimpleTools(
StateServer: true,
StateServerPEM: serverPEM,
+ RootCertPEM: rootCertPEM,
StateInfo: &state.Info{
Password: "arble",
},
@@ -56,6 +57,7 @@
AuthorizedKeys: "sshkey1",
DataDir: "/var/lib/juju",
StateServer: false,
+ RootCertPEM: rootCertPEM,
Tools: newSimpleTools(
StateInfo: &state.Info{
Addrs: []string{
@@ -260,6 +262,13 @@
{"missing state server PEM", func(cfg *cloudinit.
cfg.
}},
+ {"missing root CA certificate PEM", func(cfg *cloudinit.
+ cfg.RootCertPEM = []byte{}
+ }},
+ {"missing root CA certificate PEM", func(cfg *cloudinit.
+ cfg.StateServer = false
+ cfg.RootCertPEM = []byte{}
+ }},
{"missing var directory", func(cfg *cloudinit.
cfg.DataDir = ""
}},
@@ -303,6 +312,7 @@
cfg := &cloudinit.
StateServer: true,
StateServerPEM: serverPEM,
+ RootCertPEM: rootCertPEM,
InstanceIdA
ProviderType: "ec2",
MachineId: 99,
@@ -349,3 +359,17 @@
2Vc9NN09ty+
-----END RSA PRIVATE KEY-----
`)
+
+var rootCertPEM = []byte(`
+-----BEGIN CERTIFICATE-----
+MIIBmjCCAUagAw
+MBMGA1UEAxMMan
+NDUyMFowJjENMA
+CwYJKoZIhvcNAQ
+PN/A4OBFIRAeG5
+A1UdDwEB/
+xPRuee2ULoDrfi
+BgkqhkiG9w0BAQ
+lJPzSvbW7xnggA
+-----END CERTIFICATE-----
+`)
Index: environs/ec2/ec2.go ec2/ec2. go'
=== modified file 'environs/
--- environs/ec2/ec2.go 2012-11-14 14:39:40 +0000
+++ environs/ec2/ec2.go 2012-11-15 16:11:30 +0000
@@ -324,11 +324,11 @@
}
func (e *environ) userData(scfg *startInstanceP arams) ([]byte, error) { MachineConfig{ rPEM, ccessor: "$(curl 169.254. 169.254/ 1.0/meta- data/instance- id)",
-
cfg := &cloudinit.
StateServer: scfg.stateServer,
StateInfo: scfg.info,
StateServerPEM: scfg.stateServe
+ RootCertPEM: []byte("fake root cert"), // TODO(rog): use proper
root cert.
InstanceIdA
http://
ProviderType: "ec2",
DataDir: "/var/lib/juju",