การคืนการตั้งค่า Secure Account: หยุดหรือปิดการใช้งาน GuardDuty

การคืนการตั้งค่า Secure Account: หยุดหรือปิดการใช้งาน GuardDuty

บทความนี้จะมาพูดถึงวิธีสั่งปิด GuardDuty Service หลังจากปิด Opt-in ใน Secure Account เพื่อให้หยุดการใช้งานได้อย่างสมบูรณ์ครับ
2025.11.05

สวัสดีครับ ผู้อ่านทุกท่าน ผมกาญจน์ครับ ในบทความนี้เราจะมาอธิบายวิธีการหยุดหรือปิดการใช้ GuardDuty ในฝั่ง AWS Console กันครับ

บทความนี้แปลมาจากบทความที่เป็นภาษาญี่ปุ่นที่ชื่อว่า 【セキュアアカウント切り戻し手順】Amazon GuardDuty停止・無効化手順のご案内 โดยเจ้าของบทความนี้คือ คุณ โคเฮ ครับ

บทความนี้เราจะแนะนำขั้นตอนการหยุดและปิดการใช้งาน Amazon GuardDuty ในบริการ Secure Account Service ที่ทาง Classmethod Members จัดหาให้ครับ

Secure Account คืออะไร

ที่ Classmethod เรามีการให้บริการบัญชี AWS ที่มีการติดตั้งด้านความปลอดภัยอย่างครบถ้วนตามแนวทาง Best practice แก่ลูกค้าของเรา

คุณลูกค้าที่ใช้บริการบัญชี AWS ผ่าน Classmethod ทุกท่านสามารถใช้บริการนี้ได้ จึงอยากเชิญชวนให้ทุกท่านมาลองใช้งานกันครับ
https://www.classmethod.co.th/th/services-secure-account

สถาปัตยกรรมของ Secure Account

Secure Account มีการตั้งค่าดังต่อไปนี้

secure-account-architecture-th

สำหรับรายละเอียดของแต่ละการตั้งค่า สามารถอ้างอิงจากบทความและเอกสารนี้ได้ครับ

https://dev.classmethod.jp/articles/th-aws-how-to-use-secure-account/

บริการที่เป็นเป้าหมายในการปิดการใช้งานครั้งนี้

Secure Account Service GuardDuty-2

ในครั้งนี้ เราจะแนะนำขั้นตอนการปิดการใช้งาน GuardDuty ซึ่งถูกเปิดใช้งานในทุก Regionใน Secure Account กันครับ

Amazon GuardDuty คืออะไร

Amazon GuardDuty เป็นบริการที่มีประสิทธิภาพในการตรวจจับการโจมตีและภัยคุกคามต่อสภาพแวดล้อม AWS ของบริษัทคุณอย่างรวดเร็ว เช่น การเข้าถึงที่ไม่ได้รับอนุญาตเพื่อรับประกันความปลอดภัยครับ

ตัวอย่างเช่น หากไม่ได้เปิดใช้งาน GuardDuty เราจะไม่สามารถรับรู้ได้ว่ามีการรั่วไหลของรหัสผ่านเข้าสู่ระบบและมีการเข้าถึงสภาพแวดล้อม AWS ของบริษัทเราโดยไม่ได้รับอนุญาต เพราะสภาพแวดล้อม AWS ไม่สามารถรักษาความปลอดภัยได้

guardduty_01

อย่างไรก็ตาม หากเปิดใช้งาน GuardDuty จะสามารถตรวจจับความเป็นไปได้ของการเข้าถึงที่ไม่ได้รับอนุญาตได้ทันที ทำให้สามารถตอบสนองได้อย่างรวดเร็ว ส่งผลให้มีโอกาสสูงที่จะลดความเสียหายที่อาจเกิดขึ้นเกิดขึ้นได้ครับ

guardduty_02
GuardDuty สุดยอดขนาดนี้ คงต้องลองใช้กันแล้วครับ

ค่าบริการ

สาเหตุที่คนมักจะยกมาเมื่อจะปิดการใช้งาน Guard Duty คือบริการสูงเกินไป (ไม่คุ้มค่ากับประสิทธิภาพ)

ในความเป็นจริงแล้ว GuardDuty มีความคุ้มค่าสูงมาก รายละเอียดได้อธิบายไว้ในบทความด้านล่าง ซึ่งอธิบายประโยชน์ของ Guardduty เอาไว้

https://dev.classmethod.jp/articles/amazon-guardduty-best-threat-detection-pricing/

https://dev.classmethod.jp/articles/amazon-guardduty/

GuardDuty เป็นบริการรักษาความปลอดภัยที่สำคัญมากสำหรับ AWS ครับ ระบบรักษาความปลอดภัยนั้นเราอาจจะมองไม่เห็นประโยชน์ได้ทันที คล้ายๆกับการซื้อประกันครับ แต่ด้วยประโยชน์ขนาดนี้ เราจึงอยากแนะนำให้เปิดไว้นะครับ

1. ข้อกำหนดเบื้องต้น

1.1 Opt-in Classmethod Members Portal (CMP)

เป็นวิธีการปิดการใช้งานโดยผ่านทางเว็บไซต์ Classmethod Members Portal (CMP)

ในระบบ Secure Account เราจะต้องไปที่เว็บไซต์ Classmethod Members Portal (CMP) เพื่อทำการปิดการใช้งาน Opt-in ของ CloudTrail

หากไม่ปิดการใช้งานในส่วนนี้ ในทุกๆวันเสาร์ Classmethod Members Portal จะทำการเปิดบริการดังกล่าวขึ้นมาใหม่โดยอัตโนมัติถึงแม้เราจะปิดการใช้งาน CloudTrail ใน Console ไปแล้ว ฉะนั้น หากต้องการจะปิดการใช้บริการไหน เราต้องปิด Opt-in ในเว็บไซต์ Classmethod Members Portal ก่อนครับ

  1. อันดับแรก ให้มาที่เว็บไซต์ Classmethod Members Portal จากหัวข้อ "AWS Account" แล้วเลือก Account ID ที่เราต้องการครับ

cloudfront02

  1. จากนั้นเลื่อนลงมาที่หัวข้อ "Security Settings" แล้วคลิกที่ Edit

cloudfront03

  1. หลังจากนั้น ให้เลื่อนลงมาที่ "Secure Settings" แล้วติ๊ก "Amazon GuardDuty" ออก

guardduty_03

1.2 IAM permission ที่จำเป็นสำหรับดำเนินการปิดการใช้งาน

Policy ที่จำเป็นสำหรับดำเนินการเพื่อทำการปิดการใช้งานในครั้งนี้มีดังต่อไปนี้

  • AWSCloudShellFullAccess
  • AmazonGuardDutyFullAccess
  • AmazonEC2ReadOnlyAccess
    Secure Account Service GuardDuty-3

2. ขั้นตอนการหยุดและปิดการใช้งาน

2.1 ระหว่างการหยุด(ชั่วคราว)และการปิดการใช้งาน อะไรดีกว่ากัน

เว้นแต่จะมีเหตุผลพิเศษ ให้หยุด GuardDuty แทนที่จะปิดการใช้งาน

โดยทั่วไปขอแนะนำให้ หยุด(ชั่วคราว) แทนการสั่งปิด GuardDuty ยกเว้นมีเหตุผลจำเป็นจริงๆที่ต้องปิด เพราะว่า

  • ในสถานะหยุด (ชั่วคราว) ไม่เสียค่าใช้จ่ายและสามารถดูผลการตรวจของ GuardDuty ได้เช่นกันครับ
  • แต่ถ้าเราปิดการใช้งาน ผลการตรวจจับที่มีอยู่และการตั้งค่า GuardDuty จะหายไปหมดและไม่สามารถกู้คืนได้

https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_suspend-disable.html

2.2 ตรวจสอบสถานะปัจจุบันของ GuardDuty

เราสามารถใช้ Cloudshell เพื่อตรวจสอบได้ (สามารถดูวิธีใช้ Cloudshell ได้ ที่นี่) ครับ

  1. เปิด CloudShell และป้อนคำสั่งต่อไปนี้ลงไปใน CLoudshell แล้วกด Enter

คำสั่งตรวจสอบสถานะของ GuardDuty

for REGION in $(aws ec2 describe-regions --query "sort(Regions[].RegionName)" --output text); do
    DETECTOR_ID=$(aws guardduty list-detectors --region "${REGION}" --query DetectorIds --output text 2>/dev/null)
    if [ -n "$DETECTOR_ID" ]; then
        DETECTOR_STATUS=$(aws guardduty get-detector --detector-id "${DETECTOR_ID}" --query 'Status' --region "${REGION}" --output text 2>/dev/null)
        if [ "$DETECTOR_STATUS" == "DISABLED" ]; then
            # แสดงสถานะที่หยุดแล้ว
            echo "${REGION}: Stopped: ${DETECTOR_ID}"
        elif [ "$DETECTOR_STATUS" == "ENABLED" ]; then
            # แสดงสถานะที่กำลังเปิดใช้งาน
            echo "${REGION}: Enabled: ${DETECTOR_ID}"
        else
            # แสดงสถานะในกรณีอื่นๆ นอกเหนือจากที่กล่าวมาข้างต้น
            echo "${REGION}: Unknown Status: ${DETECTOR_ID}"
        fi
    else
        # แสดงสถานะที่กำลังปิดการใช้งาน
        echo "${REGION}: Disabled: -"
    fi
done
  1. ใน CloudShell จะแสดงสถานะของ GuardDuty ทุก Region กรณีข้างล่าง GuardDuty ทุก Region ถูกเปิดหมด (Enabled)

GuardDuty Detector ID ที่ต่อท้ายของแต่ละ Account จะต่างกัน และแต่ละ Region จะมีเลขไม่เหมือนกัน

ap-northeast-1: Enabled: {GuardDuty Detector ID}
ap-northeast-2: Enabled: {GuardDuty Detector ID}
ap-northeast-3: Enabled: {GuardDuty Detector ID}
ap-south-1: Enabled: {GuardDuty Detector ID}
ap-southeast-1: Enabled: {GuardDuty Detector ID}
ap-southeast-2: Enabled: {GuardDuty Detector ID}
ca-central-1: Enabled: {GuardDuty Detector ID}
eu-central-1: Enabled: {GuardDuty Detector ID}
eu-north-1: Enabled: {GuardDuty Detector ID}
eu-west-1: Enabled: {GuardDuty Detector ID}
eu-west-2: Enabled: {GuardDuty Detector ID}
eu-west-3: Enabled: {GuardDuty Detector ID}
sa-east-1: Enabled: {GuardDuty Detector ID}
us-east-1: Enabled: {GuardDuty Detector ID}
us-east-2: Enabled: {GuardDuty Detector ID}
us-west-1: Enabled: {GuardDuty Detector ID}
us-west-2: Enabled: {GuardDuty Detector ID}
สถานะที่แสดง คำอธิบาย
Enabled สถานะเปิดใช้งาน
Stopped สถานะหยุด
Disabled สถานะปิดการใช้งาน (ไม่แนะนำ)
  1. ตัวอย่างผลลัพธ์เมื่อใช้คำสั่งใน CloudShell

Secure Account Service GuardDuty-4

2.3 ใช้ CloudShell

การใช้ CloudShell จะสะดวกที่สุดครับ กรณีสั่งหยุดหรือปิด GuardDuty ทุก Region หรือหลาย Region พร้อมกันนะครับ

Note: CloudShell ไม่ได้มีทุก Region นะครับ ณ วันที่เขียนบทความ (10 กรกฎาคม พ.ศ.2568) ใน Thailand Region ยังไม่มี CloudShell สามารถไปใช้ CloudShell ของ Singaporeได้ครับ

วิธีสั่งหยุด (ชั่วคราว)

  1. ข้างล่างคือ คำสั่งหยุดพร้อมกันทุก Region สำหรับใส่ใน CLoudshell ครับ
aws ec2 describe-regions --query Regions[*].RegionName \
  | jq -r '.[]' \
  | while read -r REGION 
    do
      # guardduty no-enable
      aws --region "${REGION}" guardduty list-detectors --query DetectorIds[*] | jq -r '.[]' \
      | while read -r DETECTORID 
      do
        aws --region "${REGION}" guardduty update-detector --detector-id "${DETECTORID}" --no-enable
        echo "${REGION} Stopped"
      done
    done
  1. แต่กรณีที่ต้องการ __ยกเว้นเฉพาะบาง Region (ตัวอย่าง: หยุดทุก Region พร้อมกัน ยกเว้นไทยและเวอร์จิเนียเหนือ)
    ※ สามารถปรับเปลี่ยน Region ได้

ให้แก้ไขส่วนนี้ โดยเราสามารถใส่ -e เพื่อเพิ่ม Region ที่จะยกเว้นได้

  | grep -v -e '<ชื่อ region1>' -e '<ชื่อ region2>' -e ... \

ข้างล่างคือตัวอย่างโค้ดที่สมบูรณ์ ที่สั่งให้หยุด GuardDuty ชั่วคราว ยกเว้นแค่ Region ของประเทศไทยและเวอร์จิเนียเหนือ

aws ec2 describe-regions --query Regions[*].RegionName \
  | jq -r '.[]' \
  | grep -v -e 'ap-southeast-7' -e 'us-east-1' \
  | while read -r REGION
    do
      # guardduty no-enable
      aws --region "${REGION}" guardduty list-detectors --query DetectorIds[*] | jq -r '.[]' \
      | while read -r DETECTORID
      do
        aws --region "${REGION}" guardduty update-detector --detector-id "${DETECTORID}" --no-enable
        echo "${REGION} Stopped"
      done
    done

วิธีปิดการใช้งาน

  1. คำสั่งปิดการใช้งานพร้อมกันทุก Region
aws ec2 describe-regions --query Regions[*].RegionName \
  | jq -r '.[]' \
  | while read -r REGION
    do
      # guardduty disable
      aws --region "${REGION}" guardduty list-detectors --query DetectorIds[*] | jq -r '.[]' \
      | while read -r DETECTORID
      do
        aws --region "${REGION}" guardduty delete-detector --detector-id "${DETECTORID}"
        echo "${REGION} Disabled"
      done
    done
  1. ยกเว้นเฉพาะบาง Region (ตัวอย่าง: หยุดทุก Region พร้อมกัน ยกเว้นไทยและเวอร์จิเนียเหนือ) ได้เหมือนวิธีหยุด(ชั่วคราว)
    ※ สามารถปรับเปลี่ยน Region ได้

ให้แก้ไขส่วนนี้ โดยเราสามารถใส่ -e เพื่อเพิ่ม Region ที่จะยกเว้นได้

  | grep -v -e '<ชื่อ region1>' -e '<ชื่อ region2>' -e ... \
aws ec2 describe-regions --query Regions[*].RegionName \
  | jq -r '.[]' \
  | grep -v -e 'ap-southeast-7' -e 'us-east-1' \
  | while read -r REGION
    do
      # guardduty disable
      aws --region "${REGION}" guardduty list-detectors --query DetectorIds[*] | jq -r '.[]' \
      | while read -r DETECTORID
      do
        aws --region "${REGION}" guardduty delete-detector --detector-id "${DETECTORID}"
        echo "${REGION} Disabled"
      done
    done
# หยุด(ชั่วคราว)
aws --region "${REGION}" guardduty update-detector --detector-id "${DETECTORID}" --no-enable

# ปิดไปเลย
aws --region "${REGION}" guardduty delete-detector --detector-id "${DETECTORID}"

2.4 ใช้ Console

คอนโซลเหมาะกับเวลาปิด GuardDuty แค่หนึ่งหรือสอง Region เพราะต้องเข้าไปใน GuardDuty ของแต่ละ Region และทำการหยุด/ปิด ซึ่งใช้เวลามาก

วิธีหยุด (ชั่วคราว)

  1. ก่อนอื่น เลือก Region ที่ต้องการ แล้วเปิด GuardDuty จากหน้าจอคอนโซล แล้วเลือก "Settings" จากเมนู

guardduty_05

  1. จากหน้าจอการตั้งค่า กด "Suspend" ที่ "Suspend GuardDuty" ด้านล่างนี้

Secure Account Service GuardDuty-6

  1. เมื่อป๊อปอัพปรากฏขึ้น ให้กด "Suspend"

Secure Account Service GuardDuty-7

  1. กลับไปที่หน้าจอการตั้งค่า หากเห็น "Re-enable GuardDuty" แสดงว่าอยู่ในสถานะหยุดแล้ว

Secure Account Service GuardDuty-8

วิธีปิดการใช้งาน

  1. เลือก Region ที่ต้องการ ไปที่ GuardDuty แล้วไปที่ Settings
    จากหน้าจอการตั้งค่า กด "Disable" จาก "Disable GuardDuty" ด้านล่างนี้

Secure Account Service GuardDuty-9

  1. เมื่อป๊อปอัพปรากฏขึ้น ให้กด "Disable"

Secure Account Service GuardDuty-10

  1. กลับไปที่หน้าจอหลักของ GuardDuty หากเห็นการแสดงผลดังต่อไปนี้ แสดงว่าการปิดการใช้งานเสร็จสมบูรณ์

Secure Account Service GuardDuty-11

2.5 ตรวจสอบสถานะ

คำสั่งตรวจสอบสถานะ GuardDuty ในทุก Region

for REGION in $(aws ec2 describe-regions --query "sort(Regions[].RegionName)" --output text); do
    DETECTOR_ID=$(aws guardduty list-detectors --region "${REGION}" --query DetectorIds --output text 2>/dev/null)
    if [ -n "$DETECTOR_ID" ]; then
        DETECTOR_STATUS=$(aws guardduty get-detector --detector-id "${DETECTOR_ID}" --query 'Status' --region "${REGION}" --output text 2>/dev/null)
        if [ "$DETECTOR_STATUS" == "DISABLED" ]; then
            # แสดงสถานะที่กำลังปิดใช้งาน
            echo "${REGION}: Stopped: ${DETECTOR_ID}"
        elif [ "$DETECTOR_STATUS" == "ENABLED" ]; then
            # แสดงสถานะที่กำลังเปิดใช้งาน
            echo "${REGION}: Enabled: ${DETECTOR_ID}"
        else
            # แสดงสถานะในกรณีอื่นๆ นอกเหนือจากที่กล่าวมาข้างต้น
            echo "${REGION}: Unknown Status: ${DETECTOR_ID}"
        fi
    else
        # แสดงสถานะที่กำลังปิดการใช้งาน
        echo "${REGION}: Disabled: -"
    fi
done

เมื่อทุก Region อยู่ในสถานะหยุด จะแสดงผลลัพธ์ดังนี้

ap-northeast-1: Stopped: {GuardDuty Detector ID}
ap-northeast-2: Stopped: {GuardDuty Detector ID}
ap-northeast-3: Stopped: {GuardDuty Detector ID}
ap-south-1: Stopped: {GuardDuty Detector ID}
ap-southeast-1: Stopped: {GuardDuty Detector ID}
ap-southeast-2: Stopped: {GuardDuty Detector ID}
ca-central-1: Stopped: {GuardDuty Detector ID}
eu-central-1: Stopped: {GuardDuty Detector ID}
eu-north-1: Stopped: {GuardDuty Detector ID}
eu-west-1: Stopped: {GuardDuty Detector ID}
eu-west-2: Stopped: {GuardDuty Detector ID}
eu-west-3: Stopped: {GuardDuty Detector ID}
sa-east-1: Stopped: {GuardDuty Detector ID}
us-east-1: Stopped: {GuardDuty Detector ID}
us-east-2: Stopped: {GuardDuty Detector ID}
us-west-1: Stopped: {GuardDuty Detector ID}
us-west-2: Stopped: {GuardDuty Detector ID}
สถานะที่แสดง คำอธิบาย
Enabled สถานะเปิดใช้งาน
Stopped สถานะหยุด
Disabled สถานะปิดการใช้งาน (ไม่แนะนำ)

3. หากต้องการเปิดการใช้งานอีกครั้ง

  1. ให้มาที่เว็บไซต์ ClassMethod Portals (CMP) จากหัวข้อ "AWS Account" ให้เลือก Account ID ที่เราต้องการ

cloudfront02

  1. จากนั้นเลื่อนลงมาที่หัวข้อ "Security Settings" แล้วคลิกที่ "Edit"

cloudfront03

  1. ที่หัวข้อ "Secure Settings" ให้ติ๊กเปิดใช้งาน Amazon GuardDuty อีกครั้ง

guardduty_04

  1. พอเสร็จเรียบร้อย การดูแลการตั้งค่าของ Secure Account จะดำเนินการตรวจสอบเป็นรายสัปดาห์ ทุกวันเสาร์เวลาเที่ยงคืน (0.00 น.) ตามเวลาไทย แล้วสั่งเปิด GuardDuty ขึ้นมาใหม่ให้โดยอัตโมัติครับ

จบไปแล้วกับบทความเรื่อง "การคืนการตั้งค่า Secure Account: หยุดหรือปิดการใช้งาน GuardDuty" ครับ หวังว่าจะเป็นประโยชน์กับลูกค้าทุกท่านนะครับ แล้วเจอกันใหม่ในบทความหน้า สวัสดีครับ

บทความต้นฉบับ

この記事をシェアする

FacebookHatena blogX

関連記事