Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9c692ff
Updated buildspec.yml
jaydenaung Oct 25, 2020
d42f281
Updated buildspec.yml
jaydenaung Oct 25, 2020
d0cc654
Updated buildspec.yml
jaydenaung Oct 25, 2020
8e5b7fe
Updated buildspec.yml
jaydenaung Oct 25, 2020
da9a458
Updated buildspec.yml
jaydenaung Oct 25, 2020
c3b0be9
Updated buildspec.yml
jaydenaung Oct 25, 2020
f6450ce
Updated buildspec.yml
jaydenaung Oct 25, 2020
e482df1
Updated buildspec.yml
jaydenaung Oct 25, 2020
eacc2ec
Updated buildspec.yml
jaydenaung Oct 25, 2020
c2766bf
Updated buildspec.yml
jaydenaung Oct 25, 2020
0dee4df
Updated buildspec.yml
jaydenaung Oct 25, 2020
02d7e0d
Updated buildspec.yml
jaydenaung Oct 25, 2020
9544a48
Updated README.md
jaydenaung Oct 26, 2020
8c77f91
Updated README.md
jaydenaung Oct 26, 2020
a9f7217
Updated README.md
jaydenaung Oct 26, 2020
94ff0e1
Updated README.md
jaydenaung Oct 26, 2020
7f3362e
Updated README.md
jaydenaung Oct 26, 2020
47fc4e5
Updated README.md
jaydenaung Oct 26, 2020
6b16d4b
Updated README.md
jaydenaung Oct 26, 2020
bc385e4
Updated README.md
jaydenaung Oct 26, 2020
b488a5d
Updated README.md
jaydenaung Oct 26, 2020
1d51ad6
Updated README.md
jaydenaung Oct 26, 2020
46614dc
Updated README.md
jaydenaung Oct 26, 2020
3e34632
Updated README.md
jaydenaung Oct 26, 2020
7435912
Updated README.md
jaydenaung Oct 26, 2020
bc52398
Updated buildspec.yml and README.md
jaydenaung Nov 6, 2020
9fda8de
Added AWS Secrets Manager script and updated README.md
jaydenaung Mar 11, 2021
0a3963f
Added AWS Secrets Manager script and updated README.md
jaydenaung Mar 11, 2021
f941278
Added AWS Secrets Manager script and updated README.md
jaydenaung Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 165 additions & 51 deletions README.md

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ phases:
build:
commands:
- echo Downloading SHIFTLEFT
# UPDATE CLOUDGUARD API KEY
- export CHKP_CLOUDGUARD_ID=YOUR-CLOUDGUARD-ID
# UPDATE API SECRET
- export CHKP_CLOUDGUARD_SECRET=YOUR-SECRET

# You need to add get-parameter permission for CodeBuild role in order to access SSM parameters
- export CHKP_CLOUDGUARD_ID=$(aws ssm get-parameter --name "CHKP_CLOUDGUARD_ID" | jq -r '.Parameter.Value')
- export CHKP_CLOUDGUARD_SECRET=$(aws ssm get-parameter --name "CHKP_CLOUDGUARD_SECRET" | jq -r '.Parameter.Value')

- wget https://jaydenstaticwebsite.s3-ap-southeast-1.amazonaws.com/download/shiftleft
- chmod -R +x ./shiftleft
- echo Build started on `date`
Expand All @@ -33,17 +34,17 @@ phases:
- echo Saving Docker image
- docker save cyberave-docker -o Your-DOCKER-IAMGE.tar
# Start Scan
- echo Starting scan at `date`
- echo Starting scan on `date`
# UPDATE the saved tar file with your docker image name
- ./shiftleft image-scan -i Your-DOCKER-IAMGE.tar > result.txt || if [ "$?" = "6" ]; then exit 0; fi
- echo Scan finished at `date`
- echo Scan finished on `date`

post_build:
commands:
- echo Pushing image to repo
# UPDATE the following push command with the URI of your own ECR repository
- docker push ECR-URI-dkr.ecr.ap-southeast-1.amazonaws.com/YOUR-DOCKER-IAMGE:latest
- echo Build completed at `date`
- echo Build completed on `date`

artifacts:
files:
Expand Down
Binary file added img/SHIFTLEFT-AWS-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/codebuild-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/shiftleft-codepipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/ssm-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions my-codepipeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"pipeline": {
"name": "my-codepipeline",
"roleArn": "arn:aws:iam::YOUR-CODEPIPELINE-ROLE",
"artifactStore": {
"type": "S3",
"location": "CODEPIPELINE-ARTIFACTS-S3-BUCKET"
},
"stages": [
{
"name": "Source",
"actions": [
{
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeCommit",
"version": "1"
},
"runOrder": 1,
"configuration": {
"BranchName": "master",
"PollForSourceChanges": "false",
"RepositoryName": "YOUR-REPO"
},
"outputArtifacts": [
{
"name": "SourceArtifact"
}
],
"inputArtifacts": [],
"region": "YOUR-REGION",
"namespace": "SourceVariables"
}
]
},
{
"name": "Build",
"actions": [
{
"name": "Build",
"actionTypeId": {
"category": "Build",
"owner": "AWS",
"provider": "CodeBuild",
"version": "1"
},
"runOrder": 1,
"configuration": {
"ProjectName": "YOUR-PROJECT"
},
"outputArtifacts": [
{
"name": "BuildArtifact"
}
],
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"region": "ap-southeast-1",
"namespace": "BuildVariables"
}
]
}
]
}
}
48 changes: 48 additions & 0 deletions secretsmanager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Storing Credentials in AWS Secrets Manager

You can securely store CloudGuard API key and API secrets in AWS Secrets Manager in order to avoid embedding them in plain text. Codebuild can make API call and retrieve the API key and secrets when building scanning container image.

1. Create secrets in secret manager

Execute the following commands to create two secret strings called "CHKP_CLOUDGUARD_ID" and "CHKP_CLOUDGUARD_SECRET". Replace the value with CloudGuard API keys and secrets that you've generated on CloudGuard portal.

```bash
# Store CloudGuard API Key in Secrets Manager

aws secretsmanager create-secret --name CHKP_CLOUDGUARD_ID --secret-string abcd1234

# Store CloudGuard API Secret in AWS Secrets Manager

aws secretsmanager create-secret --name CHKP_CLOUDGUARD_SECRET --secret-string 67890xyz

```


2. Test retrieving the secret for the CloudGuard API key

Execute the following command;

```bash
aws secretsmanager get-secret-value --secret-id CHKP_CLOUDGUARD_ID | jq -r '.SecretString'
```

**Expected output**

```
abcd1234
```

3. Export variables in [buildspec.yml](buildspec.yml)

Then you'll need to export the commands in the [buildspec.yml](buildspec.yml) as variables. CloudGuard will use the API key and secrets stored in the AWS Secrets Manager when running assessments.

```
export CHKP_CLOUDGUARD_ID=$(aws secretsmanager get-secret-value --secret-id cloudguard-api-1 | jq -r '.SecretString')

export CHKP_CLOUDGUARD_SECRET=$(aws secretsmanager get-secret-value --secret-id cloudguard-api-secret | jq -r '.SecretString')

```
---
## Conclusion

Not storing any credentials in clear text is one of the DevSecOps best practices. When using CodeBuild, you can use either AWS SSM or Secrets Manager to store your credentials required by security scanning tools.