Skip to content

Commit

Permalink
mantle/aws: add configuration support for VolumeType and IMDSv2-only …
Browse files Browse the repository at this point in the history
…support

IMDSV2-only has the potential to break existing systems, expose configuration
through an environment vairable defined in 'image-default.yaml' to overide
defaults.

Default volume type to 'gp3', while 'gp3' is generally better there could be
a reason to change it. Expose configuration through enviornment variable
defined in 'image-default.yaml' to allow for overiding.

Docs:
IMDSv2: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html#configure-IMDS-new-instances-ami-configuration
GP3: https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-storage-compare-volume-types.html
  • Loading branch information
prestist committed Sep 12, 2023
1 parent 3c03739 commit c1c4711
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion mantle/cmd/ore/aws/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ After a successful run, the final line of output will be a line of JSON describi
uploadGrantUsers []string
uploadGrantUsersSnapshot []string
uploadTags []string
uploadIMDSv2OnlySupport bool
uploadVolumeType string
)

func init() {
Expand All @@ -85,6 +87,8 @@ func init() {
cmdUpload.Flags().StringSliceVar(&uploadGrantUsers, "grant-user", []string{}, "grant launch permission to this AWS user ID")
cmdUpload.Flags().StringSliceVar(&uploadGrantUsersSnapshot, "grant-user-snapshot", []string{}, "grant snapshot volume permission to this AWS user ID")
cmdUpload.Flags().StringSliceVar(&uploadTags, "tags", []string{}, "list of key=value tags to attach to the AMI")
cmdUpload.Flags().BoolVar(&uploadIMDSv2OnlySupport, "public", false, "enable IMDSv2-only support")
cmdUpload.Flags().StringVar(&uploadVolumeType, "volume-type", "gp2", "EBS volume type (gp3, gp2, io1, st1, sc1, standard, etc.)")
}

func defaultBucketNameForRegion(region string) string {
Expand Down Expand Up @@ -243,7 +247,7 @@ func runUpload(cmd *cobra.Command, args []string) error {
}

// create AMIs and grant permissions
amiID, err := API.CreateHVMImage(sourceSnapshot, uploadDiskSizeGiB, uploadAMIName, uploadAMIDescription, uploadImageArchitecture)
amiID, err := API.CreateHVMImage(sourceSnapshot, uploadDiskSizeGiB, uploadAMIName, uploadAMIDescription, uploadImageArchitecture, uploadVolumeType, uploadIMDSv2OnlySupport)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to create HVM image: %v\n", err)
os.Exit(1)
Expand Down
17 changes: 13 additions & 4 deletions mantle/platform/api/aws/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (a *API) CreateImportRole(bucket string) error {
return nil
}

func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, description string, architecture string) (string, error) {
func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, description string, architecture string, volumetype string, imdsv2Only bool) (string, error) {
var awsArch string
var bootmode string
if architecture == "" {
Expand All @@ -346,7 +346,11 @@ func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, d
return "", fmt.Errorf("unsupported ec2 architecture %q", architecture)
}

return a.createImage(&ec2.RegisterImageInput{
// default to gp2
if volumetype == "" {
volumetype = "gp2"
}
params := &ec2.RegisterImageInput{
Name: aws.String(name),
Description: aws.String(description),
Architecture: aws.String(awsArch),
Expand All @@ -359,7 +363,7 @@ func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, d
SnapshotId: aws.String(snapshotID),
DeleteOnTermination: aws.Bool(true),
VolumeSize: aws.Int64(int64(diskSizeGiB)),
VolumeType: aws.String("gp2"),
VolumeType: aws.String(volumetype),
},
},
{
Expand All @@ -370,7 +374,12 @@ func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, d
EnaSupport: aws.Bool(true),
SriovNetSupport: aws.String("simple"),
BootMode: aws.String(bootmode),
})
}
if imdsv2Only {
params.ImdsSupport = aws.String("v2.0")
}

return a.createImage(params)
}

func (a *API) deregisterImageIfExists(name string) error {
Expand Down

0 comments on commit c1c4711

Please sign in to comment.