Skip to content

Commit 984f45d

Browse files
authored
Updating the metadata server URL for Application Default Credentials (#568)
* Migrating ADC implementation to the v1 metadata endpoint * Added Metadata-Flavor header to the request
1 parent 6c0204c commit 984f45d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/auth/credential.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const GOOGLE_AUTH_TOKEN_PATH = '/o/oauth2/token';
2929

3030
// NOTE: the Google Metadata Service uses HTTP over a vlan
3131
const GOOGLE_METADATA_SERVICE_HOST = 'metadata.google.internal';
32-
const GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1beta1/instance/service-accounts/default/token';
32+
const GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1/instance/service-accounts/default/token';
3333

3434
const configDir = (() => {
3535
// Windows has a dedicated low-rights location for apps at ~/Application Data
@@ -351,6 +351,9 @@ export class MetadataServiceCredential implements Credential {
351351
const request: HttpRequestConfig = {
352352
method: 'GET',
353353
url: `http://${GOOGLE_METADATA_SERVICE_HOST}${GOOGLE_METADATA_SERVICE_PATH}`,
354+
headers: {
355+
'Metadata-Flavor': 'Google',
356+
},
354357
httpAgent: this.httpAgent,
355358
};
356359
return requestAccessToken(this.httpClient, request);

test/unit/auth/credential.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ describe('Credential', () => {
337337
return c.getAccessToken().then((token) => {
338338
expect(token.access_token).to.equal('anAccessToken');
339339
expect(token.expires_in).to.equal(42);
340+
expect(httpStub).to.have.been.calledOnce.and.calledWith({
341+
method: 'GET',
342+
url: 'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token',
343+
headers: {'Metadata-Flavor': 'Google'},
344+
httpAgent: undefined,
345+
});
340346
});
341347
});
342348
});

0 commit comments

Comments
 (0)