取得redfish RESTful API的存取權限

server 都有提供嵌入式的系統來管理及監控主機,HPE 有 iLO(HPE Integrated Lights-Out),而 DELL 有 iDRAC(Integrated Dell Remote Access Controller),除了能以網頁進行管理,同時也提供 API,兩家都使用Redfish這個 API 標準,減少不同品牌間 API 不相容的問題

iLO/iDRAC 登入機制

使用 Redfish API 對 iLO/iDRAC 進行存取時,首先要通過認證,授權用戶才能進行後讀操作,認證方式有兩種

  • Basic authentication 每次存取 API 時都要帶上帳號與密碼,適合簡單存取

  • Session-based authentication 先取得 token(X-Auth-Token),接下來的操作都使用這組X-Auth-Token,最後再結束前再DELETE token,釋放資源

下面以REST Client這個 VS code 工具來測試 API

Basic authentication

每次在執行 get mothod 時,在 header 加上Authorization Base <帳號>:<密碼>的內容

1
2
GET https://{{host}}/redfish/v1/SeesionService/Sessions HTTP/1.1
Authorization Base <帳號>:<密碼>

cURL版本

1
2
3
4
5
6
HOST="10.10.10.10" # iDRAC或iLO IP
USER="username" # iDRAC username
PASS="password" # iDRAC password
curl --request GET \
  --url "https://$HOST/redfish/v1/SeesionService/Sessions" \
  --header 'authorization: Basic $(echo -n "$USER:$PASS" | base64)'

Session-based authentication

  1. 取得 token

Basic authentication 是把帳密塞在 header,而這裡是塞在 payload

1
2
3
4
5
6
7
8
# @name iDRAC_token
POST https://{{host}}/redfish/v1/SeesionService/Sessions HTTP/1.1
Content-Type: application/json

{
    "UserName": "<iDRAC帳號>",
    "Password": "<iDRAC密碼>"
}

response header 中的X-Auth-TokenLocation這兩個屬性,接下來會使用到

  1. 接下來所有操作,使用前一步取得的 token,塞在 header 的X-Auth-Token的屬性
1
2
GET https://{{host}}/redfish/v1/Systems/System.Embedded.1
X-Auth-Token: {{iDRAC_token.response.headers.X-Auth-Token}}
  1. 取得結束後刪除 token,釋放資源

DELETE 會用到稍早取得的 Location 屬性的值

1
2
DELETE https://{{host}}{{iDRAC_token.response.headers.Location}}
X-Auth-Token: {{iDRAC_token.response.headers.X-Auth-Token}}
Built with Hugo
Theme Stack designed by Jimmy