3.4. OAuth 身份验证概述
作为基本身份验证的替代选择,您可以使用有限的 OAuth 1.0 身份验证。这有时被称为协议版本 1.0a 中的 1 委派 OAuth。
要查看 OAuth 设置,在 Satellite Web UI 中导航至 Administer > Settings > Authentication。OAuth 使用者密钥是 所有 OAuth 客户端要使用的令牌。
Satellite 将 OAuth 设置存储在 /etc/foreman/settings.yaml 文件中。使用 satellite-installer 脚本配置这些设置,因为 Satellite 会升级时覆盖此文件的任何手动更改。
3.4.1. 配置 OAuth 复制链接链接已复制到粘贴板!
要更改 OAuth 设置,请使用所需选项输入 satellite-installer。输入以下命令列出所有与 OAuth 相关的安装程序选项:
satellite-installer --full-help | grep oauth
# satellite-installer --full-help | grep oauth
启用 OAuth 映射
默认情况下,Satellite 将所有 OAuth API 请求授权为内置的匿名 API 管理员帐户。因此,API 响应包括所有 Satellite 数据。但是,您还可以指定向该用户发出请求并限制对数据访问权限的 Foreman 用户。
要启用 OAuth 用户映射,请输入以下命令:
satellite-installer --foreman-oauth-map-users true
# satellite-installer --foreman-oauth-map-users true
Satellite 不在 OAuth 请求中签署标头。具有有效消费者密钥的任何人都可以模拟任何 Foreman 用户。
3.4.2. OAuth 请求格式 复制链接链接已复制到粘贴板!
使用 OAuth 客户端库构建所有 OAuth 参数。每个 OAuth API 请求都需要带有现有 Foreman 用户和 Authorization 标头的 FOREMAN-USER 标头,格式为:
--header 'FOREMAN-USER: sat_username' \ --header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
--header 'FOREMAN-USER: sat_username' \
--header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
示例
本例列出了使用 OAuth 进行身份验证的架构。请求使用 FOREMAN-USER 标头中的 sat_username 用户名。将 --foreman-oauth-map-users 设置为 true 时,响应仅包含用户可访问的架构。签名反映了每个参数、HTTP 方法和 URI 更改。
请求示例:
curl 'https://satellite.example.com/api/architectures' \ --header 'Content-Type: application/json' \ --header 'Accept:application/json' \ --header 'FOREMAN-USER: sat_username' \ --header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
$ curl 'https://satellite.example.com/api/architectures' \
--header 'Content-Type: application/json' \
--header 'Accept:application/json' \
--header 'FOREMAN-USER: sat_username' \
--header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='