Skip to content

Commit afd81a7

Browse files
eybergIan Eyberg
andauthored
adding in initial KMS (#1555)
Co-authored-by: Ian Eyberg <[email protected]>
1 parent e0fc870 commit afd81a7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

provider/aws/aws_image.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (p *AWS) CreateImage(ctx *lepton.Context, imagePath string) error {
110110
key := c.CloudConfig.ImageName
111111

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

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

253-
snapshotOutput, err := p.volumeService.StartSnapshot(&ebs.StartSnapshotInput{
253+
esi := &ebs.StartSnapshotInput{
254254
Tags: []*ebs.Tag{},
255255
VolumeSize: aws.Int64(sizeInGb),
256-
})
256+
}
257+
258+
if kms != "" {
259+
esi.Encrypted = aws.Bool(true)
260+
261+
if kms != "default" {
262+
esi.KmsKeyArn = aws.String(kms)
263+
}
264+
}
265+
266+
snapshotOutput, err := p.volumeService.StartSnapshot(esi)
257267
if err != nil {
258268
return "", err
259269
}

types/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ type ProviderConfig struct {
168168
// you can use to pass role information to an EC2 instance when the instance starts.
169169
InstanceProfile string `json:",omitempty"`
170170

171+
// KMS optionally encrypts AMIs if set. 'default' may be used for
172+
// the default key or a KMS arn may be specified.
173+
KMS string `json:",omitempty"`
174+
171175
// Platform defines the cloud provider to use with the ops CLI, currently
172176
// supporting aws, azure, and gcp.
173177
Platform string `cloud:"platform" json:",omitempty"`

0 commit comments

Comments
 (0)