本頁適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
除了在 Apigee UI 中使用安全性動作,您也可以透過 Apigee API 存取所有安全性動作功能。
安全性動作限制
如要瞭解安全性動作的限制,請參閱「安全性動作的限制」。
延遲
安全性動作的延遲時間如下:
- 建立安全防護動作時,該動作最多可能需要 10 分鐘才會生效。措施生效並套用至部分 API 流量後,您就能在「安全性動作詳細資料」頁面中查看措施的影響。注意:即使已採取行動,您也無法從「安全性操作詳細資料」頁面判斷,除非該操作已套用至部分 API 流量。
- 啟用安全性動作會導致 API 代理程式回應時間略微增加 (不到 2%)。
建立安全性動作
以下範例說明如何使用 API 呼叫建立安全性動作。在所有範例中:
ORG
是機構。ENV
是安全性動作的環境。ACTION_NAME
是安全性動作的名稱。
建立拒絕動作
如要建立拒絕動作,請輸入類似下列的指令:
curl -XPOST "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions?security_action_id=ACTION_NAME \ -H "Content-Type: application/json" \ -d '{"state": "ENABLED", "deny": {"response_code": 404}, "condition_config": {"ip_address_ranges": ["100.0.225.0"]}}'
這會建立安全性動作,拒絕存取 ip_address_ranges
後方所列 IP 位址的要求,並傳回回應代碼 404
。
建立標記動作
如要建立標記動作,請輸入類似下列的指令:
curl -XPOST "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions?security_action_id=ACTION_NAME" \ -H "Content-Type: application/json" \ -d '{"state": "ENABLED", "flag": {"headers": [{"name": "senseflag", "value": "flagvalue"}]}, "condition_config": {"ip_address_ranges": ["100.0.230.0"]}}'
這會建立安全性動作,標記 ip_address_ranges
後方所列 IP 位址的請求,並新增標頭 senseflag
,其值為 flagvalue
。
建立允許動作
如要建立允許動作,請輸入類似下列的指令:
curl -XPOST "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions?security_action_id=ACTION_NAME \ -H "Content-Type: application/json" \ -d '{"state": "ENABLED", "allow": {}, "condition_config": {"ip_address_ranges": ["100.0.220.0", "200.0.0.0"]}}'
這會建立安全性動作,允許來自 ip_address_ranges
後方所列 IP 位址的要求。
啟用或停用安全性動作
以下範例說明如何透過 API 呼叫啟用或停用安全性動作。
啟用安全性動作
如要啟用安全性動作,請輸入類似下列的指令:
curl -XPOST "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions/ACTION_NAME:enable"
這會傳回類似以下的回應:
{ "name": "ACTION_ALLOW", "state": "ENABLED", "createTime": "2022-12-29T18:27:31Z", "updateTime": "2023-01-03T23:19:26.650965481Z", "conditionConfig": { "ipAddressRanges": [ "100.0.220.0", "200.0.0.0" ] }, "allow": {}, "expireTime": "2028-01-01T00:00:00Z" }
停用安全性動作
如要停用安全性動作,請輸入類似以下的指令:
curl -XPOST "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions/ACTION_NAME:disable"
這會傳回類似以下的回應:
{ "name": "actionallow", "state": "DISABLED", "createTime": "2022-12-29T18:27:31Z", "updateTime": "2023-01-03T23:13:04.874540001Z", "conditionConfig": { "ipAddressRanges": [ "100.0.220.0", "200.0.0.0" ] }, "allow": {}, "expireTime": "2028-01-01T00:00:00Z" }
取得或列出安全性動作
以下範例說明如何取得或列出安全性動作
取得安全性動作
如要取得安全性動作,請輸入類似以下的指令:
curl -XGET "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions/ACTION_NAME"
這會傳回類似以下的回應:
{ "name": "ACTION_NAME", "state": "DISABLED", "createTime": "2022-12-29T18:27:31Z", "updateTime": "2023-01-03T23:13:04Z", "conditionConfig": { "ipAddressRanges": [ "100.0.220.0", "200.0.0.0" ] }, "allow": {}, "expireTime": "2028-01-01T00:00:00Z" }
列出安全性動作
如要列出所有安全性動作,請輸入類似下方的指令:
curl -XGET "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActions"
暫停或繼續執行安全性動作
以下範例說明如何暫停或恢復安全性動作
暫停所有安全性動作
如要暫停所有安全性動作,請輸入類似下列的指令:
curl -XPATCH "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActionsConfig" \ -H "Content-Type: application/json" \ -d '{"enabled": "false", "name": "organizations/ORG/environments/ENV/securityActionsConfig"}'
這會傳回類似以下的回應:
{ "name": "organizations//environments/ENV/securityActionsConfig", "enabled": false, "updateTime": "2023-01-23T21:44:58.063807Z" } }
繼續執行暫停的安全性動作
如要恢復已暫停的安全防護動作,請輸入類似以下的指令:
curl -XPATCH "https://apigee.googleapis.com/v1/organizations/ORG/environments/ENV/securityActionsConfig" \ -H "Content-Type: application/json" \ -d '{"enabled": "true", "name": "organizations/ORG/environments/ENV/securityActionsConfig"}'
這會傳回類似以下的回應:
{ "name": "organizations/ORG/environments/ENV/securityActionsConfig", "enabled": true, "updateTime": "2023-01-23T21:44:58.063807Z" } }