feat: validate new certificate on connect#3551
feat: validate new certificate on connect#3551didier-wenzek merged 16 commits intothin-edge:mainfrom
Conversation
bea5756 to
dad9115
Compare
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Robot Results
|
|
@didier-wenzek I just tried out some of the commands (what is implemented so far), and it works nicely...it will definitely simplify the integration with custom renewers. We can discuss the open points shortly, to finalize the direction of the PR. |
|
My thoughts on the open points:
No, we don't need this. The .new cert is only created as a by-product of the current certificate needing renewal. The
I don't think this will be required. As the tedge cert upload won't work anyway during cert renewals (as you need Tenant Admin priv.), so supporting some fallback is probably overkill for now. We can always add this later if required.
This should remove both the current cert (which is the expected output when executing it), plus deleting the .new file (if present). And another topic that came up during my quick usage of the feature:
Example renewal scripts |
I think the better is to not delete the .new certificate when the connection is not successful.
Offline, we agreed to exit with a specific status code when the connection failed with the .new certificate.
|
Done: 8be4190 |
|
@didier-wenzek Overall it works nicely (especially the new exit code for the There was only 1 item which could be improved: Item 1: tedge cert upload uploads the new certificate when there is oneIf there is a .new certificate and the Below shows the current output when there was both a "main" certificate and a .new certificate. # create some initial certificate
tedge cert create --device-id example01
# copy the cert (so both the cert and .new cert exist)
cp /etc/tedge/device-certs/tedge-certificate.pem /etc/tedge/device-certs/tedge-certificate.pem.new
# remove the current cert and create a new cert with a new device-id
tedge cert remove
tedge cert create --device-id example02
# upload to Cumulocity (though the output does not show which cert is uploaded)
tedge cert upload c8y
Certificate uploaded successfully. |
|
The steps I have done is below. I didn't upload both old and new self-signed certificate with intention to cause an error. root@11d89e85c51e:/setup# tedge cert remove
Certificate was successfully removed
root@11d89e85c51e:/setup# tedge cert create --device-id aaa
Certificate was successfully created
Certificate: /etc/tedge/device-certs/tedge-certificate.pem
Subject: CN=aaa, O=Thin Edge, OU=Device
Issuer: CN=aaa, O=Thin Edge, OU=Device
Status: VALID (expires in: 11months 29days 3h 50m 23s)
Valid from: Thu, 10 Apr 2025 13:04:23 +0000
Valid until: Fri, 10 Apr 2026 13:04:23 +0000
Serial number: 525188842049310620321124847034595044436808047873 (0x5bfe483c5c128f4bc6d974814f1e3f42ec2c1d01)
Thumbprint: B2B6EBA9118F82A3FF188F5960D7EB8D46F36B3A
root@11d89e85c51e:/setup# tedge cert renew --self-signed
Certificate was successfully renewed, for un-interrupted service, the certificate has to be uploaded to the cloud
# I didn't upload both old and new certificates
root@11d89e85c51e:/setup# tedge connect c8y
connect to Cumulocity cloud.:
device id: aaa
cloud profile: <none>
cloud host: rina.xxx.xxx:8883. #masked
auth type: Certificate
certificate file: /etc/tedge/device-certs/tedge-certificate.pem
cryptoki: false
bridge: mosquitto
service manager: systemd
mosquitto version: 2.0.11
Checking new certificate validity: /etc/tedge/device-certs/tedge-certificate.pem.new... ✗
error: Connection error while creating device in Cumulocity: Mqtt state: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: IO: received fatal alert: CertificateUnknown: received fatal alert: CertificateUnknown
Error validating the new certificate: Connection error while creating device in Cumulocity: Mqtt state: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: IO: received fatal alert: CertificateUnknown: received fatal alert: CertificateUnknown
=> keep using the current certificate unchanged /etc/tedge/device-certs/tedge-certificate.pem
Creating device in Cumulocity cloud... ✗
error: Connection error while creating device in Cumulocity: Mqtt state: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: Mqtt serialization/deserialization error: IO: received fatal alert: CertificateUnknown: IO: received fatal alert: CertificateUnknown: received fatal alert: CertificateUnknown |
This isn't actually repeating, there is one error per certificate (in this case 2 attempts where both failed). Also, a failed .new certificate is not deleted (this is the responsibility of the caller). In practice, the deletion of the failed .new certificate will be done by the cert renewer service after it receives a non-zero exit code from the |
|
Sorry what I meant "repeating" is a different point... one error message contains 4 times
|
|
As agreed offline:
I also updated Addressed by: |
albinsuresh
left a comment
There was a problem hiding this comment.
Everything is working nicely. The command outputs are really clear now.
Not for this PR, but just a thought: Should the tedge cert show command give any hints about the presence of the .new certificate if one is present (with an additional hint about how to view it using the --new option)? Since the cert renew command output is sufficiently verbose right now, this isn't such a strong requirement. Just an additional guidance, that's all.
This is a very first re-organization step. The end goal is to be able to check a new certificate before connecting the cloud and to fallback to the current one on failure. For that the code of the connect command has to be re-organize to clearly separate: - connection checks using the bridge - connection checks using a direct connection - bridge configuration and processes restart. Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
…cate Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
334b684 to
2037802
Compare
Proposed changes
Let thin-edge maintain 2 certificates (current and new) for each cloud profile.
The paths to these certificates are derived from the
device.cert_pathtedge config setting."$(tedge config get device.cert_path)"is the path to the certificate currently used to connect the cloud endpoint"$(tedge config get device.cert_path).new"is the path to a new certificate still to be validated (if any).The command
tedge cert renewdoes no more replace the current certificate but store the new certificate in its own file for further validation. The promotion of a new certificate as the current one is done by thetedge connectcommand after a successful connection.tedge cert renewdoesn't replace the current certificate but creates a new file.tedge connect c8yvalidates any new certificate before promoting it as the current certificatetedge connect azvalidates any new certificate before promoting it as the current certificatetedge connect awsvalidates any new certificate before promoting it as the current certificatetedge connect --offlineignores with warning any new certificatetedge cert uploaduploads the new certificate when there is onetedge cert removeremoves removes new and current certificates. uselesstedge cert needs-renewal --newchecks the new certificate if anyShouldno, uselesstedge cert uploaduploads the current and the new certificate when there are both?tedge cert renewshows the new certificatetedge cert renewwarns that the device must be reconnectedtedge cert renewuses the CA given by the--caoption (c8yby default)Types of changes
Paste Link to the issue
#3541
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments