Running Firebase-Tools 3.9.1 on a Mac, when I store a \ it adds slashes and converts to \\.
This is an issue when trying to store the Firebase Storage PEM file in environment settings.
--- BEGIN PRIVATE KEY ---\n
...
--- END PRIVATE KEY ---\n
Converts to
--- BEGIN PRIVATE KEY ---\\n
...
--- END PRIVATE KEY ---\\n
Which causes the authentication to fail.
This issue wasn't happening last week, so it appears to be a new issue.
Can you please add repro instructions, including the exact set command you used? Thanks.
$ firebase functions:config:set foo.bar="Hello\World" --project my-project-0000
✔ Functions config updated.
Please deploy your functions for the change to take effect by running firebase deploy --only functions
$ firebase functions:config:get foo.bar --project my-project-0000
"Hello\\World"
Should it be adding slashes? Last week (Not sure of the version) I added a string with a slash and it didn't double up, but this week it does. So not sure how to handle it in code.
In real-world apps I've been adding the firebase json credentials to the config so I can connect with the storage tools. Last week PEM uploaded correctly, this week it adds slashes on the \n and converts to \\n.
Thanks for the repro instructions, I've reproduced it and will work on a fix.
Hey @sketchthat , after some investigations, I figured out that this is an issue with one of our dependencies - Cloud Runtime Configuration. I've filed the bug with the team, and will keep you posted on their progress.
I have the same issue.
Hi @laurenzlong I don't know why my comment was downvoted, but is there any update on this issue?
@janakaj Comments like "I have the same issue" and "is there any update" are spam to watchers of Github repos.
If you have the same issue as reported, upvote the original, and then please exercise patience rather than filling our inboxes with comments that don't add to the conversation.
I found a walkthrough (or awful solution) :S I don't wanna to do that but ... It's works >,<
You can do it a .replace(/\\n/g, '\n') to the private_key
const serviceAccount = functions.config().fireenv;
admin.initializeApp({
credential: admin.credential.cert({
"projectId": serviceAccount.project_id,
"private_key": serviceAccount.private_key.replace(/\\n/g, '\n'),
"clientEmail": serviceAccount.client_email
}),
databaseURL: whatever,
...
});
@sketchthat @janakagamini @patrickmcd I know it was 4 months ago but .. :)
@YuniorGlez - Are you using the environment details to initialise the admin library? Cloud Functions will do this by itself.
I needed the environment details to access Google Cloud Storage. I ended up including a json file into the build.
const storage = await import('@google-cloud/storage');
const storageCreds = require('credentials.json');
const gcs = storage({
projectId: storageCreds.project_id,
credentials: storageCreds,
});
const bucket = gcs.bucket(functions.config().firebase.storageBucket);
Has this issue been fixed? I just came across a similar issue when using a dollar sign in the value-part of functions:config:set. E.g. firebase functions:config:set test.var="abc$def" deploys fine. But firebase functions:config:get test.var gives only "abc". The same issue arises when reading the environment variables with functions.config().
I am using firebase-tools v4.1.0 and OS X 10.13.6
If you add a slash it fixes it abc\$def.
Similar to #378 - should investigate this as well and do make a decision. Maybe documentation needs to be updated to talk about using special characters?
in Feb 2020 this still seems to be an issue. With no mention in the documentation. Any update?
I know we are supposed to up vote issues, but a year later I feels warrants a comment here.
@YuniorGlez Thanks for the save here. The amount of time I spent trying to figure out what was going on with my keys is too much.
This really needs to be updated.
@laurenzlong @worknudge @lukeinthecloud
Also faced this. Couldn't find a solution on Windows except spinning up a WSL with firebase CLI and using:
firebase functions:config:set service_account="$(cat service-account.json)"
It's way too hard to securely access Google APIs from a Dart function (without saving credentials in code). All the Dart APIs are http wrappers, but some googleapis_auth functions like clientViaMetadataServer don't work on Node, GCloud Function Env Vars aren't exposed in Firebase Functions Interop, and getting the key into Firebase env config takes silly backflips :)
Hey @sketchthat , after some investigations, I figured out that this is an issue with one of our dependencies - Cloud Runtime Configuration. I've filed the bug with the team, and will keep you posted on their progress.
Hi @laurenzlong @kevinajian, any update on this issue? thanks.
just found this today
I stored
"hosting": {
"base_url": "https://mentor-cv-staging.web.app"
},
which adds a slash and breaks my CORS setting
app.use(cors({ origin: functions.config().hosting.base_url}))
Access to fetch at 'https://us-central1-mentor-cv-staging.cloudfunctions.net/allFunctions/createUser' from origin 'https://mentor-cv-staging.web.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://mentor-cv-staging.web.app/' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
For now I just done
app.use(cors({ origin: functions.config().hosting.base_url.replace(/\/$/, "") }))
Most helpful comment
I found a walkthrough (or awful solution) :S I don't wanna to do that but ... It's works >,<
You can do it a
.replace(/\\n/g, '\n')to the private_key@sketchthat @janakagamini @patrickmcd I know it was 4 months ago but .. :)