Search code examples
google-cloud-platformsshgoogle-secret-manager

SSH Private Key Not Working After Fetching It From Google's Secret Manager


I have an SSH Private Key which I use to SSH into some server. I have tested the key and it works perfectly. I have uploaded the key to Google Cloud Secret Manager, but when I fetch it from the Secret Manager using the gcloud secrets versions access command, the key does not work and this error is returned instead:

Load key "id_rsa": invalid format

Is there a way I can get the key while preserving its format? Or can I reformat the key?

What I have tried so far

I have tried getting the key in using different formats;

gcloud secrets versions access latest --secret=${SECRET} --format="json" | jq -r .payload.data | base64 --decode > id_rsa

gcloud secrets versions access latest --secret=${SECRET} --format='get(payload.data)' | tr '_-' '/+' | base64 -d > id_rsa

But it has not worked.


Solution

  • Hi I had a similar situation, in my case it was an empty line at the end missing.