Bỏ qua tới nội dung
CloudDojo
Phần 3/7 · 7 phút

Listener rule của Application Load Balancer

0/3
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

Khi hệ thống tách thành nhiều service, một load balancer vẫn có thể đứng trước tất cả và chuyển từng request tới đúng service dựa trên đường dẫn hoặc tên miền.

MFTECH tách hệ thống thành service đơn hàng, service sản phẩm và các microsite khuyến mãi, mỗi thành phần có một target group riêng. Tất cả vẫn nằm sau một ALB. Mỗi request đi qua listener HTTPS: lựa chọn chứng chỉ (SNI), AWS WAF, sau đó listener rule khớp điều kiện (path, host) thực hiện các action của rule: xác thực (nếu có action authenticate) rồi forward tới target group. Chọn tình huống và gửi request:

GET https://mftech.vn/products/ao-thunnguồn: Việt Nam
Application Load Balancer · listener HTTPS :443Người dùngChứng chỉchọn theo SNIAWS WAFweb ACLRuleđiều kiệnActionauthenticateTG orderspath /orders/*TG productspath /products/*TG micrositehost *.mftech.vnTG webdefault action

Nhấn Gửi request để quan sát từng bước xử lý.

Xem request qua trạm điều phối: kiểm chứng chỉ, qua tường thành WAF, rồi xét luật theo thứ tự: đường dẫn, tên miền, đăng nhập Cognito.

Ngoài path và host, listener rule có thêm bốn loại điều kiện: http-header, http-request-method, query-string và source-ip (dạng CIDR). Mỗi rule có priority; ALB xét rule từ giá trị priority nhỏ tới lớn, dừng ở rule đầu tiên khớp mọi điều kiện, và default rule luôn được xét cuối cùng. Action có thể là forward, redirect (301 hoặc 302; chuyển được HTTP sang HTTPS, không chuyển được HTTPS sang HTTP), fixed-response (trả mã 2XX, 4XX hoặc 5XX ngay tại ALB) hoặc authenticate. Chọn request và quan sát rule nào xử lý:

Request
GET https://mftech.vn/products/ao-thunIP nguồn: 198.51.100.7
Listener HTTP :80priority · điều kiện · action
default(mọi request còn lại)redirect 301 → HTTPS :443
Listener HTTPS :443priority · điều kiện · action
10source-ip: 203.0.113.0/24path-pattern: /admin/*forward → TG admin
20path-pattern: /admin/*fixed-response 403
30http-header: X-App-Platform: mobileforward → TG mobile-api
40query-string: version=betaforward → TG products-beta
50http-request-method: POSTpath-pattern: /orders/*forward → TG orders-write
60path-pattern: /orders/*forward → TG orders
70path-pattern: /products/*forward → TG products
default(mọi request còn lại)forward → TG web

Chọn một request, sau đó nhấn Đánh giá rule. ALB xét các rule theo priority từ giá trị nhỏ tới lớn và dừng ở rule đầu tiên khớp mọi điều kiện.

Ghi nhớ:
  • Listener rule định tuyến theo path (/orders/*, không xét query string), host (*.mftech.vn khớp khuyenmai.mftech.vn nhưng không khớp tên miền gốc mftech.vn), header, method, query string và IP nguồn; rule có priority nhỏ hơn được xét trước.
  • Listener HTTP :80 dùng action redirect để chuyển sang HTTPS.
  • ALB không có cơ chế giới hạn tốc độ request: liên kết AWS WAF và dùng rate-based rule (mặc định đếm theo IP nguồn, evaluation window 1, 2, 5 hoặc 10 phút, ngưỡng tối thiểu 10 request).
  • ALB tích hợp xác thực với Cognito.
Part 3/7 · 7 phút

Listener rules for your Application Load Balancer

0/3
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

When a system splits into several services, one load balancer can still front them all and send each request to the right service by path or domain name.

MFTECH splits its system into an orders service, a products service and promotional microsites, each with its own target group. They all still sit behind one ALB. Each request goes through the HTTPS listener: certificate selection (SNI), AWS WAF, then the listener rule whose conditions (path, host) match performs the rule’s actions: authentication (if there is an authenticate action), then forward to a target group. Pick a scenario and send a request:

GET https://mftech.vn/products/ao-thunnguồn: Việt Nam
Application Load Balancer · listener HTTPS :443Người dùngChứng chỉchọn theo SNIAWS WAFweb ACLRuleđiều kiệnActionauthenticateTG orderspath /orders/*TG productspath /products/*TG micrositehost *.mftech.vnTG webdefault action

Nhấn Gửi request để quan sát từng bước xử lý.

Xem request qua trạm điều phối: kiểm chứng chỉ, qua tường thành WAF, rồi xét luật theo thứ tự: đường dẫn, tên miền, đăng nhập Cognito.

Besides path and host, listener rules have four more condition types: http-header, http-request-method, query-string and source-ip (in CIDR form). Each rule has a priority; the ALB evaluates rules from the lowest priority value to the highest, stops at the first rule whose conditions all match, and always evaluates the default rule last. An action can be forward, redirect (301 or 302; HTTP to HTTPS is allowed, HTTPS to HTTP is not), fixed-response (returns a 2XX, 4XX or 5XX code at the ALB) or authenticate. Pick a request and see which rule handles it:

Request
GET https://mftech.vn/products/ao-thunIP nguồn: 198.51.100.7
Listener HTTP :80priority · điều kiện · action
default(mọi request còn lại)redirect 301 → HTTPS :443
Listener HTTPS :443priority · điều kiện · action
10source-ip: 203.0.113.0/24path-pattern: /admin/*forward → TG admin
20path-pattern: /admin/*fixed-response 403
30http-header: X-App-Platform: mobileforward → TG mobile-api
40query-string: version=betaforward → TG products-beta
50http-request-method: POSTpath-pattern: /orders/*forward → TG orders-write
60path-pattern: /orders/*forward → TG orders
70path-pattern: /products/*forward → TG products
default(mọi request còn lại)forward → TG web

Chọn một request, sau đó nhấn Đánh giá rule. ALB xét các rule theo priority từ giá trị nhỏ tới lớn và dừng ở rule đầu tiên khớp mọi điều kiện.

Ghi nhớ:
  • Listener rules route by path (/orders/*, the query string is not considered), host (*.mftech.vn matches khuyenmai.mftech.vn but not the apex domain mftech.vn), header, method, query string and source IP; a rule with a lower priority value is evaluated first.
  • The HTTP :80 listener uses a redirect action to move clients to HTTPS.
  • The ALB has no built-in request rate limiting: associate AWS WAF and use a rate-based rule (counts by source IP by default, evaluation window of 1, 2, 5 or 10 minutes, minimum limit of 10 requests).
  • The ALB integrates authentication with Cognito.

Kiểm tra nhanh

Trả lời để ghi nhận đã đọc phần này. Câu trả lời sai sẽ được nhắc ôn lại vào những ngày sau.

ALB có listener rule với điều kiện host *.mftech.vn chuyển tới target group khuyến mãi. Request tới https://mftech.vn/ được xử lý thế nào?
Một nhóm IP gửi hơn 100 request mỗi giây tới website sau ALB. Cách nào chặn được các IP vượt ngưỡng?

Đã trả lời 0/2 câu