簡介
本文檔介紹使用OpenAPI管理思科身份服務引擎(ISE)策略的過程。
必要條件
需求
思科建議您瞭解以下主題:
- 思科身分識別服務引擎(ISE)
- REST API
- Python
採用元件
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
背景資訊
從Cisco ISE 3.1開始,更新的API以OpenAPI格式提供。管理策略通過增強互操作性、提高自動化效率、加強安全性、促進創新以及降低成本來最佳化網路安全和管理。此策略允許ISE與其他系統無縫整合,實現自動配置和管理,提供精細的訪問控制,鼓勵第三方創新,並簡化管理流程,從而降低維護成本並提高總體投資回報。
設定
網路圖表
拓撲
ISE上的配置
步驟1.添加OpenAPI admin 帳戶。
要新增API管理員,請導航至Administration > System > Admin Access > Administrators > Admin Users > Add。
API管理員
步驟2.在ISE上啟用OpenAPI。
Open API在ISE上預設禁用。要啟用它,請導航到管理>系統>設定> API設定> API服務設定。切換OpenAPI選項。按一下「Save」。
啟用OpenAPI
步驟3.探索ISE OpenAPI。
導航到Administration > System > Settings > API Settings > Overview。按一下OpenAPI以訪問連結。
訪問OpenAPI
Python示例
Device Admin — 策略集清單
此API檢索裝置管理策略集資訊。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/device-admin/policy-set
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索裝置管理策略集資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/device-admin/policy-set"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'default': True, 'id': '41ed8579-429b-42a8-879e-61861cb82bbf', 'name': 'Default', 'description': 'Tacacs Default policy set', 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': None, 'serviceName': 'Default Device Admin', 'isProxy': False, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/device-admin/policy-set/41ed8579-429b-42a8-879e-61861cb82bbf', 'type': 'application/json'}}]}
Device Admin — 獲取身份驗證規則
此API檢索特定策略集的身份驗證規則。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/device-admin/policy-set/<ID-Of-Policy-Set>/authentication
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索身份驗證規則資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/device-admin/policy-set/41ed8579-429b-42a8-879e-61861cb82bbf/authentication"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
附註:ID來自Device Admin - List Of Policy Sets的步驟3中的API輸出。例如,41ed8579-429b-42a8-879e-61861cb82bbf是TACACS預設策略集。
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'rule': {'default': True, 'id': '73461597-0133-45ce-b4cb-6511ce56f262', 'name': 'Default', 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': None}, 'identitySourceName': 'All_User_ID_Stores', 'ifAuthFail': 'REJECT', 'ifUserNotFound': 'REJECT', 'ifProcessFail': 'DROP', 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/device-admin/policy-set/41ed8579-429b-42a8-879e-61861cb82bbf/authentication/73461597-0133-45ce-b4cb-6511ce56f262', 'type': 'application/json'}}]}
Device Admin — 獲取授權規則
此API檢索特定策略集的授權規則。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/device-admin/policy-set/<ID-Of-Policy-Set>/authorization
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索授權規則資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/device-admin/policy-set/41ed8579-429b-42a8-879e-61861cb82bbf/authorization"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
附註:ID來自Device Admin - List Of Policy Sets的步驟3中的API輸出。例如,41ed8579-429b-42a8-879e-61861cb82bbf是TACACS預設策略集。
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'rule': {'default': True, 'id': '39d9f546-e58c-4f79-9856-c0a244b8a2ae', 'name': 'Default', 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': None}, 'commands': ['DenyAllCommands'], 'profile': 'Deny All Shell Profile', 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/device-admin/policy-set/41ed8579-429b-42a8-879e-61861cb82bbf/authorization/39d9f546-e58c-4f79-9856-c0a244b8a2ae', 'type': 'application/json'}}]}
網路訪問 — 策略集清單
此API檢索ISE部署的網路訪問策略集。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/network-access/policy-set
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索特定ISE節點資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/network-access/policy-set"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'default': False, 'id': 'ba71a417-4a48-4411-8bc3-d5df9b115769', 'name': 'BGL_CFME02-FMC', 'description': None, 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': {'link': None, 'conditionType': 'ConditionAndBlock', 'isNegate': False, 'children': [{'link': None, 'conditionType': 'ConditionAttributes', 'isNegate': False, 'dictionaryName': 'DEVICE', 'attributeName': 'Location', 'operator': 'equals', 'dictionaryValue': None, 'attributeValue': 'All Locations#BGL_CFME02'}, {'link': None, 'conditionType': 'ConditionAttributes', 'isNegate': False, 'dictionaryName': 'DEVICE', 'attributeName': 'Device Type', 'operator': 'equals', 'dictionaryValue': None, 'attributeValue': 'All Device Types#FMCv'}]}, 'serviceName': 'Default Network Access', 'isProxy': False, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769', 'type': 'application/json'}}, {'default': False, 'id': 'f7d82b2d-1007-44f6-961b-efa721d6ebec', 'name': 'SPRT', 'description': None, 'hitCounts': 0, 'rank': 1, 'state': 'enabled', 'condition': {'link': None, 'conditionType': 'ConditionAttributes', 'isNegate': False, 'dictionaryName': 'DEVICE', 'attributeName': 'Device Type', 'operator': 'equals', 'dictionaryValue': None, 'attributeValue': 'All Device Types#SPRT'}, 'serviceName': 'Default Network Access', 'isProxy': False, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/f7d82b2d-1007-44f6-961b-efa721d6ebec', 'type': 'application/json'}}, {'default': True, 'id': '467f6a69-344d-407f-81a4-e87c5dc7e438', 'name': 'Default', 'description': 'Default policy set', 'hitCounts': 0, 'rank': 2, 'state': 'enabled', 'condition': None, 'serviceName': 'Default Network Access', 'isProxy': False, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/467f6a69-344d-407f-81a4-e87c5dc7e438', 'type': 'application/json'}}]}
網路訪問 — 獲取身份驗證規則
此API檢索特定策略集的身份驗證規則。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/network-access/policy-set/<ID-Of-Policy-Set>/authentication
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索身份驗證規則資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769/authentication"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
附註:ID來自網路存取 — 原則設定清單步驟3中的API輸出。例如,ba71a417-4a48-4411-8bc3-d5df9b115769
是BGL_CFME02-FMC
。
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'rule': {'default': True, 'id': '03875777-6c98-4114-a72e-a3e1651e533a', 'name': 'Default', 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': None}, 'identitySourceName': 'S.H.I.E.L.D', 'ifAuthFail': 'REJECT', 'ifUserNotFound': 'REJECT', 'ifProcessFail': 'DROP', 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769/authentication/03875777-6c98-4114-a72e-a3e1651e533a', 'type': 'application/json'}}]}
網路訪問 — 獲取授權規則
此API檢索特定策略集的授權規則。
步驟1. API呼叫所需的資訊。
方法 |
GET |
URL |
https://<ISE-PAN-IP>/api/v1/policy/network-access/policy-set/<ID-Of-Policy-Set>/authorization
|
憑證 |
使用OpenAPI帳戶憑據。 |
標頭 |
接受:application/json
Content-Type:application/json
|
步驟2.查詢用於檢索授權規則資訊的URL。
API URI
步驟3.這是Python代碼的一個示例。複製並貼上內容。替換ISE IP、使用者名稱和密碼。另存為python檔案執行。
確保ISE與運行Python代碼示例的裝置之間的良好連線。
from requests.auth import HTTPBasicAuth
import requests
requests.packages.urllib3.disable_warnings()
if __name__ == "__main__":
url = "https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769/authorization"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
basicAuth = HTTPBasicAuth("ApiAdmin", "Admin123")
response = requests.get(url=url, auth=basicAuth, headers=headers, verify=False)
print("Return Code:")
print(response.status_code)
print("Expected Outputs:")
print(response.json())
附註:ID來自網路訪問 — 策略集清單步驟3中的API輸出。例如,ba71a417-4a48-4411-8bc3-d5df9b115769是BGL_CFME02-FMC。
以下是預期輸出的範例。
Return Code:
200
Expected Outputs:
{'version': '1.0.0', 'response': [{'rule': {'default': False, 'id': 'bc67a4e5-9000-4645-9d75-7c2403ca22ac', 'name': 'FMC Admin', 'hitCounts': 0, 'rank': 0, 'state': 'enabled', 'condition': {'link': None, 'conditionType': 'ConditionAttributes', 'isNegate': False, 'dictionaryName': 'S.H.I.E.L.D', 'attributeName': 'ExternalGroups', 'operator': 'equals', 'dictionaryValue': None, 'attributeValue': 'cisco.com/Cisco/Lab/Groups/FmcAdmin'}}, 'profile': ['FMC-BGL_CFME02-Admin'], 'securityGroup': None, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769/authorization/bc67a4e5-9000-4645-9d75-7c2403ca22ac', 'type': 'application/json'}}, {'rule': {'default': True, 'id': 'e9f3034c-b768-4479-b6c3-3bb64bb6722c', 'name': 'Default', 'hitCounts': 0, 'rank': 1, 'state': 'enabled', 'condition': None}, 'profile': ['DenyAccess'], 'securityGroup': None, 'link': {'rel': 'self', 'href': 'https://10.106.33.92/api/v1/policy/network-access/policy-set/ba71a417-4a48-4411-8bc3-d5df9b115769/authorization/e9f3034c-b768-4479-b6c3-3bb64bb6722c', 'type': 'application/json'}}]}
疑難排解
要排除與OpenAPI相關的問題,請在Debug Log Configurationwindow中將theapiservicecomponent的Log Level設定為DEBUG。
要啟用調試,請導航至操作>故障排除>調試嚮導>調試日誌配置> ISE節點> apiservice。
API服務調試
要下載調試日誌檔案,請導航至操作>故障排除>下載日誌> ISE PAN節點>調試日誌。
下載調試日誌