Score:2

Firebase private key file as environment variable

uy flag

I'm very new to Ubuntu and developing a project based on firebase firestore database. Trying to run services on ubuntu server 22.04. I can connect firestore database (in windows I can do this by using environment variables also) with a private key file and I want to keep this file secret. To achieve this, created a file with secret and referenced it in my service config file like this.

[Unit]
Description=myservice

[Service]
Type=simple
Restart=always
RestartSec=5sec
EnvironmetnFile=/etc/mysecrets/mysecret

[Install]
WantedBy=multi-user.target

It's working for small variables like

MYSECRET=111111

But not working a file like the following

    MYSECRET= {
  "type": "service_account",
  "project_id": "my-project-id",
  "private_key_id": "1234567890abcdef",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDzq3MW0BWT4skj\n6pSG0ZXl...U6XyUrhRz\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]",
  "client_id": "1234567890abcdef",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/my-project-id%40my-project-id.iam.gserviceaccount.com"
}

private_key will be 1700+ chacter long with \n characters.

How can I create a secure secret file with such a big information in Ubuntu server? Any idea?

PS: This is not a real or valid private key file

muru avatar
us flag
Try https://stackoverflow.com/a/70825379/2072269
newbie avatar
uy flag
Thanks for the idea. It solved my issue too.
Score:1
uy flag

Like muru told above comment, single quota solved my problem. I've just typed secret like this and now works like a charm.

This answer solved my issue.

MYSECRET= '{
  "type": "service_account",
  "project_id": "my-project-id",
  "private_key_id": "1234567890abcdef",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDzq3MW0BWT4skj\n6pSG0ZXl...U6XyUrhRz\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]",
  "client_id": "1234567890abcdef",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/my-project-id%40my-project-id.iam.gserviceaccount.com"
}'
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.