Skip to Content
コードとしてのポリシー
book

コードとしてのポリシー

by Jimmy Ray
March 2025
Intermediate to advanced
556 pages
9h 13m
Japanese
O'Reilly Media, Inc.
Audio summary available
Content preview from コードとしてのポリシー

第12章 PaCとTerraform IaC PaCとTerraform IaC

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

第11章では、IaCを使ったPaCを紹介した。その章では、主にAWS CloudFormationとTerraformを使ったAWSに焦点を当てた。しかし、TerraformはAWS以外でも使われており、よく管理されたセキュアなIaC実装の要件を満たすPaCツールは他にもある。

この章では、PaCの選択肢を広げながら、IaCのためのTerraformの使い方を引き続き見ていく。第11章と初期化するため、この章ではAWSの例から始める。その後、PaCソリューションを使ったGCPの例に移る。

まずは、HashiCorp Sentinelについて調べてみよう。

ハシコープセンチネル

第11章で、OPAがTerraformプランのJSON出力を評価するのに効果的であることを学んだだろう。この章の後半で説明するように、いくつかのIaCツールはOPAをサポートしている。しかし、HashiCorpはTerraform成果物を検証するために独自のPaC言語を開発した。

ドキュメントによると、HashiCorp Sentinelはプログラマにもノンプログラマにも使いやすいように設計されている。私は30年近くコードを書いているが、Sentinelの構文は理解しやすいと思う。例外はあるが、ほとんどの言語はシンプルな構文を持っている。例えば、私が書いたシンプルなHello Worldの例を:

# sentinel hello world
h = "Hello"
s = " "
w = "World"

func msg(m) {
  return m + w
}

main = rule {
  print(msg(h + s)) 
}

この方針がどのように評価されるかを理解するためには、まずセンチネルのグラウンド の規則をいくつか考えなければならない:

  1. ポリシーは規則、関数、変数、パラメータなどで構成される。

  2. すべてのポリシーは、少なくとも1つの規則、main 規則を持たなければならない。

  3. main 規則は、ブールを返すオペランドを少なくともひとつ持たなければならない。

  4. Trueはブール真、ゼロ、またはゼロ長のコレクションである。

  5. print のように、true を返す関数もある。

の先行コードをSentinel Playgroundで実行すると、次のような出力が得られた:

# sentinel hello world playground output
Sentinel Result: true

This result means that all Sentinel policies passed and the protected
behavior is allowed.

1 policies evaluated.

## Policy 1: policy.sentinel (advisory)

Result: true

Print messages:

Hello World

policy.sentinel:9:1 - Rule "main"
  Value:
    true

Sentinelプレイグラウンドは、第2章と 第11章で使ったRegoプレイグラウンドや、第8章のKyvernoプレイグラウンドに似ている。出力は、すべてのポリシーがパスし、評価された振る舞いが許可されたことを示している。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

クラウドアプリケーションアーキテクチャパターン

クラウドアプリケーションアーキテクチャパターン

Kyle Brown, Bobby Woolf, Joseph Yoder
初めてのGraphQL ―Webサービスを作って学ぶ新世代API

初めてのGraphQL ―Webサービスを作って学ぶ新世代API

Eve Porcello, Alex Banks, 尾崎 沙耶, あんどうやすし

Publisher Resources

ISBN: 9798341627093