Skip to content

feat(2196): secrets management - #2721

Merged
thomastaylor312 merged 1 commit into
helm:masterfrom
RemingtonReackhof:secrets-support
Oct 12, 2017
Merged

thomastaylor312 merged 1 commit into
helm:masterfrom
RemingtonReackhof:secrets-support

Conversation

@RemingtonReackhof

Copy link
Copy Markdown
Contributor

Implemented #2196 to add support for tiller to use secrets to store releases. This includes support for secrets.yaml use alongside of values.yaml.

Reference these secrets in templates the same as values, such as {{ .Secrets.type }}

Also adds support for arguments to install and upgrade identical to those used by values, e.g.:
--set-secrets type=ClusterIP and
--secrets=mysecrets.yaml

For use of secrets storage backend in Tiller, a new option was added to the --storage argument when starting Tiller:

tiller --storage=secret

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 25, 2017
@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof Thank you for submitting this! This is a pretty big feature add, so several of us are going to have to review this before merge.

@RemingtonReackhof
RemingtonReackhof force-pushed the secrets-support branch 2 times, most recently from 475c5f1 to 884ae9e Compare August 2, 2017 16:15
@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof Just to update you on this. We will be reviewing this and merging in once we have released 2.6. Most of our efforts are focused on 2.6 right now

@k8s-ci-robot

Copy link
Copy Markdown

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 8, 2017
@RemingtonReackhof

Copy link
Copy Markdown
Contributor Author

@thomastaylor312 I appreciate the update, best of luck with the 2.6 release!

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 8, 2017
@thomastaylor312
thomastaylor312 self-requested a review August 25, 2017 02:29
@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof I plan on getting to this no later than Monday, but hopefully tomorrow. I want to make sure I put adequate time into reviewing this well

@thomastaylor312

Copy link
Copy Markdown
Contributor

Ok, I've started on this. It is going to take a bit to go all through

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have not tested this yet (will do soon), but wanted to get you my feedback on the code. Mostly small comments or nits.

I am going to label this as breaking because of one of the changes could be considered such.

Comment thread _proto/hapi/services/tiller.proto Outdated
bool reuse_values = 10;
// Force resource update through delete/recreate if needed.
bool force = 11;
// Secrets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Can this comment be a bit more descriptive?

Comment thread cmd/helm/install_test.go Outdated
{
name: "install with multiple secrets",
args: []string{"testdata/testcharts/alpine"},
flags: strings.Split("--set-secrets foo=bar", "--set-secrets bar=foo"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume you meant this to be strings.Split("--set-secrets foo=bar --set-secrets bar=foo", " ")?

Comment thread cmd/helm/upgrade.go Outdated
if err != nil {
return err
}
rawSecrets, err := vals(u.secretFiles, u.secrets)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make sure to pass secretFiles and secrets to the installCmd above. Otherwise if a user does helm upgrade --install, they won't end up using the secrets

Comment thread pkg/chartutil/load.go
@@ -135,6 +135,9 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
return c, errors.New("values.toml is illegal as of 2.0.0-alpha.2")
} else if f.Name == "values.yaml" {
c.Values = &chart.Config{Raw: string(f.Data)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you also need to set c.Values.Type here?

@RemingtonReackhof RemingtonReackhof Sep 8, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The type will default to chart.ConfType_VALUES since it is default initialized to 0 but I can make it explicit if that would be clearer?

Comment thread pkg/chartutil/save.go Outdated
// Save secrets.yaml
if c.Secrets != nil && len(c.Secrets.Raw) > 0 {
vf := filepath.Join(outdir, SecretsfileName)
if err := ioutil.WriteFile(vf, []byte(c.Secrets.Raw), 0755); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because these are secrets, it may be better to do 500 for the permissions

return object, nil
}

// List returns the a of Secret.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Comment looks like it has a copy/paste error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like line 108 of the same file has the same typo. Not entirely sure what the word should be, probably list ?

@thomastaylor312 thomastaylor312 Sep 12, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I think so. Some thing like "returns a list of secrets." Not going to hold up the review on this though

Comment thread pkg/storage/driver/mock_test.go Outdated

secret, err := newSecretsObject(objkey, rls, nil)
if err != nil {
t.Fatalf("Failed to create configmap: %s", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be "Failed to create secret"

}

// apply labels
lbs.set("NAME", rls.Name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because these are used in Secrets and ConfigMaps, it may be useful to define them as constants

Comment thread pkg/storage/driver/secrets.go Outdated
@@ -0,0 +1,262 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be 2017 in this and a couple other of the new files 🙂

Comment thread pkg/storage/driver/secrets.go Outdated
// SecretsDriverName is the string name of the driver.
const SecretsDriverName = "Secret"

// var b64 = base64.StdEncoding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This and the next var look like copy/paste remnants.

@RemingtonReackhof

Copy link
Copy Markdown
Contributor Author

@thomastaylor312 Thank you for the comments! I apologize for the late response I've been without a computer for the last week. I'll get on these changes asap

@bacongobbler

Copy link
Copy Markdown
Member

once conflicts/comments have been addressed, I'd be happy to take a look at this as well.

@bacongobbler bacongobbler left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm concerned about the design RE: the CLI flags. Why can't we just continue to use --set and --values when the storage type is set to secrets?

I'm also concerned that this will make other storage layers like inmemory (the testing driver) and configmap (the stable storage backend) degenerate use cases since they can no longer fulfill all of the feature flags the secret storage layer provides. Perhaps we should consider tabling this until 3.0.

Comment thread cmd/helm/install.go Outdated
f.StringVar(&inst.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&inst.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&inst.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-a'. If --version is set, this is ignored.")
f.Var(&inst.secretFiles, "secrets", "specify secrets in a yaml file (can specify multiple)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there any way we can make it explicit that these flags only work with tiller set to --storage=secret?

@thomastaylor312

Copy link
Copy Markdown
Contributor

Now that @bacongobbler mentions it, I think that using --set and --values should be sufficient here. There is nothing different about a secrets.yaml and a values.yaml except for the fact that you shouldn't commit secrets. Thoughts @RemingtonReackhof?

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One tiny little change I discovered during testing. Otherwise testing all checks out

Comment thread cmd/tiller/tiller.go

storageMemory = "memory"
storageConfigMap = "configmap"
storageSecret = "secret"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The store flag needs to be updated to show that secret is now an option

@RemingtonReackhof

Copy link
Copy Markdown
Contributor Author

@thomastaylor312 @bacongobbler I agree with those points, the added CLI flags aren't necessary. I think the most important part of this PR is adding the secrets storage for releases. I can go ahead and remove those changes if that's what we decide is best.

@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof It isn't too much to ask someone to edit a line in the tiller deployment, but you are right in saying that it isn't ideal. We'll be adding some other flags to helm init that allow you to customize it a bit, but for now, I would just have people edit the deployment manually.

@bacongobbler thoughts?

@jakehow

jakehow commented Oct 9, 2017

Copy link
Copy Markdown

@RemingtonReackhof if you added an option to helm init you could modify the generateDeployment function in install.go

I think you could just have it set the command that is used with the image explicitly in the deployment.yaml if the flag is present. Separate images shouldn't be necessary.

@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof So we will be merging #2557 soon. That has support for better manipulation of the Tiller manifest. You can see the docs here and can use that as a basis. Probably something using --output or --set

@thomastaylor312

Copy link
Copy Markdown
Contributor

@jakehow

jakehow commented Oct 11, 2017

Copy link
Copy Markdown

@thomastaylor312 with that PR it seems like we should be able to document the option and just do:

helm init --override "spec.template.spec.containers[0].command"="tiller --storage=secret"

or if using curly braces works like it does for --set:

helm init --override "spec.template.spec.containers[0].command"={"tiller", "--storage=secret"}

@redbaron

Copy link
Copy Markdown
Contributor

Forgive me if I miss anything, but it looks like it doesn't implement original proposal where secrets are stored as hashes and are not retrievable by subseqent calls. If it is the case, then only difference between this storage driver and ConfigMap stroage driver is .impl type. Can't we alter ConfigMaps to support storing data in Secrets if needed?

There is also no conversion from old storage to new, so I can see how it will cause major pain for anybody willing to enable this feature in existing setups.

@thomastaylor312

Copy link
Copy Markdown
Contributor

@jakehow That is correct, should be pretty simple.

@redbaron This is just the first step of that proposal. Now that encrypted secrets are an option, some people will want to use it and we can implement the rest of the proposal later on. As for the conversion, that is a good point, but I am not sure if that is something that needs to go in to the release itself, but it may be useful to create a script to use out of band. Thoughts?

@bacongobbler

Copy link
Copy Markdown
Member

There is also no conversion from old storage to new, so I can see how it will cause major pain for anybody willing to enable this feature in existing setups.

As for the conversion, that is a good point, but I am not sure if that is something that needs to go in to the release itself, but it may be useful to create a script to use out of band.

I think it's completely fine (and I would prefer) to ship this as a new "experimental" storage backend with no migration story. This is already a massive addition to the codebase (thank you @RemingtonReackhof, btw) and will likely need some battle testing before we go ahead and start writing data migration scripts from configmaps to secrets. If anything that should be a follow-up PR or an out-of-band script like @thomastaylor312 mentions IMO. If we're writing data migration scripts, it's probably best to hold that off until Helm 3.

@thomastaylor312

Copy link
Copy Markdown
Contributor

@RemingtonReackhof We discussed this in the dev call and decided we are going to go ahead and merge. You have already spent a good deal of time on this PR, so one of us can add the documentation in a separate PR.

@thomastaylor312
thomastaylor312 merged commit ab096b8 into helm:master Oct 12, 2017
thomastaylor312 added a commit that referenced this pull request Oct 13, 2017
Adds documentation for running `tiller` with the new secrets backend
added in #2721
@redbaron

Copy link
Copy Markdown
Contributor

@bacongobbler , @thomastaylor312 this "massive addition" is a copypaste of a configmap driver, there is simply nothing to battle test, it is as robust as old driver. It adds very little value without a migration path :(

$ sed -i -e 's,secrets,cfgmaps,g' -e 's,Secret,ConfigMap,g' -e 's,//.*,,g' secrets.go    # rename IDs, delete comments 
$ sed -i -e 's,//.*,,g' cfgmaps.go   # delete comments
$ diff -u cfgmaps.go secrets.go
--- cfgmaps.go  2017-10-13 07:35:06.714096200 +0100
+++ secrets.go  2017-10-13 07:34:55.949777000 +0100
@@ -1,5 +1,5 @@
 /*
-Copyright 2016 The Kubernetes Authors All rights reserved.
+Copyright 2017 The Kubernetes Authors All rights reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@
                return nil, err
        }

-       r, err := decodeRelease(obj.Data["release"])
+       r, err := decodeRelease(string(obj.Data["release"]))
        if err != nil {
                cfgmaps.Log("get: failed to decode data %q: %s", key, err)
                return nil, err
@@ -99,7 +99,7 @@


        for _, item := range list.Items {
-               rls, err := decodeRelease(item.Data["release"])
+               rls, err := decodeRelease(string(item.Data["release"]))
                if err != nil {
                        cfgmaps.Log("list: failed to decode release: %v: %s", item, err)
                        continue
@@ -136,7 +136,7 @@

        var results []*rspb.Release
        for _, item := range list.Items {
-               rls, err := decodeRelease(item.Data["release"])
+               rls, err := decodeRelease(string(item.Data["release"]))
                if err != nil {
                        cfgmaps.Log("query: failed to decode release: %s", err)
                        continue
@@ -164,7 +164,7 @@

        if _, err := cfgmaps.impl.Create(obj); err != nil {
                if apierrors.IsAlreadyExists(err) {
-                       return ErrReleaseExists(key)
+                       return ErrReleaseExists(rls.Name)
                }

                cfgmaps.Log("create: failed to create: %s", err)

@thomastaylor312

Copy link
Copy Markdown
Contributor

@redbaron I have to disagree on that point (although it is very similar code to the config map backend). It definitely is a value add mainly because you can now encrypt Secret objects by default and there is the possibility of future integration of secrets with a backend like Vault. See the discussion starting here for reference.

@pavel-rosputko

Copy link
Copy Markdown

<.Secrets.global.aws....>: can't evaluate field global in type interface {}
global is not supported for Secrets?

@arm4b

arm4b commented Jun 29, 2018

Copy link
Copy Markdown

@marty-stranger According to code, the PR only implements tiller --storage=secret and there is a corresponding documentation change for that: #3034

I couldn't find (as advertised in PR description) implementation for secrets.yaml, {{ .Secrets.type }} and --set-secrets/--secrets options for helm install and helm upgrade.

^^ That's a confusing part about this PR to know about.

@bitsofinfo

Copy link
Copy Markdown

How do we reference the {{ .Secrets....}}? or is that still in progress

@Magizhchi

Copy link
Copy Markdown

@marty-stranger According to code, the PR only implements tiller --storage=secret and there is a corresponding documentation change for that: #3034

I couldn't find (as advertised in PR description) implementation for secrets.yaml, {{ .Secrets.type }} and --set-secrets/--secrets options for helm install and helm upgrade.

^^ That's a confusing part about this PR to know about.

Is there any guidance on this, I am also looking to use {{ .Secrets.mySecretValue }} in my charts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. feature in progress size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants