From 767e8909d7b8989c41153b90101cc10898ce882e Mon Sep 17 00:00:00 2001 From: Joel May Date: Thu, 17 Sep 2020 06:03:01 -0700 Subject: [PATCH] fingerprinting: add AWS MAC and public-ipv6 (#8887) --- client/fingerprint/env_aws.go | 25 +++++++++++++++++++++++++ client/fingerprint/env_aws_test.go | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/client/fingerprint/env_aws.go b/client/fingerprint/env_aws.go index 87becff9e9a..bfe4ea24d57 100644 --- a/client/fingerprint/env_aws.go +++ b/client/fingerprint/env_aws.go @@ -443,6 +443,7 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F "local-ipv4": true, "public-hostname": true, "public-ipv4": true, + "mac": true, "placement/availability-zone": false, } @@ -494,6 +495,30 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F } } + // copy over IPv6 network specific information + if val, ok := response.Attributes["unique.platform.aws.mac"]; ok && val != "" { + k := "network/interfaces/macs/" + val + "/ipv6s" + addrsStr, err := ec2meta.GetMetadata(k) + addrsStr = strings.TrimSpace(addrsStr) + if addrsStr == "" { + f.logger.Debug("read an empty value", "attribute", k) + } else if awsErr, ok := err.(awserr.RequestFailure); ok { + f.logger.Debug("could not read attribute value", "attribute", k, "error", awsErr) + } else if awsErr, ok := err.(awserr.Error); ok { + // if it's a URL error, assume we're not in an AWS environment + // TODO: better way to detect AWS? Check xen virtualization? + if _, ok := awsErr.OrigErr().(*url.Error); ok { + return nil + } + + // not sure what other errors it would return + return err + } else { + addrs := strings.SplitN(addrsStr, "\n", 2) + response.AddAttribute("unique.platform.aws.public-ipv6", addrs[0]) + } + } + // copy over CPU speed information if specs := f.lookupCPU(ec2meta); specs != nil { response.AddAttribute("cpu.modelname", specs.model) diff --git a/client/fingerprint/env_aws_test.go b/client/fingerprint/env_aws_test.go index 598ad3653c4..a2b78b066cf 100644 --- a/client/fingerprint/env_aws_test.go +++ b/client/fingerprint/env_aws_test.go @@ -342,6 +342,11 @@ var awsStubs = []endpoint{ ContentType: "text/plain", Body: "54.191.117.175", }, + { + Uri: "/latest/meta-data/mac", + ContentType: "text/plain", + Body: "0a:20:d2:42:b3:55", + }, } var unknownInstanceType = []endpoint{