Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix audit log to record client real IP instead of ALB internal IP#37

Merged
ogadra merged 2 commits into
mainfrom
fix/audit-log-client-ip
Mar 27, 2026
Merged

Fix audit log to record client real IP instead of ALB internal IP#37
ogadra merged 2 commits into
mainfrom
fix/audit-log-client-ip

Conversation

@ogadra

@ogadra ogadra commented Mar 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Nginx: Change X-Forwarded-For from $remote_addr to $proxy_add_x_forwarded_for to preserve the CloudFront→ALB IP chain instead of overwriting it with ALB's internal IP
  • Runner: Set TrustedProxies to RFC 1918 ranges so c.ClientIP() correctly extracts the first non-private IP from the X-Forwarded-For chain
  • Runner: Remove meaningless X-Forwarded-Port (Nginx's $server_port = 8080) from audit log remote field, log IP only

Test plan

  • docker build --target test runner/ passes with 100% coverage
  • Nginx config test passes via pre-commit hook
  • After deploy, verify remote= in audit logs shows client global IP instead of 10.x.x.x:8080

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 改善
    • プロキシされたリクエストにおけるクライアントIP検出の精度を向上させました。複数のプロキシを経由するリクエストに対して、より正確なIPアドレスの追跡が可能になります。
    • 特定のプライベートネットワーク範囲からのプロキシを信頼できるものとして認識するよう設定を更新しました。
    • 監査ログの記録形式を簡潔にしました。

@ogadra ogadra added runner Runner microservice nginx Nginx microservice labels Mar 27, 2026
@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f54559d2-06b7-4394-a926-788a90aca9da

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

nginxプロキシのX-Forwarded-Forヘッダーを$remote_addrから$proxy_add_x_forwarded_forに変更し、Goハンドラーで信頼済みプロキシの設定を追加して、クライアントIP解決時にこのヘッダーを参照するよう構成しました。監査ログからX-Forwarded-Portの記録も削除しました。

Changes

Cohort / File(s) Summary
nginx プロキシ設定
nginx/nginx.conf
/api/execute/api/の両位置で、プロキシ時のX-Forwarded-Forヘッダーを$remote_addrから$proxy_add_x_forwarded_forに変更し、クライアントIP履歴チェーンを保持。
Go ハンドラーロジック
runner/handler.go
newHandlerで信頼済みプロキシCIDR(10.0.0.0/8、172.16.0.0/12、192.168.0.0/16)を設定し、handleExecuteの監査ログからX-Forwarded-Portを除去。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 信頼のプロキシ環境で、
IPの旅路を優しく追い、
ヘッダーチェーンは保たれて、
クライアントの足取り、
より真実に近づけり。 ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the PR: fixing the audit log to record the client's real IP instead of the ALB internal IP.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/audit-log-client-ip

Comment @coderabbitai help to get the list of available commands and usage tips.

@ogadra ogadra marked this pull request as ready for review March 27, 2026 09:25
coderabbitai[bot]

This comment was marked as resolved.

@ogadra ogadra merged commit 4dbf5be into main Mar 27, 2026
13 of 14 checks passed
@ogadra ogadra deleted the fix/audit-log-client-ip branch March 27, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nginx Nginx microservice runner Runner microservice

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant