Skip to content

Commit

Permalink
try trivy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryosuke Tomita committed Dec 16, 2023
1 parent baf8851 commit c5b353e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
- node:20
******


# ABOUT
Sample for DevSecOps environment.
If you need help or questions, plase contact [twitter](https://twitter.com/sigma5736394841), issues.
If you need help or questions, please contact [twitter](https://twitter.com/sigma5736394841), issues.
## AWS
- app-infrastructure-roles
![app-infrastructure-roles](./doc/fig/cfn/app-infrastructure-roles.png)
Expand Down Expand Up @@ -166,10 +167,14 @@ git secrets --register-aws # awsのクレデンシャル検知ルールを登録
# HOW TO USE
[PREPARING](#PREPARING)の設定後にはGitHubにコードをコミットしたり,pushするだけ。
1. [PREPARING](#PREPARING)の設定を先にやる。
2. commit時にはpre-commitとgit-secretが作動
3. push時にはGitHub ActionsによりSAST(semgrep),UnitTest(jest),Dependency Check(trivy)が実行される。
4. masterブランチにマージしたりmasterにpushした時にCodePipelineによってAWSへリポジトリがクローンされ,ビルド(image scanを含む),developmentへのデプロイが始まる。
5. developmentで問題がなければCodePipeline上で承認し,productionへデプロイ
******
# MEMO
## nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
- [ECSの仕様で非特権ユーザを使用したコンテナでは80番ポートが使えないっぽい](https://repost.aws/questions/QU1bCV9wT4T5iBrrP1c2ISfg/container-cannot-bind-to-port-80-running-as-non-root-user-on-ecs-fargate) --> つまり,localのdockerで80でサービスが起動できてもECSだと権限エラーになる。このため,コンテナで開放するportは8080としている(ALBに対して8080がマッピングされているためブラウザからは80でアクセスできる)。
> nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
14 changes: 9 additions & 5 deletions copilot/pipelines/react-app-pipeline/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ phases:
# Download the copilot linux binary.
- wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.32.0 -O copilot-linux
- chmod +x ./copilot-linux
# Download trivy.
- docker pull ghcr.io/aquasecurity/trivy:canary
build:
commands:
- echo "Run your tests"
Expand Down Expand Up @@ -48,11 +50,11 @@ phases:
for env in $pl_envs; do
tag=$(echo ${CODEBUILD_BUILD_ID##*:}-$env | sed 's/:/-/g' | rev | cut -c 1-128 | rev)
for svc in $svcs; do
./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
if [ $? -ne 0 ]; then
echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
exit 1;
fi
./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
if [ $? -ne 0 ]; then
echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
exit 1;
fi
done;
for job in $jobs; do
./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
Expand All @@ -63,6 +65,8 @@ phases:
done;
done;
- ls -lah ./infrastructure
# Run trivy scan on the docker images.
- docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/aquasecurity/trivy:canary --exit-code 1 --severity HIGH,CRITICAL --no-progress --format json -o ./trivy-results.json $(jq -r '.services[].image' ./infrastructure/manifest.json)
artifacts:
files:
- "infrastructure/*"
4 changes: 2 additions & 2 deletions docker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Author: Ryosuke Tomita
# Date: 2023/12/06
##########################################################################
docker rmi react-app:latest -f
#docker rmi react-app:latest -f
docker build -t react-app:latest . --no-cache
docker run -p 80:80 react-app:latest # -p containerport:localport
docker run --rm -p 8080:80 react-app:latest # -p containerport:localport

# open your browser and go to `localhost:80`.

0 comments on commit c5b353e

Please sign in to comment.