Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .templatesyncignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
:!docs/secret-manager.ja.md
:!docs/webapp-policy.md
:!docs/webapp-policy.ja.md
:!docs/governance.md
:!docs/governance.ja.md

# Scripts
:!scripts/init.sh
Expand Down
101 changes: 101 additions & 0 deletions docs/governance.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Governance ガイド

[English](governance.md)

**Fleet が提供する統制手段**と、その組み合わせ例のカタログです。CI-only
モードの必須要件(そのモードの前提条件 —
[secret-manager.ja.md](secret-manager.ja.md#ci-only-モード-必須要件) 参照)
を除き、ここに「必須」「すべき」はありません。各組織が自分のポリシーに
合わせて選びます。

## 1. 統制手段一覧(Fleet が提供するもの)

| 統制手段 | 何を制御するか | 参照 |
| --- | --- | --- |
| **CI-only デプロイ ID モード** | 共有デプロイトークンを読める主体を CD の deploy 環境ジョブに限定(GitHub: `workflow_run` 起動の `main` 上 `cd.yml`、GitLab: 保護 ref)。必須要件: WIF attribute condition / deployment branch policy / org 全体のブランチ保護 / WIF 必須。 | [secret-manager.ja.md — デプロイ ID の運用モード](secret-manager.ja.md#デプロイ-id-の運用モード-ci-only--permissive) |
| **個人 sandbox** | 共有 ID を使わない手元 clasp 開発。CI-only モードでも開発者の日常は変わらない。 | README「個人 Sandbox」、`scripts/init-sandbox.sh` |
| **Web App 公開範囲ポリシーゲート** | `appsscript.json` の web app `access` / `executeAs` をデプロイ直前に組織の上限と照合。例外は org 管理者のみ編集できる custom property で付与。 | [webapp-policy.ja.md](webapp-policy.ja.md) |
| **environment 保護オプション** | `production` / `development` の required reviewers・prevent self-review・deployment branch policy を初期化時に設定。 | `scripts/init.sh --production-reviewers/--development-reviewers/--prevent-self-review/--branch-policy`、`scripts/configure-environments.sh` |
| **台帳生成** | custom properties と各リポの `appsscript.json` から、公開範囲の例外と実際のマニフェスト値の一覧を出力。 | [下記の例](#台帳生成の例) |

## 2. 組み合わせ例

いずれも例示であり、推奨ではありません。

- **小規模・信頼ベース**: Permissive モードのみ。テンプレのデフォルト
(`deploy:prod` スクリプト無し、environment 経由の CD)がそのまま効きます。
- **監査重視**: CI-only モード + 個人 sandbox。production の変更はすべて
レビュー済みマージになり、共有トークンは CI の外に出ません。
- **外部公開を扱う**: 上記 + ポリシーゲート(org 全体に
`WEBAPP_ACCESS_POLICY=DOMAIN`、例外は custom property
`webapp-access-allow`)+ `init.sh` の `--production-reviewers` と
`--prevent-self-review`。

## 3. GitHub / GitLab 側の機能(各一行)

- **GitHub org ルールセット** — `dev` / `main` のブランチ保護と CODEOWNERS
レビュー必須を org 全体で強制。custom property でリポを絞り込めます。
[公式ドキュメント](https://docs.github.com/en/organizations/managing-organization-settings/managing-rulesets-for-repositories-in-your-organization)
- **CODEOWNERS** — 特定ファイルの変更に指名チームのレビューを要求。例:
`/appsscript.json @your-org/script-admins`。
[公式ドキュメント](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)
- **GitLab protected branches** — group レベルの MR 必須保護。
[公式ドキュメント](https://docs.gitlab.com/ee/user/project/repository/branches/protected.html)
- **GitLab protected environments** — environment ごとのデプロイ承認ルール。
[公式ドキュメント](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
- **GitLab compliance pipelines** — プロジェクトメンバーが上書きできない
group 強制ジョブ。GitLab でポリシーゲートを強制力のある形にする置き場所。
[公式ドキュメント](https://docs.gitlab.com/ee/user/group/compliance_pipelines.html)

## 4. 組織ごとに決めること

このガイドでは意図的に値を決めません:

- 公開範囲の例外を誰が承認するか(= custom property `webapp-access-allow` /
group の allowlist 変数を編集できる人)
- production デプロイの承認者(environment の required reviewers)
- 管理者の冗長性 — 1人が不在でも承認とローテーションが止まらないか
- 台帳の出力先と閲覧者、既存の申請・承認フローとの関係

## 5. その他の指針(現行どおり)

- **executeAs**: 社内向け web app は極力 `USER_ACCESSING`。
`USER_DEPLOYING` は本当に必要なものに限定します(危険な組み合わせは
ポリシーゲートが警告 — [webapp-policy.ja.md](webapp-policy.ja.md) 参照)。
- **ログ**: `clasp logs` ではなく GCP プロジェクト紐付けによる Cloud
Logging を使います。開発者に必要なのは中央プロジェクトの閲覧 IAM だけで、
スクリプトへのアクセス権は不要です。

## 台帳生成の例

例示です — 名前や出力先は環境に合わせて調整してください。フリート各リポの
公開範囲 custom property と、デフォルトブランチ上の実際のマニフェスト値を
一覧します(GitHub):

```bash
ORG=your-org
printf 'repo\tpolicy-prop\tallow-prop\tmanifest-access\tmanifest-executeAs\n'
gh api --paginate "orgs/${ORG}/properties/values" --jq '
.[] | [
.repository_name,
((.properties[] | select(.property_name == "webapp-access-policy") | .value) // "-"),
((.properties[] | select(.property_name == "webapp-access-allow") | .value) // "-")
] | @tsv' |
while IFS=$'\t' read -r repo policy allow; do
manifest=$(gh api "repos/${ORG}/${repo}/contents/appsscript.json" --jq .content 2>/dev/null | base64 -d) || manifest='{}'
fields=$(node -e '
let m = {};
try { m = JSON.parse(require("fs").readFileSync(0, "utf8")); } catch {}
process.stdout.write(`${m.webapp?.access ?? ""}\t${m.webapp?.executeAs ?? ""}`);
' <<<"$manifest")
printf '%s\t%s\t%s\t%s\n' "$repo" "$policy" "$allow" "$fields"
done
```

GitLab では group のプロジェクトを列挙し(`glab api "groups/<id>/projects"`)、
各リポの `appsscript.json` を repository files API から読み、許可値は custom
property の代わりに group 変数 `WEBAPP_ACCESS_ALLOWLIST` から取ります。

台帳が読むのは**コミットされた**マニフェストです。実際にデプロイされるのは
ビルド後の `dist/appsscript.json` で、そちらは CD のゲートが検査します。
台帳は棚卸し、ゲートが統制、と使い分けてください。
106 changes: 106 additions & 0 deletions docs/governance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Governance Guide

[日本語](governance.ja.md)

A catalog of the **controls the fleet provides** and example ways to combine
them. Apart from the CI-only mode's required controls (prerequisites of that
mode, see
[secret-manager.md](secret-manager.md#ci-only-mode-required-controls)),
nothing here is prescriptive: each organization picks what matches its own
policy.

## 1. Controls the fleet provides

| Control | What it governs | Reference |
| --- | --- | --- |
| **CI-only deploy identity mode** | Who can read the shared deploy token: only CD deploy-environment jobs (GitHub: `cd.yml` on `main` started via `workflow_run`; GitLab: protected refs). Required controls: WIF attribute condition, deployment branch policies, org-wide branch protection, WIF itself. | [secret-manager.md — Deploy Identity Modes](secret-manager.md#deploy-identity-modes-ci-only-vs-permissive) |
| **Personal sandbox** | Local clasp development without the shared identity, so CI-only mode costs developers nothing day to day. | README "Personal Sandbox", `scripts/init-sandbox.sh` |
| **Web App exposure policy gate** | `appsscript.json` web-app `access` / `executeAs` checked against an org ceiling right before deploy; exceptions live in org-admin-only custom properties. | [webapp-policy.md](webapp-policy.md) |
| **Environment protection options** | Required reviewers and prevent-self-review on `production` / `development`, plus deployment branch policies, set at init time. | `scripts/init.sh --production-reviewers/--development-reviewers/--prevent-self-review/--branch-policy`, `scripts/configure-environments.sh` |
| **Fleet ledger** | A listing of each repo's exposure policy exception and actual manifest values, generated from custom properties + `appsscript.json`. | [Example below](#ledger-generation-example) |

## 2. Combination examples

Examples, not recommendations.

- **Small team, trust-based**: Permissive mode, nothing else. The template's
defaults (no `deploy:prod` script, CD through environments) already apply.
- **Audit-focused**: CI-only mode + personal sandboxes. Every production
change is a reviewed merge; the shared token never leaves CI.
- **Handles external exposure**: the above + the Web App policy gate
(`WEBAPP_ACCESS_POLICY=DOMAIN` org-wide, exceptions via the
`webapp-access-allow` custom property) + `init.sh` with
`--production-reviewers` and `--prevent-self-review`.

## 3. Platform features (one line each)

- **GitHub org rulesets** — org-wide branch protection for `dev` / `main` and
required CODEOWNERS review; can target repos by custom property.
[Docs](https://docs.github.com/en/organizations/managing-organization-settings/managing-rulesets-for-repositories-in-your-organization)
- **CODEOWNERS** — require a named team's review for specific files, e.g.
`/appsscript.json @your-org/script-admins`.
[Docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)
- **GitLab protected branches** — group-level merge-request-required
protection. [Docs](https://docs.gitlab.com/ee/user/project/repository/branches/protected.html)
- **GitLab protected environments** — deploy-approval rules per environment.
[Docs](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
- **GitLab compliance pipelines** — group-enforced jobs that project members
cannot override; the enforcement-grade home for the policy gate on GitLab.
[Docs](https://docs.gitlab.com/ee/user/group/compliance_pipelines.html)

## 4. Decisions each organization must make

This guide deliberately does not pick values for these:

- Who approves Web App exposure exceptions (= who can edit the
`webapp-access-allow` custom property / group allowlist variable).
- Who reviews production deployments (environment required reviewers).
- Admin redundancy — can approvals and rotations proceed when one admin is
unavailable?
- Where the ledger output goes, who reads it, and how it relates to any
existing request/approval workflow.

## 5. Other guidance (unchanged template defaults)

- **executeAs**: prefer `USER_ACCESSING` for internal web apps; reserve
`USER_DEPLOYING` for the cases that genuinely need it (the policy gate
warns on risky combinations — see
[webapp-policy.md](webapp-policy.md)).
- **Logs**: use Cloud Logging via the GCP project binding instead of
`clasp logs`; developers need only viewer IAM on the central project, not
script access.

## Ledger generation example

Illustrative only — adapt names and output to your environment. Lists, per
fleet repo, the exposure-policy custom properties and the actual manifest
values on the default branch (GitHub):

```bash
ORG=your-org
printf 'repo\tpolicy-prop\tallow-prop\tmanifest-access\tmanifest-executeAs\n'
gh api --paginate "orgs/${ORG}/properties/values" --jq '
.[] | [
.repository_name,
((.properties[] | select(.property_name == "webapp-access-policy") | .value) // "-"),
((.properties[] | select(.property_name == "webapp-access-allow") | .value) // "-")
] | @tsv' |
while IFS=$'\t' read -r repo policy allow; do
manifest=$(gh api "repos/${ORG}/${repo}/contents/appsscript.json" --jq .content 2>/dev/null | base64 -d) || manifest='{}'
fields=$(node -e '
let m = {};
try { m = JSON.parse(require("fs").readFileSync(0, "utf8")); } catch {}
process.stdout.write(`${m.webapp?.access ?? ""}\t${m.webapp?.executeAs ?? ""}`);
' <<<"$manifest")
printf '%s\t%s\t%s\t%s\n' "$repo" "$policy" "$allow" "$fields"
done
```

On GitLab, iterate the group's projects (`glab api "groups/<id>/projects"`),
read each `appsscript.json` from the repository files API, and take the
allowlist from the group variable `WEBAPP_ACCESS_ALLOWLIST` instead of custom
properties.

Note the ledger reads the **committed** manifest; what actually deploys is the
built `dist/appsscript.json`, which the CD gate checks. Treat the ledger as an
inventory, the gate as the control.
Loading