|
73 | 73 | errorNoSubnetsFound = errors.New("The desired subnet could not be located in this region. Is '--amazonec2-subnet-id' or AWS_SUBNET_ID configured correctly?")
|
74 | 74 | errorDisableSSLWithoutCustomEndpoint = errors.New("using --amazonec2-insecure-transport also requires --amazonec2-endpoint")
|
75 | 75 | 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") |
76 | 78 | )
|
77 | 79 |
|
78 | 80 | type Driver struct {
|
@@ -128,6 +130,10 @@ type Driver struct {
|
128 | 130 | EncryptEbsVolume bool
|
129 | 131 | spotInstanceRequestId string
|
130 | 132 | kmsKeyId *string
|
| 133 | + |
| 134 | + // Metadata Options |
| 135 | + HttpEndpoint string |
| 136 | + HttpTokens string |
131 | 137 | }
|
132 | 138 |
|
133 | 139 | type clientFactory interface {
|
@@ -304,6 +310,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
|
304 | 310 | Usage: "Custom KMS key using the AWS Managed CMK",
|
305 | 311 | EnvVar: "AWS_KMS_KEY",
|
306 | 312 | },
|
| 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 | + }, |
307 | 323 | }
|
308 | 324 | }
|
309 | 325 |
|
@@ -403,6 +419,22 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
403 | 419 | d.UserDataFile = flags.String("amazonec2-userdata")
|
404 | 420 | d.EncryptEbsVolume = flags.Bool("amazonec2-encrypt-ebs-volume")
|
405 | 421 |
|
| 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 | + |
406 | 438 | kmskeyid := flags.String("amazonec2-kms-key")
|
407 | 439 | if kmskeyid != "" {
|
408 | 440 | d.kmsKeyId = aws.String(kmskeyid)
|
@@ -752,6 +784,17 @@ func (d *Driver) innerCreate() error {
|
752 | 784 |
|
753 | 785 | d.waitForInstance()
|
754 | 786 |
|
| 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 | + |
755 | 798 | log.Debugf("created instance ID %s, IP address %s, Private IP address %s",
|
756 | 799 | d.InstanceId,
|
757 | 800 | d.IPAddress,
|
|
0 commit comments