Skip to content
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

Can't resolve metadata server in ComputeTokenUrl #1179

Closed
MricMoho opened this issue Apr 4, 2018 · 5 comments
Closed

Can't resolve metadata server in ComputeTokenUrl #1179

MricMoho opened this issue Apr 4, 2018 · 5 comments
Assignees

Comments

@MricMoho
Copy link

MricMoho commented Apr 4, 2018

Hi,

I have actually some servers in compute engine and i wanted to the use ComputeCredential to create my client but I get an error because the host "metadata" can't be resolved:

        public const string ComputeTokenUrl =
            "http://metadata/computeMetadata/v1/instance/service-accounts/default/token";

https://github.com/google/google-api-dotnet-client/blob/master/Src/Support/Google.Apis.Auth/OAuth2/GoogleAuthConsts.cs

It should not be "metadata.google.internal" instead?
Or directly the IP like you did in last realease in the ComputeCredential class?
public const string MetadataServerUrl = "http://169.254.169.254"; // IP address instead of name to avoid DNS resolution
https://github.com/google/google-api-dotnet-client/pull/1158/files

@jskeet
Copy link
Collaborator

jskeet commented Apr 4, 2018

Could you give me more background about how you're running into this?

  • What platform within Compute Engine are you running on? (Is this plain GCE with a VM, and if so, what kind of VM? Or is it Kubernetes Engine etc?)
  • What code are you using at the moment? Are you fetching the default credentials, or something else?

@MricMoho
Copy link
Author

MricMoho commented Apr 4, 2018

Yes, it's a plain GCE with a VM, running on Windows Server 2012 R2 Datacenter.

Type de machine
n1-standard-2 :2 vCPU, 7,5 Go de mémoire
Plate-forme du processeur
Intel Haswell
Zone
europe-west1-d

I am fetching them using GetApplicationDefault()

        static void Main(string[] args)
        {
            GoogleCredential credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefault();
            try
            {
                var client = StorageClient.Create(credentials);

                var testFile = new StreamReader("test.png");
                client.UploadObject("bucketname", "test.png", "image/png", testFile.BaseStream);
                Console.WriteLine("all ok");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException);
            }
        }

@jskeet
Copy link
Collaborator

jskeet commented Apr 4, 2018

As an aside, if you call StorageClient.Create(), that will use the application default credentials for you, so your code can be simplified further :)

However, for the moment, if you know you're running on GCE, you could try this workaround:

var url = "http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token";
var initializer = new ComputeCredential.Initializer(url);
var credential = new ComputeCredential(initializer);

Then pass that to StorageClient.Create. That would give us a good idea of whether the URL is really the problem.

@MricMoho
Copy link
Author

MricMoho commented Apr 5, 2018

Thx for the workaround.
Works fine with that

@jskeet
Copy link
Collaborator

jskeet commented Apr 5, 2018

Great - in that case, I'll leave this issue open for now, and we can modify that constant.

chrisdunelm added a commit to chrisdunelm/google-api-dotnet-client that referenced this issue Apr 16, 2018
chrisdunelm added a commit that referenced this issue Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants