New Relic Infrastructure - セキュリティログ監視の設定と運用
はじめに
セキュリティインシデントの早期検知には、OSレベルのセキュリティログとシステムログの継続的な監視が不可欠です。New Relic Infrastructure Agentのログ転送機能を活用すると、Linux/WindowsのセキュリティイベントをリアルタイムでNew Relicプラットフォームに送信し、分析・アラートを実装できます。
この記事では、セキュリティログ監視の設定方法、実践的なクエリ、アラート条件の構築について詳しく解説します。
セキュリティログ監視の概要
監視対象のログ
Linux環境
| ログソース | 内容 | 主な用途 |
|---|---|---|
| systemd | サービスの起動/停止、エラー | サービス異常検知 |
| auditd | システムコール監査、ファイルアクセス | セキュリティ監査 |
| SELinux | アクセス制御の拒否イベント | ポリシー違反検知 |
| SSH | リモートログイン試行、成功/失敗 | 不正アクセス検知 |
| sudo | 特権コマンドの実行 | 権限昇格の追跡 |
| firewalld/iptables | ファイアウォールログ | ネットワークアクセス制御 |
Windows環境
| ログソース | 内容 | 主な用途 |
|---|---|---|
| Security | ログオン/ログオフ、アカウント管理 | 認証イベント監視 |
| System | システムサービス、デバイス | システム異常検知 |
| Application | アプリケーションエラー | アプリ障害検知 |
| Windows Firewall | ファイアウォールイベント | ネットワーク監視 |
| PowerShell | スクリプト実行ログ | 不正スクリプト検知 |
アーキテクチャ
ログ転送機能の設定
前提条件
- Infrastructure Agent バージョン 1.11.4 以降
- Linux: Fluent Bit が同梱(バージョン 1.42.0 以降)
- Windows: Fluent Bit が同梱
- 適切なファイル/ログへのアクセス権限
Fluent Bitへの移行(Linux)
バージョン 1.42.0 以降では、Fluent Bitがデフォルトのログフォワーダーです:
bash
# 現在のフォワーダーを確認
sudo grep -i "log_forwarder" /etc/newrelic-infra.yml
# Fluent Bitに明示的に切り替え(推奨)
sudo tee -a /etc/newrelic-infra.yml > /dev/null <<EOF
# Fluent Bitを使用(デフォルト)
log_forwarder: fluent-bit
EOF
# エージェントの再起動
sudo systemctl restart newrelic-infraLinux環境の設定
systemdログの監視
基本設定
yaml
# /etc/newrelic-infra/logging.d/systemd-logs.yml
logs:
# SSHサービスのログ
- name: systemd-ssh
systemd: sshd
attributes:
service: ssh
log_type: security
# ファイアウォールログ
- name: systemd-firewalld
systemd: firewalld
attributes:
service: firewall
log_type: security
# systemd全般のエラー
- name: systemd-errors
systemd: systemd
pattern: 'error|failed|critical'
attributes:
log_type: system
severity: error高度な設定
yaml
# /etc/newrelic-infra/logging.d/systemd-advanced.yml
logs:
# Nginxのログ(複数フィルタ)
- name: nginx-systemd
systemd: nginx
pattern: 'error|warn'
attributes:
service: nginx
tier: frontend
# MySQLのログ
- name: mysql-systemd
systemd: mysqld
pattern: 'error|warning|crash'
attributes:
service: mysql
tier: database
critical: true
# Docker関連のログ
- name: docker-systemd
systemd: docker
attributes:
service: docker
container_runtime: trueauditdログの監視
auditd(Linux Audit Framework)は、システムコールやファイルアクセスを監査します。
auditdの設定確認
bash
# auditdの状態確認
sudo systemctl status auditd
# 監査ルールの確認
sudo auditctl -l
# ログファイルの場所確認
sudo cat /etc/audit/auditd.conf | grep log_fileNew Relicへの転送設定
yaml
# /etc/newrelic-infra/logging.d/auditd.yml
logs:
# auditdのメインログ
- name: auditd-security
file: /var/log/audit/audit.log
attributes:
log_type: audit
security: true
compliance: true
# 特定のイベントのみフィルタ(オプション)
- name: auditd-critical
file: /var/log/audit/audit.log
pattern: 'SYSCALL|USER_AUTH|USER_LOGIN|USER_LOGOUT|EXECVE|PATH'
attributes:
log_type: audit
severity: critical重要な監査イベントの例
bash
# 特定のファイルへのアクセスを監視
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
sudo auditctl -w /etc/shadow -p wa -k shadow_changes
sudo auditctl -w /etc/sudoers -p wa -k sudoers_changes
# SSH設定ファイルの監視
sudo auditctl -w /etc/ssh/sshd_config -p wa -k sshd_config_changes
# 永続化(再起動後も有効)
sudo tee -a /etc/audit/rules.d/audit.rules > /dev/null <<EOF
-w /etc/passwd -p wa -k passwd_changes
-w /etc/shadow -p wa -k shadow_changes
-w /etc/sudoers -p wa -k sudoers_changes
-w /etc/ssh/sshd_config -p wa -k sshd_config_changes
EOF
sudo service auditd restartSELinuxログの監視
yaml
# /etc/newrelic-infra/logging.d/selinux.yml
logs:
# SELinux拒否イベント
- name: selinux-denials
file: /var/log/audit/audit.log
pattern: 'AVC.*denied'
attributes:
log_type: selinux
security: true
# SELinux全般
- name: selinux-all
file: /var/log/audit/audit.log
pattern: 'type=AVC|type=SELINUX'
attributes:
log_type: selinuxSSH認証ログの監視
yaml
# /etc/newrelic-infra/logging.d/ssh-auth.yml
logs:
# SSHログイン試行(Ubuntu/Debian)
- name: ssh-auth-debian
file: /var/log/auth.log
pattern: 'sshd'
attributes:
service: ssh
log_type: authentication
# SSHログイン試行(CentOS/RHEL)
- name: ssh-auth-rhel
file: /var/log/secure
pattern: 'sshd'
attributes:
service: ssh
log_type: authentication
# 失敗したログイン試行のみ
- name: ssh-failed-logins
file: /var/log/auth.log
pattern: 'sshd.*Failed|sshd.*Invalid|sshd.*Disconnected'
attributes:
service: ssh
log_type: authentication
status: failed
severity: warningsudoコマンドの監視
yaml
# /etc/newrelic-infra/logging.d/sudo.yml
logs:
# sudoコマンド実行ログ
- name: sudo-commands
file: /var/log/auth.log # または /var/log/secure
pattern: 'sudo'
attributes:
log_type: privilege_escalation
security: true
# sudo失敗ログ
- name: sudo-failures
file: /var/log/auth.log
pattern: 'sudo.*authentication failure|sudo.*incorrect password'
attributes:
log_type: privilege_escalation
status: failed
severity: criticalファイアウォールログの監視
yaml
# /etc/newrelic-infra/logging.d/firewall.yml
logs:
# firewalldログ
- name: firewalld-logs
systemd: firewalld
attributes:
service: firewall
log_type: security
# iptablesログ(syslogに出力される場合)
- name: iptables-logs
file: /var/log/syslog # または /var/log/messages
pattern: 'iptables|firewall'
attributes:
service: firewall
log_type: security総合的なLinux設定例
yaml
# /etc/newrelic-infra/logging.d/security-comprehensive.yml
logs:
# システム認証
- name: system-auth
file: /var/log/auth.log
attributes:
category: authentication
# システムメッセージ
- name: system-messages
file: /var/log/messages
pattern: 'error|critical|alert|emerg'
attributes:
category: system
severity: high
# カーネルログ
- name: kernel-logs
file: /var/log/kern.log
pattern: 'error|panic|oops'
attributes:
category: kernel
severity: critical
# Cronジョブのエラー
- name: cron-errors
file: /var/log/cron
pattern: 'error|failed'
attributes:
category: scheduled_tasksWindows環境の設定
Windowsイベントログの基本設定
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-security.yml
logs:
# Securityイベントログ
- name: windows-security
winlog:
channel: Security
collect-eventids:
# ログオン成功
- 4624
# ログオン失敗
- 4625
# アカウントロックアウト
- 4740
# ユーザーアカウント作成
- 4720
# ユーザーアカウント削除
- 4726
# グループメンバーシップ変更
- 4728
- 4732
- 4756
# パスワード変更
- 4723
- 4724
# 特権使用
- 4672
# サービスのインストール
- 4697
attributes:
log_type: security
critical: trueイベントIDの詳細
重要なSecurityイベントID
| イベントID | 説明 | 重要度 |
|---|---|---|
| 4624 | アカウントのログオン成功 | Info |
| 4625 | アカウントのログオン失敗 | Warning |
| 4634 | アカウントのログオフ | Info |
| 4648 | 明示的な資格情報を使用したログオン試行 | Info |
| 4672 | 特権アカウントでのログオン | Warning |
| 4719 | システム監査ポリシーの変更 | Critical |
| 4720 | ユーザーアカウントの作成 | Warning |
| 4722 | ユーザーアカウントの有効化 | Warning |
| 4723 | パスワード変更の試行 | Info |
| 4724 | パスワードリセットの試行 | Warning |
| 4725 | ユーザーアカウントの無効化 | Warning |
| 4726 | ユーザーアカウントの削除 | Critical |
| 4728 | グローバルグループへのメンバー追加 | Warning |
| 4732 | ローカルグループへのメンバー追加 | Warning |
| 4740 | ユーザーアカウントのロックアウト | Warning |
| 4756 | ユニバーサルグループへのメンバー追加 | Warning |
| 4776 | ドメインコントローラーによる資格情報の検証試行 | Info |
高度なWindows設定
ログオン失敗の詳細監視
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-auth-failures.yml
logs:
- name: windows-auth-failures
winlog:
channel: Security
collect-eventids:
- 4625 # ログオン失敗
- 4740 # アカウントロックアウト
- 4771 # Kerberos事前認証失敗
- 4776 # 資格情報検証失敗
exclude-eventids:
- 4735 # 除外したいイベントがある場合
attributes:
log_type: authentication_failure
severity: warning
alert: trueアカウント管理の監視
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-account-mgmt.yml
logs:
- name: windows-account-management
winlog:
channel: Security
collect-eventids:
# アカウントライフサイクル
- 4720 # 作成
- 4722 # 有効化
- 4725 # 無効化
- 4726 # 削除
# パスワード管理
- 4723 # パスワード変更試行
- 4724 # パスワードリセット試行
- 4738 # ユーザーアカウント変更
# グループ管理
- 4728 # グローバルグループメンバー追加
- 4729 # グローバルグループメンバー削除
- 4732 # ローカルグループメンバー追加
- 4733 # ローカルグループメンバー削除
attributes:
log_type: account_management
compliance: true
critical: true特権操作の監視
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-privileged-ops.yml
logs:
- name: windows-privileged-operations
winlog:
channel: Security
collect-eventids:
- 4672 # 特権アカウントログオン
- 4673 # 特権サービス呼び出し
- 4674 # 特権オブジェクト操作試行
- 4688 # 新しいプロセス作成
- 4697 # サービスのインストール
- 4698 # スケジュールされたタスクの作成
- 4699 # スケジュールされたタスクの削除
- 4700 # スケジュールされたタスクの有効化
- 4701 # スケジュールされたタスクの無効化
- 4702 # スケジュールされたタスクの更新
attributes:
log_type: privileged_operations
security: critical
compliance: trueSystemイベントログ
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-system.yml
logs:
- name: windows-system-errors
winlog:
channel: System
# レベルによるフィルタ(1=Critical, 2=Error, 3=Warning)
collect-levels:
- 1 # Critical
- 2 # Error
attributes:
log_type: system
severity: highApplicationイベントログ
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-application.yml
logs:
- name: windows-application-errors
winlog:
channel: Application
collect-levels:
- 1 # Critical
- 2 # Error
attributes:
log_type: applicationPowerShell実行ログ
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-powershell.yml
logs:
- name: powershell-script-execution
winlog:
channel: Microsoft-Windows-PowerShell/Operational
collect-eventids:
- 4103 # モジュールログ
- 4104 # スクリプトブロックログ
- 4105 # スクリプト開始
- 4106 # スクリプト停止
attributes:
log_type: powershell
security: trueWindows Firewallログ
yaml
# C:\Program Files\New Relic\newrelic-infra\logging.d\windows-firewall.yml
logs:
- name: windows-firewall
winlog:
channel: Microsoft-Windows-Windows Firewall With Advanced Security/Firewall
attributes:
log_type: firewall
security: truePowerShellスクリプトでの設定確認
powershell
# 設定ファイルの存在確認
Get-ChildItem "C:\Program Files\New Relic\newrelic-infra\logging.d\" -Filter "*.yml"
# Infrastructure Agentの再起動
Restart-Service -Name "newrelic-infra"
# サービスの状態確認
Get-Service -Name "newrelic-infra"
# ログでFluent Bitの起動を確認
Get-Content "C:\Program Files\New Relic\newrelic-infra\logs\newrelic-infra.log" -Tail 50 | Select-String -Pattern "fluent|logging"
# Windowsイベントログのイベント数確認
Get-WinEvent -ListLog Security | Select-Object RecordCount, LogNameデータクエリと可視化
Linux セキュリティログのクエリ
SSH失敗ログインの検知
sql
SELECT count(*) AS 'Failed SSH Attempts'
FROM Log
WHERE message LIKE '%sshd%Failed%' OR message LIKE '%sshd%Invalid%'
FACET hostname
SINCE 1 HOUR AGO
TIMESERIESsudo失敗の検知
sql
SELECT count(*) AS 'Failed sudo Attempts'
FROM Log
WHERE message LIKE '%sudo%authentication failure%'
OR message LIKE '%sudo%incorrect password%'
FACET hostname, message
SINCE 1 HOUR AGOSELinux拒否イベント
sql
SELECT count(*) AS 'SELinux Denials'
FROM Log
WHERE message LIKE '%AVC%denied%'
FACET hostname
SINCE 1 HOUR AGO
TIMESERIESauditdイベントの分析
sql
SELECT count(*) AS 'Audit Events'
FROM Log
WHERE log_type = 'audit'
FACET hostname, message
SINCE 1 HOUR AGO
LIMIT 100Windows セキュリティログのクエリ
ログオン失敗の分析
sql
SELECT count(*) AS 'Failed Logon Attempts'
FROM Log
WHERE channel = 'Security' AND eventId = 4625
FACET hostname, message
SINCE 1 HOUR AGO
TIMESERIESアカウントロックアウトの検知
sql
SELECT count(*) AS 'Account Lockouts'
FROM Log
WHERE channel = 'Security' AND eventId = 4740
FACET hostname, message
SINCE 1 DAY AGOアカウント作成/削除の監視
sql
SELECT count(*) AS 'Account Changes'
FROM Log
WHERE channel = 'Security'
AND eventId IN (4720, 4726)
FACET eventId, hostname, message
SINCE 1 DAY AGO特権アカウントのログオン
sql
SELECT count(*) AS 'Privileged Logons'
FROM Log
WHERE channel = 'Security' AND eventId = 4672
FACET hostname
SINCE 1 HOUR AGO
TIMESERIES横断的なセキュリティダッシュボード
認証失敗の集計
sql
-- Linux + Windows 統合
SELECT count(*) AS 'Failed Authentications'
FROM Log
WHERE (message LIKE '%Failed%' AND service = 'ssh')
OR (channel = 'Security' AND eventId IN (4625, 4771, 4776))
FACET hostname
SINCE 1 HOUR AGO
TIMESERIESセキュリティイベントのヒートマップ
sql
SELECT count(*) AS 'Security Events'
FROM Log
WHERE log_type IN ('security', 'authentication', 'audit')
OR channel = 'Security'
FACET hostname, hour(timestamp)
SINCE 1 DAY AGO
LIMIT 1000アラート設定
Linux環境のアラート
SSH brute-force攻撃の検知
sql
-- アラートクエリ
SELECT count(*) AS 'failed_attempts'
FROM Log
WHERE message LIKE '%sshd%Failed%'
FACET hostname閾値:
- Warning: 10 回以上の失敗(5分間)
- Critical: 50 回以上の失敗(5分間)SELinux拒否の急増
sql
SELECT count(*) AS 'selinux_denials'
FROM Log
WHERE message LIKE '%AVC%denied%'
FACET hostname閾値:
- Warning: 10 回以上の拒否(10分間)
- Critical: 50 回以上の拒否(10分間)sudoの不正使用試行
sql
SELECT count(*) AS 'sudo_failures'
FROM Log
WHERE message LIKE '%sudo%authentication failure%'
FACET hostname閾値:
- Critical: 3 回以上の失敗(5分間)Windows環境のアラート
ログオン失敗の異常検知
sql
SELECT count(*) AS 'failed_logons'
FROM Log
WHERE channel = 'Security' AND eventId = 4625
FACET hostname閾値:
- Warning: 5 回以上の失敗(5分間)
- Critical: 20 回以上の失敗(5分間)不正なアカウント操作
sql
SELECT count(*) AS 'account_changes'
FROM Log
WHERE channel = 'Security'
AND eventId IN (4720, 4722, 4726, 4738)閾値:
- Warning: 営業時間外(18:00-9:00)に1件以上のアカウント変更
- Critical: 10分間に 5 件以上のアカウント変更特権アカウントの異常使用
sql
SELECT count(*) AS 'privileged_operations'
FROM Log
WHERE channel = 'Security'
AND eventId IN (4672, 4697)
FACET hostname閾値:
- Warning: 通常より2倍の特権操作(ベースライン比較)複合条件のアラート(NRQL Joins)
複数ホストでの同時攻撃検知
sql
SELECT uniqueCount(hostname) AS 'affected_hosts'
FROM Log
WHERE (message LIKE '%Failed%' AND service = 'ssh')
OR (channel = 'Security' AND eventId = 4625)閾値:
- Critical: 3 台以上のホストで同時に認証失敗(5分間)ベストプラクティス
ログ収集の最適化
必要なログのみを収集
yaml
# ✅ 良い例: セキュリティ関連のみ
logs:
- name: security-only
file: /var/log/auth.log
pattern: 'Failed|Invalid|Denied|sudo'
# ❌ 悪い例: すべてのログを収集
# logs:
# - name: all-logs
# file: /var/log/*行長の制限
yaml
logs:
- name: system-logs
file: /var/log/syslog
max_line_kb: 64 # 1行あたり最大64KB
attributes:
log_type: systemセキュリティとコンプライアンス
機密情報のマスキング
パスワードやトークンなど、ログに含まれる機密情報はNew Relicに送信する前にマスキングします:
bash
# rsyslogでマスキング(例)
# /etc/rsyslog.d/50-privacy.conf
$ModLoad omprog
*.* :omprog:/usr/local/bin/mask-sensitive-data.sh監査証跡の保持
New Relicのデータ保持ポリシーに加えて、コンプライアンス要件に応じてローカルにもログを保持:
yaml
# Linuxローカルログの保持設定
# /etc/logrotate.d/security-logs
/var/log/auth.log /var/log/audit/audit.log {
rotate 365
daily
compress
delaycompress
notifempty
create 0600 root root
}パフォーマンスへの影響
ログ転送によるリソース使用量の目安:
| ログ量/日 | CPU使用率増加 | メモリ使用量増加 |
|---|---|---|
| 1 GB | 1-2% | 50-100 MB |
| 10 GB | 3-5% | 100-200 MB |
| 50 GB | 5-10% | 200-500 MB |
トラブルシューティング
ログが表示されない
Linux環境
bash
# 1. 設定ファイルの確認
sudo ls -la /etc/newrelic-infra/logging.d/
# 2. 構文チェック
sudo newrelic-infra -dry-run -verbose
# 3. Fluent Bitの状態確認
sudo journalctl -u newrelic-infra -f | grep -i fluent
# 4. ファイル権限の確認
sudo ls -la /var/log/auth.log
sudo ls -la /var/log/audit/audit.log
# 5. SELinuxコンテキストの確認(SELinux有効時)
ls -Z /var/log/auth.log
sudo semanage fcontext -l | grep authWindows環境
powershell
# 1. 設定ファイルの確認
Get-ChildItem "C:\Program Files\New Relic\newrelic-infra\logging.d\"
# 2. Fluent Bitログの確認
Get-Content "C:\Program Files\New Relic\newrelic-infra\logs\newrelic-infra.log" -Tail 100 | Select-String -Pattern "fluent|error"
# 3. イベントログへのアクセス権限確認
Get-WinEvent -ListLog Security
# 4. サービスの再起動
Restart-Service -Name "newrelic-infra" -Verboseログが不完全
パターンマッチの問題
yaml
# パターンを広げて確認
logs:
- name: debug-all-ssh
file: /var/log/auth.log
pattern: 'ssh' # 広いパターンで確認
# pattern: 'sshd.*Failed' # 狭すぎる可能性バッファリング設定
yaml
# /etc/newrelic-infra.yml
log_forward_buffer_size: 10000 # デフォルトより大きくまとめ
New Relic Infrastructure Agentのログ転送機能を活用すると、Linux/Windowsのセキュリティログを一元的に監視し、迅速なインシデント対応が可能になります。適切な設定とアラート条件により、セキュリティ態勢を大幅に強化できます。
重要なポイント
- 適切なログソースの選択: セキュリティ関連ログに焦点を当てる
- 効果的なフィルタリング: 必要なイベントのみを収集してコスト削減
- アラートの実装: 異常パターンを迅速に検知
- コンプライアンス: 監査要件に応じたログ保持ポリシー
- パフォーマンス最適化: リソース使用量とログ量のバランス
次のステップ
- プロセス監視の設定 - プロセスレベルの異常検知
- ポート監視の設定 - ネットワークポート監視
- Linux環境でのエージェント導入 - Infrastructure Agentのインストール
- Windows環境でのエージェント導入 - Windows固有の設定
関連記事: Infrastructure Agent概要とアーキテクチャ関連記事: 設定ファイル完全リファレンス