So, is auth from a certificate for Google Cloud Client Libraries not
supported?
Depends on the definition of auth
using a certificate. Google Cloud SDKs and respective APIs do not support certificate authorization. The only part of a certificate that Google uses is the private key. The same private key that exists in both P12/PFX certificate files and JSON key files.
The P12/PFX certificate format is legacy and is no longer recommended. The newer JSON key format contains more information which improves items like key lookup during validation. However, the only required item is the private key which is the same for both formats but encoded differently (Binary versus PEM).
Seems like the only way to access a Google service using the Google
Cloud Client Libraries when you're not running in GCP is to download a
service account key (JSON) and store it in a file, then provide that
to the libraries via an environment variable.
I think you are making an incorrect assumption that you can create your own certificate file and use that for authorization. You can only use private keys that are generated by Google Cloud. Therefore you have the same limitation for both P12/PFX certificate files and for JSON key files. You must download both types unless you are using service account impersonation or running on a Google Cloud service that supports the Metadata server for fetching tokens.
Now, the legacy Google API Client Libraries offered a way to create a
ServiceAccountCredential from a certificate via a FromCertificate()
method. I can't seem to find a way to do that in the Google Cloud
Client Libraries.
The libraries support loading service accounts from JSON. You can extract the private key from a P12/PFX certificate, encode in PEM, build the JSON structure and proceed as if you originally had a service account in JSON key format.
On my website are a number of articles about P12 certificate service accounts including converting from P12 to JSON.
My advice is to switch to service accounts in JSON format.
FromCertificate
. See googleapis.github.io/google-cloud-dotnet/docs/… – Jon SkeetUserCredential
example, just using a ServiceAccountCredential. – Jon Skeet