準確識別 API 要求中的用戶端 IP 位址,對於 Apigee 中的某些功能 (包括數據分析和進階 API 安全防護) 十分重要,例如濫用行為偵測和安全防護措施。
在採用 Proxy 和負載平衡器的現代網路架構中,用戶端 IP 識別程序相當具有挑戰性,因為這些中介裝置可能會遮蔽真正的來源 IP 位址。
為克服這項挑戰,Apigee 支援環境層級設定,可指定如何從 X-Forwarded-For (XFF) 標頭解析用戶端 IP 位址,並識別標頭中符合網路拓撲和安全需求 IP 位址的索引。使用這項設定可讓您掌握環境中所有要求的用戶端 IP 位址判斷方式,並確保環境中的進階 API 安全性、流程變數和 Analytics 變數,都能一致地識別用戶端 IP 位址。
如果未按照本頁說明設定環境層級的用戶端 IP 位址解析度,系統會使用預設用戶端 IP 位址解析度行為,填入用戶端 IP 位址變數。
預設用戶端 IP 位址解析度
如果未在環境層級設定用戶端 IP 位址解析度,系統會按照「Analytics 維度」一文的說明,計算 ax_resolved_client_ip 維度的預設值。
如果環境已設定用戶端 IP 解析,系統會根據用戶端 IP 解析設定,設定流程和 Analytics 變數。請參閱「為環境設定用戶端 IP 解析」。
何時為環境設定用戶端 IP 位址解析
雖然不一定要設定用戶端 IP 位址解析,但如果預設用戶端 IP 位址解析不符合您的需求,且您想覆寫該設定,為 Analytics、進階 API 安全防護或任何其他需要用戶端 IP 位址一致且可靠資訊的功能提供指定的用戶端 IP 位址解析,則建議您進行設定。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThis page provides guidance on how to accurately identify the client IP address in API requests within Apigee and Apigee hybrid, which is crucial for features like Analytics and Advanced API Security.\u003c/p\u003e\n"],["\u003cp\u003eApigee supports configuring environment-level client IP resolution using the X-Forwarded-For (XFF) header to handle challenges posed by proxies and load balancers that may obscure the true originating IP address.\u003c/p\u003e\n"],["\u003cp\u003eThe client IP resolution configuration uses an \u003ccode\u003eipHeaderName\u003c/code\u003e (currently only X-Forwarded-For) and an \u003ccode\u003eipHeaderIndex\u003c/code\u003e to specify how to extract the client IP from the header, allowing selection from either the left or right side of the address list.\u003c/p\u003e\n"],["\u003cp\u003eIf the client IP resolution is not configured at the environment level, the default client IP address resolution method is applied, but it can be overridden to provide a more precise identification method.\u003c/p\u003e\n"],["\u003cp\u003eAfter setting a client IP resolution, changes can take up to 5 minutes to be applied, updates should not be frequent, and the config can be seen but only set using the API.\u003c/p\u003e\n"]]],[],null,["# Client IP resolution\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nAccurately identifying the client IP address on API requests is important for some functionality\nwithin Apigee, including\n[Analytics](/apigee/docs/api-platform/analytics/analytics-services-overview) and\n[Advanced API Security](/apigee/docs/api-security)\nfeatures such as abuse detection and security actions.\n\nThe client IP identification process is challenging in modern network architectures that employ proxies and load balancers, as\nthese intermediaries can obscure the true originating IP address.\n\nTo overcome this challenge, Apigee supports an environment-level setting specifying\nhow to resolve the client IP address from the X-Forwarded-For (XFF) header, identifying\nthe index in the header that matches the IP address for your network topology and security\nrequirements. Using this setting provides visibility, consistency, and control over how client IP addresses\nare determined for all requests in the environment and results in consistent client IP address identification\nacross Advanced API Security, flow variables, and analytics variables in the environment.\n\nIf the environment-level client IP resolution is not configured as described on this page, the\nclient IP address variables are populated using the\n[default client IP address resolution](#default-client-ip-address-resolution) behavior.\n\nDefault client IP address resolution\n------------------------------------\n\nIf client IP resolution is not configured at the environment level, the default value of the\n`ax_resolved_client_ip` dimension is calculated as described in\n[Analytics dimensions](/apigee/docs/api-platform/analytics/analytics-reference#dimensions).\n\nIf client IP resolution *is* configured for an environment, the flow and Analytics\nvariables are set from the client IP resolution configuration. See\n[Set the client IP resolution for an environment](#set-client-ip-resolution-for-an-environment).\n\nWhen to set the client IP resolution for an environment\n-------------------------------------------------------\n\nAlthough it's not required to set client IP resolution, you might want to if the\n[default client IP address resolution](#default-client-ip-address-resolution) does not\nmeet your needs and you want to override it to provide a specified client IP address\nresolution for Analytics, Advanced API Security, or performing any other function that requires\nconsistent and reliable information on client IP addresses.\n\nUnderstand the client IP resolution configuration syntax\n--------------------------------------------------------\n\nThe client IP resolution setting has this format: \n\n```\n\"clientIpResolutionConfig\": {\n \"headerIndexAlgorithm\": {\n \"ipHeaderName\" : \"X-Forwarded-For\",\n \"ipHeaderIndex\": 2\n }\n}\n```\nwhere\n\n- `ipHeaderName` is the header to use for the client IP. At this time, `X-Forwarded-For` is the supported header value.\n- `ipHeaderIndex` is the index value within the `ipHeaderName`. \n\n A positive number selects an address starting from the left (the first address added to the header), where the first position on the left is `0` and increases by one for each subsequent address (e.g. `0, 1, 2`). For example, if the list is `192.0.2.1, 192.0.2.2, 192.0.2.3`, an index of `1` resolves to `192.0.2.2`. \n\n A negative number selects an address starting from the right (the last address added to the header) where the first position on the right is `-1` and decrements by one for each subsequent address (e.g. `-3, -2, -1`). For example, if the list is `192.0.2.1, 192.0.2.2, 192.0.2.3, 192.0.2.4`, an index of `-1` resolves to `192.0.2.4` and the index `-2` resolves to `192.0.2.3`.\n\nSee the [organizations.environment API](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments#Environment)\nfor additional information about this setting.\n\nView client IP resolution configurations\n----------------------------------------\n\nYou can view the current client IP resolution configuration for an environment using either\nthe Apigee UI or Management APIs.\n\n### View the client IP resolution configuration using the UI\n\nTo view the client IP resolution configuration:\n\n1. In the Google Cloud console, go to the **Management \\\u003e Environments** page.\n\n [Go to Environments](https://console.cloud.google.com/apigee/environments)\n2. Select the environment, and see **Client IP configuration** in\n the **About** tab.\n\n### View the client IP resolution configuration using the API\n\nTo use the Apigee Management APIs to view the client IP resolution configuration, send a request to the\n[organizations.environments.get API](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/get).\n\nSet client IP resolution for an environment\n-------------------------------------------\n\nAfter setting the client IP resolution configuration for an environment, the [`client.resolved.ip`](/apigee/docs/api-platform/reference/variables-reference#client)\nflow variable populates using the specified algorithm. So does the\n[`Resolved Client IP` Analytics dimension](/apigee/docs/api-platform/analytics/analytics-reference#dimensions).\n\nOnce you've set the client IP resolution configuration for an environment, the changes\nmight impact existing Advanced API Security configurations for security action rules. Review and, if necessary, regenerate\nexisting rules to use the new variables and settings.\n\nKeep these implications in mind when selecting the index for Client IP resolution:\n\n- Apigee to Apigee calls are not handled as a special case. Take care to note and skip the number of IPs accordingly.\n- Since the X-Forwarded-For header can be spoofed, it's better to use the right index based on the number of expected hops between the client and the Apigee load balancer. A malicious user can send a pre-filled X-Forwarded-For header. While the first IP in the XFF is closest to the actual client IP, the last IP in the XFF is most trustworthy, given the load balancer knows the TCP client which is connected to it.\n\nTo set client IP resolution on an environment, use one of the Apigee API Management APIs to set\nthe client IP resolution for the environment in the `client_ip_resolution_config`.\nUse\n[organizations.environments.create](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/create)\nfor new environments. Use\n[updateEnvironment](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/updateEnvironment) or\n[modifyEnvironment](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/modifyEnvironment)\nfor existing environments.\n\nTest the client IP address resolution\n-------------------------------------\n\nAfter saving a new client IP configuration, you can test it by following these instructions:\n\n1. Wait at least 5 minutes after saving a new configuration setting.\n2. Start a [debug session](/apigee/docs/api-platform/debug/trace). Enable the setting to **Show all FlowInfos**.\n3. Check the **FlowInfo** just before **Proxy Request Flow Started**. You should see the configured client IP address captured in that section.\n\nLook for these variables in the FlowInfo:\n\n- `client_ip_resolution.resolved.ip`: The resolved client IP address.\n- `client_ip_resolution.used.fallback`: Boolean. This value is `false` unless Apigee fell back to the default client IP resolution due to an inability to use a configured client IP resolution. For example, if the configured resolution specifies an index which doesn't exist in the header.\n- `client_ip_resolution.algorithm`: The algorithm used to determine the client IP address. If configured, this is `\"HeaderIndexAlgorithm{IpHeaderName:`\u003cvar translate=\"no\"\u003eheader_name\u003c/var\u003e`, IpHeaderIndex: `\u003cvar translate=\"no\"\u003e$header_index\u003c/var\u003e`}\"`. Otherwise, this shows `default`.\n\nLimitations\n-----------\n\nThese limitations apply to environment-level client IP resolution:\n\n- Updates to client IP resolution configurations can take up to 5 minutes to be effective.\n- Avoid frequent (for example, every 5 minutes) changes to the client IP resolution configuration, as this could cause performance degradation.\n- Setting the client IP resolution configuration for an environment in Apigee hybrid is available with hybrid versions 1.14.0 and later.\n- The configuration can be viewed via the Apigee Console or API but can be set only via the API.\n- Even in the absence of malicious users, the X-Forwarded-For list relies on each proxy to add the right information to the list. That complete list is outside Apigee's oversight and control, so setting the client IP resolution configuration does not guarantee identification of the correct request IP address."]]