Merge lp:~dimitern/juju-core/147-apiprovisioner-blank-env-secrets into lp:~go-bot/juju-core/trunk

Proposed by Dimiter Naydenov
Status: Merged
Approved by: Dimiter Naydenov
Approved revision: no longer in the source branch.
Merged at revision: 1892
Proposed branch: lp:~dimitern/juju-core/147-apiprovisioner-blank-env-secrets
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~dimitern/juju-core/146-apiprovisioner-addresses
Diff against target: 66 lines (+37/-1)
2 files modified
state/apiserver/provisioner/provisioner.go (+20/-1)
state/apiserver/provisioner/provisioner_test.go (+17/-0)
To merge this branch: bzr merge lp:~dimitern/juju-core/147-apiprovisioner-blank-env-secrets
Reviewer Review Type Date Requested Status
Dimiter Naydenov (community) Approve
Review via email: mp+187738@code.launchpad.net

Commit message

apiserver/provisioner: Mask out secret env attrs

This changes the provisioner API EnvironConfig()
call to mask out any secret attributes before
returning the config to non-manager agents.
The environment manager agents still get everything.

This closes off a security issue with LXC provisioner
having access to the environment configuration and
its secrets via the API.

Live tested on EC2 successfully.

https://codereview.appspot.com/13964043/

R=dimitern, jameinel

Description of the change

apiserver/provisioner: Mask out secret env attrs

This changes the provisioner API EnvironConfig()
call to mask out any secret attributes before
returning the config to non-manager agents.
The environment manager agents still get everything.

This closes off a security issue with LXC provisioner
having access to the environment configuration and
its secrets via the API.

Live tested on EC2 successfully.

https://codereview.appspot.com/13964043/

To post a comment you must log in.
Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Download full text (3.4 KiB)

Reviewers: mp+187738_code.launchpad.net,

Message:
Please take a look.

Description:
apiserver/provisioner: Mask out secret env attrs

This changes the provisioner API EnvironConfig()
call to mask out any secret attributes before
returning the config to non-manager agents.
The environment manager agents still get everything.

This closes off a security issue with LXC provisioner
having access to the environment configuration and
its secrets via the API.

Live tested on EC2 successfully.

https://code.launchpad.net/~dimitern/juju-core/147-apiprovisioner-blank-env-secrets/+merge/187738

Requires:
https://code.launchpad.net/~dimitern/juju-core/146-apiprovisioner-addresses/+merge/187719

(do not edit description out of merge proposal)

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

Affected files (+38, -1 lines):
   A [revision details]
   M state/apiserver/provisioner/provisioner.go
   M state/apiserver/provisioner/provisioner_test.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: state/apiserver/provisioner/provisioner.go
=== modified file 'state/apiserver/provisioner/provisioner.go'
--- state/apiserver/provisioner/provisioner.go 2013-09-26 10:38:59 +0000
+++ state/apiserver/provisioner/provisioner.go 2013-09-26 11:15:31 +0000
@@ -157,7 +157,25 @@
   if err != nil {
    return result, err
   }
- result.Config = config.AllAttrs()
+ allAttrs := config.AllAttrs()
+ if !p.authorizer.AuthEnvironManager() {
+ // Mask out any secrets in the environment configuration
+ // with values of the same type, so it'll pass validation.
+ //
+ // TODO(dimitern) 201309-26 bug #1231384
+ // This needs to change so we won't return anything to
+ // entities other than the environment manager, but the
+ // provisioner code should be refactored first.
+ env, err := environs.New(config)
+ if err != nil {
+ return result, err
+ }
+ secretAttrs, err := env.Provider().SecretAttrs(config)
+ for k := range secretAttrs {
+ allAttrs[k] = "not available"
+ }
+ }
+ result.Config = allAttrs
   return result, nil
  }

Index: state/apiserver/provisioner/provisioner_test.go
=== modified file 'state/apiserver/provisioner/provisioner_test.go'
--- state/apiserver/provisioner/provisioner_test.go 2013-09-26 10:38:59
+0000
+++ state/apiserver/provisioner/provisioner_test.go 2013-09-26 11:15:31
+0000
@@ -422,6 +422,23 @@
   c.Assert(err, gc.IsNil)
   c.Assert(result.Error, gc.IsNil)
   c.Assert(result.Config, gc.DeepEquals,
params.Config(envConfig.AllAttrs()))
+
+ // Now test it with a non-environment manager and make sure
+ // the secret attributes are masked.
+ anAuthorizer := s.authorizer
+ anAuthorizer.MachineAgent = true
+ anAuthorizer.Manager = false
+ aProvisioner, err := provisioner.NewProvisionerAPI(s.State, s.resources,
+ anAuthorizer)
+ c.Assert(err, gc.IsNil)
+
+ // We need to see the secret attributes masked out, and for
+ // the dummy pro...

Read more...

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

LGTM given it is the same as the previous submisison which had already
been approved.

https://codereview.appspot.com/13964043/

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

On 2013/09/26 13:10:37, jameinel wrote:
> LGTM given it is the same as the previous submisison which had already
been
> approved.

I do still have the question why we set the values to "not available"
rather than just deleting them. I guess so Env creation doesn't complain
about missing entries?

https://codereview.appspot.com/13964043/

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

On 2013/09/26 13:12:01, jameinel wrote:
> On 2013/09/26 13:10:37, jameinel wrote:
> > LGTM given it is the same as the previous submisison which had
already been
> > approved.

> I do still have the question why we set the values to "not available"
rather
> than just deleting them. I guess so Env creation doesn't complain
about missing
> entries?

Setting them to something is needed for validation. And since this is
temporary,
it'll go away soon (when the provisioner is properly refactored).

https://codereview.appspot.com/13964043/

Revision history for this message
Go Bot (go-bot) wrote :

The attempt to merge lp:~dimitern/juju-core/147-apiprovisioner-blank-env-secrets into lp:juju-core failed. Below is the output from the failed tests.

# launchpad.net/juju-core/state/apiserver/provisioner
state/apiserver/provisioner/provisioner.go:169: undefined: environs

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Self-approving: Added a missing import to fix a build failure.

review: Approve
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'state/apiserver/provisioner/provisioner.go'
--- state/apiserver/provisioner/provisioner.go 2013-09-26 13:20:24 +0000
+++ state/apiserver/provisioner/provisioner.go 2013-09-26 16:02:23 +0000
@@ -7,6 +7,7 @@
7 "fmt"7 "fmt"
88
9 "launchpad.net/juju-core/constraints"9 "launchpad.net/juju-core/constraints"
10 "launchpad.net/juju-core/environs"
10 "launchpad.net/juju-core/instance"11 "launchpad.net/juju-core/instance"
11 "launchpad.net/juju-core/names"12 "launchpad.net/juju-core/names"
12 "launchpad.net/juju-core/state"13 "launchpad.net/juju-core/state"
@@ -157,7 +158,25 @@
157 if err != nil {158 if err != nil {
158 return result, err159 return result, err
159 }160 }
160 result.Config = config.AllAttrs()161 allAttrs := config.AllAttrs()
162 if !p.authorizer.AuthEnvironManager() {
163 // Mask out any secrets in the environment configuration
164 // with values of the same type, so it'll pass validation.
165 //
166 // TODO(dimitern) 201309-26 bug #1231384
167 // This needs to change so we won't return anything to
168 // entities other than the environment manager, but the
169 // provisioner code should be refactored first.
170 env, err := environs.New(config)
171 if err != nil {
172 return result, err
173 }
174 secretAttrs, err := env.Provider().SecretAttrs(config)
175 for k := range secretAttrs {
176 allAttrs[k] = "not available"
177 }
178 }
179 result.Config = allAttrs
161 return result, nil180 return result, nil
162}181}
163182
164183
=== modified file 'state/apiserver/provisioner/provisioner_test.go'
--- state/apiserver/provisioner/provisioner_test.go 2013-09-26 10:38:59 +0000
+++ state/apiserver/provisioner/provisioner_test.go 2013-09-26 16:02:23 +0000
@@ -422,6 +422,23 @@
422 c.Assert(err, gc.IsNil)422 c.Assert(err, gc.IsNil)
423 c.Assert(result.Error, gc.IsNil)423 c.Assert(result.Error, gc.IsNil)
424 c.Assert(result.Config, gc.DeepEquals, params.Config(envConfig.AllAttrs()))424 c.Assert(result.Config, gc.DeepEquals, params.Config(envConfig.AllAttrs()))
425
426 // Now test it with a non-environment manager and make sure
427 // the secret attributes are masked.
428 anAuthorizer := s.authorizer
429 anAuthorizer.MachineAgent = true
430 anAuthorizer.Manager = false
431 aProvisioner, err := provisioner.NewProvisionerAPI(s.State, s.resources,
432 anAuthorizer)
433 c.Assert(err, gc.IsNil)
434
435 // We need to see the secret attributes masked out, and for
436 // the dummy provider it's only one: "secret".
437 expectedConfig := envConfig.AllAttrs()
438 expectedConfig["secret"] = "not available"
439 result, err = aProvisioner.EnvironConfig()
440 c.Assert(err, gc.IsNil)
441 c.Assert(result.Error, gc.IsNil)
425}442}
426443
427func (s *provisionerSuite) TestStatus(c *gc.C) {444func (s *provisionerSuite) TestStatus(c *gc.C) {

Subscribers

People subscribed via source and target branches

to status/vote changes: