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

feat: cert-manager integration #1261

Merged
merged 2 commits into from
Nov 12, 2019
Merged

feat: cert-manager integration #1261

merged 2 commits into from
Nov 12, 2019

Conversation

10ko
Copy link
Member

@10ko 10ko commented Oct 10, 2019

What this PR does / why we need it:
Implement the cert-manager integration. This will allow installation and configuration of Tls certificates through Garden.

Special notes for your reviewer:
NOTE: please merge after #1317
For this feature to work properly, it needs better "readiness" check for Pods. I implemented and reverted a basic check in favour of @edvald implementation in the "artifact PR".

@10ko 10ko changed the title WIP: feat: implement installation of cert-manager WIP: feat: cert-manager integration Oct 10, 2019
@@ -342,6 +345,14 @@ export const kubernetesConfigBase = providerConfigBaseSchema
tlsCertificates: joiArray(tlsCertificateSchema)
.unique("name")
.description("One or more certificates to use for ingress."),
tlsManager: joi.string()
.optional()
.example("cert-manager")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pro-tip: You can use .allow(...values) to specify which specific values are allowed

await helm({ ctx, namespace: systemNamespace, log, args: [...installArgs] })
console.log("Success?")
return ""
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just use a helm module and additionally set that label on the system namespace? Is there something else that requires the custom code?

Copy link
Member Author

@10ko 10ko Oct 11, 2019

Choose a reason for hiding this comment

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

I thought of implementing the installation programmatically because I wanted to create other resources needed (like Issuers, etc) before starting to deploy the services.
I see your point and I might end up doing that since I might be able to delegate the creation of those resources later on but still before deploying.

Still working that part out because we need the certificate in order to deploy an ingress but cert-manager issues a certifcate annotating the ingress itself.
This part will undoubtely change soon.

@10ko 10ko force-pushed the cert-manager branch 7 times, most recently from 83f7d5b to 2ec44f7 Compare October 31, 2019 13:55
@10ko 10ko marked this pull request as ready for review October 31, 2019 15:30
@10ko
Copy link
Member Author

10ko commented Oct 31, 2019

Still working on the guide and on an example, code is here and has been tested against one of our dev clusters.
Will remove the "WIP:" part once the documentation is up.

name: joi.string()
.required()
.allow("cert-manager")
.description("The name of the certificate manager of choice. Currently supporting only cert-manager.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we actually anticipate supporting multiple ones? I think I'd suggest calling the config key certManager and having a certManager.enable field. If we do end up supporting others, I expect it'll be after this functionality is split into separate plugins.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is fair enough. I am still not sure how the plugin architecture would develop but if you think it would be possible to support something like this, that's ok with me. :)
I'll change it to be more specific.

Copy link
Member Author

@10ko 10ko Nov 1, 2019

Choose a reason for hiding this comment

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

I would though leave the field managedBy: cert-manager on the IngressTlsCertificate or change it to managedBy: "cert-manager" | "manual" with a default to "manual" of course.
I am not a big fan of managedByCertManager: boolean, certManagerCertificate or similar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, makes sense 👍

@edvald
Copy link
Collaborator

edvald commented Oct 31, 2019

Just noticed this, probably worth documenting that the minimum supported K8s version is 1.11: https://docs.cert-manager.io/en/latest/getting-started/install/kubernetes.html

docs/reference/providers/kubernetes.md Outdated Show resolved Hide resolved

[providers](#providers) > [tlsCertificates](#providerstlscertificates) > managedBy

A reference to the Tls certificates manager used to generate the certificate.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tls -> TLS


[providers](#providers) > [certManager](#providerscertmanager) > enable

Enable the cert-manager integration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to link the guide here.

docs/reference/providers/kubernetes.md Outdated Show resolved Hide resolved
@@ -19,10 +19,21 @@ export interface ProviderSecretRef {
namespace: string
}

export type TlsManager = "cert-manager" | "manual"
export type LEServerType = "staging" | "prod"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer a more verbose name, LetsEncryptServerType

export interface CertManagerConfig {
enable: boolean
email?: string
installOnly?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest removing installOnly and replacing enable with install. That way people can choose to use their own cert-manager installation but still use the managedBy: cert-manager feature.

Copy link
Member Author

@10ko 10ko Nov 7, 2019

Choose a reason for hiding this comment

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

If we remove the enable, what would the config file look like in the case I want to use my own installation? Because all other options are not mandatory.

Copy link
Member Author

Choose a reason for hiding this comment

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

You would still need to specify the email if you want Garden to take care of it.
Nevermind. 🤦‍♂

Copy link
Collaborator

Choose a reason for hiding this comment

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

For semantic validation, e.g. "this is required if that other field is set, but otherwise not", we can add explicit checks and error messages in the configureProvider handler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented that on the kubernetes.configureProvider

The email which will be used for creating Let's Encrypt certificates:
if your certificates are being created by Garden this field is required.`)
.example("[email protected]"),
installOnly: joi.boolean()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be good, just for clarity, to add a few fields that don't actually do anything for now, but set the config structure and serve to document our coverage a bit better. My suggestion:

  1. Add an acmeChallengeType field with the only option we support (e.g. .allow("HTTP-01").
  2. Add an issuer field with just "acme" supported for now.
  3. Add an acmeServer field with just "letsencrypt-staging" and "letsencrypt-prod" supported for now (as shorthands for the appropriate server URLs, and later we could support custom URLs).

@10ko 10ko force-pushed the cert-manager branch 4 times, most recently from 079a2b5 to eabf8eb Compare November 7, 2019 14:54
@10ko 10ko changed the title WIP: feat: cert-manager integration feat: cert-manager integration Nov 7, 2019

The goal of this integration is to give you a head start when setting the TLS certificates for your project with cert-manager, providing an easy way for installation and some sensible defaults while allowing full control of the underlying configuration.

The goal of this integrations is NOT to be a wrapper around cert-manager, nor to allow a garden user to fully-customize certificates generation through Garden.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a little hard to digest. I suppose the point is that we don't aim to fully support all the features of cert-manager, but rather accommodate the most common use case, something to that effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, what I wanted to express is that cert-manager is there, we just make your life easier at the beginning but at the same time you won't get a full wrapper around. Your sentece express it better.


### Requirements

We assume you have been taking care of setting up your domain names and your networking configuration is in place and functioning correctly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could use more clarification. Specifically, we require you to have configured your DNS and routing so that the domains you will configure below are pointed to your ingress controller.


### Challenge Type

The challenge type currently supported is Let's Encrypt [HTTP-01 challenge](https://letsencrypt.org/docs/challenge-types/).
Copy link
Collaborator

Choose a reason for hiding this comment

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

On a second read, the flow in this section feels a little odd. I'd prefer to start the "Issuing your first certificate" section with what you're supposed to do + an example. Then we can elaborate with what's happening behind the scenes + the note on the limitations.

@10ko 10ko force-pushed the cert-manager branch 2 times, most recently from 32dec73 to 788c752 Compare November 8, 2019 16:59
@edvald
Copy link
Collaborator

edvald commented Nov 11, 2019

I've added a commit with some iteration on the docs. @eysi09 could you perhaps lend another pair of eyes on the docs+reference, and see if it all holds up?

@edvald edvald force-pushed the cert-manager branch 2 times, most recently from bcbf756 to d64a761 Compare November 11, 2019 19:36
Copy link
Collaborator

@eysi09 eysi09 left a comment

Choose a reason for hiding this comment

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

Had some comments on the docs. Some of these are my own opinions so feel free to to pipe through your own style and preferences.


### Scope

This guide aims at outlining configuration and best practices when dealing with TLS certificates, cert-manager and Garden.
Copy link
Collaborator

Choose a reason for hiding this comment

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

aims at outlining sounds a little weird. Why not just outlines?


This guide aims at outlining configuration and best practices when dealing with TLS certificates, cert-manager and Garden.

When starting a new project or when maintaining your existing ones, dealing with the creation and renewal of certificates can easily become a very complex task. Many projects appeared in the last few years to help managing this complexity and one that stood out is [cert-manager](https://github.com/jetstack/cert-manager).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Many projects have appeared... (add have)


When starting a new project or when maintaining your existing ones, dealing with the creation and renewal of certificates can easily become a very complex task. Many projects appeared in the last few years to help managing this complexity and one that stood out is [cert-manager](https://github.com/jetstack/cert-manager).

The goal of this integration is to give you a head start when setting the TLS certificates for your project with cert-manager, providing an easy way for installation and some sensible defaults while allowing full control of the underlying configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The motivation behind this integration...


When starting a new project or when maintaining your existing ones, dealing with the creation and renewal of certificates can easily become a very complex task. Many projects appeared in the last few years to help managing this complexity and one that stood out is [cert-manager](https://github.com/jetstack/cert-manager).

The goal of this integration is to give you a head start when setting the TLS certificates for your project with cert-manager, providing an easy way for installation and some sensible defaults while allowing full control of the underlying configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

full control over the underlying (over instead of of)

The goal of this integration is to give you a head start when setting the TLS certificates for your project with cert-manager, providing an easy way for installation and some sensible defaults while allowing full control of the underlying configuration.
We don't aim to fully support all the features of cert-manager, but rather accommodate the most common use case while still allowing full control of the underlying setup.

Please read the defaults settings and configurations in each of the following sections.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please read about the default settings (s/read the/read about the/, s/defaults/default).

Or maybe just:

You can read about the default settings and configurations...

1) cert-manager will create a ClusterIssuer in your cluster which will generate your certificate.
2) It will then create a Certificate resource to request the TLS certificate.
3) Cert-manager will then automatically spin up an nginx ingress to solve the HTTP-01 acmeChallenge.
4) Once the challenge is solved the TLS certificate will be stored as a secret using the name/namespace specified above (eg. `cert-manager-example/tls-secret-for-certificate`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/solved/solved,/


### ClusterIssuer vs Issuer

cert-manager have two different Certificate issuers: namespaced and cluster one. Garden will only create ClusterIssuers.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/have/has/


### The certificate creation timeouts and garden terminates

> Please make sure your domain name is pointing at the right ip address.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/ip/IP/

Please find more info in the ["Issuing an ACME certificate using HTTP validation"](https://docs.cert-manager.io/en/release-0.11/tutorials/acme/http-validation.html#issuing-an-acme-certificate-using-http-validation) guide in the official cert-manager documentation.

---
If have any issue, found a bug or something is not clear in the documentation, please don't hesitate opening a new [Github issue](https://github.com/garden-io/garden/issues/new?template=BUG_REPORT.md) or ask us any question in our [Slack channel](https://chat.garden.io/).
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/opening/to open/


[providers](#providers) > [certManager](#providerscertmanager) > issuer

the type of issuer for the certificate. Currently only supporting ACME Let's Encrypt issuers.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/the/The

@edvald edvald merged commit 21f2775 into master Nov 12, 2019
@edvald edvald deleted the cert-manager branch November 12, 2019 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants