Problem with k8s reading keys "ValueError: Could not deserialize key data."

I have deployed app on GKE private cluster, and i have backend service, but the problem is that the backend service cant read the GOOGLE_ACCOUNT_PRIVATE_KEY, I am getting the following error:

line 1526, in _handle_key_loading_error
    raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.

This is part of the backend deployment where this env is found:

env:
 - name: GOOGLE_ACCOUNT_PRIVATE_KEY
   valueFrom: 
     configMapKeyRef:
       name: gapk
       key: GOOGLE_ACCOUNT_PRIVATE_KEY

I have also other env that are successfully and i don't have any error for them

This is how i keep the GOOGLE_ACCOUNT_PRIVATE_KEY env:

apiVersion: v1
kind: ConfigMap
metadata:
  name: gapk
data:
 GOOGLE_ACCOUNT_PRIVATE_KEY: '-----BEGIN PRIVATE KEY-----\private key\n-----END PRIVATE KEY-----\n'

with " " instead of ' ' is interpreted \n like new row but when i put the key in ' ' I have the serialize error, in both ways i got it wrong :( Am I doing some mistake while decoding, also i put the original value of the key, not encoded in base64, and still getting the error ValueError: Could not deserialize key data.

Upvotes: 0

Views: 371

Answers (1)

Rob Evans
Rob Evans

Reputation: 2874

Have you tried replacing \n with \\n?

The other thing to try is just to remove the \ns and insert real newlines over mulitple lines. So long as the string is quoted it should be fine. The other thing to try is to remove the trailing newline since private key regex's not always consistent on this one.

Upvotes: 2

Related Questions