Skip to content

Conversation

@yifan-gu
Copy link
Contributor

@yifan-gu yifan-gu commented Aug 17, 2018

  • Created CertKey type that implements the asset interface.
  • Pulling the tls asset generation logic from /installer/pkg/config-generator/tls.go

@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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 17, 2018
@yifan-gu yifan-gu force-pushed the generate_tls branch 2 times, most recently from 3db2959 to 7d3a374 Compare August 17, 2018 21:49
@yifan-gu yifan-gu force-pushed the generate_tls branch 2 times, most recently from 32cabef to 7773def Compare August 17, 2018 22:22
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather use separate assets for the key and the cert. I guess most folks who want to bring their own keys will also bring their own certs, but having separate assets would support us cert'ing folks who bring only their own keys. A potentially more-useful reason for splitting certs from keys is that we could recycle keys and only rebuild certs if something feeding the cert changed (e.g. the DNS names because the user decided to change that config and rebuild their assets).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we support user provided key/certs?
cc @crawford @abhinavdahiya @aaronlevy @smarterclayton

Copy link
Contributor

Choose a reason for hiding this comment

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

In Tectonic we were going to target just allowing a user to show up with a CA (or assets to generate intermediate CA), but that was it (they wouldn't get to provide component level certificates).

I don't know if that's acceptable from the Openshift product side. IMO letting user provide component level certs is just asking for them to mess it up (and rotation may not work as expected). But I've heard various things across the spectrum in various meetings, from:

  • We generate everything (offline root + in-cluster CA). No option to customize
  • We generate everything, but a user can provide is a CSR endpoint that we can use to ask for an in-cluster CA (and we'd plug endpoint into installer).
  • User can provide cluster-CA or root CA used to generating cluster-CA (a-la Tectonic plans).
  • User can provide all component certs.

@smarterclayton / @eparis -- any specific constraints here we should be working from? My position is going to be the less options we provide (and the more we control) the better - but not always realistic.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see you setting this false anywhere:

$ git grep AppendParent origin/pr/145
origin/pr/145:pkg/asset/tls/certkey.go: AppendParent bool // Whether append the parent CA in the cert.
origin/pr/145:pkg/asset/tls/certkey.go:         key, crt, err = generateCert(caKey, caCert, cfg, c.AppendParent)
origin/pr/145:pkg/asset/tls/variables.go:               AppendParent: true,
origin/pr/145:pkg/asset/tls/variables.go:               AppendParent:   true,
origin/pr/145:pkg/asset/tls/variables.go:               AppendParent:   true,
origin/pr/145:pkg/asset/tls/variables.go:               AppendParent: true,

Can we drop it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For CAs I didn't set it so it's default to false, I can set it to false explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

For CAs I didn't set it...

Ah, that explains my grep. Can we just use !IsCA then, or do we need to toggle this independently sometimes?

Copy link
Contributor

Choose a reason for hiding this comment

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

only server certs need to append the signing CA; client certs don't need append.

Also, IsCA vs IsRoot ?

https://github.com/openshift/library-go/blob/master/pkg/crypto/crypto.go

Copy link
Member

Choose a reason for hiding this comment

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

only server certs need to append the signing CA; client certs don't need append.

Can we distinguish that using ExtKeyUsageClientAuth?

Also, IsCA vs IsRoot ?

Won't root just be "IsCA set, but ParentCA unset"?

Copy link
Contributor Author

@yifan-gu yifan-gu Aug 21, 2018

Choose a reason for hiding this comment

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

The IsCA boolean is required by the x509.Certificate type.

Can we distinguish that using ExtKeyUsageClientAuth?

Seems we can't, the apiserver-proxy cert still has ExtKeyUsageClientAuth but it doesn't have the AppendParent

BTW, I split the root into a separate type as it shares less code with others.

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's used by the kubelet cert

Copy link
Member

Choose a reason for hiding this comment

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

If everyone is using 10-years for this, we can drop this knob to simplify the structure.

Copy link
Member

Choose a reason for hiding this comment

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

If everyone is using 10-years for this...

They aren't, so this property is fine as it stands.

Copy link
Member

Choose a reason for hiding this comment

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

How important is it to vary OrganizationalUnit? I'd expect that CommonName is sufficient context and we can just hard-code []string{"openshift"} for this in your cert-Asset method (instead of having it configurable via a cert-Asset-struct property).

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, there's also Organization field, I am not sure what's the best way of dealing with all those, so maybe just leave as is for now, and we can refactor later?

Copy link
Member

Choose a reason for hiding this comment

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

I expect we can generate these filenames from the subject common name, in which case they don't have to be part of our CertKey config. For an example in my mockup, see here (my Assets have names, so getting the asset filename is a generic Asset method, not a TLS-specific method).

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 point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wking After a second look, seems like we have some tls assets whose subject name is not a fixed value (e.g. tnc, ingress), so might just keep as is unless you feel strong about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think many packages will need to perform this. so either move it to a common helpfer func (ideally it can just take the asset.State and iterate over the contents) or make the Store to do it? But I am aware that some targets won't need to write stuff into disk (e.g. the targetable assets like Cluster)

Copy link
Member

Choose a reason for hiding this comment

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

But I am aware that some targets won't need to write stuff into disk (e.g. the targetable assets like Cluster)

I think we should just write all the assets to disk. It should help with reloading from disk for regeneration (or for generating the next asset group). And even if an asset will never be needed again, disk space isn't that expensive ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wking I know, by targetable assets I mean things like Cluster, Manifests which are not the actual assets, they just represent a group of assets, so they don't have any content to write.

Copy link
Member

Choose a reason for hiding this comment

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

... by targetable assets I mean things like Cluster, Manifests which are not the actual assets, they just represent a group of assets, so they don't have any content to write.

I'd rather not create pseudo-assets for grouping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's already part of the dependency graph, it's meant to be the entrypoint for different stages of the installer, so that users can insert their customization.
The installer's subcommands (openshift-install installconfig, openshift-install ignition) also correspond to these targets.

@yifan-gu yifan-gu force-pushed the generate_tls branch 6 times, most recently from 19e5240 to 6e736c8 Compare August 23, 2018 22:47
@yifan-gu yifan-gu changed the title WIP: Generate TLS assets tls: Generate TLS assets through dependency graph Aug 23, 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 Aug 23, 2018
@yifan-gu yifan-gu force-pushed the generate_tls branch 3 times, most recently from 81629de to 4fc301f Compare August 28, 2018 01:16
@abhinavdahiya
Copy link
Contributor

@wking PTAL (all green)

Copy link
Member

Choose a reason for hiding this comment

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

It looks like you're ignoring an error here. Can you replace this with:

installConfigState, err := installConfig.Generate(nil)
if err != nil {
  t.Fatal(err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah cuz it's fake install config, but I added anyway.

@wking
Copy link
Member

wking commented Aug 29, 2018

Ok, I've got just the three nits (which I'm fine punting on or handling in this PR), and the golint errors (which I think we should fix before merging). Once we get the golint issues fixed I'll /lgtm.

Move helper functions from 'installer/pkg/tls.go' and
'installer/pkg/utils.go'
@yifan-gu
Copy link
Contributor Author

/lint

Copy link
Contributor

@openshift-ci-robot openshift-ci-robot left a comment

Choose a reason for hiding this comment

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

@yifan-gu: 2 unresolved warnings and 4 new warnings.

Details

In response to this:

/lint

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Golint comments: should have a package comment, unless it's in another file for this package. More info.

Copy link
Member

Choose a reason for hiding this comment

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

Golint comments: should have a package comment, unless it's in another file for this package.

I think this is just a limitation of the golint plugin, because you have package docs in a sibling file:

$ git grep '// Package tls ' 0a7e6f4 -- pkg/asset/tls
0a7e6f4:pkg/asset/tls/doc.go:// Package tls defines and generates the tls assets based on its dependencies.

And the golint Prow job is happy, so I don't think we need to worry about these.

Copy link
Contributor

Choose a reason for hiding this comment

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

Golint comments: should have a package comment, unless it's in another file for this package. More info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Golint comments: should have a package comment, unless it's in another file for this package. More info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported const ValidityTenYears should have comment (or a comment on this block) or be unexported. More info.

@yifan-gu
Copy link
Contributor Author

/lint

Copy link
Contributor

@openshift-ci-robot openshift-ci-robot left a comment

Choose a reason for hiding this comment

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

@yifan-gu: 5 unresolved warnings and 0 new warnings.

Details

In response to this:

/lint

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.

The Generate* functions should not write files to disk in the function.
It should be done by the caller.
@wking
Copy link
Member

wking commented Aug 29, 2018

The go-vet errors are:

# github.com/openshift/installer/pkg/asset/tls
pkg/asset/tls/certkey_test.go:77:20: undefined: validityTenYears
pkg/asset/tls/certkey_test.go:94:21: undefined: validityTenYears
pkg/asset/tls/certkey_test.go:116:21: undefined: validityTenYears
# github.com/openshift/installer/installer/pkg/config-generator
installer/pkg/config-generator/generator_test.go:134:13: undefined: validityTenYears
installer/pkg/config-generator/generator_test.go:154:19: undefined: validityTenYears

You probably need to convert to the new public versions there too.

Copy link
Member

Choose a reason for hiding this comment

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

nit: add a trailing period. From here:

Notice this comment is a complete sentence that begins with the name of the element it describes.

Copy link
Member

Choose a reason for hiding this comment

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

nit: "key/cert" -> "key".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is generating both public and private key pair, why just saying "key"?

Copy link
Member

Choose a reason for hiding this comment

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

It is generating both public and private key pair, why just saying "key"?

Making a "key/cert" -> "key" replacement will leave us with "...generates the service-account key pair.". I'm fine if you want to call out public/private as well, but I don't want to claim there's a cert involved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Member

Choose a reason for hiding this comment

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

nit: "key/cert" -> "key".

@yifan-gu yifan-gu force-pushed the generate_tls branch 2 times, most recently from a8c7460 to d7428e8 Compare August 29, 2018 20:09
yifan-gu and others added 6 commits August 29, 2018 13:13
Add more helper functions to compute some tls info from installconfig.
CertKey implements the asset.Asset interface and generates
private key and certs that are signed by the parent CA.
KeyPair implements the asset.Asset interface and create an RSA
public/private key pair.
RootCA implements asset.Asset interface and generate a pair of
root ca cert/key.
All tls assets are either of CertKey type or KeyPair type, they all
implements the asset.Asset interface with different configuration.
@wking
Copy link
Member

wking commented Aug 29, 2018

/lgtm

/wking crosses his fingers for the e2e and smoke tests ;)

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wking, yifan-gu

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

The pull request process is described here

Details 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-merge-robot openshift-merge-robot merged commit ae7fe33 into openshift:master Aug 29, 2018
@yifan-gu yifan-gu deleted the generate_tls branch August 29, 2018 21:03
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants