thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
222 stars 55 forks source link

feat: Integration with Cumulocity CA #3248

Open didier-wenzek opened 1 week ago

didier-wenzek commented 1 week ago

A planned PKI feature of Cumulocity IoT will allow a tenant to act as a Certificate Authority (CA) for its fleet of connected devices. Once enabled, this feature:

To leverage this feature, thin-edge must be extended along the following lines.

Device Registration

Security tokens are used to prove the legitimacy of certificate requests issued by the devices.

Technically, thin-edge could provide a command combining these steps. However,

Hence:

Certificate Creation

A new tedge cert download c8y cli sub-command is introduced, designed along similar lines as for tedge cert upload c8y.

$ tedge cert download c8y --help
Request and download the device certificate from Cumulocity

- generate a private key and Signing Certificate Request (CSR) for the device
- upload this CSR on Cumulocity, using the provided device identifier and security token
- loop till the device is registered by an administrator and the CSR accepted 
- store the certificate created by Cumulocity

Usage: tedge cert download c8y [OPTIONS] --device-id <ID> --token <TOKEN>

Options:
      --device-id <ID>

          The device identifier to be used as the common name for the certificate

      --token <TOKEN>

          The security token assigned to this device when registered to Cumulocity

      --config-dir <CONFIG_DIR>

          Use the following settings from the config:

          - c8y.http  HTTP Endpoint for the Cumulocity tenant, with optional port.
          - device.key_path  Path where the device's private key is stored.
          - device.cert_path  Path where the device's certificate is stored.
          - device.csr_path  Path where the device's certificate signing request is stored. 

          [env: TEDGE_CONFIG_DIR, default: /etc/tedge]

  -h, --help
          Print help (see a summary with '-h')

Certificate Renewal

As long as a device is actually connected to Cumulocity with a valid certificate, the device can renew its certificate using the tedge cert renew c8y command.

$ tedge cert renew c8y --help
Renew the device certificate from Cumulocity

- keep the device identifier (CN) unchanged
- keep the current private key unchanged
- generate a new Signing Certificate Request (CSR) for the device
- upload this CSR on Cumulocity, using JWT to authenticate
- store the updated certificate without erasing the current certificate

Usage: tedge cert renew c8y [OPTIONS]

Options:
      --config-dir <CONFIG_DIR>

          Use the following settings from the config:

          - c8y.http  HTTP Endpoint for the Cumulocity tenant, with optional port.
          - device.key_path  Path where the device's private key is stored.
          - device.cert_path  Path where the device's certificate is stored.
          - device.csr_path  Path where the device's certificate signing request is stored. 

          [env: TEDGE_CONFIG_DIR, default: /etc/tedge]

  -h, --help
          Print help (see a summary with '-h')

Note that a certificate renewal should not erase the current certificate that is still in use.

Several points need to be clarified:

Some helpers have to be added:

reubenmiller commented 1 week ago

Looks good. It isn't explicitly mentioned in the example, but it would be good to support setting the the cli's flags (e.g. --device-id and --token) from environment variables as well (useful for automating the container use-case)