camel-k icon indicating copy to clipboard operation
camel-k copied to clipboard

CertManager automatic discover

Open squakez opened this issue 2 years ago • 13 comments

We can identify the presence of the operator and create the custom resources to issue certificates automatically.

squakez avatar Sep 20 '24 06:09 squakez

This issue has been automatically marked as stale due to 90 days of inactivity. It will be closed if no further activity occurs within 15 days. If you think that’s incorrect or the issue should never stale, please simply write any comment. Thanks for your contributions!

github-actions[bot] avatar Dec 20 '24 00:12 github-actions[bot]

@squakez As per my understanding we need to do the following

  1. Camel K should be able to detect if cert-manager is installed.
  2. Create Certificate CR
  3. Mount that secret (by name) into pod

If you are not working on this already I can take a stab at it.

pkalsi97 avatar Dec 16 '25 07:12 pkalsi97

That's correct. I think we can verify the existence of Cert Manager custom resources definition (like we do for Knative, for example) and try to autotune the Cert Manager Issuer when the Ingress trait is provided. Feel free to have a look and run some experiment to see what it makes sense.

squakez avatar Dec 16 '25 08:12 squakez

@squakez I am thinking of implementing this approach

  1. To detect Cert-Manager we can use cert-manager.io/v1 via ServerResourcesForGroupVersion(), return false if CRD not found, no error.
  2. Extend the ingress-trait -> tlsIssuerName , tlsIssuerKind
  3. Automatic cert creation:
  • Trigger conditions: TLSHosts set + TLSSecretName empty + TLSIssuerName provided
  • Check cert-manager availability at runtime, only when needed.
  • Create certmanagerv1.Certificate with Secret name, Labels integration, References issuer, DNSNames
  1. Separate RBAC files for cert-manager resources (Certificates, Issuers, ClusterIssuers)
user sets tls-issuer-name
         |
         v
  ingress trait runs
         |
         v
  cert-manager installed? ---no---> do nothing
         |
        yes
         |
         v
  create Certificate CR
         |
         v
  cert-manager issues secret
         |
         v
  ingress uses secret for TLS

What do you think about this approach ? am I missing something ?

pkalsi97 avatar Dec 17 '25 10:12 pkalsi97

I think we can make it much easier by leveraging the annotated ingress resources: https://cert-manager.io/docs/usage/ingress/ - I think what we need is the verify the existence of the clusterIssuer and, if it exists, just add the annotation, so that the Cert Manager operator manages it. We can start looking for ClusterIssuer as a default, and, if missing, any namespaced Issuer. It could be an auto (default false) option to perform the logic. Beside that we can have the user providing the name of the issuer forcefully, so, the operator only verify the existence of the CertManager and the issuer. Hope it makes sense. What could be challenging (and funny at the same time) is the e2e where we can have a real https call with some autogenerated certificate.

squakez avatar Dec 17 '25 14:12 squakez

@squakez thanks for this approach. I'll look into this. I plan to work on it and finish it before the coming Saturday!

pkalsi97 avatar Dec 17 '25 14:12 pkalsi97

@squakez thanks for this approach. I'll look into this. I plan to work on it and finish it before the coming Saturday!

No rush, take your time and, above all, have fun!

squakez avatar Dec 17 '25 14:12 squakez

Hi @pkalsi97 how are you doing? fyi, we're planning to release 2.10.0 in a few days (see #6552). If the work of this issue is completed by then, make sure to do a PR some day before. If not, we will move this for next version. Thanks!

squakez avatar Mar 28 '26 08:03 squakez

@squakez hey, I am doing okay. How are you ? Recently I am busy with some client work so I was not able to put my time and efforts into solving this issue. I don't think I wont be able to create a fix for this in the coming 2/3 weeks. If anyone else wants to pick this up, feel free to do so!

pkalsi97 avatar Mar 28 '26 09:03 pkalsi97

@squakez hey, I am doing okay. How are you ? Recently I am busy with some client work so I was not able to put my time and efforts into solving this issue. I don't think I wont be able to create a fix for this in the coming 2/3 weeks. If anyone else wants to pick this up, feel free to do so!

Okey, thanks for letting us know. We can postpone this for 2.11 then.

squakez avatar Mar 29 '26 10:03 squakez

@pkalsi97 removing the assignment so that any contributor can pick this up. Feel free to comment or reassign again if you still can contribute to the issue. Thanks for the work so far!

squakez avatar Sep 14 '26 06:09 squakez

Hi @squakez! I've gone through the discussion and would like to pick this up if it's still open — thanks to @pkalsi97 for the groundwork here, it made this much easier to frame.

My understanding of the approach, building on what you proposed:

  1. Detection — check for cert-manager's CRDs (e.g. via ServerResourcesForGroupVersion on cert-manager.io/v1, similar to the existing Knative detection pattern). Absence just means "skip silently," not an error.
  2. Issuer resolution — look for a ClusterIssuer by default; if none exists, fall back to a namespaced Issuer. Alternatively, the user can explicitly force an issuer name/kind via new trait fields (e.g. tlsIssuerName, tlsIssuerKind), in which case Camel K just verifies cert-manager and that issuer exist, no auto-discovery needed.
  3. Annotation, not CR creation — rather than creating Certificate CRs ourselves, add the standard cert-manager ingress-shim annotation to the Ingress so cert-manager handles issuance/renewal itself.
  4. Opt-in — gate the auto-detect behavior behind a flag defaulting to false, so this is non-disruptive for existing users.

Trigger conditions for the automatic path would be something like: TLSHosts set + TLSSecretName empty + issuer available (auto-detected or forced).

On testing — I know you flagged the e2e case (a real HTTPS call against an autogenerated cert) as the trickiest part. I'd plan to spin up cert-manager with a self-signed ClusterIssuer in the e2e environment and validate the resulting secret/cert rather than hitting a public CA, unless you have a preferred pattern already in mind.

Thundercloud12 avatar Sep 15 '26 11:09 Thundercloud12

@Thundercloud12 feel free to go ahead, it seems a good plan. One tip for the test, you may start a new workflow in order to make it easy and avoid adjusting existing flows and tests, as it is done, for example, for the gateway.

squakez avatar Sep 15 '26 13:09 squakez