Skip to content

Commit

Permalink
fingerprinting: add AWS MAC and public-ipv6 (#8887)
Browse files Browse the repository at this point in the history
  • Loading branch information
joel0 authored Sep 17, 2020
1 parent 1232d3d commit 767e890
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions client/fingerprint/env_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions client/fingerprint/env_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 767e890

Please sign in to comment.