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

Generalize the certificate generation configuration #220

Merged
merged 6 commits into from
Jun 11, 2024

Conversation

giorio94
Copy link
Member

@giorio94 giorio94 commented May 23, 2024

Currently, certgen has detailed knowledge of the specific certificates used by Cilium, hence requiring any changes (e.g., introduction of a new certificate) to be manually applied to this tool as well. Moreover, it strongly relies on default values, making it difficult to predict the final output looking at the Cilium's configuration only.

Let's instead introduce a generic configuration, which can be used to express the list of certificates to be generated, and their characteristics. The configuration shall be provided in yaml format through the dedicated flags (--config or --config-file), and an example is presented in the following:

certs:
- name: foo
  namespace: kube-system
  commonName: foo.cilium.io
  hosts:
  - foo.cilium.io
  - qux.cilium.io
  - 192.0.2.237
  usage:
  - signing
  - key encipherment
  - server auth
  validity: 72h
- name: bar
  ...

WIP changes on the Cilium's side, as an example of how the proposed configuration could be used: giorio94/cilium@8583b14

Note: this obviously introduces backward incompatibility changes if merged, and we should decide whether to backport the Cilium's changes to stable versions, which is more risky, or keep using the old version there (hence needing to support two parallel versions for a while).

@giorio94 giorio94 requested review from a team as code owners May 23, 2024 09:31
@giorio94 giorio94 requested review from marseel and kaworu and removed request for a team May 23, 2024 09:31
@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch 2 times, most recently from 0e1817a to 319e66f Compare May 23, 2024 09:41
@kaworu kaworu added the needs-rebase This PR needs to be rebased because it has merge conflicts. label May 29, 2024
@kaworu
Copy link
Member

kaworu commented May 29, 2024

First of all, the flag cleanup is impressive and functionally certgen is way more flexible after this patch, so thank you @giorio94 for tackling this 🙏

we should decide whether to backport the Cilium's changes to stable versions

In any case, we're still on v0.1.x so the first version with this change should be v0.2.x. IMO there is so little maintenance on cergen that we shouldn't bother backporting, but no strong opinion here. If we do not backport, then we should consider branching a v0.1 branch in case we need to do patch releases for previous cilium versions, hence not approving the PR until this question has reached a conclusion (but patch LGTM).

Finally, it's a tad scary to see such a huge change without any related test change, we definitely should consider adding at least a couple of functional tests (i.e. one for the initial cert /CA creation and one for renew), but of course not necessarily on this PR.

@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch from 319e66f to 540d434 Compare May 29, 2024 15:07
@giorio94
Copy link
Member Author

Rebased onto main to fix a conflict.

In any case, we're still on v0.1.x so the first version with this change should be v0.2.x. IMO there is so little maintenance on cergen that we shouldn't bother backporting, but no strong opinion here. If we do not backport, then we should consider branching a v0.1 branch in case we need to do patch releases for previous cilium versions, hence not approving the PR until this question has reached a conclusion (but patch LGTM).

👍 I personally agree on starting using the new version on Cilium v1.16, and keep the previous one for all the other stable branches. And I also agree about branching a dedicated branch for dependency updates for the old version.

Finally, it's a tad scary to see such a huge change without any related test change, we definitely should consider adding at least a couple of functional tests (i.e. one for the initial cert /CA creation and one for renew), but of course not necessarily on this PR.

Agreed. To be fair certgen doesn't include any tests at the moment, hence adding tests requires definitely some extra effort (and likely push this to Cilium v1.17). In a certain sense, the new configuration is also arguably simpler compared to the previous one (~ 1/10 LoCs).

Copy link

@marseel marseel left a comment

Choose a reason for hiding this comment

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

lgtm vendor changes.

I personally agree on starting using the new version on Cilium v1.16, and keep the previous one for all the other stable branches. And I also agree about branching a dedicated branch for dependency updates for the old version.

+1

@kaworu kaworu added the dont-merge/blocked Another PR must be merged before this one. label May 31, 2024
@giorio94
Copy link
Member Author

giorio94 commented Jun 6, 2024

Converting back to draft while I'm putting together an E2E test workflow.

@giorio94 giorio94 marked this pull request as draft June 6, 2024 08:23
@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch from 540d434 to f917bcd Compare June 6, 2024 13:01
@giorio94 giorio94 marked this pull request as ready for review June 6, 2024 13:08
@giorio94 giorio94 requested review from a team as code owners June 6, 2024 13:08
@giorio94 giorio94 requested review from brlbil and removed request for a team June 6, 2024 13:08
@giorio94
Copy link
Member Author

giorio94 commented Jun 6, 2024

Back reviewable, I've additionally dropped the now superfluous cilium-namespace option, and added an E2E test to validate certificate generation. The test runs the certgen binary once and verifies that both the CA and the leaf certificates specified through the configuration are generated correctly. Then, it reruns the tool a second time, and it asserts that
only the leaf certificates are regenerated, while the CA is not modified.

@kaworu PTAL 🙏

Copy link

@brlbil brlbil left a comment

Choose a reason for hiding this comment

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

I love the assert functions.

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

Thanks for the addition of the e2e test! I left a couple suggestions below but nothing blocking. Great work, thanks, making certgen flexible is a really nice improvement! And it shaves many lines of code as an added benefit 🙂

cmd/certgen.go Outdated Show resolved Hide resolved
@rolinh
Copy link
Member

rolinh commented Jun 7, 2024

Huh, looks like one of my review comment mysteriously disappeared. I was suggesting to replace references to "Cilium CA" by simply "CA" in the remaining flags, logs and error messages now that the tool is actually generic.

giorio94 added 3 commits June 7, 2024 15:59
Currently, certgen has detailed knowledge of the specific certificates
used by Cilium, hence requiring any changes (e.g., introduction of a
new certificate) to be manually applied to this tool as well. Moreover,
it strongly relies on default values, making it difficult to predict
the final output looking at the Cilium's configuration only.

Let's instead introduce a generic configuration, which can be used
to express the list of certificates to be generated, and their
characteristics. The configuration shall be provided in yaml format
through the dedicated flags (--config or --config-file), and an
example is presented in the following:

certs:
- name: foo
  namespace: kube-system
  commonName: foo.cilium.io
  hosts:
  - foo.cilium.io
  - qux.cilium.io
  - 192.0.2.237
  usage:
  - signing
  - key encipherment
  - server auth
  validity: 72h
- name: bar
  ...

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
So that the tool returns an error to the user in case the usage is not
correct, rather than ignoring it silently.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Following the introduction of a dedicated configuration file to define
the certificates to be generated, the only remaining usage of the
cilium-namespace option is as an alias of ca-secret-namespace. Hence,
let's remove it in favor of the more specific option.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
In an effort towards generality, let's remove the extra hard-coded
names (besides the user-configurable common name) from the autogenerated
CA certificate.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch from f917bcd to e958ca1 Compare June 7, 2024 14:21
Now that certgen is more generic and not specifically tied to Cilium,
let's further drop the remaining references to the Cilium CA from
flags, logs and comments.

Suggested-by: Robin Hahling <robin.hahling@gw-computing.net>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch from e958ca1 to 328d1f3 Compare June 7, 2024 14:25
@giorio94
Copy link
Member Author

giorio94 commented Jun 7, 2024

Huh, looks like one of my review comment mysteriously disappeared. I was suggesting to replace references to "Cilium CA" by simply "CA" in the remaining flags, logs and error messages now that the tool is actually generic.

I should have removed all the remaining references. PTAL and let me know if that's what you had in mind.

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

Yes exactly what I had in mind 🚀

@giorio94
Copy link
Member Author

Opened cilium/cilium#32998 to prevent renovate from upgrading the certgen version in stable Cilium branches.

@kaworu kaworu added enhancement New feature or request github_actions Pull requests that update Github_actions code go Pull requests that update Go code and removed needs-rebase This PR needs to be rebased because it has merge conflicts. dont-merge/blocked Another PR must be merged before this one. labels Jun 11, 2024
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Awesome work @giorio94 thanks for adding the test! 🙏

.github/workflows/tests-smoke.yaml Outdated Show resolved Hide resolved
The test runs the certgen binary once and verifies that both the CA and
the leaf certificates specified through the configuration are generated
correctly. Then, it reruns the tool a second time, and it asserts that
only the leaf certificates are regenerated, while the CA is not modified.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the pr/giorio94/generalize-cert-generation branch from 328d1f3 to 777d116 Compare June 11, 2024 13:15
@rolinh rolinh merged commit d51b6f1 into cilium:main Jun 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request github_actions Pull requests that update Github_actions code go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants