Hub XMLRPC APIの認証モード

Table of Contents

Hub XMLRPC APIでは、異なる3つの認証モードがサポートされています。

  • 手動モード(デフォルト): API資格情報を明示的に各サーバに提供する必要があります。

  • リレーモード: Hubでの認証に使用する資格情報を、各サーバに対して認証する際にも使用します。 接続先のサーバのリストを指定する必要があります。

  • 自動接続モード: 資格情報を各サーバに対して再利用し、アクセス権がある周辺サーバは自動的に接続されます。

1. 認証の例

このセクションでは、各認証方法の例を示します。

例: 手動認証

手動モードでは、周辺サーバに接続するには、資格情報を各周辺サーバに対して明示的に提供する必要があります。

手動認証の標準的なワークフローは次のとおりです。

  1. Hubの資格情報がloginメソッドに渡され、Hubのセッションキーが返されます(hubSessionKey)。

  2. 前のステップで返されたセッションキーを使用し、hub.listServerIdsメソッドを介して、Hubに接続されているすべての周辺サーバのSUSE ManagerサーバIDが取得されます。

  3. 各周辺サーバの資格情報がattachToServersメソッドに提供されます。 これが、各サーバのXMLRPC APIエンドポイントに対して認証を実行します。

  4. 一連のサーバ上でmulticastの呼び出しが実行されます。 これはserverIdsで定義され、ターゲットにするサーバのIDが含まれます。バックグラウンドでは、各サーバのXMLRPC APIでsystem.list_systemが呼び出されます。

  5. Hubが結果を集約し、応答をマップの形式で返します。 マップには次の2つのエントリがあります。

    • Successful: 呼び出しが成功した周辺サーバの応答のリスト。

    • Failed: 呼び出しが失敗した周辺サーバの応答のリスト。

1つのSUSE Managerサーバでのみメソッドを呼び出したい場合、Hub APIではunicastネームスペースも提供されています。この場合、SUSE ManagerサーバのAPIを直接呼び出した場合と同じように、応答はマップではなく単一の値になります。

Listing 1. 手動認証用のPythonスクリプトの例:
#!/usr/bin/python3
import xmlrpc.client

HUB_XMLRPC_API_URL = "<HUB_XMLRPC_API_URL>"
HUB_USERNAME = "<USERNAME>"
HUB_PASSWORD = "<PASSWORD>"

client = xmlrpc.client.ServerProxy(HUB_XMLRPC_API_URL, verbose=0)

hubSessionKey = client.hub.login(HUB_USERNAME, HUB_PASSWORD)

# Get the server IDs
serverIds = client.hub.listServerIds(hubSessionKey)

# 簡潔にするため、この例では、ここでHubサーバと同じユーザ名とパスワードを使用していることを想定しています。
# ただし、ほとんどの場合、すべてのサーバには専用の個別の資格情報があります。
usernames = [HUB_USERNAME for s in serverIds]
passwords = [HUB_PASSWORD for s in serverIds]

# 各サーバは上記の資格情報セットを使用します。client.hub.attachToServersに、
# サーバの数と同じ数の要素が含まれるリストとしてこの資格情報を渡す必要があります。
client.hub.attachToServers(hubSessionKey, serverIds, usernames, passwords)

# Perform the operation
systemsPerServer = client.multicast.system.list_systems(hubSessionKey, serverIds)
successfulResponses = systemsPerServer["Successful"]["Responses"]
failedResponses = systemsPerServer["Failed"]["Responses"]

for system in successfulResponses:
  print(system)

# Log out
client.hub.logout(hubSessionKey)
例: リレー認証

リレー認証モードでは、Hub APIへのサインインに使用された資格情報を、ユーザが操作する周辺サーバのAPIへのサインインにも使用します。この認証モードでは、同じ資格情報がすべてのサーバで有効であること、およびその資格情報が適切な許可を持つユーザに対応していることが前提になります。

サインイン後、attachToServersメソッドを呼び出す必要があります。このメソッドにより、後続のすべての呼び出しでターゲットにするサーバを定義します。

リレー認証の標準的なワークフローは次のとおりです。

  1. Hubの資格情報がloginWithAuthRelayModeメソッドに渡され、Hubのセッションキーが返されます(hubSessionKey)。

  2. 前のステップで返されたセッションキーを使用し、hub.listServerIdsメソッドを介して、Hubに接続されているすべての周辺サーバのSUSE ManagerサーバIDが取得されます。

  3. `attachToServers`の呼び出しが実行され、Hubへのサインインに使用されたものと同じ資格情報が各サーバに渡されます。 これが、各サーバのXMLRPC APIエンドポイントに対して認証を実行します。

  4. 一連のサーバ上でmulticastの呼び出しが実行されます。 これはserverIdsで定義され、ターゲットにするサーバのIDが含まれます。バックグラウンドでは、各サーバのXMLRPC APIでsystem.list_systemが呼び出されます。

  5. Hubが結果を集約し、応答をマップの形式で返します。 マップには次の2つのエントリがあります。

    • Successful: 呼び出しが成功した周辺サーバの応答のリスト。

    • Failed: 呼び出しが失敗した周辺サーバの応答のリスト。

Listing 2. リレー認証のPythonスクリプトの例:
#!/usr/bin/python3
import xmlrpc.client

HUB_XMLRPC_API_URL = "<HUB_XMLRPC_API_URL>"
HUB_USERNAME = "<USERNAME>"
HUB_PASSWORD = "<PASSWORD>"

client = xmlrpc.client.ServerProxy(HUB_XMLRPC_API_URL, verbose=0)

hubSessionKey = client.hub.loginWithAuthRelayMode(HUB_USERNAME, HUB_PASSWORD)

# Get the server IDs
serverIds = client.hub.listServerIds(hubSessionKey)

# サーバを認証します(Hubに対する認証に使用されたものと同じ資格情報が使用されます)
client.hub.attachToServers(hubSessionKey, serverIds)

# 必要な操作を実行します
systemsPerServer = client.multicast.system.list_systems(hubSessionKey, serverIds)
successfulResponses = systemsPerServer["Successful"]["Responses"]
failedResponses = systemsPerServer["Failed"]["Responses"]

for system in successfulResponses:
  print(system)

# Log out
client.hub.logout(hubSessionKey)
例: 自動接続認証

Auto-connect mode is similar to relay mode, it uses the Hub credentials to sign in in to all peripheral servers. However, there is no need to use the attachToServers method, as auto-connect mode connects to all available peripheral servers. This occurs at the same time as you sign in to the Hub.

A typical workflow for auto-connect authentication is:

  1. Credentials for the Hub are passed to the loginWithAutoconnectMode method, and a session key for the Hub is returned (hubSessionKey).

  2. 一連のサーバ上でmulticastの呼び出しが実行されます。 これはserverIdsで定義され、ターゲットにするサーバのIDが含まれます。バックグラウンドでは、各サーバのXMLRPC APIでsystem.list_systemが呼び出されます。

  3. Hubが結果を集約し、応答をマップの形式で返します。 マップには次の2つのエントリがあります。

    • Successful: 呼び出しが成功した周辺サーバの応答のリスト。

    • Failed: 呼び出しが失敗した周辺サーバの応答のリスト。

Listing 3. Example Python Script for Auto-Connect Authentication:
#!/usr/bin/python3
import xmlrpc.client

HUB_XMLRPC_API_URL = "<HUB_XMLRPC_API_URL>"
HUB_USERNAME = "<USERNAME>"
HUB_PASSWORD = "<PASSWORD>"

client = xmlrpc.client.ServerProxy(HUB_XMLRPC_API_URL, verbose=0)

loginResponse = client.hub.loginWithAutoconnectMode(HUB_USERNAME, HUB_PASSWORD)
hubSessionKey = loginResponse["SessionKey"]

# Get the server IDs
serverIds = client.hub.listServerIds(hubSessionKey)

# 必要な操作を実行します
systemsPerServer = client.multicast.system.list_systems(hubSessionKey, serverIds)
successfulResponses = systemsPerServer["Successful"]["Responses"]
failedResponses = systemsPerServer["Failed"]["Responses"]

for system in successfulResponses:
  print(system)

# Log out
client.hub.logout(hubSessionKey)