Skip to content

Google Cloud Functions: Could not authenticate request #2158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leonardoam opened this issue Mar 29, 2017 · 10 comments
Closed

Google Cloud Functions: Could not authenticate request #2158

leonardoam opened this issue Mar 29, 2017 · 10 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@leonardoam
Copy link

leonardoam commented Mar 29, 2017

I am using a node.js function on Google Cloud Functions to save Pub/Sub messages to GCS (Storage), but it randomly gives me the following error for some messages (most of the messages are succesfully written):

"Error: Could not authenticate request. Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information."

It doesn't make sense, once running on GCE would use same service-account for all messages, which has the proper permissions, and all messages comes from the same source and goes to the same destination. Can someone enlighten me on what could I do?

I'm using google-cloud/storage version 0.8.0.

/*Google Cloud Functions used in this project*/

/**
 * Triggered from a message on a Cloud Pub/Sub topic.
 *
 * @param {!Object} event The Cloud Functions event.
 * @param {!Function} The callback function.
 */

const bucketName = 'backup-queue-bucket';

const util = require('util')
const gcs = require('@google-cloud/storage')();
const crypto = require('crypto');

exports.backupQueue = function backupQueue(event, callback) {
    // The Cloud Pub/Sub Message object.
    const timestamp = event.timestamp;
    const resources = event.resource.split('/');
    const pubsubMessage = event.data;
    const messageContent = Buffer.from(pubsubMessage.data, 'base64').toString();

    // We're just going to log the message to prove that
    // it worked.      
      var queueName = resources[resources.length-1];
    console.log(`Message received: ${messageContent} in queue ${queueName}`);

    const filename = timestamp+'_'+crypto.createHash('md5').update(messageContent).digest('hex');

    const bucket = gcs.bucket(bucketName);
    const file = bucket.file(queueName+'/'+filename);
    const fs = file.createWriteStream({});
    fs.on('finish', function () {
        console.log(`Message ${filename} successfully written to file.`);
    });
    fs.on('error', function (error) {
        console.warn(`Message ${filename} could not be written to file. Retry will be called. Error: ${error.message}`);
      	setTimeout(backupQueue(event, callback), 1000);
    });

    fs.write(Buffer.from(pubsubMessage.data, 'base64').toString());
    fs.end();

    callback();
};
@lukesneeringer
Copy link
Contributor

Hi @leonardoam. Thanks for reporting.

At the moment, I am just acking your issue. I am not sure what to do (but giving it some background thought while I hope someone else speaks up).

@lukesneeringer lukesneeringer added api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 29, 2017
@lukesneeringer
Copy link
Contributor

Possibly related to #2139.

@stephenplusplus
Copy link
Contributor

@leonardoam is there a way to find out which version of @google-cloud/common is being loaded? We sent through a fix recently that was released with @google-cloud/[email protected], which would hopefully resolve this.

@stephenplusplus
Copy link
Contributor

Sorry @leonardoam, that was bad information. We didn't actually release the fix yet, but I am even more certain now that it will resolve this issue. This issue is another flavor of #1908, which reported this same error in Compute Engine environments.

I'm going to close and try to remember to ping you when we release an update (hopefully the coming days), and we'll re-investigate if it turns out not to be the fix. Sorry for the trouble.

@lukesneeringer
Copy link
Contributor

@leonardoam Release party is happening now, so this should be good to go in a couple hours.

@leonardoam
Copy link
Author

Thanks guys. What version will this fix affect?
Last ocurrence happened at 14:49 BRT, I will keep monitoring and let you know if this fixed the issue.

@lukesneeringer
Copy link
Contributor

@leonardoam Should be fixed in the newest version, which for storage is 1.0.0.

@Chandler
Copy link

What is the newest version? I'm seeing this error on "@google-cloud/[email protected]" inside of a Google Cloud Functions routine.

Error: Could not authenticate request Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
at wrapError (/user_code/node_modules/@google-cloud/storage/node_modules/gcs-resumable-upload/index.js:24)
at (/user_code/node_modules/@google-cloud/storage/node_modules/gcs-resumable-upload/index.js:268)
at (/user_code/node_modules/@google-cloud/storage/node_modules/google-auto-auth/index.js:25)
at (/user_code/node_modules/@google-cloud/storage/node_modules/google-auto-auth/index.js:173)
at process._tickDomainCallback (next_tick.js:129)

it's not happening for every queue item, it's sporadic.

@FreakTheMighty
Copy link

I too am confused. What modules need to be updated to what version to resolve this issue?

@adirzoari
Copy link

@Chandler same issue, it's happen sometimes. did you find solution??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants