Skip to content

Cluster scoped Issuer support - #101

Merged
munnerz merged 11 commits into
masterfrom
cluster-issuer
Oct 12, 2017
Merged

munnerz merged 11 commits into
masterfrom
cluster-issuer

Conversation

@munnerz

@munnerz munnerz commented Sep 22, 2017 •

Copy link
Copy Markdown
Member

This is an attempt at a ClusterIssuer resource.

It shares the same fields as an Issuer resource, including the same IssuerSpec and IssuerStatus.

To overcome issues with fields in the Issuer spec not containing namespace fields, the namespace to store resources in for ClusterIssuers is specified as a CLI flag to cert-manager itself. I'm not sure if this is an acceptable tradeoff, but it makes the addition of this feature much cleaner.

In order to support both types of issuer within the pkg/issuer package, I have created a GenericIssuer interface in pkg/apis/certmanager/v1alpha1/helper.go. This is probably not the best final resting place for this type.

This also changes the Certificate spec so that the spec.issuer field is now spec.issuerRef. A Certificate can reference a ClusterIssuer by setting the kind field to 'ClusterIssuer'.

apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
  name: test-example-com
  namespace: test-ns
spec:
  secretName: test-example-com
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
...

The above resource would use the ClusterIssuer named letsencrypt-prod.

If a Certificate were to omit the spec.issuerRef.Kind field or set it to 'Issuer', it would use the Issuer letsencrypt-prod in the namespace test-ns, e.g.:

apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
  name: test-example-com
  namespace: test-ns
spec:
  secretName: test-example-com
  issuerRef:
    name: letsencrypt-prod
...

@mikebryant I'm keen to hear your feedback. This is actually surprisingly tricky to implement, between the API surface exposed to users and how we deal with the differences between the two types internally.

Closes #91

/cc @simonswine @mattbates @dippynark

@munnerz

munnerz commented Sep 22, 2017

Copy link
Copy Markdown
Member Author

I think with some additional work, it'd also be possible to refactor out the clusterissuer control loop altogether and unify the two (to save the extra code duplication).

To do this, we'll need to make the control loops convert Issuer resources to GenericIssuer's early on. This may lead to us not being able to validate extensively in future however, so I've avoided it for now.

@simonswine

Copy link
Copy Markdown
Contributor

I think not having namespaces in the references of Issuers is an acceptable trade-off for keep things simple (esp. in the various Issuer implementations). The cli flag for specifying a namespace makes sense to me. Would you set the cert-manager namespace as a default for that?

For the IssuerRef field i think it's crucial to document "" == non namespaced vs. nil == same namespace properly otherwise people will get confused. I think there is a similar thing in core kubernetes and it took me a while to get my head around at the beginning...

defaultNamespace = ""
defaultAPIServerHost = ""
defaultNamespace = ""
defaultClusterResourceNamespace = "kube-system"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we default to the current namespace instead? e.g. /var/run/secrets/kubernetes.io/serviceaccount/namespace

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just remembered this comment after merging. I've opened #103

@mikebryant

Copy link
Copy Markdown
Member

I agree, "" vs nil is subtle and easy to overlook.

Maybe we could just be more "magic" in issuer selection - leave it as issuer: name, and if that exists in the same namespace, use it, if not, use the ClusterIssuer of that name instead.

This does mean it's:

  • not possible to use an issuer in a different namespace. I don't see this as a huge problem, as presumably you would use ClusterIssuer if you wanted that
  • not possible to use a ClusterIssuer if you've created Issuer of the same name in your namespace.

All that said, I suspect most peoples use-case for ClusterIssuer will involve defaulting, so the entire issuer section will just be left out - so maybe this isn't such a problem.

@errordeveloper

Copy link
Copy Markdown

I agree, "" vs nil is subtle and easy to overlook.

I also agree.

I probably don't have enough context, but I wonder whether Issuer has to be a namespaced type of resource. Especially I am really unsure what is the use-case for namespaced/non-default issuer. So it sounds like there will be ClusterIssuer, a default one...

Maybe, we should consider having non-namespaced issuers, and per-namespace issuer binding of some sort. Perhaps, this is not dissimilar from ClusterRole (non-namespaced), and ClusterRoleBinding (optionally namespaced).

In fact, I'd consider making ServicesAccount the link between an Issuer and a Pod, that would allow to model things similar to ClusterRole and ClusterRoleBinding.

@munnerz

munnerz commented Oct 6, 2017 •

Copy link
Copy Markdown
Member Author

A suggestion from @dippynark -

RBAC uses a kind field in order to disambiguate between ClusterRole and Role - we could model it like so:

apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
  name: test-example-com
  namespace: test-ns
spec:
  secretName: test-example-com
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer

The default kind would then be an Issuer. Any other value would be invalid.

Any thoughts on that? It's probably clearer for users to understand than the namespace "" vs nil case. For reference, this PR does not introduce Certificates obtaining certs from Issuers in other namespaces, it simply introduces a non-namespaced issuer resource.

Using a kind field as above would potentially allow us to still support crossing namespace boundaries in future if it makes sense (through the addition of a namespace field)

@errordeveloper

errordeveloper commented Oct 10, 2017 via email

Copy link
Copy Markdown

@munnerz

munnerz commented Oct 12, 2017

Copy link
Copy Markdown
Member Author

I've updated this to use a kind field, and updated the original comment on this PR to reflect the changes. Going to merge now, and if we decide against this route in future we can reconsider as this is still an alpha API.

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.

4 participants