Minh họa workflow n8n tự động cấp quyền internet theo thời gian trên FortiGate

n8n Workflow: Tự động cấp quyền Internet theo thời gian (FortiGate)

n8n FortiGate Workflow – Node by Node

🔐 n8n Workflow FortiGate: cấp quyền Internet theo giờ (Node-by-Node)

📅 Cập nhật: 23/03/2026 🧪 Mức: Thực chiến Production 🛡️ Đã ẩn toàn bộ thông tin nhạy cảm

1) Tổng quan workflow

Workflow này tự động hóa quy trình cấp quyền truy cập Internet tạm thời cho user theo form yêu cầu, với đầy đủ vòng đời Create → Enforce → Notify → Wait → Cleanup.

  • Tạo group cloud, add user theo email.
  • Clone profile bảo mật trên FortiGate theo template.
  • Tạo schedule theo giờ bắt đầu/kết thúc và tạo firewall policy.
  • Đến giờ hết hạn: tự xóa policy/schedule/profile/group + deauth user session.
  • Gửi email thông báo và lưu log Data Table để audit.
Điểm mạnh: giảm thao tác tay, giảm lỗi người vận hành, có kiểm soát và truy vết đầy đủ.

2) Sơ đồ workflow chi tiết

Sơ đồ workflow n8n FortiGate chi tiết

Hình thực tế workflow trong n8n Editor (đã làm mờ thông tin nhạy cảm).

Form Trigger
  └─ Random code1 → HTTP Request Token (Graph)
      └─ Tạo Group → get user id1 → ADD User vào group
          └─ create group fortigate
              └─ Code in JavaScript1 → Date & Time1 → Fortinet create time1
                  └─ If1
                      ├─ Nhánh A (không_có): create rule → move rule
                      └─ Nhánh B (có ứng dụng):
                          Get app_web
                            ├─ clone aplication profile → Get entries → create/get/update entries
                            └─ clone web profile
                          Merge → Random code_rule → create rule fortigate → move rule
                  └─ Fortigate get rule → Send a message1 → Insert row
                  └─ Wait (đến giờ kết thúc)
                      └─ delete rule → delete schedule → delete app/web profile
                          └─ delete fortigate group → delete azure group
                          └─ monitor firewall user → if active → deauth
                          └─ Send a message2

3) JSON mẫu đã sanitize (public-safe)

Ví dụ một số đoạn endpoint/secret đã được thay bằng placeholder:

{
  "method": "POST",
  "url": "https://<FORTIGATE_HOST>/api/v2/cmdb/firewall/policy/",
  "authentication": "predefinedCredentialType",
  "nodeCredentialType": "fortiGateApi"
}

{
  "url": "https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token",
  "body": {
    "client_id": "<CLIENT_ID>",
    "client_secret": "<CLIENT_SECRET>",
    "grant_type": "client_credentials",
    "scope": "https://graph.microsoft.com/.default"
  }
}

4) Giải thích từng node + vì sao dùng

4.1 Nhóm Input & Identity

NodeLoạiLàm gìVì sao cần
On form submission1FormNhận email user, phòng ban, dịch vụ, ngày giờ, lý do.Chuẩn hóa input, tạo đầu vào duy nhất cho toàn bộ workflow.
Random code1CodeTạo chuỗi random cho naming object.Tránh trùng tên group/rule/profile khi chạy nhiều request.
HTTP Request TokenHTTPLấy access token từ Microsoft OAuth2.Graph API bắt buộc bearer token trước mọi thao tác.
Tạo GroupHTTPTạo security group tạm trên cloud.Tách quyền theo request, dễ thu hồi về sau.
get user id1HTTPTra cứu user object theo email.Cần object id để add member vào group.
ADD User vào groupHTTPThêm user vào group vừa tạo.Hoàn tất identity mapping cloud side.

4.2 Nhóm FortiGate object

NodeLoạiLàm gìVì sao cần
create group fortigateHTTPTạo user group và map với cloud group.Policy FortiGate áp vào group, không áp trực tiếp user.
Code in JavaScript1CodeTạo mã random cho schedule/rule name.Đồng bộ naming giữa nhiều object trong 1 phiên.
Date & Time1DateTimeFormat ngày từ form về chuẩn FortiGate.Tránh lỗi parse khi tạo onetime schedule.
Fortinet create time1HTTPTạo schedule theo giờ bắt đầu/kết thúc.Rule có hạn sử dụng tự động theo business request.
If1IfRẽ nhánh theo loại dịch vụ.Tối ưu: nhánh đơn giản nếu không cần app profile.

4.3 Nhánh “có dịch vụ app/web”

NodeLoạiLàm gìVì sao cần
Get app_webDataTableLấy mapping template theo phòng ban.Tách dữ liệu chính sách khỏi logic workflow.
clone aplication profileHTTPClone app profile từ template.Không sửa trực tiếp profile gốc, giảm rủi ro.
Get entriesDataTableLấy danh sách app entries theo nhu cầu.Cho phép chuẩn hóa quyền theo service catalog.
create/get/update entries aplication profileHTTPĐẩy entries vào profile clone và reorder.Đảm bảo profile đúng thứ tự ưu tiên mong muốn.
clone web profileHTTPClone web filter profile.Tạo profile riêng cho request tạm thời.
Merge + Random code_rule + LimitFlowHợp nhất dữ liệu và giới hạn input tạo rule.Ổn định đầu vào cho node tạo policy.

4.4 Tạo policy + ghi nhận

NodeLoạiLàm gìVì sao cần
create rule / create rule fortigateHTTPTạo firewall policy theo nhánh.Áp dụng quyền truy cập đúng requirement.
Fortigate move rule1 / move rule_NOHTTPMove policy đến vị trí chuẩn.Giữ logic rulebase nhất quán, tránh shadow.
Fortigate get ruleHTTPĐọc lại policy vừa tạo.Lấy policyid và thông tin phục vụ notify/log/cleanup.
Send a message1OutlookGửi mail xác nhận đã tạo.Minh bạch vận hành, thông báo cho IT team.
Insert rowDataTableLưu log rule + thời gian + lý do.Audit trail cho kiểm tra sau này.

4.5 Cleanup tự động khi hết hạn

NodeLoạiLàm gìVì sao cần
WaitWaitChờ đến giờ kết thúc từ form.Thu hồi quyền đúng thời điểm, không cần thao tác tay.
Fortinet delete rule1HTTPXóa policy đã tạo.Loại bỏ quyền truy cập tạm.
Fortinet delete time1HTTPXóa onetime schedule.Dọn tài nguyên phụ trợ.
delete aplication controller + Delete web profileHTTPXóa profile clone.Tránh rác cấu hình theo thời gian.
Delete group fortigateHTTPXóa group trên FortiGate.Đóng vòng identity local.
HTTP Request Token1 + Delete Group AzureHTTPLấy token và xóa cloud group.Đóng vòng identity cloud.
firewall user monitor → If → Wait2 → deauthLogicNếu user vẫn online thì deauth session.Đảm bảo quyền bị thu hồi ngay lập tức.
Send a message2OutlookMail xác nhận đã xóa.Khép vòng kiểm soát thay đổi.

📅 Cập nhật: 2026-03-23 · Workflow: n8n Workflow: Tự động cấp quyền Internet theo thời gian (FortiGate) · n8n / API Automation

Nếu cần file JSON đầy đủ của workflow, vui lòng gửi mail về: [email protected]

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *