Skip to content

Commit

Permalink
fix: aws registry encryptionConfiguration to be applied
Browse files Browse the repository at this point in the history
fixes #598
  • Loading branch information
almoelda committed Oct 27, 2024
1 parent 39189bc commit c468c3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ImageScanningConfiguration struct {
}

type EncryptionConfiguration struct {
EncryptionType string `yaml:"encryptionType"`
EncryptionType string `yaml:"encryptionType" validate:"oneof=KMS AWS256"`
KmsKey string `yaml:"kmsKey"`
}

Expand Down Expand Up @@ -140,6 +140,9 @@ func CheckRegistryConfiguration(r Registry) error {
if r.AWS.AccountID == "" {
return errorWithType(`requires a field "accountdId"`)
}
if r.AWS.ECROptions.EncryptionConfiguration.EncryptionType == "KMS" && r.AWS.ECROptions.EncryptionConfiguration.KmsKey == "" {
return errorWithType(`requires a field "kmsKey" if encryptionType is set to "KMS"`)
}
case types.RegistryGCP:
if r.GCP.Location == "" {
return errorWithType(`requires a field "location"`)
Expand All @@ -160,4 +163,5 @@ func SetViperDefaults(v *viper.Viper) {
v.SetDefault("Target.Type", "aws")
v.SetDefault("Target.AWS.ECROptions.ImageScanningConfiguration.ImageScanOnPush", true)
v.SetDefault("Target.AWS.ECROptions.ImageTagMutability", "MUTABLE")
v.SetDefault("Target.AWS.ECROptions.EncryptionConfiguration.EncryptionType", "AES256")
}
11 changes: 10 additions & 1 deletion pkg/registry/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ func (e *ECRClient) CreateRepository(ctx context.Context, name string) error {

log.Ctx(ctx).Debug().Str("repository", name).Msg("create repository")

encryptionConfiguration := &ecr.EncryptionConfiguration{
EncryptionType: aws.String(e.options.EncryptionConfiguration.EncryptionType),
}

if e.options.EncryptionConfiguration.EncryptionType == "KMS" {
encryptionConfiguration.KmsKey = aws.String(e.options.EncryptionConfiguration.KmsKey)
}

_, err := e.client.CreateRepositoryWithContext(ctx, &ecr.CreateRepositoryInput{
RepositoryName: aws.String(name),
RepositoryName: aws.String(name),
EncryptionConfiguration: encryptionConfiguration,
ImageScanningConfiguration: &ecr.ImageScanningConfiguration{
ScanOnPush: aws.Bool(e.options.ImageScanningConfiguration.ImageScanOnPush),
},
Expand Down

0 comments on commit c468c3e

Please sign in to comment.