Setting firebase secrets from JSON

So I am trying to update a secret to my project. It is JSON string. On windows it is not even possible. I kept getting the following error:

Error could not parse secrets: 'PRIVATE': must be in the format NAME=VALUE

I ran WSL ubuntu terminal, where I was able to set the secret. I have escape the quotes(") for the keys, but it worked.

"{ \"key\": \"value\",...}"

However on deploy I get the following error at run time:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

The app was imported form heroku, which already had an env var that was just a json string. How do I assign the data to a secret?

I solved this issue on Windows by setting each key in the JSON file as a separate environment variable.
I was facing an issue with the private_key because it has a humongous value.

Here is the Windows Powershell Command that did the job for me:

flyctl secrets set private_key="$((Get-Content secrets.json | ConvertFrom-Json).private_key)" --json 

Here is the bash equivalent of this(Not verified):

flyctl secrets set private_key="$(jq -r '.private_key' secrets.json)" --json

These commands basically extract private_key from the secrets.json file in my root directory.
The resulting value is passed as a parameter to the flyctl secrets set command.

1 Like

I haven’t tested this out personally, but you could encode the secret in base64 before setting it. Then in your application, decode it back into the JSON string.

EDIT: I see this was also suggested by @ignoramous in another thread.

2 Likes