Skip to content

Commit cdcfa4c

Browse files
authored
Merge pull request rancher#94 from aiyengar2/add_metadata_options
Add flags for metadata options
2 parents 7fde9d7 + bc7cfaa commit cdcfa4c

File tree

103 files changed

+48906
-20281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+48906
-20281
lines changed

drivers/amazonec2/amazonec2.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ var (
7373
errorNoSubnetsFound = errors.New("The desired subnet could not be located in this region. Is '--amazonec2-subnet-id' or AWS_SUBNET_ID configured correctly?")
7474
errorDisableSSLWithoutCustomEndpoint = errors.New("using --amazonec2-insecure-transport also requires --amazonec2-endpoint")
7575
errorReadingUserData = errors.New("unable to read --amazonec2-userdata file")
76+
errorInvalidValueForHTTPToken = errors.New("httpToken must be either optional or required")
77+
errorInvalidValueForHTTPEndpoint = errors.New("httpEndpoint must be either enabled or disabled")
7678
)
7779

7880
type Driver struct {
@@ -128,6 +130,10 @@ type Driver struct {
128130
EncryptEbsVolume bool
129131
spotInstanceRequestId string
130132
kmsKeyId *string
133+
134+
// Metadata Options
135+
HttpEndpoint string
136+
HttpTokens string
131137
}
132138

133139
type clientFactory interface {
@@ -304,6 +310,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
304310
Usage: "Custom KMS key using the AWS Managed CMK",
305311
EnvVar: "AWS_KMS_KEY",
306312
},
313+
mcnflag.StringFlag{
314+
Name: "amazonec2-http-endpoint",
315+
Usage: "Enables or disables the HTTP metadata endpoint on your instances",
316+
EnvVar: "AWS_HTTP_ENDPOINT",
317+
},
318+
mcnflag.StringFlag{
319+
Name: "amazonec2-http-tokens",
320+
Usage: "The state of token usage for your instance metadata requests.",
321+
EnvVar: "AWS_HTTP_TOKENS",
322+
},
307323
}
308324
}
309325

@@ -403,6 +419,22 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
403419
d.UserDataFile = flags.String("amazonec2-userdata")
404420
d.EncryptEbsVolume = flags.Bool("amazonec2-encrypt-ebs-volume")
405421

422+
httpEndpoint := flags.String("amazonec2-http-endpoint")
423+
if httpEndpoint != "" {
424+
if httpEndpoint != "disabled" && httpEndpoint != "enabled" {
425+
return errorInvalidValueForHTTPEndpoint
426+
}
427+
d.HttpEndpoint = httpEndpoint
428+
}
429+
430+
httpTokens := flags.String("amazonec2-http-tokens")
431+
if httpTokens != "" {
432+
if httpTokens != "optional" && httpTokens != "required" {
433+
return errorInvalidValueForHTTPToken
434+
}
435+
d.HttpTokens = httpTokens
436+
}
437+
406438
kmskeyid := flags.String("amazonec2-kms-key")
407439
if kmskeyid != "" {
408440
d.kmsKeyId = aws.String(kmskeyid)
@@ -752,6 +784,17 @@ func (d *Driver) innerCreate() error {
752784

753785
d.waitForInstance()
754786

787+
if d.HttpEndpoint != "" || d.HttpTokens != "" {
788+
_, err := d.getClient().ModifyInstanceMetadataOptions(&ec2.ModifyInstanceMetadataOptionsInput{
789+
InstanceId: aws.String(d.InstanceId),
790+
HttpEndpoint: aws.String(d.HttpEndpoint),
791+
HttpTokens: aws.String(d.HttpTokens),
792+
})
793+
if err != nil {
794+
return fmt.Errorf("Error modifying instance metadata options for instance: %s", err)
795+
}
796+
}
797+
755798
log.Debugf("created instance ID %s, IP address %s, Private IP address %s",
756799
d.InstanceId,
757800
d.IPAddress,

drivers/amazonec2/ec2client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type Ec2Client interface {
99

1010
CreateTags(input *ec2.CreateTagsInput) (*ec2.CreateTagsOutput, error)
1111

12+
ModifyInstanceMetadataOptions(input *ec2.ModifyInstanceMetadataOptionsInput) (*ec2.ModifyInstanceMetadataOptionsOutput, error)
13+
1214
//SecurityGroup
1315

1416
CreateSecurityGroup(input *ec2.CreateSecurityGroupInput) (*ec2.CreateSecurityGroupOutput, error)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2
1414
github.com/Azure/go-autorest/autorest/to v0.3.0
1515
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
16-
github.com/aws/aws-sdk-go v1.20.20
16+
github.com/aws/aws-sdk-go v1.33.14
1717
github.com/bitly/go-simplejson v0.5.0 // indirect
1818
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
1919
github.com/bugsnag/bugsnag-go v0.0.0-20151120182711-02e952891c52
@@ -37,7 +37,7 @@ require (
3737
github.com/samalba/dockerclient v0.0.0-20151231000007-f661dd4754aa
3838
github.com/sirupsen/logrus v1.0.4 // indirect
3939
github.com/skarademir/naturalsort v0.0.0-20150715044055-69a5d87bef62
40-
github.com/stretchr/testify v1.4.0
40+
github.com/stretchr/testify v1.5.1
4141
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect
4242
github.com/urfave/cli v1.11.1-0.20151120215642-0302d3914d2a
4343
github.com/vmware/govcloudair v0.0.2

go.sum

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VY
5252
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
5353
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5454
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
55-
github.com/aws/aws-sdk-go v1.20.20 h1:OAR/GtjMOhenkp1NNKr1N1FgIP3mQXHeGbRhvVIAQp0=
56-
github.com/aws/aws-sdk-go v1.20.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
55+
github.com/aws/aws-sdk-go v1.33.14 h1:ucjyVEvtIdtn4acf+RKsgk6ybAYeMLXpGZeqoVvi7Kk=
56+
github.com/aws/aws-sdk-go v1.33.14/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
5757
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
5858
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
5959
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
@@ -92,6 +92,7 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
9292
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
9393
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
9494
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
95+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
9596
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
9697
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
9798
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -141,8 +142,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
141142
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
142143
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
143144
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
144-
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
145-
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
145+
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
146+
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
146147
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
147148
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
148149
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 h1:UUHMLvzt/31azWTN/ifGWef4WUqvXk0iRqdhdy/2uzI=
@@ -164,6 +165,7 @@ github.com/onsi/ginkgo v1.9.0 h1:SZjF721BByVj8QH636/8S2DnX4n0Re3SteMmw3N+tzc=
164165
github.com/onsi/ginkgo v1.9.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
165166
github.com/onsi/gomega v1.6.0 h1:8XTW0fcJZEq9q+Upcyws4JSGua2MFysCL5xkaSgHc+M=
166167
github.com/onsi/gomega v1.6.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
168+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
167169
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
168170
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
169171
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -184,6 +186,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
184186
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
185187
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
186188
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
189+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
190+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
187191
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 h1:/Bsw4C+DEdqPjt8vAqaC9LAqpAQnaCQQqmolqq3S1T4=
188192
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9/go.mod h1:RHkNRtSLfOK7qBTHaeSX1D6BNpI3qw7NTxsmNr4RvN8=
189193
github.com/urfave/cli v1.11.1-0.20151120215642-0302d3914d2a h1:i6gus1o4iDkjlzGJCIvhbKmyk6zeIhIqgdSOcJi493g=

vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go/aws/client/client.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)