Skip to content

pkg/tlsutil: implement the case ca and key are in the cluster #412

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

Merged
merged 2 commits into from
Aug 24, 2018

Conversation

fanminshi
Copy link
Contributor

@fanminshi fanminshi commented Aug 15, 2018

Implement the case where the CA and encryption key and cert are in the cluster.
When both are in the cluster, we simply retrieve them and return them to the user.

@fanminshi fanminshi changed the title [WIP] pkg/tlsutil: implement CertGenerator interface pkg/tlsutil: implement the case ca and key are in cache Aug 17, 2018
@fanminshi fanminshi mentioned this pull request Aug 17, 2018
10 tasks
@fanminshi
Copy link
Contributor Author

cc/ @hasbro17

return nil, nil, nil, err
}

secretName := strings.ToLower(k) + "-" + n + "-" + config.CertName
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify that config.CertName exists.

return nil, nil, nil, nil
}

func toSecret(kc *keyAndCert, name, namespace string) *v1.Secret {
Copy link
Contributor

Choose a reason for hiding this comment

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

toTLSSecret for a client/server TLS secret.

}
}

func toSecretAndConfigmap(cakc *keyAndCert, name, namespace string) (*v1.ConfigMap, *v1.Secret) {
Copy link
Contributor

Choose a reason for hiding this comment

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

toCASecretAndConfigmap

ns, err := a.Namespace(cr)
if err != nil {
return nil, nil, nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap the above in a helper to get name and namespace.

@fanminshi fanminshi force-pushed the tls_impl branch 2 times, most recently from 422856b to e5235b1 Compare August 20, 2018 23:22
@fanminshi
Copy link
Contributor Author

all fixed. PTAL cc/ @hasbro17

// appKeyAndCertMap holds the application key and cert for a given cr + config.CertName.
appKeyAndCertMap sync.Map
// caKeyAndCertMap holds the CA key and cert for a given cr.
caKeyAndCertMap sync.Map
Copy link
Member

Choose a reason for hiding this comment

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

Why is a sync.Map needed here? I might not understand the interaction model so I am more asking for my understanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about making this function thread safe. On a second thought, sync.map is probably not enough. I'll just use a lock instead and use normal map.

cakcv, hasCAKeyAndCert := scg.caKeyAndCertMap.Load(cascn + "-" + ns)
// TODO: handle passed in CA
if hasAppKeyAndCert && hasCAKeyAndCert {
s := toTLSSecret(appkcv.(*keyAndCert), asn, ns)
Copy link
Member

Choose a reason for hiding this comment

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

If the AppKeyAndCert and CAKeyAndCert are found then, the secrets and config map should be in the cluster. If that is true, I would expect that the secrets and config maps that are returned are the actual values from the cluster.

The reason I think this could be important is if for whatever reason a user wants to update those values, they will not be able to do, do to resource version mismatch I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shawn-hurley that makes sense. Now if we want to maintain the cache with your suggestion, it can be tricky because once user updates the secret, the one in the cache is going to be outdated. Maintaining cache consistency is hard and error prone. Alternatively, CertGenerator always queries Kubernetes cluster to check for the existence of the Application Key and Cert and CA Key and Cert. However, this approach can leads to potential performance issue. I am fine going to the latter approach for the sake of simplicity. We can tackle the cache optimization later. Let's aim for correctness first.

cc/ @shawn-hurley and @hasbro17

@fanminshi fanminshi changed the title pkg/tlsutil: implement the case ca and key are in cache pkg/tlsutil: implement the case ca and key are in the cluster Aug 23, 2018
@fanminshi
Copy link
Contributor Author

all fixed PTAL cc/ @hasbro17 @shawn-hurley

@shawn-hurley
Copy link
Member

We can add this back later, but we need to think about the case, where I have a custom CA, and I have not created the secret or config map in the cluster. This case will be implemented later, but I want to make sure this doesn't get lost. Other than that LGTM

@hasbro17
Copy link
Contributor

LGTM

we need to think about the case, where I have a custom CA, and I have not created the secret or config map in the cluster

@shawn-hurley right, we're tracking all the cases in #419 and the custom CA is part of that.

@fanminshi fanminshi merged commit d314923 into operator-framework:master Aug 24, 2018
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