gravitational / teleport

The easiest, and most secure way to access and protect all of your infrastructure.
https://goteleport.com
GNU Affero General Public License v3.0
17.69k stars 1.77k forks source link

tctl and webapi auth export commands fail with multiple active CAs #35444

Open programmerq opened 11 months ago

programmerq commented 11 months ago

Expected behavior:

When using tctl auth export --type windows or accessing https://<proxy_address>/webapi/auth/export?type=windows, even when two active CAs of type 'user' are present, the export should handle and allow for exporting each CA.

Current behavior:

Executing tctl auth export --type windows or accessing the webapi endpoint when two active CAs of type 'user' are present results in an error: expected one TLS key pair, got 2. This prevents exporting the necessary certificates for external service configuration, such as Windows service integration.

Bug details:

programmerq commented 11 months ago

I was able to find the following workaround in case anyone else runs into this when setting up Desktop Access with Active Directory:

tctl get cert_authority - this will dump all the cert authorities on this auth service, even if there are multiple of the same time.

For the cert authorities of type user, there will be a tls section:

  spec:
    active_keys:
      tls:
      - public_key: c3N...
      - cert: LS0tL...

The cert field is what you want. base64 decode that value, and you will be left with an x509 PEM formatted cert.

To convert that to DER format, to match what the tctl auth export --type windows does for you:

openssl x509 -in user.pem -inform PEM -outform DER -out windows.cer

If those two certificate authorities are at all different, you will want to import both during the setup step for importing the cert during desktop access setup.

tctl auth export appends a newline at the end of its output, but the OpenSSL command does not. This should not pose a problem, but you can append a newline to make it match.

GavinFrazar commented 11 months ago

during CA rotation there are additional trusted keys that (imo) should also be exported, but we only export a single active key.