Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding in initial KMS #1555

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions provider/aws/aws_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (p *AWS) CreateImage(ctx *lepton.Context, imagePath string) error {
key := c.CloudConfig.ImageName

ctx.Logger().Info("Creating snapshot")
snapshotID, err := p.createSnapshot(imagePath)
snapshotID, err := p.createSnapshot(imagePath, c.CloudConfig.KMS)
if err != nil {
return err
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (p *AWS) MirrorImage(ctx *lepton.Context, imageName, srcRegion, dstRegion s

// createSnapshot process create Snapshot to EBS
// Returns snapshotID and err
func (p *AWS) createSnapshot(imagePath string) (string, error) {
func (p *AWS) createSnapshot(imagePath string, kms string) (string, error) {
// Open file first
f, err := os.Open(imagePath)
if err != nil {
Expand All @@ -250,10 +250,20 @@ func (p *AWS) createSnapshot(imagePath string) (string, error) {
maxBar := (snapshotSize/int64(SnapshotBlockDataLength))*2 + 2
bar := progressbar.Default(maxBar)

snapshotOutput, err := p.volumeService.StartSnapshot(&ebs.StartSnapshotInput{
esi := &ebs.StartSnapshotInput{
Tags: []*ebs.Tag{},
VolumeSize: aws.Int64(sizeInGb),
})
}

if kms != "" {
esi.Encrypted = aws.Bool(true)

if kms != "default" {
esi.KmsKeyArn = aws.String(kms)
}
}

snapshotOutput, err := p.volumeService.StartSnapshot(esi)
if err != nil {
return "", err
}
Expand Down
4 changes: 4 additions & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ type ProviderConfig struct {
// you can use to pass role information to an EC2 instance when the instance starts.
InstanceProfile string `json:",omitempty"`

// KMS optionally encrypts AMIs if set. 'default' may be used for
// the default key or a KMS arn may be specified.
KMS string `json:",omitempty"`

// Platform defines the cloud provider to use with the ops CLI, currently
// supporting aws, azure, and gcp.
Platform string `cloud:"platform" json:",omitempty"`
Expand Down