community.general.keycloak_clientscope 模块 – 允许通过 Keycloak API 管理 Keycloak client_scopes

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定:community.general.keycloak_clientscope

community.general 3.4.0 中的新增功能

概要

  • 此模块允许您通过 Keycloak REST API 添加、删除或修改 Keycloak client_scopes。它需要通过 OpenID Connect 访问 REST API;连接的用户和正在使用的客户端必须具有所需的访问权限。在默认的 Keycloak 安装中,admin-cli 和管理员用户可以工作,单独的客户端定义也可以工作,该客户端定义的范围根据您的需要量身定制,并且用户具有预期的角色。

  • 模块选项的名称是 Keycloak API 及其文档中找到的 camelCase 版本的 snake_cased 版本,网址为 https://keycloak.java.net.cn/docs-api/8.0/rest-api/index.html

  • 属性在 Keycloak API 中是多值的。所有属性都是单个值的列表,并且将由此模块以这种方式返回。您可以在调用模块时为属性传递单个值,这将被转换为适合 API 的列表。

  • 在更新 client_scope 时,请尽可能向模块提供 client_scope ID。这将删除 API 的查找,以将名称转换为 client_scope ID。

参数

参数

注释

attributes

字典

一个键/值对字典,设置为 client_scope 的自定义属性。

值可以是单个值(例如字符串)或字符串列表。

auth_client_id

字符串

OpenID Connect client_id,用于使用 API 进行身份验证。

默认值: "admin-cli"

auth_client_secret

字符串

auth_client_id 结合使用的客户端密钥(如果需要)。

auth_keycloak_url

别名:url

字符串 / 必需

Keycloak 实例的 URL。

auth_password

别名:password

字符串

用于使用 API 访问进行身份验证的密码。

auth_realm

字符串

用于使用 API 访问进行身份验证的 Keycloak 领域名称。

auth_username

别名:username

字符串

用于使用 API 访问进行身份验证的用户名。

connection_timeout

整数

在 community.general 4.5.0 中添加

控制到 Keycloak API 的 HTTP 连接超时时间段(以秒为单位)。

默认值: 10

description

字符串

此 client_scope 的描述。

此参数不是更新或删除 client_scope 所必需的。

http_agent

字符串

在 community.general 5.4.0 中添加

配置 HTTP User-Agent 标头。

默认值: "Ansible"

id

字符串

此 client_scope 的唯一标识符。

此参数不是更新或删除 client_scope 所必需的,但是提供它会减少所需的 API 调用次数。

name

字符串

client_scope 的名称。

仅在创建或更新 client_scope 时才需要此参数。

protocol

字符串

客户端的类型。

docker-v2 值在 community.general 8.6.0 中添加。

选择

  • "openid-connect"

  • "saml"

  • "wsfed"

  • "docker-v2"

protocol_mappers

别名:protocolMappers

列表 / 元素=字典

定义此客户端的协议映射器的字典列表。

这是 Keycloak REST API 中的“protocolMappers”。

config

字典

指定协议映射器配置选项的字典;内容因 protocol_mappers[].protocolMapper 的值而异,并且除了映射器的源代码及其父类之外没有其他文档。下面给出一个示例。最容易通过 existing 返回值中的检查模式转储现有的协议映射器配置来获得有效的配置值。

id

字符串

通常是指定此协议映射器实例内部 ID 的 UUID。

name

字符串

此协议映射器的名称。

protocol

字符串

指定此协议映射器所对应的协议。

是否启用。

选择

  • "openid-connect"

  • "saml"

  • "wsfed"

  • "docker-v2"

protocolMapper

字符串

此协议映射器类型的 Keycloak 内部名称。由于用户可以通过 SPI 扩展 Keycloak,因此无法提供详尽的列表。但默认情况下,截至 3.4 版本,Keycloak 至少包含以下映射器:

docker-v2-allow-all-mapper

oidc-address-mapper

oidc-full-name-mapper

oidc-group-membership-mapper

oidc-hardcoded-claim-mapper

oidc-hardcoded-role-mapper

oidc-role-name-mapper

oidc-script-based-protocol-mapper

oidc-sha256-pairwise-sub-mapper

oidc-usermodel-attribute-mapper

oidc-usermodel-client-role-mapper

oidc-usermodel-property-mapper

oidc-usermodel-realm-role-mapper

oidc-usersessionmodel-note-mapper

saml-group-membership-mapper

saml-hardcode-attribute-mapper

saml-hardcode-role-mapper

saml-role-list-mapper

saml-role-name-mapper

saml-user-attribute-mapper

saml-user-property-mapper

saml-user-session-note-mapper

您可以通过访问管理控制台的“服务器信息” -> “提供程序”,并在“协议映射器”下查看您的安装中可用的所有映射器。

realm

字符串

此客户端作用域所在的 Keycloak 域。

默认值: "master"

state

字符串

客户端作用域的状态。

当设置为 present 时,如果客户端作用域尚不存在,则会创建该作用域;如果已存在,则会使用您提供的参数更新该作用域。

当设置为 absent 时,如果客户端作用域存在,则会将其删除。

选择

  • "present" ← (默认)

  • "absent"

token

字符串

在 community.general 3.0.0 中添加。

用于 Keycloak API 的身份验证令牌。

validate_certs

布尔值

验证 TLS 证书(请勿在生产环境中禁用此选项)。

选择

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持: 完整

可以在 check_mode 中运行,并返回更改状态预测,而无需修改目标。

diff_mode

支持: 完整

当处于 diff 模式时,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

示例

- name: Create a Keycloak client_scopes, authentication with credentials
  community.general.keycloak_clientscope:
    name: my-new-kc-clientscope
    realm: MyCustomRealm
    state: present
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
  delegate_to: localhost

- name: Create a Keycloak client_scopes, authentication with token
  community.general.keycloak_clientscope:
    name: my-new-kc-clientscope
    realm: MyCustomRealm
    state: present
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    token: TOKEN
  delegate_to: localhost

- name: Delete a keycloak client_scopes
  community.general.keycloak_clientscope:
    id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
    state: absent
    realm: MyCustomRealm
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
  delegate_to: localhost

- name: Delete a Keycloak client_scope based on name
  community.general.keycloak_clientscope:
    name: my-clientscope-for-deletion
    state: absent
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
  delegate_to: localhost

- name: Update the name of a Keycloak client_scope
  community.general.keycloak_clientscope:
    id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
    name: an-updated-kc-clientscope-name
    state: present
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
  delegate_to: localhost

- name: Create a Keycloak client_scope with some custom attributes
  community.general.keycloak_clientscope:
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    name: my-new_clientscope
    description: description-of-clientscope
    protocol: openid-connect
    protocol_mappers:
      - config:
          access.token.claim: true
          claim.name: "family_name"
          id.token.claim: true
          jsonType.label: String
          user.attribute: lastName
          userinfo.token.claim: true
        name: family name
        protocol: openid-connect
        protocolMapper: oidc-usermodel-property-mapper
      - config:
          attribute.name: Role
          attribute.nameformat: Basic
          single: false
        name: role list
        protocol: saml
        protocolMapper: saml-role-list-mapper
    attributes:
        attrib1: value1
        attrib2: value2
        attrib3:
            - with
            - numerous
            - individual
            - list
            - items
  delegate_to: localhost

返回值

通用返回值已在此处记录:此处,以下是此模块特有的字段

描述

end_state

字典

模块执行后客户端作用域的表示形式(示例已截断)。

返回: 成功时

示例: {"adminUrl": "http://www.example.com/admin_url", "attributes": {"request.object.signature.alg": "RS256"}}

existing

字典

现有客户端作用域的表示形式(示例已截断)。

返回: 总是

示例: {"adminUrl": "http://www.example.com/admin_url", "attributes": {"request.object.signature.alg": "RS256"}}

msg

字符串

有关已采取操作的消息。

返回: 总是

示例: "客户端作用域 testclientscope 更新"

proposed

字典

提议的客户端作用域的表示形式。

返回: 总是

示例: {"clientId": "test"}

作者

  • Gaëtan Daubresse (@Gaetan2907)