124 lines
3.9 KiB
Markdown
124 lines
3.9 KiB
Markdown
# Cert Authority 使用ガイド
|
||
|
||
## 概要
|
||
|
||
`cert-authority`は、PhotonCloudクラスタ内のmTLS通信に使用する証明書を発行・管理するツールです。
|
||
|
||
## 機能
|
||
|
||
1. **CA証明書の生成** (`init-ca`)
|
||
2. **証明書の発行** (`issue`)
|
||
3. **証明書ローテーションのチェック** (`check-rotation`)
|
||
|
||
## 使用方法
|
||
|
||
### 1. CA証明書の生成
|
||
|
||
初回セットアップ時に、ルートCA証明書とキーを生成します。
|
||
|
||
```bash
|
||
cert-authority \
|
||
--chainfire-endpoint http://localhost:2379 \
|
||
--cluster-id test-cluster-01 \
|
||
--ca-cert-path /etc/photoncloud/ca.crt \
|
||
--ca-key-path /etc/photoncloud/ca.key \
|
||
init-ca
|
||
```
|
||
|
||
これにより、以下のファイルが生成されます:
|
||
- `/etc/photoncloud/ca.crt`: CA証明書(PEM形式)
|
||
- `/etc/photoncloud/ca.key`: CA秘密鍵(PEM形式)
|
||
|
||
### 2. 証明書の発行
|
||
|
||
ノードまたはサービス用の証明書を発行します。
|
||
|
||
```bash
|
||
# ノード用証明書
|
||
cert-authority \
|
||
--chainfire-endpoint http://localhost:2379 \
|
||
--cluster-id test-cluster-01 \
|
||
--ca-cert-path /etc/photoncloud/ca.crt \
|
||
--ca-key-path /etc/photoncloud/ca.key \
|
||
issue \
|
||
--csr-path /tmp/node-01.csr \
|
||
--cert-path /etc/photoncloud/node-01.crt \
|
||
--node-id node-01
|
||
|
||
# サービス用証明書
|
||
cert-authority \
|
||
--chainfire-endpoint http://localhost:2379 \
|
||
--cluster-id test-cluster-01 \
|
||
--ca-cert-path /etc/photoncloud/ca.crt \
|
||
--ca-key-path /etc/photoncloud/ca.key \
|
||
issue \
|
||
--csr-path /tmp/api-server.csr \
|
||
--cert-path /etc/photoncloud/api-server.crt \
|
||
--service-name api-server
|
||
```
|
||
|
||
**注意**: 現在の実装では、CSRファイルは読み込まれず、新しいキーペアが自動生成されます。CSRパース機能は今後の拡張予定です。
|
||
|
||
発行された証明書は以下の場所に保存されます:
|
||
- `{cert_path}`: 証明書(PEM形式)
|
||
- `{cert_path}.key`: 秘密鍵(PEM形式)
|
||
|
||
また、証明書バインディング情報がChainfireに記録されます:
|
||
- キー: `photoncloud/clusters/{cluster_id}/mtls/certs/{node_id or service_name}/...`
|
||
- 値: `CertificateBinding` JSON(シリアル番号、発行日時、有効期限など)
|
||
|
||
### 3. 証明書ローテーションのチェック
|
||
|
||
証明書の有効期限をチェックし、ローテーションが必要かどうかを判定します。
|
||
|
||
```bash
|
||
cert-authority \
|
||
--chainfire-endpoint http://localhost:2379 \
|
||
--cluster-id test-cluster-01 \
|
||
--ca-cert-path /etc/photoncloud/ca.crt \
|
||
--ca-key-path /etc/photoncloud/ca.key \
|
||
check-rotation \
|
||
--cert-path /etc/photoncloud/node-01.crt
|
||
```
|
||
|
||
有効期限が30日以内の場合、警告が表示されます。
|
||
|
||
## 証明書の有効期限
|
||
|
||
- **デフォルトTTL**: 90日
|
||
- **ローテーション推奨期間**: 30日
|
||
|
||
これらの値は`deployer/crates/cert-authority/src/main.rs`の定数で定義されています:
|
||
- `CERT_TTL_DAYS`: 90
|
||
- `ROTATION_THRESHOLD_DAYS`: 30
|
||
|
||
## Chainfire統合
|
||
|
||
証明書発行時、以下の情報がChainfireに記録されます:
|
||
|
||
```json
|
||
{
|
||
"node_id": "node-01",
|
||
"service_name": null,
|
||
"cert_serial": "abc123...",
|
||
"issued_at": 1234567890,
|
||
"expires_at": 1234567890
|
||
}
|
||
```
|
||
|
||
この情報は、証明書の追跡やローテーション管理に使用されます。
|
||
|
||
## セキュリティ考慮事項
|
||
|
||
1. **CA秘密鍵の保護**: CA秘密鍵は厳重に管理し、アクセス権限を最小限に抑えてください。
|
||
2. **証明書の配布**: 発行された証明書と秘密鍵は、適切な権限で保護された場所に保存してください。
|
||
3. **ローテーション**: 定期的に証明書をローテーションし、古い証明書を無効化してください。
|
||
|
||
## 今後の拡張予定
|
||
|
||
- [ ] CSRパース機能の実装
|
||
- [ ] 証明書の自動ローテーション
|
||
- [ ] 証明書失効リスト(CRL)のサポート
|
||
- [ ] SPIFFEライクなアイデンティティ検証
|
||
|
||
|