查看 Apigee Edge 說明文件。
前往
Apigee X說明文件。 資訊
結果
- 傳入驗證和授權:驗證 SAML 宣告
政策
透過 SAML 政策類型,API Proxy 可以驗證已附加的 SAML 宣告 傳入的 SOAP 請求中。SAML 政策會驗證傳入郵件, 數位簽署的 SAML 斷言、拒絕無效宣告,並設定 允許額外的政策或後端服務本身,進一步驗證資訊 插入文字。 - 產生傳出權杖:產生 SAML 宣告政策
SAML 政策類型可讓 API Proxy 將 SAML 宣告附加至傳出 XML 要求。 這些斷言可供後端服務運用,進一步套用安全性 來處理驗證和授權的程序
範例
產生 SAML 宣告
<GenerateSAMLAssertion name="SAML" ignoreContentType="false"> <CanonicalizationAlgorithm /> <Issuer ref="reference">Issuer name</Issuer> <KeyStore> <Name ref="reference">keystorename</Name> <Alias ref="reference">alias</Alias> </KeyStore> <OutputVariable> <FlowVariable>assertion.content</FlowVariable> <Message name="request"> <Namespaces> <Namespace prefix="test">http://www.example.com/test</Namespace> </Namespaces> <XPath>/envelope/header</XPath> </Message> </OutputVariable> <SignatureAlgorithm /> <Subject ref="reference">Subject name</Subject> <Template ignoreUnresolvedVariables="false"> <!-- A lot of XML goes here, in CDATA, with {} around each variable --> </Template> </GenerateSAMLAssertion>
產生 SAML 宣告
驗證 SAML 宣告
<ValidateSAMLAssertion name="SAML" ignoreContentType="false"> <Source name="request"> <Namespaces> <Namespace prefix='soap'>http://schemas.xmlsoap.org/soap/envelope/</Namespace> <Namespace prefix='wsse'>http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd</Namespace> <Namespace prefix='saml'>urn:oasis:names:tc:SAML:2.0:assertion</Namespace> </Namespaces> <AssertionXPath>/soap:Envelope/soap:Header/wsse:Security/saml:Assertion</AssertionXPath> <SignedElementXPath>/soap:Envelope/soap:Header/wsse:Security/saml:Assertion</SignedElementXPath> </Source> <TrustStore>TrustStoreName</TrustStore> <RemoveAssertion>false</RemoveAssertion> </ValidateSAMLAssertion>
驗證 SAML 宣告
元素參照
產生 SAML 宣告
| 欄位名稱 | 說明 | ||
|---|---|---|---|
name 項屬性 |
政策執行個體的名稱。名稱不得重複
並根據貴機構的使命
價值觀和目標進行調整名稱中可使用的字元上限為 A-Z0-9._\-$
%。然而,管理 UI 會強制執行其他限制,例如
自動移除非英數字元。 |
||
ignoreContentType 項屬性 |
布林值,可設為 true 或 false。根據預設,
如果訊息的內容類型不是 XML,則系統不會產生斷言
內容類型。如果設為 true,系統會將訊息視為 XML
所有內容類型 |
||
Issuer |
識別資訊提供者的專屬 ID,如果選用
ref
屬性,則系統會根據
指定的變數。如果沒有選用的 ref 屬性,則
值。
|
||
KeyStore |
包含私密金鑰的 KeyStore 名稱以及私密金鑰的別名
。
|
||
OutputVariable |
|||
FlowVariable |
|||
Message |
政策的目標。有效值為 message、request、
和 response。設為 message 時,系統會有條件地政策
根據政策的附件點擷取訊息物件。附加至
要求流程,政策會解析 message 要求,當附加至要求時
回應的流程,政策會解析 message 以回應。 |
||
XPath |
XPath 運算式,會指出傳出 XML 文件中的元素 政策會附加 SAML 宣告。 | ||
SignatureAlgorithm |
SHA1 或 SHA256 | ||
Subject |
SAML 宣告主體的專屬 ID。如果非必要
如果有
ref 屬性,則主體值會在
產生執行要求如果選用的 ref 屬性為
那麼標題就會使用主旨的值
|
||
Template |
如果有的話,就會透過執行這個範本產生斷言
包含對應變數的
{} 物件,然後數位
簽署結果。系統會按照 AssignMessage 政策規則處理範本。
請參閱指派
訊息政策:
|
||
驗證 SAML 宣告
| 欄位名稱 | 說明 |
|---|---|
name 項屬性 |
政策執行個體的名稱。機構中的名稱不得重複。
名稱中可使用的字元上限為
A-Z0-9._\-$ %。
不過,管理 UI 會強制執行其他限制,例如
移除非英數字元。
|
ignoreContentType 項屬性 |
布林值,可設為 true 或 false。根據預設,
如果訊息的內容類型不是 XML,則系統不會產生斷言
內容類型。如果設為 true,系統會將訊息視為 XML
所有內容類型 |
Source |
政策的目標。有效值為 message、request、
和 response。設為 message 時,系統會有條件地政策
根據政策的附件點擷取訊息物件。附加至
要求流程,政策會解析 message 要求,當附加至要求時
回應的流程,政策會解析 message 以回應。 |
XPath |
已淘汰。
Source 的子項。使用
《AssertionXPath》和《SignedElementXPath》。
|
AssertionXPath |
Source 的子項。XPath 運算式,能指出
允許政策擷取 SAML 宣告的傳入 XML 文件。
|
SignedElementXPath |
Source 的子項。XPath 運算式,能指出
繫結 XML 文件,政策可從中擷取已簽署的元素。這個
可能與 AssertionXPath 的 XPath 不同或相同。
|
TrustStore |
包含用於驗證之受信任 X.509 憑證的 TrustStore 名稱
進行數位簽章簽署。
|
RemoveAssertion |
布林值,可設為
true 或 false。時間
true,系統會將 SAML 宣告從要求訊息中移除
便會將訊息轉送至後端服務
|
使用須知
安全宣告標記語言 (SAML) 規格會定義 可讓應用程式交換 XML 格式資訊,以進行驗證及 或授權。
一項「安全性聲明」是信任的權杖,用於描述應用程式使用者的屬性、應用程式使用者 或交易中的其他參與者。資安斷言是由兩個端點管理及消耗 實體類型:
- 識別資訊提供者:代表參與者產生安全性斷言
- 服務供應商:透過與身分的信任關係驗證安全性斷言 提供者
API 平台能夠做為識別資訊提供者和服務供應商。如同 產生斷言並附加至要求訊息,藉此建立斷言 可供後端服務處理的斷言。做為服務供應商 驗證傳入要求訊息的斷言。
SAML 政策類型支援與 SAML Core 2.0 版相符的 SAML 宣告 WS-Security SAML 權杖設定檔規格的規格和 1.0 版。
產生 SAML 宣告
政策處理:
- 如果訊息不是 XML,且 IgnoreContentType 未設為
true,則 並傳送錯誤 - 如果為「Template」,然後按照 AssignMessage 政策中說明處理範本。 如果缺少任何變數且未設定 IgnoreUnresolvedVariables,請引發錯誤。
- 如果為「Template」未設定,然後建構內含 主旨和核發者參數或其參照。
- 使用指定金鑰簽署斷言。
- 將斷言新增至指定的 XPath 訊息。
驗證 SAML 宣告
政策處理:
- 這項政策會檢查傳入訊息,驗證要求的媒體類型是否為 XML。
請檢查內容類型是否符合
text/(.*+)?xml或application/(.*+)?xml。如果媒體類型不是 XML, 如果未設定<IgnoreContentType>,這項政策會引發錯誤。 - 這項政策會剖析 XML。如果剖析失敗,就會引發錯誤。
- 這項政策會使用各自的 XPath 擷取已簽署元素和斷言
指定 (
<SignedElementXPath>和<AssertionXPath>)。 如果上述任一路徑未傳回元素,政策就會引發錯誤。 - 這項政策會驗證斷言與已簽署的元素相同。 是已簽署元素的子項。如果禁止,政策就會引發錯誤。
- 如果
<NotBefore>或<NotOnOrAfter>其中之一 元素都存在於斷言中,政策就會根據 這些值如 SAML Core 第 2.5.1 節所述。 - 這項政策將套用任何其他處理「條件」規則 。
- 這項政策會使用
<TrustStore>和<ValidateSigner>(如上所述)。 如果驗證失敗,這項政策會引發錯誤。
等政策完成後再提出錯誤,但 Proxy 的開發人員 下列項目:
- 斷言中的數位簽章有效,且由信任的 CA 簽署
- 斷言在目前時間範圍內有效
- 系統會擷取斷言的主體和核發者,並在流程變數中設定。是 其他政策也必須負責將這些值用於其他驗證,例如 檢查主體名稱是否有效,或傳遞至目標系統進行驗證。
ExtractVariables 等其他政策可能會用於剖析斷言的原始 XML 來處理更複雜的驗證方式
流程變數
SAML 宣告中可以指定許多資訊。SAML 斷言本身是 XML,可使用 ExtractVariables 政策和其他 機制來處理更複雜的驗證。
| 變數 | 說明 |
|---|---|
saml.id |
SAML 宣告 ID |
saml.issuer |
「核發者」的斷言,從其原生 XML 型別轉換為字串 |
saml.subject |
「Subject」的斷言,從其原生 XML 型別轉換為字串 |
saml.valid |
根據有效性檢查結果傳回 true 或 false |
saml.issueInstant |
IssueInstant |
saml.subjectFormat |
主旨格式 |
saml.scmethod |
主旨確認方式 |
saml.scdaddress |
主體確認資料地址 |
saml.scdinresponse |
回覆中的主旨確認資料 |
saml.scdrcpt |
主旨確認資料收件者 |
saml.authnSnooa |
驗證 SessionNotOnOr 後 |
saml.authnContextClassRef |
AuthnStatement AuthnContextClassRef |
saml.authnInstant |
AuthnStatement 驗證即時性 |
saml.authnSessionIndex |
驗證工作階段索引 |
錯誤參考資料
This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Deployment errors
These errors can occur when you deploy a proxy containing this policy.
| Error name | Cause | Fix |
|---|---|---|
SourceNotConfigured |
One or more of the following elements of the Validate SAML Assertion
policy is not defined or empty: <Source>, <XPath>,
<Namespaces>, <Namespace>.
|
build |
TrustStoreNotConfigured |
If the <TrustStore> element is empty or not specified in the
ValidateSAMLAssertion policy, then the deployment of the API proxy fails.
A valid Trust Store is required.
|
build |
NullKeyStoreAlias |
If the child element <Alias> is empty or not specified in the <Keystore>
element of Generate SAML Assertion policy, then the deployment of the API
proxy fails. A valid Keystore alias is required.
|
build |
NullKeyStore |
If the child element <Name> is empty or not specified in the <Keystore>
element of GenerateSAMLAssertion policy, then the deployment of the API
proxy fails. A valid Keystore name is required.
|
build |
NullIssuer |
If the <Issuer> element is empty or not specified in the Generate SAML
Assertion policy, then the deployment of the API proxy fails. A
valid <Issuer> value is required.
|
build |
Fault variables
These variables are set when a runtime error occurs. For more information, see What you need to know about policy errors.
| Variables | Where | Example |
|---|---|---|
fault.name="fault_name" |
fault_name is the name of the fault. The fault name is the last part of the fault code. | fault.name = "InvalidMediaTpe" |
GenerateSAMLAssertion.failed |
For a validate SAML assertion policy configuration, the error prefix is
ValidateSAMLAssertion. |
GenerateSAMLAssertion.failed = true |
Example error response
{ "fault": { "faultstring": "GenerateSAMLAssertion[GenSAMLAssert]: Invalid media type", "detail": { "errorcode": "steps.saml.generate.InvalidMediaTpe" } } }
Example fault rule
<FaultRules>
<FaultRule name="invalid_saml_rule">
<Step>
<Name>invalid-saml</Name>
</Step>
<Condition>(GenerateSAMLAssertion.failed = "true")</Condition>
</FaultRule>
</FaultRules>相關主題
擷取變數:擷取變數 政策