feat: Add Real IP forwarding feature for bare-metal clusters
All checks were successful
Helm Chart Release / release-chart (push) Successful in 12s

ベアメタルKubernetesクラスターやLoadBalancer環境において、
PHP側で訪問者の実IPアドレスを取得できる機能を追加。

Changes:
- Add nginx.forwardRealIP configuration in values.yaml
- Implement real_ip_header and set_real_ip_from in Nginx config
- Pass real IP info to PHP-FPM via fastcgi_param
- Add usage example and documentation in README.md
- Create test-real-ip.php for verification
- Update chart version to 8.5.2-a

Features:
- Compatible with existing customConfig.snippet
- Configurable trusted proxy networks
- Supports multi-tier proxy with recursive option
- Default disabled for backward compatibility

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 09:21:55 +09:00
parent 59a21fca9b
commit 02696fc55e
6 changed files with 434 additions and 3 deletions

95
CHANGELOG-8.5.2-a.md Normal file
View File

@@ -0,0 +1,95 @@
# Changelog - Version 8.5.2-a
## 新機能
### リアルIP転送機能の追加
ベアメタルKubernetesクラスターやLoadBalancer環境において、PHP側で訪問者の実IPアドレスを取得できる機能を追加しました。
#### 主な変更点
1. **values.yaml**
- `nginx.forwardRealIP` セクションを追加
- `enabled`: リアルIP取得機能の有効/無効
- `header`: リアルIPを取得するHTTPヘッダー名デフォルト: X-Forwarded-For
- `recursive`: 再帰的にリアルIPを検索多段プロキシ対応
- `trustedProxies`: 信頼するプロキシのネットワーク範囲
- `additionalTrustedProxies`: 環境に応じた追加プロキシ設定
2. **templates/configmap.yaml**
- Nginx の `http` セクションにリアルIP設定を追加
- `real_ip_header`, `real_ip_recursive`, `set_real_ip_from` ディレクティブを実装
- PHP-FPM へ渡す fastcgi_param にリアルIP情報を追加
- 既存の `customConfig.snippet` と競合しない構造
3. **README.md**
- リアルIP転送機能の設定パラメータ表を追加
- 例7としてベアメタル環境でのリアルIP取得の使用例を追加
- 検証用PHPコード例を追加
4. **examples/test-real-ip.php** (新規作成)
- リアルIP転送設定の動作確認用テストスクリプト
- WebUIで各種IP関連変数を確認可能
- 診断機能付き
## 技術詳細
### Nginx設定
```nginx
# HTTP-levelで設定
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 192.168.0.0/16;
# PHP-FPMへ渡すパラメータ
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param HTTP_X_REAL_IP $remote_addr;
fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for;
```
### PHPでの利用
```php
// リアルIPアドレスの取得
$realIP = $_SERVER['REMOTE_ADDR'];
```
## 互換性
- 既存の `nginx.customConfig.snippet` 機能と完全に互換性あり
- デフォルトは `enabled: false` のため、既存環境への影響なし
- 有効化時のみ、リアルIP取得ロジックが動作
## セキュリティ
- `trustedProxies` には信頼できるプロキシのみを指定してください
- 不正なプロキシを信頼すると、IPスプーフィング攻撃のリスクがあります
## 使用例
```yaml
# values.yaml
nginx:
forwardRealIP:
enabled: true
header: "X-Forwarded-For"
recursive: true
trustedProxies:
- "10.0.0.0/8"
- "172.16.0.0/12"
- "192.168.0.0/16"
additionalTrustedProxies:
- "203.0.113.0/24" # 外部LoadBalancerのIPレンジ
```
## 検証方法
1. `examples/test-real-ip.php``/var/www/html/` に配置
2. ブラウザでアクセス: `http://your-service/test-real-ip.php`
3. `REMOTE_ADDR` にパブリックIPが表示されることを確認
---
**リリース日**: 2026-02-10
**担当**: プロサーバーエンジニアClaude