Skip to content

Commit fb91802

Browse files
brivufruit
andauthored
feat: repository encryption parameter (#289)
* feat: Adds params to control repo encryption during repo creation (#284) * chore: code cleanup * fix: extra "<" in parameters (#287) * feat: Adds params to control repo encryption during repo creation * fix: extra "<" in parameters --------- Co-authored-by: Brian Vu <[email protected]> * chore: update aws_domain description * chore: update aws_domain description * refactor: add env subst * fix: remove duplicate expansion * fix: address pr issues * chore: rename parameters --------- Co-authored-by: Ilya Sabelnikov <[email protected]>
1 parent dbc2ccb commit fb91802

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

src/commands/build_and_push_image.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ parameters:
192192
provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
193193
type: steps
194194

195+
repo_encryption_type:
196+
type: enum
197+
description: The encryption type to use.
198+
default: "AES256"
199+
enum: ["AES256", "KMS"]
200+
201+
repo_encryption_kms_key:
202+
type: string
203+
description: >
204+
If you use the KMS encryption type, specify the KMS key to use for encryption.
205+
The alias, key ID, or full ARN of the KMS key can be specified.
206+
default: ""
207+
195208
steps:
196209
- when:
197210
condition: <<parameters.checkout>>
@@ -230,6 +243,8 @@ steps:
230243
repo: <<parameters.repo>>
231244
repo_scan_on_push: <<parameters.repo_scan_on_push>>
232245
public_registry: <<parameters.public_registry>>
246+
repo_encryption_type: <<parameters.repo_encryption_type>>
247+
encryption_kms_key: <<parameters.repo_encryption_kms_key>>
233248
- when:
234249
condition: <<parameters.set_repo_policy>>
235250
steps:

src/commands/create_repo.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ parameters:
2828
description: Set to true if building and pushing an image to a Public Registry on ECR.
2929
default: false
3030

31+
repo_encryption_type:
32+
type: enum
33+
description: The encryption type to use.
34+
default: "AES256"
35+
enum: ["AES256", "KMS"]
36+
37+
encryption_kms_key:
38+
type: string
39+
description: >
40+
If you use the KMS encryption type, specify the KMS key to use for encryption.
41+
The alias, key ID, or full ARN of the KMS key can be specified.
42+
default: ""
43+
3144
steps:
3245
- run:
3346
name: Create Repository
@@ -37,4 +50,6 @@ steps:
3750
ORB_STR_REPO: <<parameters.repo>>
3851
ORB_BOOL_REPO_SCAN_ON_PUSH: <<parameters.repo_scan_on_push>>
3952
ORB_BOOL_PUBLIC_REGISTRY: <<parameters.public_registry>>
53+
ORB_ENUM_ENCRYPTION_TYPE: <<parameters.repo_encryption_type>>
54+
ORB_STR_ENCRYPTION_KMS_KEY: <<parameters.encryption_kms_key>>
4055
command: <<include(scripts/create_repo.sh)>>

src/examples/simple_build_and_push.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ usage:
8383

8484
# requires `set_repo_policy: true`, pass in a file with the repo permissions policy
8585
repo_policy_path: repo-policy.json
86+
87+
# Switches the default encryption AES256 to KMS
88+
repo_encryption_type: KMS
89+
90+
# Specifies ARN of KMS key
91+
repo_encryption_kms_key: arn:aws:kms::123456789012:key/UUID4_OF_KMS_KEY_ID

src/jobs/build_and_push_image.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,26 @@ parameters:
189189
provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
190190
type: steps
191191

192+
repo_encryption_type:
193+
type: enum
194+
description: The encryption type to use.
195+
default: "AES256"
196+
enum: ["AES256", "KMS"]
197+
198+
repo_encryption_kms_key:
199+
type: string
200+
description: >
201+
If you use the KMS encryption type, specify the KMS key to use for encryption.
202+
The alias, key ID, or full ARN of the KMS key can be specified.
203+
default: ""
204+
192205
aws_domain:
193206
type: string
194207
default: "amazonaws.com"
195208
description: >
196-
AWS domain, China regions will require override.
209+
The AWS domain for your region, e.g in China, the AWS domain is amazonaws.com.cn
210+
The default value is amazonaws.com
211+
197212
198213
steps:
199214
- build_and_push_image:
@@ -227,4 +242,6 @@ steps:
227242
repo_policy_path: <<parameters.repo_policy_path>>
228243
build_path: <<parameters.build_path>>
229244
auth: <<parameters.auth>>
245+
repo_encryption_type: <<parameters.repo_encryption_type>>
246+
repo_encryption_kms_key: <<parameters.repo_encryption_kms_key>>
230247
aws_domain: <<parameters.aws_domain>>

src/scripts/create_repo.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
ORB_STR_REGION="$(circleci env subst "${ORB_STR_REGION}")"
33
ORB_STR_REPO="$(circleci env subst "${ORB_STR_REPO}")"
44
ORB_STR_PROFILE_NAME="$(circleci env subst "${ORB_STR_PROFILE_NAME}")"
5+
ORB_STR_ENCRYPTION_KMS_KEY="$(circleci env subst "${ORB_STR_ENCRYPTION_KMS_KEY}")"
56

67
if [ "$ORB_BOOL_PUBLIC_REGISTRY" == "1" ]; then
78
aws ecr-public describe-repositories --profile "${ORB_STR_PROFILE_NAME}" --region us-east-1 --repository-names "${ORB_STR_REPO}" >/dev/null 2>&1 ||
89
aws ecr-public create-repository --profile "${ORB_STR_PROFILE_NAME}" --region us-east-1 --repository-name "${ORB_STR_REPO}"
910
else
10-
aws ecr describe-repositories --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_STR_REGION}" --repository-names "${ORB_STR_REPO}" >/dev/null 2>&1 ||
11-
if [ "$ORB_BOOL_REPO_SCAN_ON_PUSH" == "1" ]; then
12-
aws ecr create-repository --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_STR_REGION}" --repository-name "${ORB_STR_REPO}" --image-scanning-configuration scanOnPush=true
13-
else
14-
aws ecr create-repository --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_STR_REGION}" --repository-name "${ORB_STR_REPO}" --image-scanning-configuration scanOnPush=false
15-
fi
11+
12+
IMAGE_SCANNING_CONFIGURATION="scanOnPush=true"
13+
if [ "$ORB_BOOL_REPO_SCAN_ON_PUSH" -ne "1" ]; then
14+
IMAGE_SCANNING_CONFIGURATION="scanOnPush=false"
15+
fi
16+
17+
ENCRYPTION_CONFIGURATION="encryptionType=${ORB_ENUM_ENCRYPTION_TYPE}"
18+
if [ "$ORB_ENUM_ENCRYPTION_TYPE" == "KMS" ]; then
19+
ENCRYPTION_CONFIGURATION+=",kmsKey=${ORB_STR_ENCRYPTION_KMS_KEY}"
20+
fi
21+
22+
aws ecr describe-repositories \
23+
--profile "${ORB_STR_PROFILE_NAME}" \
24+
--region "${ORB_STR_REGION}" \
25+
--repository-names "${ORB_STR_REPO}" >/dev/null 2>&1 ||
26+
aws ecr create-repository \
27+
--profile "${ORB_STR_PROFILE_NAME}" \
28+
--region "${ORB_STR_REGION}" \
29+
--repository-name "${ORB_STR_REPO}" \
30+
--image-scanning-configuration "${IMAGE_SCANNING_CONFIGURATION}" \
31+
--encryption-configuration "${ENCRYPTION_CONFIGURATION}"
1632
fi

0 commit comments

Comments
 (0)