---
title: CI_CDでセキュリティとアジリティを高めるTerraform
tags: 
author: [小林拓磨](https://docswell.com/user/norit4ma)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/8JDLDQ137G.jpg?width=480
description: IaC Summit#2の登壇資料です https://finatext.connpass.com/event/337761/
published: November 25, 24
canonical: https://docswell.com/s/norit4ma/5YDM3P-terraform-ci-cd
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/8JDLDQ137G.jpg)

CI/CDでセキュリティとアジリティを高めるTerraform
IaC Summit #2
Kobayashi Takuma
© 2024 Finatext Holdings Ltd.


# Page. 2

![Page Image](https://bcdn.docswell.com/page/VEP2XLQPE8.jpg)

自己紹介
● 小林拓磨（X: @takuma5884rbb）
● 2023 (株)Finatext 入社
● ソフトウェア・AWSエンジニア
○ Go・AWSを用いた証券取引サービスの開発・運用
○ Terraformを用いたIaC
○ 新卒エンジニア採用
● 2024 Japan AWS Jr. Champions
● 趣味
○ 料理
○ ランニング
© 2024 Finatext Holdings Ltd.
1


# Page. 3

![Page Image](https://bcdn.docswell.com/page/27VDLQ5V7Q.jpg)

Speaker’s background
● DevOpsエンジニア
● メインのスキルはバックエンド
○ 要するにアプリケーション寄り
● AWS学習のかなり早い段階でIaCに触れていました
© 2024 Finatext Holdings Ltd.
2


# Page. 4

![Page Image](https://bcdn.docswell.com/page/5JGYXW61JL.jpg)

振り返り：Terraformとは？
データ記述言語からクラウドリソースを管理するIaCツール
データ記述言語を用いてインフラの
プロパティを記述
記述を元にクラウドプロバイダの
APIをラップし、リソースのCRUDを
行う
© 2024 Finatext Holdings Ltd.
3


# Page. 5

![Page Image](https://bcdn.docswell.com/page/47QM834NEP.jpg)

振り返り：Terraformとは？
設定ファイルのほうな書き心地
● Hashicorp Conﬁguration Language（HCL）という独自言語を採用
リソースを記述するブロック
各種プロパティ
© 2024 Finatext Holdings Ltd.
4


# Page. 6

![Page Image](https://bcdn.docswell.com/page/KE4V21Q371.jpg)

CI/CD
リソースの更新を自動化する仕組み
● Continuous Integration(CI)
○ コード変更の度に、ビルドやテストが実行される仕組み
● Continuous Delivery(CD)
○ コード変更の度に、自動的に実稼働環境へのリリース準備が実行される仕組み
© 2024 Finatext Holdings Ltd.
5


# Page. 7

![Page Image](https://bcdn.docswell.com/page/L713MGPZEG.jpg)

Atlantis
Pull RequestからTerraformのワークフローを動かすためのツール
● Pull Requestのコメントをトリガーに
Terraformのコマンドを実行
https://www.runatlantis.io/
call webhook
make Pull Request
create resources
AWS Cloud
IAM Role for Atlantis
engineers
GitHub
Atlantis on
Amazon ECS
© 2024 Finatext Holdings Ltd.
AWS Account
6


# Page. 8

![Page Image](https://bcdn.docswell.com/page/G7WP3K26E2.jpg)

GitHubからの利用例
© 2024 Finatext Holdings Ltd.
7


# Page. 9

![Page Image](https://bcdn.docswell.com/page/4JZKVZDRJ3.jpg)

Atlantisを用いたCDのメリット
ソフトウェア開発と同様のサイクルでレビュー・適用
アプリ・インフラを統一されたフローでデプロイ可能
インフラ運用についても
品質・アジリティを担保できる
無理なくDevOpsを実施
© 2024 Finatext Holdings Ltd.
8


# Page. 10

![Page Image](https://bcdn.docswell.com/page/YE6Q5Z11EV.jpg)

conftest
静的解析によるコードポリシーチェック
● DevSecOps
○ DevOps×Security
○ コードの脆弱性や設定不備・セキュリティーホールを自動検知
© 2024 Finatext Holdings Ltd.
9


# Page. 11

![Page Image](https://bcdn.docswell.com/page/GE5RYW4LJ4.jpg)

conftest
コード例/ALBのアクセスログ設定の必須化
● Bullet Point
○ Sub Bullet
© 2024 Finatext Holdings Ltd.
10


# Page. 12

![Page Image](https://bcdn.docswell.com/page/972DGQV37R.jpg)

conftest
コード例/ALBのアクセスログ設定の必須化
● Bullet Point
○ Sub Bullet
© 2024 Finatext Holdings Ltd.
11


# Page. 13

![Page Image](https://bcdn.docswell.com/page/DJY2VW38JM.jpg)

conftest
コード例/Parameter StoreのSecret Value
● with_decriptionをfalseにしておかないと、stateファイル（Terrafromがリソー
スの状態を記述し管理するファイル）に機微情報が平文で出力されてしまう
○ default true(!)
○ パラメータの中身は知る必要がないので、暗号化したまま参照すれば十分
© 2024 Finatext Holdings Ltd.
12


# Page. 14

![Page Image](https://bcdn.docswell.com/page/V7N8M9V9E8.jpg)

conftest
Atlantisからの利用
● CDの中でリソースのdiﬀに対しチェックをかけてくれる
○ https://www.runatlantis.io/docs/policy-checking.html#pulling-policies-fro
m-a-remote-location
○ S3などにポリシーを配置し参照することも可能
■ マルチアカウント運用でも安心！
© 2024 Finatext Holdings Ltd.
13


# Page. 15

![Page Image](https://bcdn.docswell.com/page/YJ9KN263J3.jpg)

tfsec
静的解析のエンジンだけでなく、ポリシーも提供してくれるOSSたち
● Trivy
○ https://trivy.dev/v0.47/tutorials/misconﬁguration/terraform/
● Semgrep
○ https://semgrep.dev
● 集合知を利用することで、手軽に質の高いセキュリティーチェックが可能
○ 自分たちが本当にやりたいチェックと必ずしも合致しないので、棚卸しや絞り込み
は必要
© 2024 Finatext Holdings Ltd.
14


# Page. 16

![Page Image](https://bcdn.docswell.com/page/GJ8RK5ZL7D.jpg)

まとめ
● IaCを用いることで、インフラもアプリケーションと同じようにCI/CDを適用でき
る
○ Pull Requestを媒介したレビュー・コマンドによる安全なデプロイ
○ 静的解析で設定漏れを検知
セキュリティーとアジリティを両立させた開発が可能！
© 2024 Finatext Holdings Ltd.
15


# Page. 17

![Page Image](https://bcdn.docswell.com/page/LJLKZYDQ7R.jpg)



# Page. 18

![Page Image](https://bcdn.docswell.com/page/47M2VNWK7W.jpg)

参考文献
● Finatextによる セキュリティとアジリティを両立する為の秘訣
● Conftestを用いたCIでのポリシーチェックの紹介 | メルカリエンジニアリング
© 2024 Finatext Holdings Ltd.
17


