diff --git a/core/packages/gcp-metadata/src/gcp-residency.ts b/core/packages/gcp-metadata/src/gcp-residency.ts index b64425f4915..dcbdf48a7ff 100644 --- a/core/packages/gcp-metadata/src/gcp-residency.ts +++ b/core/packages/gcp-metadata/src/gcp-residency.ts @@ -85,9 +85,15 @@ export function isGoogleComputeEngineLinux(): boolean { * Determines if the process is running on a Google Compute Engine instance with a known * MAC address. * + * Always `false` on macOS: Compute Engine does not run macOS, and macOS assigns + * random, locally administered MAC addresses (which can begin with `42:01`) to + * interfaces such as `awdl0` and `llw0`. + * * @returns {boolean} `true` if the process is running on GCE (as determined by MAC address), `false` otherwise. */ export function isGoogleComputeEngineMACAddress(): boolean { + if (platform() === 'darwin') return false; + const interfaces = networkInterfaces(); for (const item of Object.values(interfaces)) { diff --git a/core/packages/gcp-metadata/test/gcp-residency.test.ts b/core/packages/gcp-metadata/test/gcp-residency.test.ts index 5255374b459..1e18e2194b7 100644 --- a/core/packages/gcp-metadata/test/gcp-residency.test.ts +++ b/core/packages/gcp-metadata/test/gcp-residency.test.ts @@ -101,6 +101,15 @@ describe('gcp-residency', () => { assert.equal(gcpResidency.isGoogleComputeEngine(), true); }); + it('should return `false` on macOS even if a MAC address begins with `42:01`', () => { + residency.setGCENetworkInterface(true); + residency.setGCEPlatform('darwin'); + residency.setGCELinuxBios(null); + + assert.equal(gcpResidency.isGoogleComputeEngineMACAddress(), false); + assert.equal(gcpResidency.isGoogleComputeEngine(), false); + }); + it('should return `false` if the host MAC address does not begin with `42:01` & is not Linux', () => { residency.setGCENetworkInterface(false); residency.setGCEPlatform('win32'); diff --git a/core/packages/gcp-metadata/test/index.test.ts b/core/packages/gcp-metadata/test/index.test.ts index 4d7eea65c36..cc615fb615f 100644 --- a/core/packages/gcp-metadata/test/index.test.ts +++ b/core/packages/gcp-metadata/test/index.test.ts @@ -785,6 +785,7 @@ describe('unit test', () => { it('should match gcp residency results by default', () => { // Set as GCP residency.setGCENetworkInterface(true); + residency.setGCEPlatform('linux'); gcp.setGCPResidency(); assert.equal(gcp.gcpResidencyCache, true);