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

add cloud-creds-secret #427

Merged

Conversation

sallyom
Copy link
Contributor

@sallyom sallyom commented Oct 5, 2018

Various components will require access to credentials to create AWS resources (such as registry - s3 bucket). This PR adds a secret aws-creds or openstack-creds to kube-system namesapce that holds the cloud-provider credentials plus a role aws|openstack-creds-secret-reader in -n kube-system to bind to to access the secret.

Made the creds secret generic and added logic to get libvirt and aws or openstack creds to generate a secret and role. Note, add whatever is required for libvirt when this lands: #296

TODO: verify the OpenStack credentials secret is what's required @flaper87. Currently the secret is encoded from /etc/openstack/clouds.yaml.
TODO in followup: Add libvirt credentials once they become necessary.

This PR adds (showing aws here):

$ oc describe secret aws-creds -n kube-system
Name:         aws-creds
Namespace:    kube-system
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
aws_access_key_id:      20 bytes
aws_secret_access_key:  40 bytes

and

$ oc describe role aws-creds-secret-reader -n kube-system
Name:         aws-creds-secret-reader
Labels:       <none>
Annotations:  <none>
PolicyRule:
  Resources  Non-Resource URLs  Resource Names  Verbs
  ---------  -----------------  --------------  -----
  secrets    []                 [aws-creds]     [get]

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 5, 2018
@wking
Copy link
Member

wking commented Oct 7, 2018

TODO: create secret/role only if cloud provider is aws, and/or make secret more generically 'cloud-creds-secret'.

The libvirt analog is probably the libvird URI (and maybe a client cert/key, #296).

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2018
@sallyom sallyom force-pushed the cloud-credentials-secret branch 3 times, most recently from 84d59dd to 3d0ec1f Compare October 8, 2018 17:22
Copy link
Contributor

@steveej steveej left a comment

Choose a reason for hiding this comment

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

I wonder if we could make the secret provider-agnostic on the storage level and have the type embedded in the data instead. A use-case which makes this a bit more difficult by requiring the simultaneous storage of different provider credentials is a multi-cloud cluster.

docs/user/environment-variables.md Show resolved Hide resolved
@steveej
Copy link
Contributor

steveej commented Oct 8, 2018

@wking

The libvirt analog is probably the libvird URI

Does the libvirt URI need to be part of the secret? It's not sensitive information and it's already handled by general cluster information.

@wking
Copy link
Member

wking commented Oct 8, 2018

The libvirt analog is probably the libvird URI

Does the libvirt URI need to be part of the secret?

No, but once you need a client cert/key, the URI won't be any use without the secret key. It seems easier to just keep the cert/key and URI in the same place. But none of this needs to happen in this PR; just something to think about when planning ahead.

@sallyom
Copy link
Contributor Author

sallyom commented Oct 8, 2018

@steveej @wking is a multi-cloud cluster possible atm? I'm going with installconfig platform (aws|libvirt|openstack) as the only options. Is there/will there be an option for more than 1 provider?

@sallyom sallyom changed the title WIP-add aws-creds-secret WIP-add cloud-creds-secret Oct 8, 2018
@wking
Copy link
Member

wking commented Oct 8, 2018

Is there/will there be an option for more than 1 provider?

Not to my knowledge. And the installer code currently assumes one provider in a few places, so I'd just roll with that approach for now.

@smarterclayton
Copy link
Contributor

/retest

namespace: kube-system
name: cloud-creds-secret
data:
aws_access_key_id: {{.CloudCreds.AwsCredsData.Base64encodeAWSaccessKeyID}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect that these resources will be identical for all platforms save for the data in the secret? If so, it may be better to use an if in the template that checks the platform type to determine which type of data to add rather than having a separate, mostly duplicated go file for each platform.

Copy link
Contributor Author

@sallyom sallyom Oct 15, 2018

Choose a reason for hiding this comment

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

👍 makes sense thanks, will push a change to that effect.. er...easier said than done but looking into it

pkg/asset/manifests/tectonic.go Outdated Show resolved Hide resolved
@@ -80,6 +121,19 @@ func (t *Tectonic) Generate(dependencies asset.Parents) error {
Data: data,
})
}
switch {
case installConfig.Config.Platform.AWS != nil:
t.files = remove(t.files, "99_openstack-creds-secret-and-reader-role.yaml")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we just add conditionally rather than adding everything and removing based on the platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, that is silly.. fixing now..

}

type cloudCredsTemplateData struct {
AwsCredsData
Copy link
Contributor

Choose a reason for hiding this comment

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

Give explicit names to these fields (e.g., AWS, OpenStack, Libvirt). That will (1) make the name in the template file shorter and (2) allow for fields in the various cred data struct to have the same names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@flaper87
Copy link
Contributor

@sallyom thanks for including OpenStack in this PR. cc'ing @tomassedovic @hardys @russellb too.

Let us know if we can do anything to help on the OpenStack side of things.

@sallyom sallyom force-pushed the cloud-credentials-secret branch 2 times, most recently from 37d62e0 to 27293f8 Compare October 15, 2018 18:05
namespace: kube-system
name: cloud-creds
data:
{{- if .CloudCreds.AWS}}
Copy link

Choose a reason for hiding this comment

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

Can we add the type of the cluster (AWS, OpenStack, etc.) so that consumers know what to expect?

Copy link
Contributor

Choose a reason for hiding this comment

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

and while we're at it (providing AWS coordinates), the registry operator would also like to know what s3 bucket name should be used for the registry (if you don't supply a name we'll create one, but it's likely users may want to create their own bucket).

Copy link
Contributor Author

@sallyom sallyom Oct 23, 2018

Choose a reason for hiding this comment

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

@dmage made it so, yes

Copy link
Contributor Author

@sallyom sallyom Oct 23, 2018

Choose a reason for hiding this comment

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

@bparees, makes sense, might not be within the scope of this PR, I'll discuss with the installer team. In a follow-up PR, we can add registry s3 bucket name to the secret if/when necessary.

@sallyom sallyom force-pushed the cloud-credentials-secret branch 3 times, most recently from 956dbbd to 32f6e1e Compare October 25, 2018 09:16
@sallyom
Copy link
Contributor Author

sallyom commented Oct 25, 2018

/retest

@sallyom
Copy link
Contributor Author

sallyom commented Oct 25, 2018

@staebler @wking, I think this is ready for approval, ptal. I've tested in libvirt, no secret/role is created and in aws aws-creds secret and aws-creds-secret-reader role are created

@flaper87 I've made the change to name os secret data clouds.yaml instead of credentials

@sallyom sallyom changed the title WIP-add cloud-creds-secret add cloud-creds-secret Oct 25, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 25, 2018
@flaper87
Copy link
Contributor

@flaper87 I've made the change to name os secret data clouds.yaml instead of credentials

Perfect, thanks!

FWIW, I've tested this with openstack and openshift/release#1824 It works fine!

@@ -16,12 +20,17 @@ import (

const (
tectonicManifestDir = "tectonic"
// TODO: Verify this is expected os creds file
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we can drop this comment?

)

var (
tectonicConfigPath = filepath.Join(tectonicManifestDir, "00_cluster-config.yaml")

_ asset.WritableAsset = (*Tectonic)(nil)

// TODO: Verify which creds file to expect
//openStackCredsFile = os.Getenv("HOME") + "/.config/openstack"
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with a GitHub issue or commit-message comment about wanting this, but I'd rather not have commented-out code stubs committed to the repo. They just make refactoring harder, e.g. if we renamed openStackCredsFile, this would be one more thing to update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 #550

var cloudCreds cloudCredsSecretData
platform := ""
switch {
case installConfig.Config.Platform.AWS != nil:
Copy link
Member

Choose a reason for hiding this comment

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

To DRY up the naming, maybe use Platform.Name:

platform := installConfig.Config.Platform.Name()
switch platform {
case "aws":
  ...

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, got it. I missed the addn of func (p *Platform) Name() string :)

}

for file, content := range conditionalAssetData {
assetData[file] = content
Copy link
Member

Choose a reason for hiding this comment

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

conditionalAssetData seems like more trouble than it's worth. Why not just:

assetData["99_..."] = applyTemplate...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because doh-duh thank you!

@sallyom sallyom force-pushed the cloud-credentials-secret branch 4 times, most recently from 379a604 to f77fda4 Compare October 26, 2018 20:06
@wking
Copy link
Member

wking commented Oct 26, 2018

When you get a moment, can you squash the commits and drop the WIP?

$ git log --oneline -2 origin/pr/427
f77fda4 trevor's feedback
47b84f0 WIP-add aws-creds-secret

is probably not a useful distinction for future readers ;). While you're editing the commit message, pasting in whatever is relevant from your initial PR comment (e.g. "Various components will require access...") will make it easier for folks running blame to understand the motivation (otherwise they have to figure out the PR number and check here ;).

@sallyom
Copy link
Contributor Author

sallyom commented Oct 27, 2018

@wking squashed, re-worded commit msg :)

Copy link
Member

@wking wking left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 27, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sallyom, wking

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 27, 2018
@openshift-merge-robot openshift-merge-robot merged commit 762ae17 into openshift:master Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.