privacy-by-design-rails について
privacy-by-design-railsは、個人データを扱うRails 8開発者向けのスキルです。スキャナーと参考資料を通じて、データ最小化、暗号化、ログ保護、同意管理、データ主体の請求などのプライバシー対策を案内します。
主な機能
- 01個人データを扱うファイルのスキャン
- 02Railsのプライバシー参考資料
- 03暗号化と鍵ローテーションの解説
- 04ログやエラー報告のマスキング案内
- 05同意とデータ保持の手順
活用シーン
- 01個人データを扱うRailsコードのレビュー
- 02Railsアプリのログマスキング計画
- 03同意管理とデータ主体の請求の実装
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ codeminer42/ skills --skill privacy-by-design-railsインストール後、Claude Code で/privacy-by-design-railsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/anonymization.mdconsent-management.mddata-minimization.mddata-retention.mddsar.mdencryption.mdlog-and-output-protection.mdpii-definition.mdpseudonymization.mdsecrets-management.mdsession-security.mdrules/consent-use-purposes-constant.mdemail-no-pii-in-body.mdencrypt-filter-parameters.mdencrypt-pii-fields.mdexport-dsar-vs-processing.mdexport-no-pii-at-rest.mdlog-no-job-arguments.mdlog-no-pii-in-cache.mdlog-pass-ids-not-data.mdscripts/rules/base_rule.rbconsent_use_purposes_constant.rbemail_no_pii_in_body.rbencrypt_filter_parameters.rbencrypt_pii_fields.rberror_reporter_scrubbing.rbexport_dsar_vs_processing.rbexport_no_pii_at_rest.rblog_no_job_arguments.rblog_no_pii_in_cache.rb詳細
Rails 8 によるプライバシー・バイ・デザイン
個人データを扱うコードを生成またはレビューする際は、まずスキャナーを実行してください:
ruby .claude/skills/privacy-by-design-rails/scripts/scanner.rb --files <relevant files>
トピックについて詳しく知りたい場合は、references/ にある関連するリファレンスファイルを読んでください。
PII に該当するものとは? 人を直接または間接的に特定できるあらゆるデータです(GDPR Art. 4、LGPD Art. 5、NIST SP 800-122)。単独では個人を特定できなくても、人と結び付けられると PII になるデータも含まれます。農場名、既知の所有者がいる動物の名前、ナンバープレート、車両の VIN、学生 ID、物件の住所、ソーシャルメディアのハンドル名、個人事業主の会社名、アカウントに関連付けられたデバイス ID、IP アドレスなどです。詳細な定義と関連付け可能性の判定については、references/pii-definition.md を参照してください。判断に迷った場合は、PII として扱ってください。
クイックリファレンス
| 原則 | Rails の機能 | ファイル |
|---|---|---|
| ログとインスペクションのフィルタリング | config.filter_parameters(両方を対象) | references/log-and-output-protection.md |
| モデルごとの PII 宣言 | self.filter_attributes(自己文書化) | references/log-and-output-protection.md |
| ジョブ引数の保護(ActiveJob) | self.log_arguments = false(ApplicationJob で設定) | references/log-and-output-protection.md |
| ジョブ引数の保護(Sidekiq) | サーバーミドルウェア + ID のみを渡す | references/log-and-output-protection.md |
| ログ内の PII のマスキング | logstop gem | references/log-and-output-protection.md |
| IP アドレスの匿名化 | ip_anonymizer ミドルウェア | references/log-and-output-protection.md |
| エラーレポーターのサニタイズ | Sentry/Rollbar などから PII を除去 | references/log-and-output-protection.md |
| APM/モニタリングのサニタイズ | AppSignal/NewRelic などから PII を除去 | references/log-and-output-protection.md |
| データの最小化 | Strong Parameters + シリアライザー | references/data-minimization.md |
| 検索可能な暗号化 | encrypts :field, deterministic: true | references/encryption.md |
| 検索不可能な暗号化 | encrypts :field | references/encryption.md |
| パスワードのハッシュ化 | has_secure_password | references/encryption.md |
| キーのローテーション | encrypts :field, previous: [...] | references/encryption.md |
| シークレット管理 | bin/rails credentials:edit | references/secrets-management.md |
| セキュリティ監査 | bundler-audit、Brakeman、pdscan | references/secrets-management.md |
| HTTPS の強制 | config.force_ssl = true + HSTS | references/session-security.md |
| セッションのセキュリティ | 署名付き Cookie/Bearer トークン | references/session-security.md |
| 同意の管理 | 変更不可の追記専用監査証跡 | references/consent-management.md |
| 同意の適用 | アクションを制御するコントローラー Concern | references/consent-management.md |
| 同意を条件とするエクスポート | 処理に ConsentGatedExportSerializer を使用 | references/consent-management.md |
| 匿名化 | PII を [ANONYMIZED] に置き換える | references/anonymization.md |
| 仮名化 | 分析上の関連性を維持する HMAC ハッシュ | references/pseudonymization.md |
| DSAR ワークフロー | アクセス/訂正/消去 | references/dsar.md |
| データ保持 | Solid Queue のスケジュール済みジョブ | references/data-retention.md |
すべてを組み合わせる — User モデル
class User < ApplicationRecord
has_secure_password
has_many :sessions, dependent: :destroy
has_many :addresses, dependent: :destroy
has_many :orders, dependent: :restrict_with_error
has_many :consents, dependent: :destroy
has_many :data_subject_requests, dependent: :destroy
include Anonymizable
include Pseudonymizable
include DataExportable
include HasConsent
encrypts :email_address, deterministic: true, downcase: true
encrypts :first_name
encrypts :last_name
encrypts :phone
encrypts :date_of_birth
self.filter_attributes = %i[
first_name last_name phone date_of_birth
email_address password_digest
]
enum :role, { customer: 0, admin: 1 }
anonymizable :first_name, :last_name, :phone, :date_of_birth
exportable :uuid, :email_address, :first_name, :last_name, :phone, :date_of_birth
normalizes :email_address, with: ->(e) { e.strip.downcase }
end
よくある間違い(スキャナーでは検出されません)
| 間違い | 修正 |
|---|---|
| 消去権への対応として、依存レコードがあるレコードを削除する | 依存レコードがある場合は匿名化を優先してください。参照整合性を維持できます。一部の当局は完全削除を推奨しているため、地域の要件を確認してください |
| 同意をブール値のフラグとして保存する | 監査証跡には変更不可の追記専用レコードを使用してください |
| API で連番 ID を公開する | 公開識別子には UUID を使用してください |
| データ保持を手動で行う | Solid Queue のスケジュール済みジョブで自動化してください |
外部リファレンス
最新のガイダンスを確認したり、公式情報源と照らし合わせてパターンを検証したりする際に参照してください。必要に応じて WebFetch を使用してください。すべてを最初から取得する必要はありません。
Rails
- Active Record Encryption: https://guides.rubyonrails.org/active_record_encryption.html
- Active Record Encryption API: https://api.rubyonrails.org/classes/ActiveRecord/Encryption.html
- Rails アプリケーションのセキュリティ対策: https://guides.rubyonrails.org/security.html
- Active Job の基本(ログ記録): https://guides.rubyonrails.org/active_job_basics.html
- Rails Credentials: https://guides.rubyonrails.org/security.html#custom-credentials
GDPR
- 第 5 条 — 原則(データの最小化、目的の制限): https://gdpr-info.eu/art-5-gdpr/
- 第 6 条 — データ処理の適法性: https://gdpr-info.eu/art-6-gdpr/
- 第 7 条 — 同意の条件: https://gdpr-info.eu/art-7-gdpr/
- 第 15 条 — アクセス権: https://gdpr-info.eu/art-15-gdpr/
- 第 16 条 — 訂正権: https://gdpr-info.eu/art-16-gdpr/
- 第 17 条 — 消去権: https://gdpr-info.eu/art-17-gdpr/
- 第 25 条 — 設計およびデフォルトによるデータ保護: https://gdpr-info.eu/art-25-gdpr/
- 第 32 条 — データ処理のセキュリティ: https://gdpr-info.eu/art-32-gdpr/
LGPD(ブラジル)
- 全文(英語): https://lgpd-brazil.info
- 第 18 条 — データ主体の権利: https://lgpd-brazil.info/chapter_03/article_18
- 第 46 条 — セキュリティ対策: https://lgpd-brazil.info/chapter_07/article_46