question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid response from metadata service: incorrect Metadata-Flavor header

See original GitHub issue

After reviewing as much as I could online to see how I could solve the issue, I wasn’t able to come to a solution, this is an issue apparently with how the JSON file holding the credentials to GCloud.

“Invalid response from metadata service: incorrect Metadata-Flavor header”

That is normally the error that keeps throwing the client when I invoke the alert function of the client.

Environment details

  • OS: macOS Mojave
  • Node.js version: v10.15.2
  • npm version: 6.10.0
  • @google-cloud/logging version: 5.2.1

Steps to reproduce

  1. Generate a quick Angular project using the CLI
  2. Make sure to have a JSON file with service account credentials properly downloaded.
  3. Generate a quick service that looks somehow like it follows, inject it, and call the function that performs the logging.

`import { Logging } from ‘@google-cloud/logging’; @Injectable() export class GCloudLogService { constructor( private readonly logging: Logging, ) {}

    async saveLog(logPayload: IServerExceptionLog) {
try {
	const metadata = {
		resource: { type: 'global' },
	  };
	const entry = this.logging.entry(metadata, logPayload);
	const log = this.logging.log(logName);
	await log.alert(entry);
	return;
} catch (err) {
	console.log(`ERR ${err.message}`);
}

} }`

No matter how many versions of the code I try I keep getting the error:

“Invalid response from metadata service: incorrect Metadata-Flavor header.”

I tried setting the project manually,

await this.logging.setProjectId({ projectId, });

but still nothing.

I did make sure that the environment variable GOOGLE_APPLICATION_CREDENTIALS was set up and it is.

Please help, I have expended too many hours trying to figure it out but still nothing.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
joshualyoncommented, Apr 7, 2020

Just wanted to add that I had this happen to me after factory resetting a PC and it turns out it was ATT’s DNS catch-all that was causing issues (paired with the internal auth/metadata module’s expectations around querying the metadata server).

I compared each and every setting that I could think of between a machine where things were working and on one that wasn’t. Everything seemed to match, so I stepped through the code line by line and realized that it was failing in google-auth-library\build\src\auth\envDetect.js where it tried to figure out what type of GCP environment, if any, the code is running in.

When it got to the isComputeEngine() check, it would call the gcpMetadata.isAvailable() method which attempts a network call to the metadata service and tries to fail fast if it’s unavailable. Unfortunately, ATT’s DNS ‘Assist’ that was catching all unknown DNS calls and returning a search result instead of just failing the network request.

I changed my DNS entries on that PC over to Google’s DNS (8.8.8.8 and 8.8.4.4) and the issue is now resolved for me.

1reaction
arianlopezccommented, Dec 27, 2019

I fully agree with you @dustingraham and with what @jtyers mentioned. As a way to validate that idea a bit, I cloned my repo on another machine and the whole thing worked just fine. There is some local configuration that either we are missing or have different that causes this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What incorrect Metadata-Flavor header at GoogleAuth means?
Solved It just required propper initialization const credential = require('./xxxxx.json') admin.
Read more >
Why can't I access Metadata Server of GCP Instance?
Show activity on this post. This can be caused by disabling the service account for the instance. You need authorization to access metadata....
Read more >
Storing and Retrieving Metadata - Google Compute Engine
This header indicates that the request was sent with the intention of retrieving metadata values, rather than unintentionally from an insecure source, and ......
Read more >
Access VM metadata - Compute Engine - Google Cloud
If you try to do this, the metadata server fails your request and returns a 400 Invalid Request error. You cannot perform a...
Read more >
project-wide metadata 404 error - Google Groups
What are we doing wrong here? ... mhardy:~$ wget -d --header="Metadata-Flavor: Google" http://metadata.google. ... HTTP request sent, awaiting response.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found