Skip to content

Commit

Permalink
Merge pull request #114 from AdRoll/support-imdsv2
Browse files Browse the repository at this point in the history
Support IMDSv2 for Rust AWS SDK
  • Loading branch information
joshua-mullins-nextroll authored May 16, 2022
2 parents a722443 + 730aebc commit 32db47c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions agent/metadata_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ Spawned in the background.
func (mds *metadataService) listen() {
handler := http.NewServeMux()
handler.HandleFunc("/latest", makeSecure(mds.getServices, mds))
handler.HandleFunc("/latest/api/token", makeSecure(mds.getv2Token, mds))
handler.HandleFunc("/latest/meta-data/iam/security-credentials/", makeSecure(mds.enumerateRoles, mds))
handler.HandleFunc("/latest/meta-data/iam/security-credentials", makeSecure(mds.enumerateRoles, mds))
handler.HandleFunc("/latest/meta-data/iam/security-credentials/hologram-access", makeSecure(mds.getCredentials, mds))
handler.HandleFunc("/latest/meta-data/instance-id", makeSecure(mds.getInstanceID, mds))
handler.HandleFunc("/latest/meta-data/placement/availability-zone", makeSecure(mds.getAvailabilityZone, mds))
Expand Down Expand Up @@ -155,6 +157,11 @@ func (mds *metadataService) getServices(w http.ResponseWriter, r *http.Request)
fmt.Fprint(w, "meta-data")
}

func (mds *metadataService) getv2Token(w http.ResponseWriter, r *http.Request) {
w.Header().Set("x-aws-ec2-metadata-token-ttl-seconds", r.Header.Get("x-aws-ec2-metadata-token-ttl-seconds"))
fmt.Fprint(w, "AQAAAO8q4JDjNt4Nk1u6A9zFMofraQ1ZWRUQ8ppb9sWxiXEbYOSlOw==")
}

func (mds *metadataService) getInstanceID(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "i-deadbeef")
}
Expand Down

0 comments on commit 32db47c

Please sign in to comment.