Skip to content
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

Reload certs 2237903 watch #7502

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

alphaprinz
Copy link
Contributor

Explain the changes

The certificate for S3 endpoint can change.
Endpoint now watches for changes in certificate file.
If so, the https servers are updated with new certificate.
(Endpoint pod doesn't need to be restarted).

Issues: Fixed #xxx / Gap #xxx

(https://bugzilla.redhat.com/show_bug.cgi?id=2237903)

Testing Instructions:

Note currently used certificate, eg-
openssl s_client -connect localhost:10443 -showcerts 2>/dev/null </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -text -noout

Create a new certificate, eg-
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"

From here, follow instructions in https://github.com/noobaa/noobaa-operator/blob/master/doc/ssl-dns-routing.md:
Delete current secret (if exists), eg-
kubectl delete secret noobaa-s3-serving-cert
Create a new secret from the new certificate. Note filenames must be tls.crt and tls.key-
kubectl create secret generic noobaa-s3-serving-cert --from-file=tls.crt --from-file=tls.key
Wait until new files are created in endpoint's pod /etc/s3-secret.
Wait until background worker runs.
Running openssl -showcerts now should have the new certificate.

  • Doc added/updated
  • Tests added

src/endpoint/endpoint.js Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 21, 2023
@alphaprinz alphaprinz changed the title Reload certs 2237903 watch DRAFT Reload certs 2237903 watch Sep 21, 2023
@alphaprinz alphaprinz added size/M and removed size/L labels Sep 26, 2023
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 26, 2023
@alphaprinz alphaprinz added size/M and removed size/L labels Sep 26, 2023
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 27, 2023
@alphaprinz alphaprinz force-pushed the reload_certs_2237903_watch branch 2 times, most recently from 3b806e3 to 4aea377 Compare September 27, 2023 08:40
@alphaprinz alphaprinz marked this pull request as ready for review September 27, 2023 12:10
@alphaprinz alphaprinz changed the title DRAFT Reload certs 2237903 watch Reload certs 2237903 watch Sep 27, 2023
src/util/ssl_utils.js Outdated Show resolved Hide resolved
src/util/ssl_utils.js Show resolved Hide resolved
src/util/postgres_client.js Outdated Show resolved Hide resolved
@alphaprinz alphaprinz force-pushed the reload_certs_2237903_watch branch 2 times, most recently from cc00f24 to f6b1c3e Compare October 3, 2023 07:08
}
return false;
try {
fs.watch(cert_info.dir, {}, cert_info.file_notification.bind(cert_info));
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we avoid this for self-generated? Or maybe check in advance if the dir exists and then we will skip both reading the files and setting the watch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I like that we can still update self-generated certs to "real" certs in containerized env, though I admit it's not a practical scenario.

At any rate, this is the rule-of-thumb I followed-
For containerized env, the directory should always exists.
Non-containerized envs are not relevant for this PR.

src/server/web_server.js Outdated Show resolved Hide resolved
src/endpoint/endpoint.js Outdated Show resolved Hide resolved
if (err.code === 'ENOENT') {
dbg.warn("Certificate folder ", cert_info.dir, " does not exist. New certificate won't be loaded.");
} else {
dbg.error("Failed to watch certificate dir ", cert_info.dir);
Copy link
Contributor

Choose a reason for hiding this comment

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

print the error.

fs.watch(cert_info.dir, {}, cert_info.file_notification.bind(cert_info));
} catch (err) {
if (err.code === 'ENOENT') {
dbg.warn("Certificate folder ", cert_info.dir, " does not exist. New certificate won't be loaded.");
Copy link
Contributor

@jackyalbo jackyalbo Oct 10, 2023

Choose a reason for hiding this comment

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

another reason to maybe check for the directory in advance and to handle this error there. although not sure why this split, the level of the print?

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 don't understand.
This is the only place non-existing directory is handled.

If you think there's still a problem despite what I wrote in previous comment (#7502 (comment)), let me know.

Copy link
Contributor

@jackyalbo jackyalbo left a comment

Choose a reason for hiding this comment

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

Approving Under the assumptions made in the comments

Signed-off-by: Amit Prinz Setter <alphaprinz@gmail.com>
@alphaprinz alphaprinz merged commit a9cb55b into noobaa:master Oct 15, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants