FiveM ACE Permission คืออะไร? วิธีจัดสิทธิ์ Admin และ Resource ให้ปลอดภัย
FiveM ACE Permission คือระบบ Access Control ที่ติดมากับ FXServer สำหรับกำหนดว่า Player, Admin, Group หรือ Resource ใด ได้รับอนุญาตหรือถูกปฏิเสธ ให้ใช้คำสั่งหรือสิทธิ์บางอย่าง
คำสั่งหลักที่ใช้คือ
add_ace
add_principal
remove_ace
remove_principal
test_ace
ตัวอย่าง Admin แบบพื้นฐานจากแนวทาง Vanilla ของ Cfx.re คือ
add_ace group.admin command allow
add_ace group.admin command.quit deny
add_principal identifier.fivem:123456 group.admin
แนวคิดคือ
Player Identifier
↓
เป็นสมาชิก group.admin
↓
group.admin ได้รับ ACE
↓
สามารถใช้คำสั่งตามที่อนุญาต
ACE จึงเป็นระบบสำคัญมากสำหรับ Server ที่ต้องควบคุม Admin Commands และสิทธิ์ของ Resources โดยไม่ต้องแจกสิทธิ์ทุกอย่างให้ทุกคน
① ACE ย่อมาจากอะไร
ACE ย่อมาจาก
Access Control Entry
คือ Rule ที่ระบุว่า Principal หนึ่งมีสิทธิ์กับ Object ใดหรือไม่
โครงสร้างพื้นฐานคือ
Principal
+
Object
+
Allow / Deny
② ตัวอย่าง ACE ง่ายที่สุด
add_ace group.admin command allow
ความหมายคือ
Principal = group.admin
Object = command
Action = allow
ทำให้กลุ่ม Admin ได้รับสิทธิ์ใน Command Object ตาม Rule ที่กำหนด
③ add_ace คืออะไร
รูปแบบคำสั่งคือ
add_ace [principal] [object] [allow|deny]
ตัวอย่าง
add_ace group.admin command.potato allow
หมายถึงอนุญาต group.admin ให้ใช้ Object
command.potato
④ allow คืออะไร
ตัวอย่าง
add_ace group.admin command.kick allow
เป็นการสร้าง ACE ที่อนุญาต Group นั้นกับ Object ดังกล่าว
แนวคิดคือ
group.admin
→ command.kick
→ ALLOW
⑤ deny คืออะไร
สามารถสร้าง Rule ปฏิเสธได้เช่นกัน
ตัวอย่างจาก Vanilla Configuration ของ Cfx.re
add_ace group.admin command.quit deny
ใช้ปฏิเสธสิทธิ์ command.quit สำหรับกลุ่ม Admin ตาม ACL Configuration
⑥ ทำไมตัวอย่าง Vanilla ให้ Command ทั้งหมดก่อน
ตัวอย่างทางการใช้
add_ace group.admin command allow
แล้วตามด้วย
add_ace group.admin command.quit deny
แนวคิดคืออนุญาต Commands ให้ Admin แต่จำกัดคำสั่งอันตรายอย่าง quit
สำหรับ Production Server คุณสามารถออกแบบให้ละเอียดกว่านี้ได้
⑦ Principal คืออะไร
Principal คือ Subject ที่กำลังได้รับหรือสืบทอด Permission
ตัวอย่าง
group.admin
identifier.fivem:123456
resource.myresource
Principal สามารถถูกผูกกับ Principal อื่นด้วย add_principal
⑧ Object คืออะไร
Object คือสิทธิ์หรือสิ่งที่ ACE ใช้ควบคุม
ตัวอย่าง
command
command.quit
command.kick
myresource.admin
jobProbe.mechanic
ชื่อ Object สามารถถูก Resource นำไปตรวจด้วยระบบ ACE ได้
⑨ add_principal คืออะไร
รูปแบบคือ
add_principal [child_principal] [parent_principal]
ใช้กำหนดให้ Child สืบทอดจาก Parent
ตัวอย่าง
add_principal identifier.fivem:123456 group.admin
หมายความว่า Identifier นั้นสืบทอดสิทธิ์จาก
group.admin
⑩ ทำไมต้องใช้ Group
แทนที่จะแจก Permission ให้แต่ละคนทีละบรรทัด สามารถสร้าง Group ก่อน
ตัวอย่าง
add_ace group.admin command allow
แล้วเพิ่ม Admin หลายคน
add_principal identifier.fivem:111111 group.admin
add_principal identifier.fivem:222222 group.admin
add_principal identifier.fivem:333333 group.admin
ดูแลง่ายกว่าการแจก ACE ซ้ำให้ทุกคน
⑪ identifier.fivem คืออะไร
FiveM มี Player Identifier หลายประเภท
หนึ่งในนั้นคือ
fivem
ซึ่งเป็น Cfx User ID
ตัวอย่าง Identifier รูปแบบ
fivem:123456
เมื่อนำไปใช้เป็น Principal จะเป็น
identifier.fivem:123456
⑫ FiveM มี Identifier อะไรอีก
เอกสาร Cfx.re ปัจจุบันระบุประเภท เช่น
steam
discord
license
license2
fivem
ip
Identifier ที่ Player มีจริงอาจแตกต่างกันตาม Account และ Connection Environment
⑬ license Identifier คืออะไร
license คือ Identifier จาก Rockstar Online Services
ตัวอย่างโครงสร้าง
license:xxxxxxxxxxxxxxxx
หากระบบ Permission ของคุณออกแบบให้ใช้ Identifier นี้ ต้อง Copy ค่าให้ถูกต้อง
⑭ license2 คืออะไร
Cfx.re ระบุว่า license2 เป็น ROS License ที่อาจมีในผู้ใช้บางกรณี และสามารถมีค่าเดียวกับ license
ดังนั้น Resource ที่จัดการ Identifier ควรเข้าใจว่าผู้เล่นหนึ่งคนอาจมี Identifier หลายประเภท
⑮ Steam Identifier ใช้ได้ไหม
FiveM ยังสามารถรายงาน
steam
Identifier เมื่อมีข้อมูลดังกล่าว
แต่ Server ใหม่ไม่ควรออกแบบ Permission ทั้งหมดโดยสมมุติว่า Player ทุกคนต้องมี Steam Identifier เสมอ
⑯ ตัวอย่าง Official ใช้ identifier.fivem
Vanilla server.cfg ของ Cfx.re มีตัวอย่าง
add_principal identifier.fivem:1 group.admin
โดย 1 เป็นตัวอย่างที่ต้องเปลี่ยนเป็น Cfx Identifier จริงของ Admin
⑰ อย่าใช้เลขตัวอย่างจริง ๆ
ถ้า Copy
add_principal identifier.fivem:1 group.admin
แล้วหวังว่าตัวเองจะได้ Admin สิทธิ์จะไม่ตรงกับ Account ของคุณ
ต้องเปลี่ยน
identifier.fivem:1
เป็น Identifier จริง
⑱ ตัวอย่างตั้ง Admin แบบพื้นฐาน
# Admin permissions
add_ace group.admin command allow
add_ace group.admin command.quit deny
# Admin users
add_principal identifier.fivem:123456 group.admin
เปลี่ยน 123456 เป็น Identifier ของ Admin จริง
⑲ group.admin มีมาให้แบบ Role สำเร็จรูปหรือไม่
group.admin เป็น Principal/Group Name ที่นิยมใช้ใน Config ตัวอย่าง
สิ่งที่ทำให้ Group นี้มี Permission จริงคือ ACE ที่คุณกำหนด เช่น
add_ace group.admin command allow
อย่าคิดว่าเพียงตั้งชื่อว่า group.admin แล้วจะมีสิทธิ์ทุกอย่างโดยอัตโนมัติ
⑳ สร้าง group.moderator ได้ไหม
ได้
ตัวอย่าง
add_ace group.moderator command.kick allow
จากนั้นเพิ่มคน
add_principal identifier.fivem:234567 group.moderator
ทำให้สามารถสร้าง Permission Model หลายระดับได้
㉑ ตัวอย่างแบ่ง Admin กับ Moderator
# Admin
add_ace group.admin command allow
add_ace group.admin command.quit deny
# Moderator
add_ace group.moderator command.kick allow
add_ace group.moderator command.ban allow
# Users
add_principal identifier.fivem:111111 group.admin
add_principal identifier.fivem:222222 group.moderator
ชื่อ Command ต้องตรงกับ Command จริงของ Resources ที่ Server ใช้
㉒ หลัก Least Privilege คืออะไร
อย่าให้ Staff ทุกคนใช้
add_ace group.staff command allow
โดยอัตโนมัติ
ถ้า Moderator ต้องเพียง
Kick
Warn
Teleport
ก็ควรให้เฉพาะ Permission ที่จำเป็นตามระบบจริง
ลดความเสียหายหาก Account ถูกยึดหรือใช้ Command ผิด
㉓ ACE ใช้ได้เฉพาะ Command หรือไม่
ไม่
ACE เป็น ACL System ที่สามารถใช้กับ Object ที่ Resource กำหนดเองได้
ตัวอย่างแนวคิด
add_ace group.admin myresource.admin allow
จากนั้น Resource สามารถตรวจว่า Player ได้รับ myresource.admin หรือไม่
㉔ Resource ตรวจ ACE อย่างไร
FiveM มี Native เช่น
IsPlayerAceAllowed
สำหรับ Server-side Script ใช้ตรวจ Permission ของ Player
แนวคิด
if IsPlayerAceAllowed(source, 'myresource.admin') then
-- อนุญาต
end
เหมาะกับการสร้าง Permission ที่ไม่ต้องผูกกับ Framework โดยตรงทุกกรณี
㉕ ACE ใช้กับ Job ได้ไหม
ในเชิงระบบทำได้
Cfx.re เคยแสดงตัวอย่างใช้ ACL แบบ Dynamic โดยสร้าง Principal เช่น
job.mechanic
และ Object
jobProbe.mechanic
แล้วให้ Resource ตรวจด้วย ACE
แต่ Framework RP จำนวนมากก็มี Job Permission System ของตัวเองเช่นกัน
㉖ ACE กับ Framework Permission เหมือนกันไหม
ไม่เหมือนกัน
ตัวอย่าง Framework อาจมี
admin
god
job
grade
group
ของ Framework เอง
ส่วน ACE เป็น Built-in ACL ของ FXServer
Resource สามารถเลือกใช้
ACE อย่างเดียว
Framework อย่างเดียว
หรือผสมกัน
ตามการออกแบบ
㉗ ACE กับ txAdmin Permission เหมือนกันไหม
ไม่เหมือนกัน และจุดนี้สำคัญมาก
ACE เป็น
FXServer ACL
ส่วน txAdmin มี Permission System ของตัวเอง เช่น
all_permissions
manage.admins
console.view
console.write
control.server
players.kick
players.ban
อย่าสับสนสองระบบ
㉘ ให้ group.admin แล้วได้ txAdmin Admin ไหม
ไม่ควรสรุปว่าได้
การใส่
add_principal identifier.fivem:123456 group.admin
เป็น ACE ของ FXServer
ไม่ได้เท่ากับการสร้าง txAdmin Account พร้อม all_permissions
txAdmin Admin ต้องจัดการผ่านระบบ Admin ของ txAdmin
㉙ txAdmin เก็บ Permission ไว้ที่ไหน
เอกสาร txAdmin ปัจจุบันระบุว่า Admin Permissions ถูกเก็บใน
txData/admins.json
และสามารถแก้ผ่าน Admin Manager โดยผู้มีสิทธิ์ที่เหมาะสม
นี่เป็นระบบคนละชุดกับ ACE ใน server.cfg
㉚ ทำไมต้องแยกสองระบบให้ออก
เพราะอาจเกิดกรณี
ACE Admin
= ใช้ Command บางคำสั่งได้
แต่
txAdmin
= ไม่มีสิทธิ์ Restart Server
หรือกลับกัน
txAdmin Admin
= Ban Player ได้
แต่
ACE
= ไม่มี command บางตัว
นี่ไม่ใช่ Error เสมอไป แต่เป็นเพราะระบบ Permission คนละชุด
㉛ Resource Principal คืออะไร
Resource เองสามารถเป็น Principal ได้
ตัวอย่าง
resource.myframework
Cfx.re มีตัวอย่างให้ Resource ได้สิทธิ์ Execute ACL Commands อย่าง
add_ace resource.myframework command.add_principal allow
add_ace resource.myframework command.remove_principal allow
㉜ ทำไม Resource ต้องขอ ACE
เพราะ Resource ไม่ควรสามารถ Execute Administrative Command ทุกชนิดโดยอัตโนมัติ
ถ้าต้องการใช้
ExecuteCommand
กับ Command ที่มี ACE Protection Resource ต้องได้รับ Permission ที่เหมาะสม
นี่ช่วยจำกัดสิทธิ์ Resource
㉝ อย่าให้ Resource command allow ทั้งหมด
ตัวอย่างที่เสี่ยงเกินไปคือ
add_ace resource.some_script command allow
ถ้า Resource ต้องใช้เพียง
command.add_principal
ก็ควรให้เฉพาะสิทธิ์นั้น
ใช้ Least Privilege กับ Resources เช่นเดียวกับ Admin
㉞ remove_ace คืออะไร
ใช้ลบ Access Control Entry
รูปแบบ
remove_ace [principal] [object] [allow|deny]
ตัวอย่างทางการ
remove_ace identifier.steam:110000112345678 command.apple deny
เหมาะสำหรับเปลี่ยน ACL ระหว่าง Runtime หรือแก้ Configuration
㉟ remove_principal คืออะไร
ใช้ลบความสัมพันธ์การสืบทอด Principal
รูปแบบ
remove_principal [child_principal] [parent_principal]
ตัวอย่าง
remove_principal identifier.fivem:123456 group.admin
ใช้ถอน Player ออกจาก Group ในระดับ ACL Relationship
㊱ ACE สามารถเปลี่ยนระหว่าง Runtime ได้ไหม
ได้
Built-in ACL สามารถถูกกำหนดและปรับระหว่าง Runtime ได้
เช่น Resource อาจใช้
add_ace
add_principal
remove_ace
remove_principal
ผ่าน ExecuteCommand หาก Resource ได้รับ Permission
แต่ Config ถาวรที่ต้องกลับมาทุกครั้งหลัง Restart มักถูกกำหนดไว้ในไฟล์ Configuration หรือระบบ Persistence ที่คุณออกแบบ
㊲ test_ace คืออะไร
ใช้ตรวจว่า Principal ได้รับอนุญาตกับ Object หรือไม่
รูปแบบ
test_ace [principal] [object]
ตัวอย่าง
test_ace group.admin command.adminstuff
เหมาะมากสำหรับ Debug Permission
㊳ ตัวอย่างทดสอบ Admin
สมมุติมี
add_ace group.admin command.kick allow
สามารถตรวจ
test_ace group.admin command.kick
ดูผลจาก ACL ก่อนโทษ Resource
㊴ list_aces คืออะไร
Console Command
list_aces
จะแสดง Access Control Entries ปัจจุบัน
ตัวอย่างแนวคิด
group.admin -> command.test = ALLOW
group.admin -> command.quit = DENY
ช่วยตรวจว่า Rule ถูกโหลดจริงหรือไม่
㊵ list_principals คืออะไร
ใช้
list_principals
เพื่อดูความสัมพันธ์ระหว่าง Child และ Parent Principals
ตัวอย่างแนวคิด
identifier.fivem:123456
← group.admin
ช่วยตรวจว่า Admin ถูกเพิ่มเข้า Group สำเร็จหรือไม่
㊶ se_debug คืออะไร
FiveM มี Console Command
se_debug true
สำหรับเปิด Verbose Logging ของ Security Features อย่าง ACL
มีประโยชน์เมื่อไม่เข้าใจว่าทำไม Player ถูก Allow หรือ Deny
หลัง Debug เสร็จสามารถปิด
se_debug false
㊷ Admin เข้าไม่ได้ให้ตรวจอะไร
ตรวจตามนี้
Identifier ถูกหรือไม่
add_principal ถูกหรือไม่
Group ถูกหรือไม่
add_ace มีหรือไม่
Object ตรงกับ Resource หรือไม่
Config ถูก Execute หรือไม่
จากนั้นใช้
list_principals
list_aces
test_ace
ช่วยยืนยันทีละส่วน
㊸ ทำไม ACE Config ไม่ทำงานหลัง Restart
ตรวจว่า ACE อยู่ใน Config ที่ FXServer โหลดจริง
เช่น
server.cfg
permissions.cfg
admins.cfg
ถ้าแยกไฟล์ ต้องมี
exec permissions.cfg
จาก Configuration หลักที่ถูก Execute
㊹ แยก permissions.cfg ดีไหม
สำหรับ Server ใหญ่ ดี
เช่น
server.cfg
permissions.cfg
resources.cfg
แล้วใน server.cfg
exec permissions.cfg
ทำให้ Permission ไม่ปนกับ Resource Configuration จำนวนมาก
㊺ ตัวอย่าง permissions.cfg
# =========================
# Groups
# =========================
add_ace group.admin command allow
add_ace group.admin command.quit deny
add_ace group.moderator command.kick allow
# =========================
# Users
# =========================
add_principal identifier.fivem:111111 group.admin
add_principal identifier.fivem:222222 group.moderator
เปลี่ยน Identifier และ Commands ตาม Server จริง
㊻ ไม่ควรแจก ACE ด้วย IP เป็นหลัก
แม้ FiveM มี ip Identifier แต่ IP สามารถเปลี่ยนได้ และผู้ใช้บางคนอยู่หลัง NAT/เครือข่ายที่เปลี่ยน Address
สำหรับ Admin Identity ควรใช้ Identifier ที่เหมาะสมกับ Authentication Architecture ของ Server
อย่าพึ่ง IP อย่างเดียวเป็น Identity หลักของ Admin
㊼ ACE ไม่ใช่ระบบ Anti-Cheat
ACE ช่วยควบคุม Permission
แต่ไม่ได้แทน
Server-side validation
Anti-cheat
Secure events
Input validation
Database permissions
ถ้า Resource มี Network Event ที่ Client สามารถเรียกเพื่อแจกเงินโดยไม่ตรวจ Server-side ต่อให้ Admin ACE ถูกต้องก็ยังมีช่องโหว่ได้
㊽ Checklist FiveM ACE Permission
ตรวจให้ครบ
เลือก Identifier ถูก
สร้าง Group ชัดเจน
add_ace เฉพาะสิทธิ์ที่จำเป็น
add_principal ถูก Child/Parent
ไม่แจก command allow เกินจำเป็น
แยก Admin/Moderator
Resource ได้ ACE เท่าที่จำเป็น
ACE กับ txAdmin Permission ไม่สับสน
list_aces ถูก
list_principals ถูก
test_ace ผ่าน
Config ถูก exec
Backup Config แล้ว
㊾ ตัวอย่างโครงสร้าง ACE สำหรับ Production
ตัวอย่างพื้นฐาน
# ==============================
# ADMIN
# ==============================
add_ace group.admin command allow
add_ace group.admin command.quit deny
# ==============================
# MODERATOR
# ==============================
add_ace group.moderator command.kick allow
# ==============================
# RESOURCE PERMISSIONS
# ==============================
add_ace resource.myframework command.add_principal allow
add_ace resource.myframework command.remove_principal allow
# ==============================
# USERS
# ==============================
add_principal identifier.fivem:111111 group.admin
add_principal identifier.fivem:222222 group.moderator
นี่เป็นเพียงโครงสร้างตัวอย่าง ต้องปรับ Object/Command ให้ตรงกับ Resources และ Security Policy จริงของ Server
㊿ สรุป FiveM ACE Permission คืออะไร
ACE Permission คือ ระบบ Access Control ของ FXServer
แกนหลักมี 2 คำสั่งสำคัญ
add_ace [principal] [object] [allow|deny]
สำหรับกำหนด Permission
และ
add_principal [child] [parent]
สำหรับทำให้ Principal หนึ่งสืบทอดสิทธิ์จากอีก Principal
ตัวอย่าง Admin พื้นฐานคือ
add_ace group.admin command allow
add_ace group.admin command.quit deny
add_principal identifier.fivem:123456 group.admin
เครื่องมือ Debug ที่ควรรู้คือ
list_aces
list_principals
test_ace
se_debug
และต้องจำให้ชัดว่า
FXServer ACE
≠
txAdmin Permissions
เพราะ txAdmin มี Permission System ของตัวเอง เช่น
all_permissions
manage.admins
console.write
control.server
players.kick
players.ban
และจัดเก็บ Admin Permissions ใน txData/admins.json
สำหรับ Production Server comsiam แนะนำให้สร้าง Group ตามหน้าที่ เช่น Admin และ Moderator แล้วแจกเฉพาะสิทธิ์ที่จำเป็น แทนการให้ command allow แก่ Staff ทุกคน
Resources ก็เช่นเดียวกัน หาก Resource ต้องใช้เพียง
command.add_principal
command.remove_principal
ก็ให้เฉพาะสองสิทธิ์นี้ ไม่ควรแจกสิทธิ์ Command ทั้งหมด
หลักสำคัญของ FiveM Server comsiam คือ
สร้าง Group
↓
กำหนด ACE
↓
เพิ่ม Identifier เข้า Group
↓
ทดสอบด้วย test_ace
↓
ตรวจด้วย list_aces / list_principals
↓
ให้สิทธิ์น้อยที่สุดที่ทำงานได้
เมื่อเข้าใจ Principal, Object, ACE และ Inheritance แล้ว การตั้ง Admin Permission จะเป็นระบบกว่าการ Hardcode รายชื่อ Admin ลงใน Scripts หลายตัว และยังลดความเสี่ยงจากการแจก Permission มากเกินความจำเป็นอีกด้วย
Comments
Post a Comment