-
Notifications
You must be signed in to change notification settings - Fork 680
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
pkg/certs: Move certgen into a public package so other projects can consume #3135
Conversation
543a1aa
to
4ddc9fa
Compare
Codecov Report
@@ Coverage Diff @@
## main #3135 +/- ##
==========================================
- Coverage 75.39% 75.30% -0.09%
==========================================
Files 97 96 -1
Lines 6023 5925 -98
==========================================
- Hits 4541 4462 -79
+ Misses 1372 1363 -9
+ Partials 110 100 -10
|
pkg/certs/certgen.go
Outdated
} | ||
|
||
// GenerateCerts performs the actual cert generation steps and then returns the certs for the output function. | ||
func GenerateCerts(certConfig *CertgenConfig) (map[string][]byte, error) { |
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.
any reason not to combine GenerateCerts
and OutputCerts
into a single exported function, since they need to be called one after the other? It'd make for a slightly cleaner public API IMHO.
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 I'll do that, less API exposed is better. =)
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 looking into this a bit more, it seems like we should have 3 public methods outlined below. The confusing part about how it's built today is that if you request a cert in yaml
or pem
format, you still need to pass a kubeclient which isn't used at all in those two situations.
- Kubernetes Secret (
--kube
),GenerateKubeCertificates(format string, kubeclient *kubernetes.Clientset, overwrite bool)
- Yaml (
--yaml
),GenerateYamlCertificates(format, outputDirectory string, force bool)
- PEM (
--pem
),GeneratePemCertificates(format, outputDirectory string, force bool)
Note: We could combine the yaml & pem into a single one, but I'd probably keep separate? /shrug
This means then that the doCertgen()
inside cmd/contour
will look at the flags passed and call each public method appropriately, but external callers have a clean API to use to code against.
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 propose just one API:
type CertificateSet struct {
Contour []byte
Envoy []byte
CA []byte
}
func GenerateCertificates(options ...) (CertificateSet, error)
The caller can deal with emitting the certificates in the way they need (i.e. contour-operator probably can't directly use any of the specific APIs above). We probably need the options so the caller can do things like set unique SAN entries.
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 operator can use the apis above as-is.
The work to serialize them to pem or yaml or secrets is a benefit of using a library as this is intended so the caller doesn't need to reinvent that work.
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 could be further customizations to add name, etc, etc, but could come as well as needed.
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 operator can use the apis above as-is.
Are you sure? The operator doesn't need GenerateYamlCertificates
or GenerateYamlCertificates
. It may need GenerateKubeCertificates
, but (1) depending on the Kubernetes framework it uses, it may not have easy access to the right client struct (2) it may need to specify the name or namespace of the secret (3) it may need to set owner references or other object meta information (4) it may combine the certificates into secrets in way this function does not anticipate.
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.
Requirements / needs will change over time, 💯 .
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 like the sound of @jpeach's suggestion, it seems like a nice, clean API. I think it's probably better to have separate Output functions for each type though, so that we can ensure that things consuming this package output their certs in the right way (ie files have the correct permissions etc, certificates are in the right formats, and so on). Callers don't have to use the Output functions, but supplying them makes keeping things in sync easier.
Marking this PR stale since there has been no activity for 14 days. It will be closed if there is no activity for another 90 days. |
8a07d0f
to
faa4f89
Compare
Ok folks, I just did a big refactor to this, please take a look. |
faa4f89
to
a97f914
Compare
…onsume Some projects like the Contour Operator, need ways to create certificates for Contour deployments. Currently, this is done via a Kubernetes Job which executes the Contour command `certgen` which generates self-signed certificates used for communication between Contour<>Envoy. This moves the generation logic into a public package (e.g. pkg/certs) which allows projects to consume this same code to generate certificates by other means other than the Contour `certgen` command. Fixes projectcontour#3130 Signed-off-by: Steve Sloka <slokas@vmware.com>
Signed-off-by: Steve Sloka <slokas@vmware.com>
e5d9e31
to
a440c9c
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.
LGTM, looks like a solid move over of the existing code and kept to the pared down interface, with some configurability
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'd be great to get @danehans to take a look at this too and validate that the public API will work for the operator's needs.
Signed-off-by: Steve Sloka <slokas@vmware.com>
Signed-off-by: Steve Sloka <slokas@vmware.com>
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.
LGTM assuming @danehans confirms this will meet the Operator's needs.
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.
LGTM, nice work @stevesloka
…onsume (projectcontour#3135) Some projects like the Contour Operator, need ways to create certificates for Contour deployments. Currently, this is done via a Kubernetes Job which executes the Contour command `certgen` which generates self-signed certificates used for communication between Contour<>Envoy. This moves the generation logic into a public package (e.g. pkg/certs) which allows projects to consume this same code to generate certificates by other means other than the Contour `certgen` command. Fixes projectcontour#3130
Some projects like the Contour Operator, need ways to create certificates for
Contour deployments. Currently, this is done via a Kubernetes Job which executes
the Contour command
certgen
which generates self-signed certificates used forcommunication between Contour<>Envoy.
This moves the generation logic into a public package (e.g. pkg/certs) which
allows projects to consume this same code to generate certificates by other
means other than the Contour
certgen
command.Fixes #3130
Signed-off-by: Steve Sloka slokas@vmware.com