Skip to content

ROX-9014: Draft TLSIssuer as a SensorComponent and CertificateIssuer#400

Closed
juanrh wants to merge 13 commits intojuanrh/ROX-8969from
juanrh/ROX-9014
Closed

ROX-9014: Draft TLSIssuer as a SensorComponent and CertificateIssuer#400
juanrh wants to merge 13 commits intojuanrh/ROX-8969from
juanrh/ROX-9014

Conversation

@juanrh
Copy link
Contributor

@juanrh juanrh commented Jan 21, 2022

Description

Draft TLSIssuer as a sensor component and CertificateIssuer that can be asked to refresh certificates by a CertRefresher acting as scheduler

Checklist

  • Investigated and inspected CI test results
  • Unit test and regression tests added
  • Evaluated and added CHANGELOG entry if required
  • Determined and documented upgrade steps

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.

@ghost
Copy link

ghost commented Jan 21, 2022

Tag for build #140132 is 3.68.x-29-g5753ddb3cf.

💻 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 roxctl binary artifact can be downloaded from CircleCI.

@juanrh juanrh changed the base branch from juanrh/ROX-8969 to master January 24, 2022 18:58
@juanrh juanrh changed the title ROX-9014: Draft TLSIssuer as a sensor component and certificate source ROX-9014: Draft TLSIssuer as a SensorComponent and CertificateIssuer Jan 24, 2022
Copy link
Contributor

@porridge porridge left a comment

Choose a reason for hiding this comment

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

I think we're on the right track!

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to add a few sentences about how this is supposed to be used.

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've added more details, please let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

The methods in this interface are so generic that it almost seems like a waste to give it such specific name...

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 have renamed this to RetryTicker that is now introduced in #350

Comment on lines 84 to 85
Copy link
Contributor

Choose a reason for hiding this comment

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

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:

  1. Rename ResponsesC in the interaface (and all implementations) to something like MsgsFromSensor or MsgsToCentral (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.
  2. avoid the words request and response in the struct fields. Perhaps msgs{From,To}{Sensor,Central}C?

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 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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to this

Comment on lines 143 to 146
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the conceptual difference between refresh and update?

Copy link
Contributor Author

@juanrh juanrh Jan 25, 2022

Choose a reason for hiding this comment

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

That's some unfortunate naming. I have replaced that with:

  • introduce an interface certSecretsRepo that certSecretsRepoImpl is implementing, that is concerned with just persisting secrets in the k8s API. updateSecrets it's now putSecrets
type certSecretsRepo interface {
	getSecrets(ctx context.Context) (map[storage.ServiceType]*v1.Secret, error)
	putSecrets(ctx context.Context, secrets map[storage.ServiceType]*v1.Secret) error
}
  • refreshSecrets it's now updateSecrets, 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)
}

@juanrh juanrh changed the base branch from master to juanrh/ROX-8969 January 25, 2022 19:13
@juanrh
Copy link
Contributor Author

juanrh commented Jan 25, 2022

This PR has grown too much, so I'll split it into pieces according to the several files that added in the latest version.
https://github.com/stackrox/stackrox/pull/350/files would be the first PR in that series

@@ -0,0 +1,30 @@
package localscanner
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be relatively simple to create fake k8s clients if you want to use it for testing.

@juanrh
Copy link
Contributor Author

juanrh commented Jan 28, 2022

Closed in favor of #474

@juanrh juanrh closed this Jan 28, 2022
@msugakov msugakov deleted the juanrh/ROX-9014 branch September 16, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants