New Relic One Audit Trail Logging คืออะไร
New Relic One Audit Trail Logging เป็นระบบบันทึกเหตุการณ์ (Event Logging) ที่ทำงานภายใน New Relic Platform โดยอัตโนมัติ ทุกครั้งที่ผู้ใช้งานในองค์กรทำการเปลี่ยนแปลงใดๆบน Account ไม่ว่าจะเป็นการสร้าง Alert Condition ใหม่ การลบ Dashboard การเปลี่ยน Permission ของ User หรือแม้แต่การ Query ข้อมูลที่สำคัญ ระบบจะบันทึกเหตุการณ์เหล่านั้นลงใน Event Type ที่ชื่อว่า NrAuditEvent โดยอัตโนมัติ
ระบบนี้สำคัญอย่างยิ่งสำหรับองค์กรที่ต้องปฏิบัติตามมาตรฐานความปลอดภัย เช่น SOC 2, ISO 27001, PCI-DSS หรือ HIPAA เพราะต้องมีหลักฐานยืนยันว่าใครทำอะไรเมื่อไหร่บนระบบ Monitoring ขององค์กร การมี Audit Trail ที่สมบูรณ์ช่วยให้ทีม Security สามารถตรวจสอบย้อนหลังได้ทันทีเมื่อเกิดเหตุการณ์ผิดปกติ
สถาปัตยกรรมของ Audit Trail ใน New Relic One
Audit Trail ใน New Relic One ทำงานผ่านหลายชั้น โดยทุก API Call และ UI Action จะถูก Intercept ที่ Gateway Layer แล้วบันทึกลงใน NRDB (New Relic Database) ภายใต้ Event Type NrAuditEvent โครงสร้างข้อมูลประกอบด้วย Field หลักดังนี้
| Field | คำอธิบาย | ตัวอย่างค่า |
|---|---|---|
| actionIdentifier | ระบุ Action ที่เกิดขึ้น | account.update_user_role |
| actorEmail | Email ของผู้กระทำ | admin@company.com |
| actorType | ประเภทของผู้กระทำ | user หรือ api_key |
| targetId | ID ของ Resource ที่ถูกเปลี่ยนแปลง | 12345678 |
| targetType | ประเภทของ Resource | ALERT_POLICY, DASHBOARD |
| description | รายละเอียดของ Action | Changed role to Admin |
| timestamp | เวลาที่เกิดเหตุการณ์ | Unix timestamp |
วิธีตั้งค่าและเข้าถึง Audit Log บน New Relic One
Audit Logging เปิดใช้งานโดยอัตโนมัติในทุก New Relic Account ไม่จำเป็นต้องติดตั้งหรือ Configure อะไรเพิ่มเติม สิ่งที่ต้องทำคือเข้าถึงข้อมูลผ่าน UI หรือ NRQL Query
เข้าถึงผ่าน UI
ไปที่ Administration → Audit log บน New Relic One UI จะแสดงรายการเหตุการณ์ล่าสุดทั้งหมดพร้อม Filter ตาม User, Action Type และช่วงเวลา
เข้าถึงผ่าน NRQL Query
วิธีที่ยืดหยุ่นที่สุดคือการใช้ NRQL Query โดยตรงผ่าน Query Builder หรือ Dashboard
-- ดูเหตุการณ์ทั้งหมดใน 24 ชั่วโมงล่าสุด
SELECT timestamp, actorEmail, actionIdentifier, description, targetType
FROM NrAuditEvent
SINCE 24 hours ago
ORDER BY timestamp DESC
LIMIT 100
-- ดูเฉพาะ Action ที่เกี่ยวกับ Alert Policy
SELECT actorEmail, actionIdentifier, description
FROM NrAuditEvent
WHERE targetType = 'ALERT_POLICY'
SINCE 7 days ago
-- นับจำนวน Action แยกตามผู้ใช้
SELECT count(*) FROM NrAuditEvent
FACET actorEmail
SINCE 30 days ago
LIMIT 20
การตั้งค่า Alert สำหรับ Audit Event ที่สำคัญ
การมี Audit Log อย่างเดียวไม่เพียงพอ ต้องตั้ง Alert ให้แจ้งเตือนเมื่อมี Action ที่น่าสงสัยเกิดขึ้น เช่น การลบ Alert Policy ทั้งหมด การเปลี่ยน Role ของ User หรือการสร้าง API Key ใหม่ในเวลาผิดปกติ
# สร้าง Alert Condition ผ่าน Terraform
resource "newrelic_nrql_alert_condition" "audit_suspicious" {
account_id = var.newrelic_account_id
policy_id = newrelic_alert_policy.security.id
type = "static"
name = "Suspicious Audit Activity"
description = "Alert when critical changes detected"
enabled = true
violation_time_limit_seconds = 86400
nrql {
query = <<-NRQL
SELECT count(*)
FROM NrAuditEvent
WHERE actionIdentifier IN (
'account.delete_alert_policy',
'account.update_user_role',
'account.create_api_key',
'account.delete_dashboard'
)
NRQL
}
critical {
operator = "above"
threshold = 5
threshold_duration = 300
threshold_occurrences = "at_least_once"
}
warning {
operator = "above"
threshold = 2
threshold_duration = 300
threshold_occurrences = "at_least_once"
}
}
การส่ง Audit Log ไปยัง SIEM ภายนอก
องค์กรส่วนใหญ่ต้องการรวม Audit Log จากทุกระบบเข้าด้วยกันใน SIEM เช่น Splunk, Elastic SIEM หรือ Microsoft Sentinel วิธีทำคือใช้ NerdGraph API ดึงข้อมูลแล้วส่งต่อ
# Python script สำหรับ Export Audit Log ไปยัง SIEM
import requests
import json
from datetime import datetime, timedelta
NEWRELIC_API_KEY = "NRAK-XXXXXXXXXXXXXXXXXXXX"
ACCOUNT_ID = "1234567"
SPLUNK_HEC_URL = "https://splunk.company.com:8088/services/collector"
SPLUNK_TOKEN = "your-hec-token"
def fetch_audit_events(hours_back=1):
"""ดึง Audit Events จาก New Relic ผ่าน NerdGraph"""
query = """
{
actor {
account(id: %s) {
nrql(query: "SELECT * FROM NrAuditEvent SINCE %d hours ago LIMIT MAX") {
results
}
}
}
}
""" % (ACCOUNT_ID, hours_back)
headers = {
"Content-Type": "application/json",
"API-Key": NEWRELIC_API_KEY
}
resp = requests.post(
"https://api.newrelic.com/graphql",
json={"query": query},
headers=headers,
timeout=30
)
resp.raise_for_status()
data = resp.json()
return data["data"]["actor"]["account"]["nrql"]["results"]
def send_to_splunk(events):
"""ส่ง Events ไปยัง Splunk HEC"""
headers = {"Authorization": f"Splunk {SPLUNK_TOKEN}"}
for event in events:
payload = {
"event": event,
"sourcetype": "newrelic:audit",
"source": "newrelic-audit-export",
"index": "security"
}
requests.post(SPLUNK_HEC_URL, json=payload,
headers=headers, verify=True, timeout=10)
if __name__ == "__main__":
events = fetch_audit_events(hours_back=1)
print(f"พบ {len(events)} events")
send_to_splunk(events)
print("ส่งข้อมูลไปยัง Splunk เรียบร้อย")
การสร้าง Dashboard สำหรับ Audit Trail Monitoring
Dashboard เป็นเครื่องมือสำคัญสำหรับทีม Security ในการมองภาพรวมของกิจกรรมทั้งหมดที่เกิดขึ้นบน New Relic Account ควรมี Widget หลักดังนี้
- Timeline ของ Audit Events: แสดงจำนวน Event ตามเวลาเพื่อดูแนวโน้มและช่วงเวลาที่มีกิจกรรมผิดปกติ
- Top Users by Activity: แสดงผู้ใช้ที่มี Activity มากที่สุดเพื่อตรวจจับ Account ที่อาจถูก Compromise
- Critical Actions Log: แสดงเฉพาะ Action ที่มีผลกระทบสูง เช่น การลบ Policy การเปลี่ยน Role
- Failed Login Attempts: แสดงความพยายามล็อกอินที่ล้มเหลวเพื่อตรวจจับ Brute Force Attack
- API Key Usage: ติดตามการใช้งาน API Key เพื่อตรวจสอบว่ามี Key ที่ถูกใช้จากที่อยู่ IP ผิดปกติหรือไม่
{
"name": "Security Audit Dashboard",
"description": "Audit Trail Monitoring for New Relic Account",
"permissions": "PUBLIC_READ_WRITE",
"pages": [
{
"name": "Audit Overview",
"widgets": [
{
"title": "Audit Events Timeline",
"visualization": { "id": "viz.line" },
"rawConfiguration": {
"nrqlQueries": [{
"accountIds": [1234567],
"query": "SELECT count(*) FROM NrAuditEvent TIMESERIES 1 hour SINCE 7 days ago"
}]
}
},
{
"title": "Top Active Users",
"visualization": { "id": "viz.bar" },
"rawConfiguration": {
"nrqlQueries": [{
"accountIds": [1234567],
"query": "SELECT count(*) FROM NrAuditEvent FACET actorEmail SINCE 7 days ago LIMIT 10"
}]
}
},
{
"title": "Critical Actions",
"visualization": { "id": "viz.table" },
"rawConfiguration": {
"nrqlQueries": [{
"accountIds": [1234567],
"query": "SELECT timestamp, actorEmail, actionIdentifier, description FROM NrAuditEvent WHERE actionIdentifier LIKE '%delete%' OR actionIdentifier LIKE '%role%' SINCE 7 days ago LIMIT 50"
}]
}
}
]
}
]
}
Compliance และ Audit Trail — การตอบสนองต่อมาตรฐานความปลอดภัย
Audit Trail Logging เป็นหัวใจสำคัญของการปฏิบัติตามมาตรฐานความปลอดภัยระดับสากล แต่ละมาตรฐานมีข้อกำหนดเฉพาะที่ New Relic Audit Log สามารถตอบสนองได้ดังนี้
- SOC 2 Type II: ต้องมีหลักฐานว่าระบบ Monitoring มีการควบคุมการเข้าถึง (Access Control) และสามารถตรวจสอบย้อนหลังได้ NrAuditEvent ตอบโจทย์ตรงนี้โดยบันทึกทุก Action พร้อม Timestamp และ Actor Identity
- ISO 27001: Control A.12.4.1 กำหนดให้ต้องมี Event Logging สำหรับ User Activities, Exceptions และ Security Events ซึ่ง Audit Trail ของ New Relic ครอบคลุมทั้งหมด
- PCI-DSS: Requirement 10 กำหนดให้ต้อง Track และ Monitor การเข้าถึง Network Resources และ Cardholder Data ทั้งหมด Audit Log ช่วยพิสูจน์ว่าระบบ Monitoring ถูกจัดการอย่างถูกต้อง
- HIPAA: Section 164.312(b) กำหนดให้ต้องมี Audit Controls ที่บันทึกและตรวจสอบกิจกรรมใน Information Systems ที่มี ePHI
สำหรับการ Audit ทุกครั้ง ให้เตรียม NRQL Query ที่พร้อมใช้สำหรับ Auditor ดังนี้
-- Query สำหรับ Auditor: แสดง Role Changes ทั้งหมดใน 90 วัน
SELECT timestamp, actorEmail, description, targetType, targetId
FROM NrAuditEvent
WHERE actionIdentifier LIKE '%role%'
OR actionIdentifier LIKE '%permission%'
SINCE 90 days ago
ORDER BY timestamp DESC
-- Query สำหรับ Auditor: แสดง API Key Management
SELECT timestamp, actorEmail, actionIdentifier, description
FROM NrAuditEvent
WHERE actionIdentifier LIKE '%api_key%'
SINCE 90 days ago
ORDER BY timestamp DESC
-- Query สำหรับ Auditor: Login Activity Summary
SELECT count(*) as 'Total Events',
uniqueCount(actorEmail) as 'Unique Users'
FROM NrAuditEvent
FACET actionIdentifier
SINCE 90 days ago
LIMIT 50
การตรวจจับ Anomaly และ Incident Response ด้วย Audit Log
Audit Log ไม่ได้มีไว้แค่ดูย้อนหลัง แต่สามารถใช้เป็นเครื่องมือ Proactive Detection ได้ด้วย โดยการสร้าง Baseline ของพฤติกรรมปกติแล้วตรวจจับเมื่อมีสิ่งผิดปกติเกิดขึ้น
สัญญาณเตือนที่ควรจับตามอง:
- ผู้ใช้คนเดียวมี Action มากกว่าปกติ 3 เท่าภายใน 1 ชั่วโมง
- มีการลบ Alert Policy หรือ Dashboard หลายรายการในเวลาสั้นๆ
- มีการสร้าง API Key ใหม่นอกเวลาทำการ
- มีการเปลี่ยน Role ของ User เป็น Admin โดยไม่มี Change Request
- มี Action จาก IP Address ที่ไม่เคยเห็นมาก่อน
เมื่อตรวจพบ Anomaly ควรมี Runbook ที่กำหนด Incident Response Steps ไว้ชัดเจน ตั้งแต่การ Isolate Account การ Revoke API Key ไปจนถึงการแจ้ง Stakeholder ที่เกี่ยวข้อง
Best Practices สำหรับ Audit Trail Management
- ใช้ Least Privilege Principle: จำกัดจำนวน Admin User ให้น้อยที่สุด ทุก Account ควรมีสิทธิ์เท่าที่จำเป็นสำหรับงานเท่านั้น เพื่อลดความเสี่ยงและทำให้ Audit Log มีข้อมูลที่มีความหมายมากขึ้น
- Export Log เป็นประจำ: แม้ New Relic จะเก็บข้อมูลไว้ 13 เดือนแต่ควร Export ไปเก็บใน Long-term Storage เช่น S3 หรือ GCS เพื่อให้ตรงตามข้อกำหนดที่ต้องเก็บนานกว่า
- สร้าง Alert สำหรับ Critical Actions: อย่าพึ่งพาการตรวจสอบด้วยตาเพียงอย่างเดียว ต้องมี Automated Alert ที่แจ้งเตือนทันทีเมื่อมี Action ที่เสี่ยง
- Review Dashboard สม่ำเสมอ: กำหนดตารางให้ทีม Security Review Audit Dashboard อย่างน้อยสัปดาห์ละครั้ง
- ทดสอบ Incident Response: จำลองสถานการณ์ Breach เพื่อทดสอบว่าทีมสามารถใช้ Audit Log ในการ Investigate ได้จริง
- Document ทุก Custom Query: เก็บ NRQL Query ที่ใช้บ่อยไว้ใน Runbook พร้อมคำอธิบายว่าใช้ในสถานการณ์ใด
การใช้ NerdGraph API สำหรับ Audit Automation
NerdGraph เป็น GraphQL API ของ New Relic ที่ช่วยให้สามารถดึงข้อมูล Audit Log แบบ Programmatic ได้ เหมาะสำหรับการสร้าง Automation Script ที่ทำงานเป็นประจำ
# Bash script สำหรับดึง Audit Events รายวันและเก็บเป็น JSON
#!/bin/bash
set -euo pipefail
API_KEY=""
ACCOUNT_ID=""
OUTPUT_DIR="/var/log/newrelic-audit"
TODAY=$(date +%Y-%m-%d)
mkdir -p ""
QUERY='{"query":"{actor{account(id:''){nrql(query:\"SELECT * FROM NrAuditEvent SINCE 1 day ago LIMIT MAX\"){results}}}}"}'
curl -s -X POST "https://api.newrelic.com/graphql" \
-H "Content-Type: application/json" \
-H "API-Key: " \
-d "" | \
python3 -m json.tool > "/audit-.json"
# บีบอัดไฟล์เก่ากว่า 7 วัน
find "" -name "audit-*.json" -mtime +7 -exec gzip {} \;
# ส่งไปเก็บใน S3
aws s3 sync "/" "s3://company-audit-logs/newrelic/" \
--exclude "*" --include "*.json.gz"
echo "[] Audit export completed: $(wc -l < /audit-.json) lines"
New Relic Audit Trail Logging คืออะไรและทำงานอย่างไร
Audit Trail Logging ใน New Relic คือระบบบันทึกเหตุการณ์ทุกอย่างที่เกิดขึ้นภายใน Account เช่น การล็อกอิน การเปลี่ยนแปลง Alert Policy การลบ Dashboard โดยข้อมูลทั้งหมดถูกเก็บไว้ใน NrAuditEvent ซึ่งสามารถ Query ได้ผ่าน NRQL ข้อมูลถูกเก็บอัตโนมัติ 13 เดือนโดยไม่ต้องตั้งค่าเพิ่มเติม
วิธีเปิดใช้งาน Audit Logging บน New Relic One ทำอย่างไร
Audit Logging เปิดใช้งานโดยอัตโนมัติในทุก Account ของ New Relic One ไม่จำเป็นต้อง Configure เพิ่มเติม สามารถเข้าดูได้ที่เมนู Administration → Audit log หรือใช้ NRQL Query SELECT * FROM NrAuditEvent SINCE 1 day ago เพื่อดูข้อมูลแบบละเอียด
สามารถส่ง Audit Log ของ New Relic ไปยัง SIEM ภายนอกได้หรือไม่
ได้ โดยใช้ NerdGraph API หรือ Streaming Data Export เพื่อดึงข้อมูล NrAuditEvent แล้วส่งต่อไปยัง SIEM เช่น Splunk ผ่าน HEC, Elastic SIEM ผ่าน Logstash หรือ Microsoft Sentinel ผ่าน Azure Function สามารถตั้ง Cron Job ให้ดึงข้อมูลทุกชั่วโมงได้
NrAuditEvent เก็บข้อมูลอะไรบ้างและเก็บนานแค่ไหน
NrAuditEvent เก็บข้อมูลสำคัญได้แก่ actionIdentifier (ประเภท Action), actorEmail (ผู้กระทำ), targetId (Resource ที่ถูกเปลี่ยนแปลง), description (รายละเอียด) และ timestamp โดย default เก็บไว้ 13 เดือน สามารถ export ออกมาเก็บระยะยาวใน S3 หรือ GCS ได้ผ่าน API
สรุปและแนวทางปฏิบัติ
New Relic One Audit Trail Logging เป็นเครื่องมือที่จำเป็นสำหรับทุกองค์กรที่ใช้ New Relic เป็น Observability Platform หลัก การเข้าใจวิธีเข้าถึง วิเคราะห์ และ Automate Audit Log จะช่วยให้ทีม Security สามารถตรวจจับภัยคุกคามได้เร็วขึ้น ปฏิบัติตามมาตรฐาน Compliance ได้ครบถ้วน และลดเวลาในการ Investigate Incident ได้อย่างมาก
สิ่งที่ควรทำทันทีหลังอ่านบทความนี้คือเปิด Query Builder บน New Relic แล้วลอง Query SELECT * FROM NrAuditEvent SINCE 7 days ago LIMIT 20 เพื่อดูว่ามี Activity อะไรเกิดขึ้นบ้างใน Account ขององค์กร จากนั้นสร้าง Dashboard และ Alert ตามแนวทางที่แนะนำ เพื่อให้ระบบ Monitoring ขององค์กรมีความปลอดภัยและตรวจสอบได้ตลอดเวลา
