-
Notifications
You must be signed in to change notification settings - Fork 1.5k
tls: Generate TLS assets through dependency graph #145
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
tls: Generate TLS assets through dependency graph #145
Conversation
3db2959 to
7d3a374
Compare
32cabef to
7773def
Compare
pkg/asset/tls/certkey.go
Outdated
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
pkg/asset/tls/certkey.go
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
pkg/asset/tls/variables.go
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pkg/asset/tls/certkey.go
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/asset/tls/variables.go
Outdated
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
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?
pkg/asset/tls/variables.go
Outdated
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
There was a problem hiding this comment.
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.
7e5d785 to
e0a7bb5
Compare
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... by
targetable assetsI mean things likeCluster,Manifestswhich 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.
There was a problem hiding this comment.
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.
19e5240 to
6e736c8
Compare
81629de to
4fc301f
Compare
|
@wking PTAL (all green) |
pkg/asset/tls/certkey_test.go
Outdated
There was a problem hiding this comment.
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)
}There was a problem hiding this comment.
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.
|
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 |
Move helper functions from 'installer/pkg/tls.go' and 'installer/pkg/utils.go'
|
/lint |
openshift-ci-robot
left a comment
There was a problem hiding this 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.
pkg/asset/tls/certkey.go
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/asset/tls/keypair.go
Outdated
There was a problem hiding this comment.
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.
pkg/asset/tls/helper.go
Outdated
There was a problem hiding this comment.
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.
pkg/asset/tls/helper.go
Outdated
There was a problem hiding this comment.
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.
|
/lint |
openshift-ci-robot
left a comment
There was a problem hiding this 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.
|
The You probably need to convert to the new public versions there too. |
pkg/asset/tls/certkey.go
Outdated
There was a problem hiding this comment.
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.
pkg/asset/tls/stock.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "key/cert" -> "key".
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
pkg/asset/tls/stock.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "key/cert" -> "key".
a8c7460 to
d7428e8
Compare
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.
|
/lgtm /wking crosses his fingers for the e2e and smoke tests ;) |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
CertKeytype that implements the asset interface./installer/pkg/config-generator/tls.go