Skip to content

API: Update the ssl context after each accepting incoming connection #8515

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

Conversation

yhabteab
Copy link
Member

resolves #8501

@icinga-probot icinga-probot bot added area/distributed Distributed monitoring (master, satellites, clients) enhancement New feature or request labels Nov 30, 2020
@icinga-probot icinga-probot bot added this to the 2.13.0 milestone Nov 30, 2020
@yhabteab yhabteab requested a review from Al2Klimov November 30, 2020 16:38
@yhabteab yhabteab requested a review from Al2Klimov December 1, 2020 15:46
@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 232413e to 26b3fec Compare December 1, 2020 16:58
@yhabteab yhabteab requested a review from Al2Klimov December 2, 2020 10:07
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

  1. Call GetCrlPath() only once at all
  2. Call Utility::GetFileCreationTime() at most once per accept.
  3. If you just start Icinga 2 with an empty CRL configured, don't touch the CRL after start and establish your first connection, will Icinga 2 update the context?

@yhabteab
Copy link
Member Author

yhabteab commented Dec 2, 2020

If you just start Icinga 2 with an empty CRL configured, don't touch the CRL after start and establish your first connection, will Icinga 2 update the context?

So, if I don't configure the CRL path in api.cnf at all, no context update is performed. But if I configure that and the CRL does not contain any revoked certificates at all, the context is updated only once before connecting to an endpoint.

@Al2Klimov
Copy link
Member

Only once? Where?

@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 2099d56 to 3e49386 Compare December 2, 2020 11:43
@yhabteab
Copy link
Member Author

yhabteab commented Dec 2, 2020

Only once? Where?

Well here!

@Al2Klimov
Copy link
Member

... and here:

UpdateSSLContext();

Do you consider your additional update neccessary?

@yhabteab
Copy link
Member Author

yhabteab commented Dec 2, 2020

No, but I can't prevent it either!

@Al2Klimov
Copy link
Member

You're writing this new code. Of course you can prevent it.

@yhabteab yhabteab requested a review from Al2Klimov December 2, 2020 13:25
@yhabteab yhabteab requested a review from Al2Klimov December 2, 2020 13:56
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

You've just addressed incoming connections here. What about outgoing ones?

@yhabteab
Copy link
Member Author

yhabteab commented Dec 2, 2020

If the incoming connection has been checked and successfully validated at the master, why do I have to add an additional check for the outgoing one. We only need to update the master and not the ones connected to it, because this has no effect at all if the master doesn't notice anything.

@Al2Klimov
Copy link
Member

Also address outgoing connections.

@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 68771e1 to 6dac79b Compare December 2, 2020 15:53
@yhabteab yhabteab changed the title API: Update the ssl context after each accepting incoming connection API: Update the ssl context after each accepting incoming & outgoing connection Dec 2, 2020
@yhabteab yhabteab requested a review from Al2Klimov December 2, 2020 15:53
@Al2Klimov
Copy link
Member

I don't see any actual changes.

@yhabteab
Copy link
Member Author

yhabteab commented Dec 4, 2020

Also address outgoing connections.

Master and agent disabled and I have revoked the certificates from the agent. After that I started both and master noticed that the crt is revoked. Agent turned off and undo crt revokation, agent started again, crt validation was successful and no error messages for revoked crts.

@Al2Klimov
Copy link
Member

Fine. Undo the commit message change.

@yhabteab yhabteab changed the title API: Update the ssl context after each accepting incoming & outgoing connection API: Update the ssl context after each accepting incoming connection Dec 4, 2020
@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 6dac79b to 2b6f484 Compare December 4, 2020 10:36
@yhabteab
Copy link
Member Author

yhabteab commented Dec 4, 2020

Do you know why the Github actions fail?

@Al2Klimov
Copy link
Member

Figure it out.

@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch 3 times, most recently from dddc7fb to 72a9768 Compare December 7, 2020 08:42
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Write a test protocol.

@yhabteab
Copy link
Member Author

yhabteab commented Dec 7, 2020

Testprotocol:

Before: See #8501

After:

Revoke the certificate while the master and the agent are stopped and then start them both.

Master Log:

[2020-12-07 12:30:11 +0100] information/ApiListener: New client connection for identity 'ha-cluster' from [::1]:49781 (certificate validation failed: code 23: certificate revoked)
[2020-12-07 12:30:11 +0100] information/JsonRpcConnection: Received certificate request for CN 'ha-cluster' signed by our CA.
[2020-12-07 12:30:11 +0100] information/JsonRpcConnection: The certificate for CN 'ha-cluster' is valid and uptodate. Skipping automated renewal.

And now update the CRL in my case, I will undo the crt revocation.

[2020-12-07 12:35:21 +0100] warning/JsonRpcConnection: API client disconnected for identity 'ha-cluster'
[2020-12-07 12:35:31 +0100] information/ApiListener: New client connection for identity 'ha-cluster' from [::1]:49823
[2020-12-07 12:35:31 +0100] information/ApiListener: Sending config updates for endpoint 'ha-cluster' in zone 'ha-cluster'.

@Al2Klimov Al2Klimov requested a review from julianbrost December 7, 2020 11:38
@julianbrost
Copy link
Contributor

Can you please test what happens in the following scenarios:

  • Removing the CRL file completely
  • Invalid CRL file (truncated file for example)

@yhabteab
Copy link
Member Author

yhabteab commented Dec 7, 2020

  • Removing the CRL file completely
[2020-12-07 12:56:28 +0100] critical/SSL: Error loading crl file '~/var/lib/icinga2/ca/ha-master.crl': 33558530, "error:02001002:system library:fopen:No such file or directory"
[2020-12-07 12:56:28 +0100] critical/config: Error: Cannot add certificate revocation list to SSL context for crl path: '~/var/lib/icinga2/ca/ha-master.crl'.
  • Invalid CRL file (truncated file for example)
[2020-12-07 13:01:15 +0100] critical/SSL: Error loading crl file '~/var/lib/icinga2/ca/ha-master.crl': 218529960, "error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag"
[2020-12-07 13:01:15 +0100] critical/config: Error: Cannot add certificate revocation list to SSL context for crl path: '~/var/lib/icinga2/ca/ha-master.crl'.

@yhabteab yhabteab self-assigned this Dec 7, 2020
@julianbrost
Copy link
Contributor

What is the general behavior in this case? Will Icinga terminate? If not, will if accept new connections? If it does, are these verified against the old CRL?

@julianbrost julianbrost removed their request for review December 23, 2020 12:57
@yhabteab
Copy link
Member Author

So, if you enter CRL path, which does not exist at all, or the CRL file is invalid Icinga2 will terminate while compiling the api.conf file with this error message.

@Al2Klimov Al2Klimov requested a review from julianbrost January 14, 2021 11:40
Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

Please use git rebase to reorder your commits. Currently the first commit already uses GetFileCreationTime which is only introduced in the second one.

@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 72a9768 to 2f0edf0 Compare January 14, 2021 17:38
@yhabteab yhabteab force-pushed the feature/update-ssl-context-after-accepting-new-connection-8501 branch from 2f0edf0 to d27f533 Compare January 14, 2021 17:41
@yhabteab yhabteab requested a review from julianbrost January 14, 2021 17:42
Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

So as this generates a whole new context, this implicitly also reloads certificates and private keys, but only when a CRL exists and is changed. I think this is fine, as nothing bad should happen there unless someone manually messes around with stuff.

@Al2Klimov Al2Klimov merged commit 4063e39 into master Jan 15, 2021
@icinga-probot icinga-probot bot deleted the feature/update-ssl-context-after-accepting-new-connection-8501 branch January 15, 2021 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/distributed Distributed monitoring (master, satellites, clients) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRL expires if the daemon is not reloaded/restarted
3 participants