Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/packages/gcp-metadata/src/gcp-residency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 9 additions & 0 deletions core/packages/gcp-metadata/test/gcp-residency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions core/packages/gcp-metadata/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading