Extract server certificate from lxd-cloud/host

Is there a means to get the server certificate from a lxd remote such that I can use that with “juju add-credentials --file ./credfile.yaml” ?

Tje juju credential file looks like this:

credentials:
  labb3:
    erik-frozen:
      auth-type: certificate
      client-cert: |
        -----BEGIN CERTIFICATE-----
        XXXXXXXXXXXXXXXXXX
        -----END CERTIFICATE-----
      client-key: |
        -----BEGIN EC PRIVATE KEY-----
        XXXXXXXXXXXXXXXXXXX
        -----END EC PRIVATE KEY-----
      server-cert: |
        -----BEGIN CERTIFICATE-----
        XXXXXXXXXXXXXXXXXXX
        -----END CERTIFICATE-----

So, I’m looking for a means to get the server-cert without having to login to the remote and get it.

Does lxc query /1.0 give you want under environmentcertificate? Looks like you need a trusted client to get certificate from that endpoint

How would I run this on a remote which is not yet added to the client?

Thanx

This should work:

echo | openssl s_client -connect xeon:8443 2>/dev/null | openssl x509

# or

echo | openssl s_client -connect xeon:8443 2>/dev/null | sed -n '/^-----BEGIN CERTIFICATE-----$/,/^-----END CERTIFICATE-----$/ p'
2 Likes