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

Plugable secret backend #348

Closed
wants to merge 2 commits into from

Conversation

liron-l
Copy link
Contributor

@liron-l liron-l commented Jul 18, 2017

This commit extends SwarmKit secret management with pluggable secret
backends support.

Following previous commits:

  1. moby/swarmkit@eebac27
  2. moby/moby@08f7cf0

Added driver parameter to docker secret command.
Specifically:

  1. docker secret create [secret_name] --driver [driver_name]
  2. Displaying the driver in
    $ docker secret ls
    $ docker secret inspect [secret_name]
    $ docker secret inspect [secret_name] -pretty

There is a bug in serialization of the secret data. Handled in moby/moby#34157.

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@liron-l liron-l force-pushed the plugable_secrets_backend branch 3 times, most recently from 40e2d6b to 0f89fe6 Compare July 18, 2017 10:24
@cpuguy83
Copy link
Collaborator

Validations and tests appear to have failed but I can't see them in CircleCI.

@liron-l
Copy link
Contributor Author

liron-l commented Jul 18, 2017

Thanks @cpuguy83, waiting for the fix in moby/moby#34157 (tests should work after updating the vendor folder).

@liron-l liron-l force-pushed the plugable_secrets_backend branch 2 times, most recently from a248bac to 17c3a85 Compare July 18, 2017 16:30
@codecov-io
Copy link

codecov-io commented Jul 18, 2017

Codecov Report

Merging #348 into master will increase coverage by 1.86%.
The diff coverage is 48.97%.

@@            Coverage Diff             @@
##           master     #348      +/-   ##
==========================================
+ Coverage   45.49%   47.35%   +1.86%     
==========================================
  Files         193      186       -7     
  Lines       16065    15355     -710     
==========================================
- Hits         7308     7271      -37     
+ Misses       8379     7707     -672     
+ Partials      378      377       -1

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

We'll also need to add this to the Compose file, but we need to get v3.4 in first, which is in #306, so a follow up PR should be fine.

@@ -23,6 +23,7 @@ Labels:
{{- range $k, $v := .Labels }}
- {{ $k }}{{if $v }}={{ $v }}{{ end }}
{{- end }}{{ end }}
Driver: {{.Driver}}
Created at: {{.CreatedAt}}
Updated at: {{.UpdatedAt}}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the existing lines have a weird mix of tabs and spaces...

I think we'll need to fix this to be all spaces so that the new line aligns properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, modified 👍

@@ -29,15 +30,18 @@ func newSecretCreateCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create [OPTIONS] SECRET file|-",
Short: "Create a secret from a file or STDIN as content",
Args: cli.ExactArgs(2),
Args: cli.RequiresRangeArgs(1, 2),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Use: line needs to be updated to make the second arg optional:

create [OPTIONS] SECRET [file | -]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks 👍

if err != nil {
return errors.Errorf("Error reading content from %q: %v", options.file, err)
var secretData []byte
if options.driver == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here will be more obvious is this check is changed to

if options.file != "" {
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as part of function refactoring 👍

secretData, err = ioutil.ReadAll(in)
if err != nil {
return errors.Errorf("Error reading content from %q: %v", options.file, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you've just adding another condition here, but now that this function is growing I think it would be appropriate to extract this as a new function.

secretData, err := readSecretData(options.file, dockerCli.In())
...

Even the initial options.file != "" check could be inside the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dnephin, makes sense.

@liron-l liron-l force-pushed the plugable_secrets_backend branch 2 times, most recently from da74b0e to 780465b Compare July 18, 2017 17:04
@@ -23,6 +23,7 @@ Labels:
{{- range $k, $v := .Labels }}
- {{ $k }}{{if $v }}={{ $v }}{{ end }}
{{- end }}{{ end }}
Driver: {{.Driver}}
Created at: {{.CreatedAt}}
Updated at: {{.UpdatedAt}}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see tabs here

Copy link
Contributor Author

@liron-l liron-l Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, you mean I should remove all tabs from the formatter 👍

}
defer in.Close()
}
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is unused I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. Thanks

var err error
data, err := ioutil.ReadAll(in)
if err != nil {
return nil, errors.Errorf("Error reading content from %q: %v", file, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrapf(err, "error reading content from %q", file)

Errors should start with lowercase so they look more appropriate when wrapped.

Copy link
Contributor Author

@liron-l liron-l Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but those lines are not wrapped with anything (they are printed directly in the cli). I returned the error and wrapped with upper case in the main method. Please let me know if this makes sense.

@liron-l
Copy link
Contributor Author

liron-l commented Jul 18, 2017

Thanks for the comments @dnephin! do you know what vndr is complaining?
CC @diogomonica @aaronlehmann @cpuguy83

@dnephin
Copy link
Contributor

dnephin commented Jul 18, 2017

If I run make -f docker.Makefile vendor locally I see the same problem. I think you vendored using an older version of vndr. If you run that command and check in the changes it should fix it.

@liron-l liron-l force-pushed the plugable_secrets_backend branch 2 times, most recently from 96fa77c to d5f1104 Compare July 18, 2017 21:10
@liron-l liron-l requested a review from vdemeester as a code owner July 19, 2017 06:10
@liron-l
Copy link
Contributor Author

liron-l commented Jul 19, 2017

Thanks @dnephin, it worked!

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83
Copy link
Collaborator

Can we do the vendoring in a separate commit?

@liron-l
Copy link
Contributor Author

liron-l commented Jul 19, 2017

Sure @cpuguy83 makes sense. I've updated the commit.

@thaJeztah
Copy link
Member

Does this also update the docker-compose format to support this?

@thaJeztah
Copy link
Member

I wonder if it would make sense to do the version bump in two stages; one to moby/moby@d0a8e73 (last commit before the upstream related change was merged), and one to moby/moby@0304c98 (the diff is quite large moby/moby@87df0e5...0304c98)

I see there's also some dependencies bumped in moby's vendor.conf; do we have to bump those as well accordingly (if used here?)

@liron-l
Copy link
Contributor Author

liron-l commented Jul 19, 2017

Thanks @thaJeztah.
Re docker-compose, I checked that setting external: true for the secret reference works with the new plugin subsystem.
Do we need to support driver: name parameter, which will create the secret value?

Re version bump, let me know which commit history makes sense or which additional packages should be updated.

@liron-l
Copy link
Contributor Author

liron-l commented Jul 19, 2017

@thaJeztah and @dnephin I've added a new parameter to secrets definitions:

driver: my-driver

So now it's possible to run:

version: '3.3'
services:
  web:
    image: nginx
    secrets:                    
     - hello-secret
secrets:                       
  hello-secret:
    driver: secrets:next

Can you please review?

@dnephin
Copy link
Contributor

dnephin commented Jul 19, 2017

Sorry, the change should not be made to v3.3. It should go into v3.4. You can cherry-pick #358 to get v3.4, or we can add the compose changes in a separate PR. I think I would prefer a separate PR

@liron-l
Copy link
Contributor Author

liron-l commented Jul 19, 2017

Thanks @dnephin makes sense. I will push those changes in the next commit.
I removed the compose changes, how do I re-trigger a build?

@dnephin
Copy link
Contributor

dnephin commented Jul 19, 2017

hmm, we've been having problems with github not triggering builds. I'm going to email github support.

@liron-l liron-l force-pushed the plugable_secrets_backend branch 2 times, most recently from 3e153c4 to 389f146 Compare July 20, 2017 15:07
@liron-l
Copy link
Contributor Author

liron-l commented Jul 20, 2017

Thanks @dnephin! was the issue resolved? can I trigger A build without closing the issue?

@dnephin
Copy link
Contributor

dnephin commented Jul 20, 2017

github said they are looking into it, and that it's likely a bug on their end.

I've been able to trigger the build by closing and re-opening the PR in some cases, so I'm going to try that now.

@dnephin dnephin closed this Jul 20, 2017
@dnephin dnephin reopened this Jul 20, 2017
@dnephin
Copy link
Contributor

dnephin commented Jul 20, 2017

and in some cases CI fails with "fatal: Could not parse object" which is what's happening this time...

@liron-l liron-l closed this Jul 20, 2017
@liron-l liron-l reopened this Jul 20, 2017
Liron Levin added 2 commits July 20, 2017 21:26
Update vendor to support plugable secret backend

Signed-off-by: Liron Levin <[email protected]>
This commit extends SwarmKit secret management with pluggable secret
backends support.
Following previous commits:
1. moby/swarmkit@eebac27
2. moby/moby@08f7cf0

Added driver parameter to `docker secret` command.
Specifically:

1. `docker secret create [secret_name] --driver [driver_name]`
2.  Displaying the driver in
```
    $ docker secret ls
    $ docker secret inspect [secret_name]
    $ docker secret inspect [secret_name] -pretty
```

Signed-off-by: Liron Levin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants