community.general.keycloak_clienttemplate (8.5.0) — module

Allows administration of Keycloak client templates via Keycloak API

Authors: Eike Frost (@eikef)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

This module allows the administration of Keycloak client templates via the Keycloak REST API. It requires access to the REST API via OpenID Connect; the user connecting and the client being used must have the requisite access rights. In a default Keycloak installation, admin-cli and an admin user would work, as would a separate client definition with the scope tailored to your needs and a user having the expected roles.

The names of module options are snake_cased versions of the camelCase ones found in the Keycloak API and its documentation at U(https://www.keycloak.org/docs-api/8.0/rest-api/index.html)

The Keycloak API does not always enforce for only sensible settings to be used -- you can set SAML-specific settings on an OpenID Connect client for instance and vice versa. Be careful. If you do not specify a setting, usually a sensible default is chosen.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create or update Keycloak client template (minimal), authentication with credentials
  community.general.keycloak_client:
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    name: this_is_a_test
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create or update Keycloak client template (minimal), authentication with token
  community.general.keycloak_clienttemplate:
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    token: TOKEN
    realm: master
    name: this_is_a_test
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete Keycloak client template
  community.general.keycloak_client:
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    state: absent
    name: test01
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create or update Keycloak client template (with a protocol mapper)
  community.general.keycloak_client:
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    realm: master
    name: this_is_a_test
    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
        consentRequired: true
        consentText: "${familyName}"
        name: family name
        protocol: openid-connect
        protocolMapper: oidc-usermodel-property-mapper
    full_scope_allowed: false
    id: bce6f5e9-d7d3-4955-817e-c5b7f8d65b3f
  delegate_to: localhost

Inputs

    
id:
    description:
    - Id of client template to be worked on. This is usually a UUID.
    type: str

name:
    description:
    - Name of the client template.
    type: str

realm:
    default: master
    description:
    - Realm this client template is found in.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - State of the client template.
    - On V(present), the client template will be created (or updated if it exists already).
    - On V(absent), the client template will be removed if it exists
    type: str

token:
    description:
    - Authentication token for Keycloak API.
    type: str
    version_added: 3.0.0
    version_added_collection: community.general

protocol:
    choices:
    - openid-connect
    - saml
    description:
    - Type of client template.
    type: str

attributes:
    description:
    - A dict of further attributes for this client template. This can contain various
      configuration settings, though in the default installation of Keycloak as of 3.4,
      none are documented or known, so this is usually empty.
    type: dict

auth_realm:
    description:
    - Keycloak realm name to authenticate to for API access.
    type: str

http_agent:
    default: Ansible
    description:
    - Configures the HTTP User-Agent header.
    type: str
    version_added: 5.4.0
    version_added_collection: community.general

description:
    description:
    - Description of the client template in Keycloak.
    type: str

auth_password:
    aliases:
    - password
    description:
    - Password to authenticate for API access with.
    type: str

auth_username:
    aliases:
    - username
    description:
    - Username to authenticate for API access with.
    type: str

auth_client_id:
    default: admin-cli
    description:
    - OpenID Connect C(client_id) to authenticate to the API with.
    type: str

validate_certs:
    default: true
    description:
    - Verify TLS certificates (do not disable this in production).
    type: bool

protocol_mappers:
    description:
    - a list of dicts defining protocol mappers for this client template. This is 'protocolMappers'
      in the Keycloak REST API.
    elements: dict
    suboptions:
      config:
        description:
        - Dict specifying the configuration options for the protocol mapper; the contents
          differ depending on the value of O(protocol_mappers[].protocolMapper) and are
          not documented other than by the source of the mappers and its parent class(es).
          An example is given below. It is easiest to obtain valid config values by dumping
          an already-existing protocol mapper configuration through check-mode in the
          RV(existing) field.
        type: dict
      consentRequired:
        description:
        - Specifies whether a user needs to provide consent to a client for this mapper
          to be active.
        type: bool
      consentText:
        description:
        - The human-readable name of the consent the user is presented to accept.
        type: str
      id:
        description:
        - Usually a UUID specifying the internal ID of this protocol mapper instance.
        type: str
      name:
        description:
        - The name of this protocol mapper.
        type: str
      protocol:
        choices:
        - openid-connect
        - saml
        description:
        - This specifies for which protocol this protocol mapper is active.
        type: str
      protocolMapper:
        description:
        - 'The Keycloak-internal name of the type of this protocol-mapper. While an exhaustive
          list is impossible to provide since this may be extended through SPIs by the
          user of Keycloak, by default Keycloak as of 3.4 ships with at least:'
        - V(docker-v2-allow-all-mapper)
        - V(oidc-address-mapper)
        - V(oidc-full-name-mapper)
        - V(oidc-group-membership-mapper)
        - V(oidc-hardcoded-claim-mapper)
        - V(oidc-hardcoded-role-mapper)
        - V(oidc-role-name-mapper)
        - V(oidc-script-based-protocol-mapper)
        - V(oidc-sha256-pairwise-sub-mapper)
        - V(oidc-usermodel-attribute-mapper)
        - V(oidc-usermodel-client-role-mapper)
        - V(oidc-usermodel-property-mapper)
        - V(oidc-usermodel-realm-role-mapper)
        - V(oidc-usersessionmodel-note-mapper)
        - V(saml-group-membership-mapper)
        - V(saml-hardcode-attribute-mapper)
        - V(saml-hardcode-role-mapper)
        - V(saml-role-list-mapper)
        - V(saml-role-name-mapper)
        - V(saml-user-attribute-mapper)
        - V(saml-user-property-mapper)
        - V(saml-user-session-note-mapper)
        - An exhaustive list of available mappers on your installation can be obtained
          on the admin console by going to Server Info -> Providers and looking under
          'protocol-mapper'.
        type: str
    type: list

auth_keycloak_url:
    aliases:
    - url
    description:
    - URL to the Keycloak instance.
    required: true
    type: str

auth_client_secret:
    description:
    - Client Secret to use in conjunction with O(auth_client_id) (if required).
    type: str

connection_timeout:
    default: 10
    description:
    - Controls the HTTP connections timeout period (in seconds) to Keycloak API.
    type: int
    version_added: 4.5.0
    version_added_collection: community.general

full_scope_allowed:
    description:
    - Is the "Full Scope Allowed" feature set for this client template or not. This is
      'fullScopeAllowed' in the Keycloak REST API.
    type: bool

Outputs

end_state:
  description: Representation of client template after module execution (sample is
    truncated).
  returned: on success
  sample:
    description: test01
    fullScopeAllowed: false
    id: 9c3712ab-decd-481e-954f-76da7b006e5f
    name: test01
    protocol: saml
  type: dict
existing:
  description: Representation of existing client template (sample is truncated).
  returned: always
  sample:
    description: test01
    fullScopeAllowed: false
    id: 9c3712ab-decd-481e-954f-76da7b006e5f
    name: test01
    protocol: saml
  type: dict
msg:
  description: Message as to what action was taken.
  returned: always
  sample: Client template testclient has been updated
  type: str
proposed:
  description: Representation of proposed client template.
  returned: always
  sample:
    name: test01
  type: dict