ROX-9014: Draft TLSIssuer as a SensorComponent and CertificateIssuer#400
ROX-9014: Draft TLSIssuer as a SensorComponent and CertificateIssuer#400juanrh wants to merge 13 commits intojuanrh/ROX-8969from
Conversation
|
Tag for build #140132 is 💻 For deploying this image using the dev scripts, run the following first: export MAIN_IMAGE_TAG='3.68.x-29-g5753ddb3cf'📦 You can also generate an installation bundle with: docker run -i --rm stackrox/main:3.68.x-29-g5753ddb3cf central generate interactive > bundle.zip🕹️ A |
porridge
left a comment
There was a problem hiding this comment.
I think we're on the right track!
There was a problem hiding this comment.
Looks like c.ctx expiring has no impact on this chain of refresh timers, it will just keep failing at backoff. Maybe this is by design (i.e. one needs to call Stop), but should probably be mentioned in the documentation?
There was a problem hiding this comment.
I have removed the context parameter of the Start method type CertRefresher interface, as it is not used properly. An alternative would be removing the Stop method launching a goroutine at Start that waits on <-ctx.Done() and then stops the CertRefresher. However, I see Start and Stop methods in several interfaces in the code like SensorComponent. Also, we'll be using CertRefresher in a SensorComponent. For those two reasons I think having Start and Stop method is what works best in this case, but please let me know what you think.
There was a problem hiding this comment.
It would be great to add a few sentences about how this is supposed to be used.
There was a problem hiding this comment.
I've added more details, please let me know what you think
There was a problem hiding this comment.
The methods in this interface are so generic that it almost seems like a waste to give it such specific name...
There was a problem hiding this comment.
I have renamed this to RetryTicker that is now introduced in #350
There was a problem hiding this comment.
I must say this contradiction is so striking that I'd like to find a way to relax this a bit. I can see two ways:
- Rename
ResponsesCin the interaface (and all implementations) to something likeMsgsFromSensororMsgsToCentral(in a prefactoring PR). This might require some effort (or maybe not, perhaps just an IDE-assisted rename and regenerating the mocks will be enough?) but will at least provide a hint that this channel might be used for spontaneously generated messages as well. - avoid the words
requestandresponsein the struct fields. Perhapsmsgs{From,To}{Sensor,Central}C?
There was a problem hiding this comment.
I have followed option 2., as this PR is already quite late, we can implement 1. later on if we want.
Specifically:
type sensorComponentImpl struct {
msgFromSensorC chan *central.MsgFromSensor
msgToSensorC chan *central.IssueLocalScannerCertsResponse
}which I think makes sense because we already have message MsgFromSensor and message MsgToSensor defined in sensor_iservice.proto, and IssueLocalScannerCertsResponse is a variant of message MsgToSensor
There was a problem hiding this comment.
What's the conceptual difference between refresh and update?
There was a problem hiding this comment.
That's some unfortunate naming. I have replaced that with:
- introduce an interface
certSecretsRepothatcertSecretsRepoImplis implementing, that is concerned with just persisting secrets in the k8s API.updateSecretsit's nowputSecrets
type certSecretsRepo interface {
getSecrets(ctx context.Context) (map[storage.ServiceType]*v1.Secret, error)
putSecrets(ctx context.Context, secrets map[storage.ServiceType]*v1.Secret) error
}refreshSecretsit's nowupdateSecrets, and a comment explains what this is doing:
// updateSecrets stores the certificates in the data of each corresponding secret, and then persists
// the secrets in k8s.
func (i *certIssuerImpl) updateSecrets(ctx context.Context, certificates *storage.TypedServiceCertificateSet,
secrets map[storage.ServiceType]*v1.Secret) error {
// FIXME: validate all fields present
for _, cert := range certificates.GetServiceCerts() {
secrets[cert.GetServiceType()].Data = map[string][]byte{
mtls.ServiceCertFileName: cert.GetCert().GetCertPem(),
mtls.CACertFileName: certificates.GetCaPem(),
mtls.ServiceKeyFileName: cert.GetCert().GetKeyPem(),
}
}
return i.putSecrets(ctx, secrets)
}That uses CertRefreher to schedule refresh
376d94f to
5753ddb
Compare
|
This PR has grown too much, so I'll split it into pieces according to the several files that added in the latest version. |
| @@ -0,0 +1,30 @@ | |||
| package localscanner | |||
There was a problem hiding this comment.
It should be relatively simple to create fake k8s clients if you want to use it for testing.
|
Closed in favor of #474 |
Description
Draft TLSIssuer as a sensor component and CertificateIssuer that can be asked to refresh certificates by a
CertRefresheracting as schedulerChecklist
If any of these don't apply, please comment below.
Testing Performed
TODO(replace-me)
Use this space to explain how you tested your PR, or, if you didn't test it, why you did not do so. (Valid reasons include "CI is sufficient" or "No testable changes")
In addition to reviewing your code, reviewers must also review your testing instructions, and make sure they are sufficient.
For more details, ref the Confluence page about this section.