Repository navigation
Adding namespace to SAN - #265
Conversation
Signed-off-by: David Hadas <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #265 +/- ##
==========================================
- Coverage 73.11% 72.68% -0.44%
==========================================
Files 23 23
Lines 1380 1380
==========================================
- Hits 1009 1003 -6
- Misses 315 319 +4
- Partials 56 58 +2
... and 1 file with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
|
/retest |
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
|
Current code terminology is a bit confusing. I would like to first have a fix for SANs in this PR, then consider if we need to open an issue and create a second PR to rearrange the code by removing the current separation of "control-plane" vs. "data-plane" certificates if this is not needed. Alternatively, we may need to add some remarks and make it more clear or improve naming in this project to make it clearer when we refer to clients or server etc.. |
|
/retest |
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
Signed-off-by: David Hadas <[email protected]>
| // Create cert template suitable for CA and hence signing | ||
| func createCACertTemplate(expirationInterval time.Duration) (*x509.Certificate, error) { | ||
| rootCert, err := createCertTemplate(expirationInterval) | ||
| rootCert, err := createCertTemplate(expirationInterval, FakeDnsName) |
There was a problem hiding this comment.
Will it create duplicated FakeDnsName in DNSNames: []string{FakeDnsName, FakeDnsName} in createCertTemplate()?
There was a problem hiding this comment.
Yes it will. This is at the CA Template where I am not sure why we have Subject Alternate Name values in the first place. I believe it can probably be removed in a later cleanup PR.
There was a problem hiding this comment.
If you take a list of SANs in createCertTemplate, you can leave the list empty here.
(In fact, you could remove the DNSNames from the CA cert if you require the callers of createCertTemplate to pass in fakeDnsName...)
| clientCert.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth} | ||
| clientCert.Subject = pkix.Name{ | ||
| cert.KeyUsage = x509.KeyUsageDigitalSignature | ||
| cert.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth} |
There was a problem hiding this comment.
Sorry I am also not sure why the original author separated the data-plane vs control-plane as you raised the question #265 (comment)
But if it is no problem for having both x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth as security practice, I think it is not necessary for the separation.
There was a problem hiding this comment.
... thinking about this, I can't see any special risk in a having a certificate with both usages.
My thinking:
- Key Usages instruct the other side (client or server) about whether the cert is intended for that authorization purpose.
- In order to confuse the client / server usage, you would need to do something like initiate a simultaneous TCP handshake (where the victim thinks they are the client, but the remote side thinks they are the server). This is likely to fall down pretty quickly after the TLS handshake, if not before, because none of our protocols are "palindromic" (you can speak them the same as client or server).
- Additionally, we're only using this for network communication, not for storing records, so it would be hard to "trick" a server into signing something and then putting it in storage on the server's behalf.
ReToCode
left a comment
There was a problem hiding this comment.
I agree with you wrt naming. Maybe we could also think about something better for the CA:
CommonName: "control-plane"
I think its not ideal, as this is also used to sign data-plane certs and potentially more in the future. Could it be something like knative-internal-ca?
| return nil, err | ||
| } | ||
| serverCertTemplate, err := createServerCertTemplate(expirationInterval) | ||
| certTemplate, err := createClientServerCertTemplate(expirationInterval, san) |
There was a problem hiding this comment.
Naming is really a bit off overall. Why is this ClientServer? The certs are just used as TLS server certs, right? If we at some point add a client cert for mTLS, we should start talking about client-certs.
There was a problem hiding this comment.
Where does the requirement to have separate certificates for client and server come from?
Certificates identify an entity - is there any reason why that entity should use two separate certificates (and reconcile them, load them etc.) - one when it is a client and another when it is a server?
This PR should enable mTLS as well so the certificates need to be defined for use as client and server (or we need to create an additional set of certificates per namespace, which I am not sure is required).
This use to be Server and changed to ClientServer. I am planning a additional PR to consolidate the code and perform renaming as needed - in this PR I changed the name from Server to ClientServer simply since it is longer true to call it a server certificate when wen enable the certificate for use as both client and server.
There was a problem hiding this comment.
I see, the current name just implies where it is used (for now just server side, future maybe also client side). Going with your explanation, maybe we could just name it createCertificateTemplate then?
There was a problem hiding this comment.
These were my thoughts also, until I realized we already have a function named createCertTemplate :) - so now, adding a function namedcreateCertificateTemplate is very confusing.
So let's fix that in the next PR when we will focus on renaming....
There was a problem hiding this comment.
👍 that a single cert for both client and server seems safe (see above, and usage elsewhere with, for example, service meshes).
I'd recommend fixing the public naming now along with the breaking API change, and leaving the internal function naming to sort out later.
| Organization: []string{Organization}, | ||
| // Do not use the same value with CA. | ||
| CommonName: "control-plane-client", | ||
| CommonName: "control-plane-client-server", |
There was a problem hiding this comment.
Same here, why is this client-server?
There was a problem hiding this comment.
See response to the other comment on the same subject
This requires changes in other packages as well. |
I'm fine with that. But I think we will, for a short period of time, break some stuff in other repos anyways. We should just make sure that the PRs to fix it are available in a timely manner. |
evankanderson
left a comment
There was a problem hiding this comment.
Overall, I like this, but I think we might want to adjust things a little bit:
- Bite the bullet and add a new
CreateServerCertmethod which takes a list of SANs. - Expose
fakeDnsNameasLegacyFakeDnsName - Migrate callers to
CreateServerCert, and addLegacyFakeDnsNameto the list of SANs provided at the caller site. - (Add a flag at the caller site to be able to drop
LegacyFakeDnsNamein the future)
There was a problem hiding this comment.
Can this be a separate PR?
It seems useful, but unrelated to the rest of the change.
There was a problem hiding this comment.
I added it since it was required to get this PR pass the tests...
|
|
||
| // Copy-pasted from https://github.com/knative/pkg/blob/975a1cf9e4470b26ce54d9cc628dbd50716b6b95/webhook/certificates/resources/certs.go | ||
| func createCertTemplate(expirationInterval time.Duration) (*x509.Certificate, error) { | ||
| func createCertTemplate(expirationInterval time.Duration, san string) (*x509.Certificate, error) { |
There was a problem hiding this comment.
Should this take a list of SANs, given some of our migration plans?
| // Create cert template suitable for CA and hence signing | ||
| func createCACertTemplate(expirationInterval time.Duration) (*x509.Certificate, error) { | ||
| rootCert, err := createCertTemplate(expirationInterval) | ||
| rootCert, err := createCertTemplate(expirationInterval, FakeDnsName) |
There was a problem hiding this comment.
If you take a list of SANs in createCertTemplate, you can leave the list empty here.
(In fact, you could remove the DNSNames from the CA cert if you require the callers of createCertTemplate to pass in fakeDnsName...)
| clientCert.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth} | ||
| clientCert.Subject = pkix.Name{ | ||
| cert.KeyUsage = x509.KeyUsageDigitalSignature | ||
| cert.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth} |
There was a problem hiding this comment.
... thinking about this, I can't see any special risk in a having a certificate with both usages.
My thinking:
- Key Usages instruct the other side (client or server) about whether the cert is intended for that authorization purpose.
- In order to confuse the client / server usage, you would need to do something like initiate a simultaneous TCP handshake (where the victim thinks they are the client, but the remote side thinks they are the server). This is likely to fall down pretty quickly after the TLS handshake, if not before, because none of our protocols are "palindromic" (you can speak them the same as client or server).
- Additionally, we're only using this for network communication, not for storing records, so it would be hard to "trick" a server into signing something and then putting it in storage on the server's behalf.
| Organization: []string{Organization}, | ||
| // Do not use the same value with CA. | ||
| CommonName: "control-plane-client", | ||
| CommonName: "control-plane-client-server", |
There was a problem hiding this comment.
Should we put in the SAN for the CommonName?
If not (and we're not worried about changing the CN), I might remove control-plane from the CN, but this is also fine.
There was a problem hiding this comment.
Which SAN? we have a list of SANs. If I recall, the common name is ignored given SANs.
Still it is customary to put some meaningful common name in a certificate.
I would like to post here "control-protocol-certificate" just to move one step away from control-plan and data-plan issues that we will need to solve next anyhow.
There was a problem hiding this comment.
This is really a nit, and isn't super-important either way.
|
|
||
| // CreateControlPlaneCert generates the certificate for the client | ||
| func CreateControlPlaneCert(ctx context.Context, caKey *rsa.PrivateKey, caCertificate *x509.Certificate, expirationInterval time.Duration) (*KeyPair, error) { | ||
| func CreateControlPlaneCert(ctx context.Context, caKey *rsa.PrivateKey, caCertificate *x509.Certificate, expirationInterval time.Duration, san string) (*KeyPair, error) { |
There was a problem hiding this comment.
I'd suggest not making a breaking change in the library. Two options:
- Make this
san ...string, and have empty string maintain the current behavior. - Add a new function, e.g.
CreateServerCertwhich takes the new arguments.
When we make breaking changes in these libraries, it gums up the dependency / buoy process for upgrading all the clients.
We could still remove this function (if we want) after we've migrated the callers, but I'd prefer not to get in the habit of making breaking library changes in broad dependencies (and, sadly, control-protocol has broad dependencies).
There was a problem hiding this comment.
nice.
Let's go with option 1
|
|
||
| // CreateDataPlaneCert generates the certificate for the server | ||
| func CreateDataPlaneCert(ctx context.Context, caKey *rsa.PrivateKey, caCertificate *x509.Certificate, expirationInterval time.Duration) (*KeyPair, error) { | ||
| func CreateDataPlaneCert(ctx context.Context, caKey *rsa.PrivateKey, caCertificate *x509.Certificate, expirationInterval time.Duration, san string) (*KeyPair, error) { |
There was a problem hiding this comment.
Ditto in terms of breaking signatures.
If CreateControlPlaneCert and CreateDataPlaneCert do the same thing now, it seems like a new function might be for the best long-run.
There was a problem hiding this comment.
Let's leave this for a subsequent PR.
There are some opportunities to merge code and rethink what we name here as data-plane or control-plane and if it has anything to do with data or control.
We also need to think if we need separation of data and control certificate wise...
If so, we don't do that today (considering that everything in knative-serving now uses the same certificate ;) )
There was a problem hiding this comment.
Now realizing that this relates to the comment below asking to fix now Public Naming...
There was a problem hiding this comment.
ok, consolidated code into CreateCet(), left the two existing public functions CreateControlPlaneCert and CreateDataPlaneCert as deprecated with the intention to clean them soon.
| return nil, err | ||
| } | ||
| serverCertTemplate, err := createServerCertTemplate(expirationInterval) | ||
| certTemplate, err := createClientServerCertTemplate(expirationInterval, san) |
There was a problem hiding this comment.
👍 that a single cert for both client and server seems safe (see above, and usage elsewhere with, for example, service meshes).
I'd recommend fixing the public naming now along with the breaking API change, and leaving the internal function naming to sort out later.
| ClientCAs: certPool, | ||
| ClientAuth: tls.RequireAndVerifyClientCert, | ||
| ServerName: certificates.FakeDnsName, | ||
| ServerName: "knative-myns", |
There was a problem hiding this comment.
Should we check the old name as well as the new name?
There was a problem hiding this comment.
My assumption is that we are on the path to getting to namespace SANs, we keep the old names just to ensure we get there in gradual non disruptive steps...
|
|
Do we want the namespace SAN to be <namespace> or <prefix>-<namespace>? |
I think the prefix is helpful for helping users connect the dots if the prefix is sufficiently specific. |
| if secret.Labels[r.secretTypeLabelName] == dataPlaneSecretType { | ||
| keyPair, err = certificates.CreateDataPlaneCert(ctx, caPk, caCert, expirationInterval) | ||
| keyPair, err = certificates.CreateCert(ctx, caPk, caCert, expirationInterval, sans...) | ||
| } else if secret.Labels[r.secretTypeLabelName] == controlPlaneSecretType { | ||
| keyPair, err = certificates.CreateControlPlaneCert(ctx, caPk, caCert, expirationInterval) | ||
| keyPair, err = certificates.CreateCert(ctx, caPk, caCert, expirationInterval, sans...) | ||
| } else { |
There was a problem hiding this comment.
Do we need both if branches here still?
There was a problem hiding this comment.
(This can be a followup PR, or maybe we're tearing all this code out...)
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: davidhadas, evankanderson, ReToCode The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| Organization = "knative.dev" | ||
| LegacyFakeDnsName = "data-plane." + Organization | ||
| DataPlaneNamePrefix = "knative-" |
There was a problem hiding this comment.
A lot of downstream repos seem to use the FakeDnsName constant - so this is breaking? Are you doing follow up PRs to the various net-* repos?
There was a problem hiding this comment.
I suggest we fix this here - see #269
And later follow up with a more gradual change in dependencies.
|
I suggest we fix this here - see #269 |
Fixes #264
This PR aims at a minimalistic change
Note:
While working on this PR many other opportunities to merge code poped up. The terminology used by the code (data-plane, control-plane) is somewhat unclear and it is hard to see the relationship between the naming and the certificates created and their use. These are left for a separate PR after a discussion of the correct terminology and the intent for the separation between control-plane and data-plane certificates.
Items for review: