Skip to content

Commit

Permalink
Merge pull request rancher#94 from aiyengar2/add_metadata_options
Browse files Browse the repository at this point in the history
Add flags for metadata options
  • Loading branch information
aiyengar2 authored Jul 30, 2020
2 parents 7fde9d7 + bc7cfaa commit cdcfa4c
Show file tree
Hide file tree
Showing 103 changed files with 48,906 additions and 20,281 deletions.
43 changes: 43 additions & 0 deletions drivers/amazonec2/amazonec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ var (
errorNoSubnetsFound = errors.New("The desired subnet could not be located in this region. Is '--amazonec2-subnet-id' or AWS_SUBNET_ID configured correctly?")
errorDisableSSLWithoutCustomEndpoint = errors.New("using --amazonec2-insecure-transport also requires --amazonec2-endpoint")
errorReadingUserData = errors.New("unable to read --amazonec2-userdata file")
errorInvalidValueForHTTPToken = errors.New("httpToken must be either optional or required")
errorInvalidValueForHTTPEndpoint = errors.New("httpEndpoint must be either enabled or disabled")
)

type Driver struct {
Expand Down Expand Up @@ -128,6 +130,10 @@ type Driver struct {
EncryptEbsVolume bool
spotInstanceRequestId string
kmsKeyId *string

// Metadata Options
HttpEndpoint string
HttpTokens string
}

type clientFactory interface {
Expand Down Expand Up @@ -304,6 +310,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Custom KMS key using the AWS Managed CMK",
EnvVar: "AWS_KMS_KEY",
},
mcnflag.StringFlag{
Name: "amazonec2-http-endpoint",
Usage: "Enables or disables the HTTP metadata endpoint on your instances",
EnvVar: "AWS_HTTP_ENDPOINT",
},
mcnflag.StringFlag{
Name: "amazonec2-http-tokens",
Usage: "The state of token usage for your instance metadata requests.",
EnvVar: "AWS_HTTP_TOKENS",
},
}
}

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

httpEndpoint := flags.String("amazonec2-http-endpoint")
if httpEndpoint != "" {
if httpEndpoint != "disabled" && httpEndpoint != "enabled" {
return errorInvalidValueForHTTPEndpoint
}
d.HttpEndpoint = httpEndpoint
}

httpTokens := flags.String("amazonec2-http-tokens")
if httpTokens != "" {
if httpTokens != "optional" && httpTokens != "required" {
return errorInvalidValueForHTTPToken
}
d.HttpTokens = httpTokens
}

kmskeyid := flags.String("amazonec2-kms-key")
if kmskeyid != "" {
d.kmsKeyId = aws.String(kmskeyid)
Expand Down Expand Up @@ -752,6 +784,17 @@ func (d *Driver) innerCreate() error {

d.waitForInstance()

if d.HttpEndpoint != "" || d.HttpTokens != "" {
_, err := d.getClient().ModifyInstanceMetadataOptions(&ec2.ModifyInstanceMetadataOptionsInput{
InstanceId: aws.String(d.InstanceId),
HttpEndpoint: aws.String(d.HttpEndpoint),
HttpTokens: aws.String(d.HttpTokens),
})
if err != nil {
return fmt.Errorf("Error modifying instance metadata options for instance: %s", err)
}
}

log.Debugf("created instance ID %s, IP address %s, Private IP address %s",
d.InstanceId,
d.IPAddress,
Expand Down
2 changes: 2 additions & 0 deletions drivers/amazonec2/ec2client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type Ec2Client interface {

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

ModifyInstanceMetadataOptions(input *ec2.ModifyInstanceMetadataOptionsInput) (*ec2.ModifyInstanceMetadataOptionsOutput, error)

//SecurityGroup

CreateSecurityGroup(input *ec2.CreateSecurityGroupInput) (*ec2.CreateSecurityGroupOutput, error)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/aws/aws-sdk-go v1.20.20
github.com/aws/aws-sdk-go v1.33.14
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/bugsnag/bugsnag-go v0.0.0-20151120182711-02e952891c52
Expand All @@ -37,7 +37,7 @@ require (
github.com/samalba/dockerclient v0.0.0-20151231000007-f661dd4754aa
github.com/sirupsen/logrus v1.0.4 // indirect
github.com/skarademir/naturalsort v0.0.0-20150715044055-69a5d87bef62
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.5.1
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect
github.com/urfave/cli v1.11.1-0.20151120215642-0302d3914d2a
github.com/vmware/govcloudair v0.0.2
Expand Down
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VY
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/aws/aws-sdk-go v1.20.20 h1:OAR/GtjMOhenkp1NNKr1N1FgIP3mQXHeGbRhvVIAQp0=
github.com/aws/aws-sdk-go v1.20.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.33.14 h1:ucjyVEvtIdtn4acf+RKsgk6ybAYeMLXpGZeqoVvi7Kk=
github.com/aws/aws-sdk-go v1.33.14/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand Down Expand Up @@ -92,6 +92,7 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -141,8 +142,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 h1:UUHMLvzt/31azWTN/ifGWef4WUqvXk0iRqdhdy/2uzI=
Expand All @@ -164,6 +165,7 @@ github.com/onsi/ginkgo v1.9.0 h1:SZjF721BByVj8QH636/8S2DnX4n0Re3SteMmw3N+tzc=
github.com/onsi/ginkgo v1.9.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.6.0 h1:8XTW0fcJZEq9q+Upcyws4JSGua2MFysCL5xkaSgHc+M=
github.com/onsi/gomega v1.6.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand All @@ -184,6 +186,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 h1:/Bsw4C+DEdqPjt8vAqaC9LAqpAQnaCQQqmolqq3S1T4=
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9/go.mod h1:RHkNRtSLfOK7qBTHaeSX1D6BNpI3qw7NTxsmNr4RvN8=
github.com/urfave/cli v1.11.1-0.20151120215642-0302d3914d2a h1:i6gus1o4iDkjlzGJCIvhbKmyk6zeIhIqgdSOcJi493g=
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/awserr/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cdcfa4c

Please sign in to comment.