mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2026-11-21 22:50:34 +00:00
Compare commits
121
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82f9a97e5a | ||
|
|
08ee1c33bc | ||
|
|
e103524781 | ||
|
|
45863b3023 | ||
|
|
9ac8274434 | ||
|
|
0716f622ad | ||
|
|
14cba062b4 | ||
|
|
9d56a54bd8 | ||
|
|
8c3c4d8cbc | ||
|
|
638f694120 | ||
|
|
86bd6c77d6 | ||
|
|
6644207e5d | ||
|
|
5ba8098c15 | ||
|
|
d6ceb63914 | ||
|
|
529b667321 | ||
|
|
8d5526aeb6 | ||
|
|
afc12b6ae2 | ||
|
|
0868b58e90 | ||
|
|
2ffe3a8f7b | ||
|
|
6814939116 | ||
|
|
24350903ed | ||
|
|
89cb1691ae | ||
|
|
79852e61fc | ||
|
|
8007d8039a | ||
|
|
85d494731a | ||
|
|
d41fc161be | ||
|
|
4e1d14c4a1 | ||
|
|
e9f74fa4a9 | ||
|
|
23d96186f5 | ||
|
|
b48b0b7334 | ||
|
|
9446e53b6e | ||
|
|
a29e1a0c0e | ||
|
|
f082e8adb1 | ||
|
|
a4cdf1b154 | ||
|
|
4112ac7d71 | ||
|
|
a965f47fb8 | ||
|
|
15356606f3 | ||
|
|
8021fd735d | ||
|
|
412f3f405d | ||
|
|
e5f6f92c5d | ||
|
|
3d9c71a2e6 | ||
|
|
742c44039c | ||
|
|
9c347d1bf0 | ||
|
|
6023cff8ca | ||
|
|
fd13175e45 | ||
|
|
c831534a48 | ||
|
|
192061d1b5 | ||
|
|
bba9d8bb23 | ||
|
|
7a1dbad76f | ||
|
|
50e1d93184 | ||
|
|
786ef844f8 | ||
|
|
8d44d73394 | ||
|
|
c8253fdbf8 | ||
|
|
9abf2e832b | ||
|
|
9e5946a2a4 | ||
|
|
ef2f24e9fc | ||
|
|
866c5e2255 | ||
|
|
a0b924b593 | ||
|
|
95c6fe1b50 | ||
|
|
9bb680b8e6 | ||
|
|
1f0a7c289f | ||
|
|
ff51c4098a | ||
|
|
f2792e32ba | ||
|
|
4f62617f2c | ||
|
|
edb38ebb3d | ||
|
|
d25bf46a6a | ||
|
|
74ca1e05ef | ||
|
|
b9181abb24 | ||
|
|
d4eafe1b30 | ||
|
|
19bd41a86a | ||
|
|
b44d754b8c | ||
|
|
404d2f6a1b | ||
|
|
bfcb125d87 | ||
|
|
1164bf008d | ||
|
|
f3353d1686 | ||
|
|
e4c3ec8046 | ||
|
|
82022b9031 | ||
|
|
0307985282 | ||
|
|
b0d1114684 | ||
|
|
728d5288ec | ||
|
|
eaeedd8d74 | ||
|
|
86a6bc63bb | ||
|
|
d557665dc9 | ||
|
|
bd82a85dea | ||
|
|
1f82f50127 | ||
|
|
adf0f7fc36 | ||
|
|
0a9e6c66eb | ||
|
|
da3d5e0ed6 | ||
|
|
f172e019b4 | ||
|
|
e764cfd6f1 | ||
|
|
01b00dfb2e | ||
|
|
1908794569 | ||
|
|
c8bcff39ef | ||
|
|
0fad56294b | ||
|
|
b2b52ddfb5 | ||
|
|
7369a5724c | ||
|
|
942f0ae896 | ||
|
|
92d6dddd49 | ||
|
|
a1bb84ea5b | ||
|
|
1ec94b961f | ||
|
|
ba3f716e5c | ||
|
|
808d137e4c | ||
|
|
1794d4ff9b | ||
|
|
e898a2511a | ||
|
|
dd2cfaa87d | ||
|
|
b114c7b252 | ||
|
|
9920dc93c9 | ||
|
|
5cb555d6c2 | ||
|
|
3ab0f2b259 | ||
|
|
9394e2598f | ||
|
|
123906d739 | ||
|
|
bdc090de64 | ||
|
|
d4a92c9f4f | ||
|
|
926ea0192d | ||
|
|
88c825c997 | ||
|
|
0e3a9e3741 | ||
|
|
7495385ccb | ||
|
|
494a522ab2 | ||
|
|
64e7fa3129 | ||
|
|
15a0c6ee46 | ||
|
|
e4d1a79d1f |
+2
-2
@@ -1,4 +1,6 @@
|
||||
# .ansible-lint
|
||||
profile: production
|
||||
|
||||
exclude_paths:
|
||||
- .cache/
|
||||
- .github/
|
||||
@@ -36,7 +38,5 @@ skip_list:
|
||||
- vars_should_not_be_used
|
||||
- file_is_small_enough
|
||||
- file_has_valid_name
|
||||
- name[template]
|
||||
- var-naming[no-role-prefix]
|
||||
|
||||
use_default_rules: true
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
# Keycloak / Ansible domain-specific words
|
||||
# Only terms NOT covered by built-in dictionaries
|
||||
|
||||
# Product names and projects
|
||||
Infinispan
|
||||
infinispan
|
||||
Wildfly
|
||||
wildfly
|
||||
keycloak
|
||||
|
||||
# Red Hat product names
|
||||
RHBK
|
||||
rhbk
|
||||
rhsso
|
||||
|
||||
# Java / JBoss terms
|
||||
Djboss
|
||||
Djgroups
|
||||
Dsun
|
||||
ispn
|
||||
ISPN
|
||||
jaegertracing
|
||||
jaxrs
|
||||
jberet
|
||||
JDBCPING
|
||||
jgroups
|
||||
JGROUPSPING
|
||||
jndi
|
||||
keytool
|
||||
MPING
|
||||
NAKACK
|
||||
passivation
|
||||
passivating
|
||||
slsb
|
||||
sfsb
|
||||
TCPPING
|
||||
tcpping
|
||||
jdbcx
|
||||
cacerts
|
||||
changeit
|
||||
|
||||
# Systemd directives
|
||||
restartsec
|
||||
runas
|
||||
startlimitburst
|
||||
systemdunit
|
||||
|
||||
# Ansible terms
|
||||
fqcn
|
||||
FQCN
|
||||
|
||||
# WildFly / JBoss terms
|
||||
jbcs
|
||||
modcluster
|
||||
|
||||
# Linux / System terms
|
||||
firewalld
|
||||
cgroupns
|
||||
zgrep
|
||||
|
||||
# Configuration terms
|
||||
xforwarded
|
||||
PYTHONHTTPSVERIFY
|
||||
|
||||
# Keycloak-specific
|
||||
ciba
|
||||
clusterless
|
||||
remembertochangeme
|
||||
|
||||
# Molecule / Testing
|
||||
hspaans
|
||||
|
||||
# CI / DevOps
|
||||
sangonzal
|
||||
rootperm
|
||||
|
||||
# RST / Sphinx directives
|
||||
toctree
|
||||
|
||||
# Task names / verbs
|
||||
Reown
|
||||
decomment
|
||||
|
||||
# British spellings (from upstream Keycloak docs)
|
||||
recognises
|
||||
|
||||
# Other
|
||||
rmaster
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
# Weekly keeps Actions dependency PRs current without daily CI load.
|
||||
interval: weekly
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
# Partner Certification Checker workflow for Automation Hub requirements.
|
||||
# See: https://github.com/ansible-collections/partner-certification-checker
|
||||
name: Run collection certification checks
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: cert-ver-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
# Files that are not related to the core functionality of your collection can
|
||||
# cause Ansible Lint to fail. If this happens, add an .ansible-lint file that
|
||||
# excludes those paths. See .ansible-lint in this repository.
|
||||
#
|
||||
# If there are sanity test failures that cannot be fixed, create a sanity ignore
|
||||
# file for each affected ansible-core version (for example, tests/sanity/ignore-2.18.txt).
|
||||
jobs:
|
||||
call:
|
||||
uses: ansible-collections/partner-certification-checker/.github/workflows/certification-reusable.yml@f4bf7ba4d3f008b2db8fc6a812fa3f89fdf42c2e # v4.1.0
|
||||
@@ -14,6 +14,18 @@ on:
|
||||
- cron: '15 6 * * *'
|
||||
|
||||
jobs:
|
||||
spellcheck:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Run cspell
|
||||
uses: streetsidesoftware/cspell-action@v9
|
||||
with:
|
||||
incremental_files_only: false
|
||||
use_cspell_files: true
|
||||
|
||||
ci:
|
||||
uses: ansible-middleware/github-actions/.github/workflows/ci.yml@rootperm
|
||||
secrets: inherit
|
||||
@@ -22,4 +34,4 @@ jobs:
|
||||
root_permission_varname: 'keycloak_install_requires_become'
|
||||
debug_verbosity: "${{ github.event.inputs.debug_verbosity }}"
|
||||
molecule_tests: >-
|
||||
[ "debian", "quarkus", "quarkus_ha", "quarkus_ha_remote", "quarkus_ha_26.4_below", "default", "quarkus_devmode", "quarkus_upgrade" ]
|
||||
[ "debian", "sso_test", "quarkus", "quarkus_ha", "quarkus_ha_remote", "quarkus_ha_26.4_below", "default", "quarkus_devmode", "quarkus_upgrade", "keycloak_modules", "quarkus_relpath" ]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Publish collection
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
uses: ansible-middleware/github-actions/.github/workflows/publish.yml@main
|
||||
with:
|
||||
collection_fqcn: 'middleware_automation.keycloak'
|
||||
downstream_name: 'rhbk'
|
||||
secrets:
|
||||
galaxy_token: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
|
||||
jira_webhook: ${{ secrets.JIRA_WEBHOOK_CREATE_VERSION }}
|
||||
push_token: ${{ secrets.TRIGGERING_PAT }}
|
||||
|
||||
dispatch:
|
||||
needs: publish
|
||||
if: needs.publish.result == 'success'
|
||||
strategy:
|
||||
matrix:
|
||||
repo: ['ansible-middleware/ansible-middleware-ee']
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v4
|
||||
with:
|
||||
token: ${{ secrets.TRIGGERING_PAT }}
|
||||
repository: ${{ matrix.repo }}
|
||||
event-type: "Dependency released - Keycloak v${{ needs.publish.outputs.tag_version }}"
|
||||
client-payload: '{ "github": ${{toJson(github)}} }'
|
||||
@@ -17,18 +17,4 @@ jobs:
|
||||
secrets:
|
||||
galaxy_token: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
|
||||
jira_webhook: ${{ secrets.JIRA_WEBHOOK_CREATE_VERSION }}
|
||||
|
||||
dispatch:
|
||||
needs: release
|
||||
strategy:
|
||||
matrix:
|
||||
repo: ['ansible-middleware/ansible-middleware-ee']
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
with:
|
||||
token: ${{ secrets.TRIGGERING_PAT }}
|
||||
repository: ${{ matrix.repo }}
|
||||
event-type: "Dependency released - Keycloak v${{ needs.release.outputs.tag_version }}"
|
||||
client-payload: '{ "github": ${{toJson(github)}} }'
|
||||
push_token: ${{ secrets.TRIGGERING_PAT }}
|
||||
|
||||
@@ -8,7 +8,7 @@ jobs:
|
||||
traffic:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
ref: "gh-pages"
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
TRAFFIC_ACTION_TOKEN: ${{ secrets.TRIGGERING_PAT }}
|
||||
|
||||
- name: Commit changes
|
||||
uses: EndBug/add-and-commit@v4
|
||||
uses: EndBug/add-and-commit@v11
|
||||
with:
|
||||
author_name: Ansible Middleware
|
||||
message: "GitHub traffic"
|
||||
|
||||
@@ -11,6 +11,9 @@ docs/_build/
|
||||
.mypy_cache/
|
||||
*.retry
|
||||
changelogs/.plugin-cache.yaml
|
||||
changelogs/fragments/*.yaml
|
||||
changelogs/fragments/*.yml
|
||||
|
||||
*.pem
|
||||
*.key
|
||||
*.p12
|
||||
|
||||
@@ -6,6 +6,88 @@ middleware\_automation.keycloak Release Notes
|
||||
|
||||
This changelog describes changes after version 0.2.6.
|
||||
|
||||
v3.0.12
|
||||
=======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- 369 add integration tests for keycloak_authentication_v2 `#374 <https://github.com/ansible-middleware/keycloak/pull/374>`_
|
||||
- AMW-615 Inconsistent support of authentication via client credentials `#400 <https://github.com/ansible-middleware/keycloak/pull/400>`_
|
||||
- AMW-622 keycloak collection spelling and grammar checking for PRs `#406 <https://github.com/ansible-middleware/keycloak/pull/406>`_
|
||||
- AMW-626 keycloak_user_rolemapping raises 403 error code while listing asignable Roles if invoker lacks view-realm Role `#411 <https://github.com/ansible-middleware/keycloak/pull/411>`_
|
||||
- Add use_netrc option to prevent .netrc overriding bearer token `#408 <https://github.com/ansible-middleware/keycloak/pull/408>`_
|
||||
- Address issue #370, add keycloak_realm: max_secondary_auth_failures parameter `#404 <https://github.com/ansible-middleware/keycloak/pull/404>`_
|
||||
- Fix #396 keycloak_user_federation.py mapper sorting now happens after unspecified mappers are merged in `#414 <https://github.com/ansible-middleware/keycloak/pull/414>`_
|
||||
- Fix issue #397 #398 crash on first role assignment `#405 <https://github.com/ansible-middleware/keycloak/pull/405>`_
|
||||
- Normalize hostname that includes http_relative_path suffix `#392 <https://github.com/ansible-middleware/keycloak/pull/392>`_
|
||||
- Replace deprecated top-level fact variables with ansible_fact `#412 <https://github.com/ansible-middleware/keycloak/pull/412>`_
|
||||
- authentication_v2: Fix validation for FormActions `#384 <https://github.com/ansible-middleware/keycloak/pull/384>`_
|
||||
- keycloak_group: fix subgroup lookup on Keycloak older than 25 `#407 <https://github.com/ansible-middleware/keycloak/pull/407>`_
|
||||
- keycloak_user: fix attributes always reporting changed=True `#399 <https://github.com/ansible-middleware/keycloak/pull/399>`_
|
||||
|
||||
v3.0.11
|
||||
=======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add certification checks to the upstream repo `#378 <https://github.com/ansible-middleware/keycloak/pull/378>`_
|
||||
- Fix cert workflow `#389 <https://github.com/ansible-middleware/keycloak/pull/389>`_
|
||||
- Fix health check URL to include HTTP relative path `#364 <https://github.com/ansible-middleware/keycloak/pull/364>`_
|
||||
- fix(keycloak_quarkus): avoid leaking maven provider password in logs `#363 <https://github.com/ansible-middleware/keycloak/pull/363>`_
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- AMW-592 AMW Github Actions are failing because of latest molecule `#366 <https://github.com/ansible-middleware/keycloak/pull/366>`_
|
||||
- AMW-594 Upstream release is failing due to recent rules change `#373 <https://github.com/ansible-middleware/keycloak/pull/373>`_
|
||||
|
||||
v3.0.10
|
||||
=======
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Fixing linting issues `#357 <https://github.com/ansible-middleware/keycloak/pull/357>`_
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- AMW-571 keycloak_identity_provider hide_on_login_page not working `#356 <https://github.com/ansible-middleware/keycloak/pull/356>`_
|
||||
- Fixing vars naming issue `#359 <https://github.com/ansible-middleware/keycloak/pull/359>`_
|
||||
- Removing from __future__ import annotations broke runtime type hints using Sequence and union syntax, causing sanity import failures and molecule module errors `#358 <https://github.com/ansible-middleware/keycloak/pull/358>`_
|
||||
|
||||
v3.0.9
|
||||
======
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- AMW-551 Providing correct rhbk version `#344 <https://github.com/ansible-middleware/keycloak/pull/344>`_
|
||||
|
||||
v3.0.8
|
||||
======
|
||||
|
||||
v3.0.7
|
||||
======
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Migrate Keycloak modules from the community.general collection to Keycloak collection. `#341 <https://github.com/ansible-middleware/keycloak/pull/341>`_
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Fixing common module usage `#343 <https://github.com/ansible-middleware/keycloak/pull/343>`_
|
||||
- fix #336: https://github.com/ansible-middleware/common/pull/38 `#338 <https://github.com/ansible-middleware/keycloak/pull/338>`_
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix molecule tests `#339 <https://github.com/ansible-middleware/keycloak/pull/339>`_
|
||||
|
||||
v3.0.6
|
||||
======
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ Clone the repository, checkout the tag you want to build, or pick the main branc
|
||||
|
||||
### Development environment
|
||||
|
||||
Make sure your development machine has avilable:
|
||||
Make sure your development machine has available:
|
||||
|
||||
* python 3.11+
|
||||
* virtualenv
|
||||
|
||||
@@ -49,33 +49,62 @@ A requirement file is provided to install:
|
||||
<!--start roles_paths -->
|
||||
### Included roles
|
||||
|
||||
* `keycloak_quarkus`: role for installing keycloak (>= 19.0.0, quarkus based).
|
||||
* `keycloak_realm`: role for configuring a realm, user federation(s), clients and users, in an installed service.
|
||||
* `keycloak`: role for installing legacy keycloak (<= 19.0, wildfly based).
|
||||
* [`keycloak_quarkus`](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak_quarkus/README.md): role for installing keycloak (>= 19.0.0, quarkus based).
|
||||
* [`keycloak_realm`](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak_realm/README.md): role for configuring a realm, user federation(s), clients and users, in an installed service.
|
||||
* [`keycloak`](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak/README.md): role for installing legacy keycloak (<= 19.0, wildfly based).
|
||||
|
||||
<!--end roles_paths -->
|
||||
|
||||
### Included modules
|
||||
|
||||
* `keycloak_realm`: module for managing Keycloak realms (create/update/delete).
|
||||
* `keycloak_client`: module for managing Keycloak clients (create/update/delete).
|
||||
* `keycloak_role`: module for managing Keycloak roles — realm roles and client roles (create/update/delete).
|
||||
* `keycloak_user_federation`: module for managing user federations such as LDAP/AD (create/update/delete).
|
||||
* `keycloak_client_scope`: module for managing client scopes and protocol mappers (create/update/delete).
|
||||
* `keycloak_authentication_flow`: module for managing authentication flows and execution steps (create/delete, copy existing flows).
|
||||
All Keycloak administration modules from `community.general` are provided in this collection for Keycloak 17+ (Quarkus). Use `auth_keycloak_url` without the legacy `/auth` context path (for example `http://localhost:8080`). Set `keycloak_context` to `/auth` only when automating WildFly-based Keycloak with the `keycloak` role.
|
||||
|
||||
* `keycloak_authentication`: manage authentication flows and executions using Keycloak Admin REST API.
|
||||
* `keycloak_authentication_flow`: manage custom authentication flows and flow executions.
|
||||
* `keycloak_authentication_required_actions`: manage required actions available in realm authentication.
|
||||
* `keycloak_authentication_v2`: manage authentication flows with newer Keycloak API handling.
|
||||
* `keycloak_authz_authorization_scope`: manage authorization scopes for a client resource server.
|
||||
* `keycloak_authz_custom_policy`: manage custom authorization policies for a client resource server.
|
||||
* `keycloak_authz_permission`: manage authorization permissions for a client resource server.
|
||||
* `keycloak_authz_permission_info`: retrieve authorization permission information for a client resource server.
|
||||
* `keycloak_client`: manage Keycloak clients (create/update/delete).
|
||||
* `keycloak_client_rolemapping`: manage client role mappings for users and groups.
|
||||
* `keycloak_client_rolescope`: manage client role scope mappings.
|
||||
* `keycloak_client_scope`: manage client scopes and protocol mappers (replaces `community.general.keycloak_clientscope`).
|
||||
* `keycloak_client_scope_type`: manage default and optional client scope assignments.
|
||||
* `keycloak_clientsecret_info`: retrieve client secret information.
|
||||
* `keycloak_clientsecret_regenerate`: regenerate a client secret.
|
||||
* `keycloak_clienttemplate`: manage legacy client templates.
|
||||
* `keycloak_component`: manage realm components.
|
||||
* `keycloak_component_info`: retrieve realm component information.
|
||||
* `keycloak_group`: manage realm groups and subgroups.
|
||||
* `keycloak_identity_provider`: manage identity provider instances and configuration.
|
||||
* `keycloak_realm`: manage realms (create/update/delete).
|
||||
* `keycloak_realm_info`: retrieve realm information.
|
||||
* `keycloak_realm_key`: manage realm key providers.
|
||||
* `keycloak_realm_keys_metadata_info`: retrieve realm keys metadata.
|
||||
* `keycloak_realm_localization`: manage realm localization texts.
|
||||
* `keycloak_realm_rolemapping`: manage realm role mappings for users and groups.
|
||||
* `keycloak_realm_users_info`: retrieve users from a realm.
|
||||
* `keycloak_role`: manage realm and client roles.
|
||||
* `keycloak_user`: manage users (create/update/delete).
|
||||
* `keycloak_user_execute_actions_email`: trigger execute-actions emails for users.
|
||||
* `keycloak_user_federation`: manage user federation providers (for example LDAP/AD).
|
||||
* `keycloak_user_rolemapping`: manage user role mappings.
|
||||
* `keycloak_userprofile`: manage user profile configuration.
|
||||
|
||||
## Usage
|
||||
|
||||
The collection provides roles to install Keycloak and modules to manage realms, clients, users, and related settings via the [Keycloak Admin REST API](https://www.keycloak.org/docs-api/latest/rest-api/index.html).
|
||||
|
||||
### Install Playbook
|
||||
<!--start rhbk_playbook -->
|
||||
* [`playbooks/keycloak_quarkus.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_quarkus.yml) installs keycloak >= 17 based on the defined variables (using most defaults).
|
||||
* [`playbooks/keycloak.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak.yml) installs keycloak legacy based on the defined variables (using most defaults).
|
||||
For Quarkus-based Keycloak (17+), set `auth_keycloak_url` to the server root URL without the legacy `/auth` path, for example `http://localhost:8080`. When using the legacy `keycloak` role with WildFly-based Keycloak, set `keycloak_context` to `/auth` in the `keycloak_realm` role.
|
||||
|
||||
Both playbooks include the `keycloak` role, with different settings, as described in the following sections.
|
||||
### Install Keycloak
|
||||
|
||||
For full service configuration details, refer to the [keycloak role README](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak/README.md).
|
||||
<!--end rhbk_playbook -->
|
||||
* [`playbooks/keycloak_quarkus.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_quarkus.yml) installs Keycloak >= 17 using the `keycloak_quarkus` role.
|
||||
* [`playbooks/keycloak.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak.yml) installs legacy Keycloak (<= 19) using the `keycloak` role.
|
||||
|
||||
For full service configuration details, refer to the [keycloak_quarkus role README](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak_quarkus/README.md) or the [keycloak role README](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak/README.md).
|
||||
|
||||
#### Install from controller node (offline)
|
||||
|
||||
@@ -96,15 +125,15 @@ keycloak_offline_install: true
|
||||
It is possible to perform downloads from alternate sources, using the `keycloak_download_url` variable; make sure the final downloaded filename matches with the source filename (ie. keycloak-legacy-x.y.zip or rh-sso-x.y.z-server-dist.zip).
|
||||
|
||||
|
||||
### Example installation command
|
||||
#### Example installation command
|
||||
|
||||
Execute the following command from the source root directory
|
||||
Execute the following command from the source root directory:
|
||||
|
||||
```
|
||||
ansible-playbook -i <ansible_hosts> -e @rhn-creds.yml playbooks/keycloak.yml -e keycloak_admin_password=<changeme>
|
||||
```bash
|
||||
ansible-playbook -i <ansible_hosts> playbooks/keycloak_quarkus.yml -e keycloak_quarkus_bootstrap_admin_password=<changeme>
|
||||
```
|
||||
|
||||
- `keycloak_admin_password` Password for the administration console user account.
|
||||
- `keycloak_quarkus_bootstrap_admin_password` password for the administration console user account.
|
||||
- `ansible_hosts` is the inventory, below is an example inventory for deploying to localhost
|
||||
|
||||
```
|
||||
@@ -114,28 +143,24 @@ ansible-playbook -i <ansible_hosts> -e @rhn-creds.yml playbooks/keycloak.yml -e
|
||||
|
||||
Note: when deploying clustered configurations, all hosts belonging to the cluster must be present in `ansible_play_batch`; ie. they must be targeted by the same ansible-playbook execution.
|
||||
|
||||
### Configure with roles
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
### Config Playbooks
|
||||
<!--start rhbk_realm_playbook -->
|
||||
* [`playbooks/keycloak_realm.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_realm.yml) creates or updates provided realm, user federation(s), client(s), client role(s) and client user(s).
|
||||
<!--end rhbk_realm_playbook -->
|
||||
* [`playbooks/keycloak_realm_client.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_realm_client.yml) creates a realm with clients, roles and users using the `keycloak_realm` role.
|
||||
* [`playbooks/keycloak_client_scope.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_client_scope.yml) creates a client scope with protocol mappers using the `keycloak_client_scope` module.
|
||||
* [`playbooks/keycloak_authentication_flow.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_authentication_flow.yml) creates a custom authentication flow with execution steps using the `keycloak_authentication_flow` module.
|
||||
* [`playbooks/keycloak_federation.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_federation.yml) configures user federation providers.
|
||||
|
||||
### Example configuration command
|
||||
#### Example configuration command
|
||||
|
||||
Execute the following command from the source root directory:
|
||||
|
||||
```bash
|
||||
ansible-playbook -i <ansible_hosts> playbooks/keycloak_realm.yml -e keycloak_admin_password=<changeme> -e keycloak_realm=test
|
||||
ansible-playbook -i <ansible_hosts> playbooks/keycloak_realm.yml -e keycloak_realm_admin_password=<changeme> -e keycloak_realm_realm=test
|
||||
```
|
||||
|
||||
- `keycloak_admin_password` password for the administration console user account.
|
||||
- `keycloak_realm` name of the realm to be created/used.
|
||||
- `keycloak_realm_admin_password` password for the administration console user account.
|
||||
- `keycloak_realm_realm` name of the realm to be created/used.
|
||||
- `ansible_hosts` is the inventory, below is an example inventory for deploying to localhost
|
||||
|
||||
```
|
||||
@@ -146,6 +171,37 @@ ansible-playbook -i <ansible_hosts> playbooks/keycloak_realm.yml -e keycloak_adm
|
||||
For full configuration details, refer to the [keycloak_realm role README](https://github.com/ansible-middleware/keycloak/blob/main/roles/keycloak_realm/README.md).
|
||||
<!--end rhbk_realm_readme -->
|
||||
|
||||
### Configure with modules
|
||||
|
||||
Module playbooks target an already running Keycloak instance. All modules use the `middleware_automation.keycloak` collection namespace.
|
||||
|
||||
* [`playbooks/keycloak_client_scope.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_client_scope.yml) creates a client scope with protocol mappers using the `keycloak_client_scope` module.
|
||||
* [`playbooks/keycloak_authentication_flow.yml`](https://github.com/ansible-middleware/keycloak/blob/main/playbooks/keycloak_authentication_flow.yml) creates a custom authentication flow with execution steps using the `keycloak_authentication_flow` module.
|
||||
|
||||
Example task using shared authentication defaults:
|
||||
|
||||
```yaml
|
||||
- hosts: localhost
|
||||
module_defaults:
|
||||
group/middleware_automation.keycloak.keycloak:
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_realm: master
|
||||
auth_username: admin
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
tasks:
|
||||
- name: Create a user in a realm
|
||||
middleware_automation.keycloak.keycloak_user:
|
||||
realm: TestRealm
|
||||
username: testuser
|
||||
first_name: Test
|
||||
last_name: User
|
||||
email: testuser@example.com
|
||||
enabled: true
|
||||
state: present
|
||||
```
|
||||
|
||||
When migrating from `community.general`, replace the collection prefix in playbooks (for example `community.general.keycloak_user` becomes `middleware_automation.keycloak.keycloak_user`) and use `keycloak_client_scope` instead of `keycloak_clientscope`.
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
@@ -165,5 +221,5 @@ For details on changes between versions, please see the [CHANGELOG](https://gith
|
||||
|
||||
Apache License v2.0 or later
|
||||
<!--start license -->
|
||||
See [LICENSE](LICENSE) to view the full text.
|
||||
See [LICENSE](https://github.com/ansible-middleware/keycloak/blob/main/LICENSE) to view the full text.
|
||||
<!--end license -->
|
||||
|
||||
@@ -6,4 +6,5 @@ python3-netaddr [platform:rpm platform:dpkg]
|
||||
python3-lxml [platform:rpm platform:dpkg]
|
||||
python3-jmespath [platform:rpm platform:dpkg]
|
||||
python3-requests [platform:rpm platform:dpkg]
|
||||
podman [platform:rpm platform:dpkg]
|
||||
|
||||
|
||||
@@ -674,6 +674,122 @@ releases:
|
||||
- 276.yaml
|
||||
- 277.yaml
|
||||
release_date: '2025-05-02'
|
||||
3.0.10:
|
||||
changes:
|
||||
major_changes:
|
||||
- 'Fixing linting issues `#357 <https://github.com/ansible-middleware/keycloak/pull/357>`_
|
||||
|
||||
'
|
||||
minor_changes:
|
||||
- 'AMW-571 keycloak_identity_provider hide_on_login_page not working `#356 <https://github.com/ansible-middleware/keycloak/pull/356>`_
|
||||
|
||||
'
|
||||
- 'Fixing vars naming issue `#359 <https://github.com/ansible-middleware/keycloak/pull/359>`_
|
||||
|
||||
'
|
||||
- 'Removing from __future__ import annotations broke runtime type hints using
|
||||
Sequence and union syntax, causing sanity import failures and molecule module
|
||||
errors `#358 <https://github.com/ansible-middleware/keycloak/pull/358>`_
|
||||
|
||||
'
|
||||
fragments:
|
||||
- 356.yaml
|
||||
- 357.yaml
|
||||
- 358.yaml
|
||||
- 359.yaml
|
||||
release_date: '2026-06-25'
|
||||
3.0.11:
|
||||
changes:
|
||||
bugfixes:
|
||||
- 'AMW-592 AMW Github Actions are failing because of latest molecule `#366 <https://github.com/ansible-middleware/keycloak/pull/366>`_
|
||||
|
||||
'
|
||||
- 'AMW-594 Upstream release is failing due to recent rules change `#373 <https://github.com/ansible-middleware/keycloak/pull/373>`_
|
||||
|
||||
'
|
||||
minor_changes:
|
||||
- 'Add certification checks to the upstream repo `#378 <https://github.com/ansible-middleware/keycloak/pull/378>`_
|
||||
|
||||
'
|
||||
- 'Fix cert workflow `#389 <https://github.com/ansible-middleware/keycloak/pull/389>`_
|
||||
|
||||
'
|
||||
- 'Fix health check URL to include HTTP relative path `#364 <https://github.com/ansible-middleware/keycloak/pull/364>`_
|
||||
|
||||
'
|
||||
- 'fix(keycloak_quarkus): avoid leaking maven provider password in logs `#363
|
||||
<https://github.com/ansible-middleware/keycloak/pull/363>`_
|
||||
|
||||
'
|
||||
fragments:
|
||||
- 363.yaml
|
||||
- 364.yaml
|
||||
- 366.yaml
|
||||
- 373.yaml
|
||||
- 378.yaml
|
||||
- 389.yaml
|
||||
release_date: '2026-08-24'
|
||||
3.0.12:
|
||||
changes:
|
||||
minor_changes:
|
||||
- '369 add integration tests for keycloak_authentication_v2 `#374 <https://github.com/ansible-middleware/keycloak/pull/374>`_
|
||||
|
||||
'
|
||||
- 'AMW-615 Inconsistent support of authentication via client credentials `#400
|
||||
<https://github.com/ansible-middleware/keycloak/pull/400>`_
|
||||
|
||||
'
|
||||
- 'AMW-622 keycloak collection spelling and grammar checking for PRs `#406 <https://github.com/ansible-middleware/keycloak/pull/406>`_
|
||||
|
||||
'
|
||||
- 'AMW-626 keycloak_user_rolemapping raises 403 error code while listing asignable
|
||||
Roles if invoker lacks view-realm Role `#411 <https://github.com/ansible-middleware/keycloak/pull/411>`_
|
||||
|
||||
'
|
||||
- 'Add use_netrc option to prevent .netrc overriding bearer token `#408 <https://github.com/ansible-middleware/keycloak/pull/408>`_
|
||||
|
||||
'
|
||||
- 'Address issue #370, add keycloak_realm: max_secondary_auth_failures parameter
|
||||
`#404 <https://github.com/ansible-middleware/keycloak/pull/404>`_
|
||||
|
||||
'
|
||||
- 'Fix #396 keycloak_user_federation.py mapper sorting now happens after unspecified
|
||||
mappers are merged in `#414 <https://github.com/ansible-middleware/keycloak/pull/414>`_
|
||||
|
||||
'
|
||||
- 'Fix issue #397 #398 crash on first role assignment `#405 <https://github.com/ansible-middleware/keycloak/pull/405>`_
|
||||
|
||||
'
|
||||
- 'Normalize hostname that includes http_relative_path suffix `#392 <https://github.com/ansible-middleware/keycloak/pull/392>`_
|
||||
|
||||
'
|
||||
- 'Replace deprecated top-level fact variables with ansible_fact `#412 <https://github.com/ansible-middleware/keycloak/pull/412>`_
|
||||
|
||||
'
|
||||
- 'authentication_v2: Fix validation for FormActions `#384 <https://github.com/ansible-middleware/keycloak/pull/384>`_
|
||||
|
||||
'
|
||||
- 'keycloak_group: fix subgroup lookup on Keycloak older than 25 `#407 <https://github.com/ansible-middleware/keycloak/pull/407>`_
|
||||
|
||||
'
|
||||
- 'keycloak_user: fix attributes always reporting changed=True `#399 <https://github.com/ansible-middleware/keycloak/pull/399>`_
|
||||
|
||||
'
|
||||
fragments:
|
||||
- 374.yaml
|
||||
- 384.yaml
|
||||
- 392.yaml
|
||||
- 399.yaml
|
||||
- 400.yaml
|
||||
- 404.yaml
|
||||
- 405.yaml
|
||||
- 406.yaml
|
||||
- 407.yaml
|
||||
- 408.yaml
|
||||
- 411.yaml
|
||||
- 412.yaml
|
||||
- 414.yaml
|
||||
release_date: '2026-09-11'
|
||||
3.0.2:
|
||||
changes:
|
||||
bugfixes:
|
||||
@@ -801,3 +917,38 @@ releases:
|
||||
fragments:
|
||||
- 337.yaml
|
||||
release_date: '2026-05-26'
|
||||
3.0.7:
|
||||
changes:
|
||||
bugfixes:
|
||||
- 'Fix molecule tests `#339 <https://github.com/ansible-middleware/keycloak/pull/339>`_
|
||||
|
||||
'
|
||||
major_changes:
|
||||
- 'Migrate Keycloak modules from the community.general collection to Keycloak
|
||||
collection. `#341 <https://github.com/ansible-middleware/keycloak/pull/341>`_
|
||||
|
||||
'
|
||||
minor_changes:
|
||||
- 'Fixing common module usage `#343 <https://github.com/ansible-middleware/keycloak/pull/343>`_
|
||||
|
||||
'
|
||||
- 'fix #336: https://github.com/ansible-middleware/common/pull/38 `#338 <https://github.com/ansible-middleware/keycloak/pull/338>`_
|
||||
|
||||
'
|
||||
fragments:
|
||||
- 338.yaml
|
||||
- 339.yaml
|
||||
- 341.yaml
|
||||
- 343.yaml
|
||||
release_date: '2026-06-01'
|
||||
3.0.8:
|
||||
release_date: '2026-06-09'
|
||||
3.0.9:
|
||||
changes:
|
||||
bugfixes:
|
||||
- 'AMW-551 Providing correct rhbk version `#344 <https://github.com/ansible-middleware/keycloak/pull/344>`_
|
||||
|
||||
'
|
||||
fragments:
|
||||
- 344.yaml
|
||||
release_date: '2026-06-11'
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
|
||||
"version": "0.2",
|
||||
"language": "en",
|
||||
"ignorePaths": ["changelogs/**", "CHANGELOG.rst"],
|
||||
"files": [
|
||||
"**/*.md",
|
||||
"**/*.rst",
|
||||
"roles/*/meta/argument_specs.yml",
|
||||
"roles/*/meta/main.yml",
|
||||
"roles/*/tasks/**/*.yml",
|
||||
"roles/*/defaults/*.yml",
|
||||
"roles/*/handlers/*.yml",
|
||||
"roles/*/templates/*.j2",
|
||||
"molecule/**/*.yml",
|
||||
"molecule/**/*.j2",
|
||||
"playbooks/**/*.yml",
|
||||
"meta/runtime.yml",
|
||||
"meta/execution-environment.yml",
|
||||
".github/workflows/*.yml",
|
||||
".github/ISSUE_TEMPLATE/*.md",
|
||||
"galaxy.yml"
|
||||
],
|
||||
"dictionaries": [
|
||||
"custom-keycloak",
|
||||
"java",
|
||||
"bash",
|
||||
"shellscript",
|
||||
"fullstack",
|
||||
"softwareTerms",
|
||||
"software-tools",
|
||||
"cpp-compound-words",
|
||||
"python",
|
||||
"docker",
|
||||
"k8s",
|
||||
"html",
|
||||
"css",
|
||||
"git",
|
||||
"networking-terms",
|
||||
"node",
|
||||
"npm"
|
||||
],
|
||||
"dictionaryDefinitions": [
|
||||
{
|
||||
"name": "custom-keycloak",
|
||||
"path": ".cspell/custom-dictionary.txt",
|
||||
"addWords": true
|
||||
}
|
||||
],
|
||||
"ignoreRegExpList": [
|
||||
"/\\{\\{.*?\\}\\}/g",
|
||||
"/`[^`]+`/g",
|
||||
"/(https?:\\/\\/[^\\s)]+)/g",
|
||||
"/\\|`?[a-z_]+`?\\|/g",
|
||||
"/\\[.*?\\]\\(.*?\\)/g",
|
||||
"/^\\s*authors?:.*$/gm",
|
||||
"/^\\s*-\\s+.*<[^>]+>.*$/gm"
|
||||
]
|
||||
}
|
||||
@@ -44,7 +44,6 @@ extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx_antsibull_ext',
|
||||
'ansible_basic_sphinx_ext',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
# ansible_basic_sphinx_ext still imports pkg_resources (removed in setuptools 82+).
|
||||
setuptools>=70.0.0,<81.0.0
|
||||
antsibull>=0.17.0
|
||||
antsibull-docs
|
||||
antsibull-changelog
|
||||
ansible-core>=2.16.0
|
||||
ansible-pygments
|
||||
sphinx-rtd-theme
|
||||
git+https://github.com/felixfontein/ansible-basic-sphinx-ext
|
||||
myst-parser
|
||||
|
||||
+2
-1
@@ -1,13 +1,14 @@
|
||||
---
|
||||
namespace: middleware_automation
|
||||
name: keycloak
|
||||
version: "3.0.6"
|
||||
version: "3.0.12"
|
||||
readme: README.md
|
||||
authors:
|
||||
- Romain Pelisse <rpelisse@redhat.com>
|
||||
- Guido Grazioli <ggraziol@redhat.com>
|
||||
- Pavan Kumar Motaparthi <pmotapar@redhat.com>
|
||||
- Helmut Wolf <hwo@world-direct.at>
|
||||
- Harsha Cherukuri <hcheruku@redhat.com>
|
||||
description: Install and configure a keycloak, or Red Hat Single Sign-on, service.
|
||||
license_file: "LICENSE"
|
||||
tags:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
v3.0.12
|
||||
=======
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- 369 add integration tests for keycloak_authentication_v2 #374
|
||||
- AMW-615 Inconsistent support of authentication via client credentials #400
|
||||
- AMW-622 keycloak collection spelling and grammar checking for PRs #406
|
||||
- AMW-626 keycloak_user_rolemapping raises 403 error code while listing asignable Roles if invoker lacks view-realm Role #411
|
||||
- Add use_netrc option to prevent .netrc overriding bearer token #408
|
||||
- Address issue #370, add keycloak_realm: max_secondary_auth_failures parameter #404
|
||||
- Fix #396 keycloak_user_federation.py mapper sorting now happens after unspecified mappers are merged in #414
|
||||
- Fix issue #397 #398 crash on first role assignment #405
|
||||
- Normalize hostname that includes http_relative_path suffix #392
|
||||
- Replace deprecated top-level fact variables with ansible_fact #412
|
||||
- authentication_v2: Fix validation for FormActions #384
|
||||
- keycloak_group: fix subgroup lookup on Keycloak older than 25 #407
|
||||
- keycloak_user: fix attributes always reporting changed=True #399
|
||||
|
||||
@@ -1,2 +1,65 @@
|
||||
---
|
||||
requires_ansible: ">=2.16.0"
|
||||
action_groups:
|
||||
keycloak:
|
||||
- keycloak_authentication
|
||||
- keycloak_authentication_flow
|
||||
- keycloak_authentication_required_actions
|
||||
- keycloak_authentication_v2
|
||||
- keycloak_authz_authorization_scope
|
||||
- keycloak_authz_custom_policy
|
||||
- keycloak_authz_permission
|
||||
- keycloak_authz_permission_info
|
||||
- keycloak_client
|
||||
- keycloak_client_rolemapping
|
||||
- keycloak_client_rolescope
|
||||
- keycloak_client_scope
|
||||
- keycloak_client_scope_type
|
||||
- keycloak_client_scope_rolemappings
|
||||
- keycloak_clientsecret_info
|
||||
- keycloak_clientsecret_regenerate
|
||||
- keycloak_clienttemplate
|
||||
- keycloak_component
|
||||
- keycloak_component_info
|
||||
- keycloak_group
|
||||
- keycloak_identity_provider
|
||||
- keycloak_organization
|
||||
- keycloak_organization_info
|
||||
- keycloak_realm
|
||||
- keycloak_realm_info
|
||||
- keycloak_realm_key
|
||||
- keycloak_realm_keys_metadata_info
|
||||
- keycloak_realm_localization
|
||||
- keycloak_realm_rolemapping
|
||||
- keycloak_realm_users_info
|
||||
- keycloak_role
|
||||
- keycloak_user
|
||||
- keycloak_user_federation
|
||||
- keycloak_user_rolemapping
|
||||
- keycloak_userprofile
|
||||
- keycloak_user_execute_actions_email
|
||||
plugin_routing:
|
||||
modules:
|
||||
keycloak_clientscope:
|
||||
redirect: middleware_automation.keycloak.keycloak_client_scope
|
||||
deprecation:
|
||||
removal_version: 5.0.0
|
||||
warning_text: >-
|
||||
The module has been renamed to keycloak_client_scope for Keycloak 17+ (Quarkus).
|
||||
Update playbooks to use middleware_automation.keycloak.keycloak_client_scope.
|
||||
|
||||
keycloak_clientscope_type:
|
||||
redirect: middleware_automation.keycloak.keycloak_client_scope_type
|
||||
deprecation:
|
||||
removal_version: 5.0.0
|
||||
warning_text: >-
|
||||
The module has been renamed to keycloak_client_scope_type for Keycloak 17+ (Quarkus).
|
||||
Update playbooks to use middleware_automation.keycloak.keycloak_client_scope_type.
|
||||
|
||||
keycloak_clientscope_rolemappings:
|
||||
redirect: middleware_automation.keycloak.keycloak_client_scope_rolemappings
|
||||
deprecation:
|
||||
removal_version: 5.0.0
|
||||
warning_text: >-
|
||||
The module has been renamed to keycloak_client_scope_rolemappings for Keycloak 17+ (Quarkus).
|
||||
Update playbooks to use middleware_automation.keycloak.keycloak_client_scope_rolemappings.
|
||||
|
||||
@@ -14,32 +14,32 @@
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
- role: keycloak_realm
|
||||
keycloak_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_client_users:
|
||||
keycloak_realm_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_realm_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_realm_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_realm_client_users:
|
||||
- username: TestUser
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- username: TestAdmin
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- client: TestClient
|
||||
role: TestRoleAdmin
|
||||
realm: "{{ keycloak_realm }}"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_clients:
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient
|
||||
realm: "{{ keycloak_realm }}"
|
||||
public_client: "{{ keycloak_client_public }}"
|
||||
web_origins: "{{ keycloak_client_web_origins }}"
|
||||
users: "{{ keycloak_client_users }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: "{{ keycloak_realm_client_public }}"
|
||||
web_origins: "{{ keycloak_realm_client_web_origins }}"
|
||||
users: "{{ keycloak_realm_client_users }}"
|
||||
client_id: TestClient
|
||||
attributes:
|
||||
post.logout.redirect.uris: '/public/logout'
|
||||
|
||||
@@ -6,7 +6,7 @@ platforms:
|
||||
image: ghcr.io/hspaans/molecule-containers:debian-13
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
|
||||
@@ -19,30 +19,30 @@
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
- role: keycloak_realm
|
||||
keycloak_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_client_users:
|
||||
keycloak_realm_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_realm_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_realm_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_realm_client_users:
|
||||
- username: TestUser
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- username: TestAdmin
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- client: TestClient
|
||||
role: TestRoleAdmin
|
||||
realm: "{{ keycloak_realm }}"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_clients:
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient
|
||||
realm: "{{ keycloak_realm }}"
|
||||
public_client: "{{ keycloak_client_public }}"
|
||||
web_origins: "{{ keycloak_client_web_origins }}"
|
||||
users: "{{ keycloak_client_users }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: "{{ keycloak_realm_client_public }}"
|
||||
web_origins: "{{ keycloak_realm_client_web_origins }}"
|
||||
users: "{{ keycloak_realm_client_users }}"
|
||||
client_id: TestClient
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
driver:
|
||||
name: podman
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
|
||||
@@ -20,8 +20,51 @@
|
||||
|
||||
- name: Download keycloak archive to controller directory
|
||||
ansible.builtin.get_url: # noqa risky-file-permissions delegated, uses controller host user
|
||||
url: https://github.com/keycloak/keycloak/releases/download/26.4.7/keycloak-26.4.7.zip
|
||||
url: https://github.com/keycloak/keycloak/releases/download/26.6.2/keycloak-26.6.2.zip
|
||||
dest: /tmp/keycloak
|
||||
mode: '0640'
|
||||
validate_certs: false
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
ignore_errors: true
|
||||
|
||||
- name: Attempt RHBK download using redhat.runtimes_common collection
|
||||
when:
|
||||
- rhn_username is defined
|
||||
- rhn_username | length > 0
|
||||
block:
|
||||
- name: Retrieve RHBK product download using Unified Downloads API
|
||||
middleware_automation.common.product_search:
|
||||
client_id: "{{ rhn_username }}"
|
||||
client_secret: "{{ rhn_password }}"
|
||||
product_type: DISTRIBUTION
|
||||
product_version: "{{ keycloak_quarkus_version | default('26.6.2') }}"
|
||||
product_category: "RHBK"
|
||||
register: rhn_products
|
||||
no_log: "{{ omit_rhn_output | default(true) }}"
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
ignore_errors: true
|
||||
|
||||
- name: Determine install zipfile from search results
|
||||
ansible.builtin.set_fact:
|
||||
rhn_matched_products: "{{ rhn_products.results | selectattr('file_name', 'match', '.*keycloak-' + (keycloak_quarkus_version | default('26.6.2')) + '.zip$') }}"
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
when:
|
||||
- rhn_products is defined
|
||||
- rhn_products.results is defined
|
||||
|
||||
- name: Download Red Hat Build of Keycloak
|
||||
middleware_automation.common.product_download:
|
||||
client_id: "{{ rhn_username }}"
|
||||
client_secret: "{{ rhn_password }}"
|
||||
product_id: "{{ (rhn_matched_products | first).id }}"
|
||||
dest: "/tmp/keycloak/keycloak-{{ keycloak_quarkus_version | default('26.6.2') }}.zip"
|
||||
no_log: "{{ omit_rhn_output | default(true) }}"
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
when:
|
||||
- rhn_matched_products is defined
|
||||
- rhn_matched_products | length > 0
|
||||
ignore_errors: true
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
---
|
||||
keycloak_download_validate_certs: false
|
||||
keycloak_validate_certs: false
|
||||
keycloak_quarkus_download_validate_certs: false
|
||||
keycloak_quarkus_validate_certs: false
|
||||
keycloak_realm_validate_certs: false
|
||||
keycloak_quarkus_require_privilege_escalation: "{{ keycloak_install_requires_become | default(true) }}"
|
||||
keycloak_quarkus_systemd_require_privilege_escalation: "{{ keycloak_install_requires_become | default(true) }}"
|
||||
keycloak_quarkus_install_require_privilege_escalation: "{{ keycloak_install_requires_become | default(true) }}"
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
keycloak_quarkus_show_deprecation_warnings: false
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
||||
keycloak_quarkus_hostname: https://proxy
|
||||
keycloak_quarkus_hostname: "http://proxy:{{ keycloak_quarkus_http_port }}"
|
||||
keycloak_quarkus_log: file
|
||||
keycloak_quarkus_http_enabled: True
|
||||
keycloak_quarkus_http_port: 8080
|
||||
keycloak_quarkus_proxy_mode: edge
|
||||
keycloak_quarkus_http_relative_path: /
|
||||
keycloak_quarkus_health_check_url: http://proxy:8080/realms/master/.well-known/openid-configuration
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
|
||||
@@ -9,7 +9,7 @@ platforms:
|
||||
command: "/usr/sbin/init"
|
||||
networks:
|
||||
- name: keycloak
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
published_ports:
|
||||
- 0.0.0.0:8080:8080/tcp
|
||||
@@ -20,7 +20,7 @@ platforms:
|
||||
command: "/usr/sbin/init"
|
||||
networks:
|
||||
- name: keycloak
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "443/tcp"
|
||||
published_ports:
|
||||
- 0.0.0.0:443:443/tcp
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- import_playbook: ../default/converge.yml
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Get access token
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/realms/{{ auth_realm }}/protocol/openid-connect/token"
|
||||
method: POST
|
||||
status_code: 200
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
body_format: form-urlencoded
|
||||
body:
|
||||
grant_type: "password"
|
||||
client_id: "admin-cli"
|
||||
username: "{{ auth_username }}"
|
||||
password: "{{ auth_password }}"
|
||||
register: token_response
|
||||
no_log: true
|
||||
|
||||
- name: Extract access token
|
||||
ansible.builtin.set_fact:
|
||||
access_token: "{{ token_response.json['access_token'] }}"
|
||||
no_log: true
|
||||
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Flow Creation/Update <Integration Test Flow> Version 1
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- providerId: idp-review-profile
|
||||
requirement: REQUIRED
|
||||
authenticationConfig:
|
||||
alias: Integration Test Flow - review profile config
|
||||
config:
|
||||
update.profile.on.first.login: "missing"
|
||||
- subFlow: Integration Test Flow - User creation or linking
|
||||
requirement: REQUIRED
|
||||
authenticationExecutions:
|
||||
- providerId: idp-create-user-if-unique
|
||||
requirement: ALTERNATIVE
|
||||
authenticationConfig:
|
||||
alias: Integration Test Flow - create unique user config
|
||||
config:
|
||||
require.password.update.after.registration: "false"
|
||||
- subFlow: Integration Test Flow - Handle Existing Account
|
||||
requirement: ALTERNATIVE
|
||||
authenticationExecutions:
|
||||
- providerId: idp-confirm-link
|
||||
requirement: REQUIRED
|
||||
- providerId: auth-cookie
|
||||
requirement: REQUIRED
|
||||
register: flow_v1_result
|
||||
|
||||
- name: Expose flow_v1_result to parent scope
|
||||
ansible.builtin.set_fact:
|
||||
flow_v1_result: "{{ flow_v1_result }}"
|
||||
no_log: true
|
||||
@@ -0,0 +1,43 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# - adding a new execution inside the sub flow 'Integration Test Flow - User creation or linking' after the execution 'idp-create-user-if-unique'
|
||||
# - disable auth-cookie at the end of the flow
|
||||
# - change the config require.password.update.after.registration to "true"
|
||||
- name: Flow Creation/Update <Integration Test Flow> Version 2
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- providerId: idp-review-profile
|
||||
requirement: REQUIRED
|
||||
authenticationConfig:
|
||||
alias: Integration Test Flow - review profile config
|
||||
config:
|
||||
update.profile.on.first.login: "missing"
|
||||
- subFlow: Integration Test Flow - User creation or linking
|
||||
requirement: REQUIRED
|
||||
authenticationExecutions:
|
||||
- providerId: idp-create-user-if-unique
|
||||
requirement: ALTERNATIVE
|
||||
authenticationConfig:
|
||||
alias: Integration Test Flow - create unique user config
|
||||
config:
|
||||
require.password.update.after.registration: "true"
|
||||
- providerId: auth-cookie
|
||||
requirement: REQUIRED
|
||||
- subFlow: Integration Test Flow - Handle Existing Account
|
||||
requirement: ALTERNATIVE
|
||||
authenticationExecutions:
|
||||
- providerId: idp-confirm-link
|
||||
requirement: REQUIRED
|
||||
- providerId: auth-cookie
|
||||
requirement: DISABLED
|
||||
register: flow_v2_result
|
||||
|
||||
- name: Expose flow_v2_result to parent scope
|
||||
ansible.builtin.set_fact:
|
||||
flow_v2_result: "{{ flow_v2_result }}"
|
||||
no_log: true
|
||||
@@ -0,0 +1,28 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Rebuilds Keycloak's own built-in "clients" flow structure as of 26.7.1.
|
||||
# validate_executions() used to raise a KeyError for client-flow parents, since only
|
||||
# basic-flow and form-flow provider sets were known.
|
||||
- name: Flow Creation/Update <Integration Test Flow - Client Flow>
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Client Flow
|
||||
providerId: client-flow
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- providerId: client-secret
|
||||
requirement: ALTERNATIVE
|
||||
- providerId: client-jwt
|
||||
requirement: ALTERNATIVE
|
||||
- providerId: client-secret-jwt
|
||||
requirement: ALTERNATIVE
|
||||
- providerId: client-x509
|
||||
requirement: ALTERNATIVE
|
||||
register: flow_v2_client_flow_result
|
||||
|
||||
- name: Expose flow_v2_client_flow_result to parent scope
|
||||
ansible.builtin.set_fact:
|
||||
flow_v2_client_flow_result: "{{ flow_v2_client_flow_result }}"
|
||||
no_log: true
|
||||
@@ -0,0 +1,31 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Rebuilds Keycloak's own built-in "registration" flow structure as of 26.7.1.
|
||||
# validate_executions() used to only check authenticator-providers and falsely flagged form actions as invalid
|
||||
# See https://github.com/ansible-middleware/keycloak/issues/382
|
||||
- name: Flow Creation/Update <Integration Test Flow - Form Actions>
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Form Actions
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- subFlow: Integration Test Flow - Form Actions - registration form
|
||||
subFlowType: form-flow
|
||||
requirement: REQUIRED
|
||||
authenticationExecutions:
|
||||
- providerId: registration-user-creation
|
||||
requirement: REQUIRED
|
||||
- providerId: registration-password-action
|
||||
requirement: REQUIRED
|
||||
- providerId: registration-recaptcha-action
|
||||
requirement: DISABLED
|
||||
- providerId: registration-terms-and-conditions
|
||||
requirement: DISABLED
|
||||
register: flow_v2_form_action_result
|
||||
|
||||
- name: Expose flow_v2_form_action_result to parent scope
|
||||
ansible.builtin.set_fact:
|
||||
flow_v2_form_action_result: "{{ flow_v2_form_action_result }}"
|
||||
no_log: true
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Fetch all authentication flows
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: keycloak_flows_response
|
||||
no_log: true
|
||||
|
||||
- name: Extract flow id for alias 'Integration Test Flow'
|
||||
ansible.builtin.set_fact:
|
||||
test_flow_id: >-
|
||||
{{ keycloak_flows_response.json
|
||||
| selectattr('alias', 'equalto', 'Integration Test Flow')
|
||||
| map(attribute='id')
|
||||
| first }}
|
||||
no_log: true
|
||||
|
||||
- name: Fetch basic flow data for 'Integration Test Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/{{ test_flow_id }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_top_level_data
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow attributes
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_top_level_data.json.alias == "Integration Test Flow"
|
||||
- test_flow_top_level_data.json.providerId == "basic-flow"
|
||||
- test_flow_top_level_data.json.topLevel == true
|
||||
- test_flow_top_level_data.json.builtIn == false
|
||||
|
||||
- name: Fetch flow executions for 'Integration Test Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_executions
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow executions
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_executions.json | length == 6
|
||||
- test_flow_executions.json[0].providerId == "idp-review-profile"
|
||||
- test_flow_executions.json[0].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[0].index == 0
|
||||
- test_flow_executions.json[0].priority == 0
|
||||
- test_flow_executions.json[0].level == 0
|
||||
- test_flow_executions.json[0].authenticationConfig is not none
|
||||
- test_flow_executions.json[0]['authenticationFlow'] is not defined or test_flow_executions.json[0].authenticationFlow == false
|
||||
- test_flow_executions.json[1].displayName == "Integration Test Flow - User creation or linking"
|
||||
- test_flow_executions.json[1].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[1].index == 1
|
||||
- test_flow_executions.json[1].priority == 1
|
||||
- test_flow_executions.json[1].level == 0
|
||||
- test_flow_executions.json[1]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[1].authenticationFlow == true
|
||||
- test_flow_executions.json[2].providerId == "idp-create-user-if-unique"
|
||||
- test_flow_executions.json[2].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[2].index == 0
|
||||
- test_flow_executions.json[2].priority == 0
|
||||
- test_flow_executions.json[2].level == 1
|
||||
- test_flow_executions.json[2].authenticationConfig is not none
|
||||
- test_flow_executions.json[2]['authenticationFlow'] is not defined or test_flow_executions.json[2].authenticationFlow == false
|
||||
- test_flow_executions.json[3].displayName == "Integration Test Flow - Handle Existing Account"
|
||||
- test_flow_executions.json[3].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[3].index == 1
|
||||
- test_flow_executions.json[3].priority == 1
|
||||
- test_flow_executions.json[3].level == 1
|
||||
- test_flow_executions.json[3]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[3].authenticationFlow == true
|
||||
- test_flow_executions.json[4].providerId == "idp-confirm-link"
|
||||
- test_flow_executions.json[4].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[4].index == 0
|
||||
- test_flow_executions.json[4].priority == 0
|
||||
- test_flow_executions.json[4].level == 2
|
||||
- test_flow_executions.json[4]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[4]['authenticationFlow'] is not defined or test_flow_executions.json[4].authenticationFlow == false
|
||||
- test_flow_executions.json[5].providerId == "auth-cookie"
|
||||
- test_flow_executions.json[5].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[5].index == 2
|
||||
- test_flow_executions.json[5].priority == 2
|
||||
- test_flow_executions.json[5].level == 0
|
||||
- test_flow_executions.json[5]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[5]['authenticationFlow'] is not defined or test_flow_executions.json[5].authenticationFlow == false
|
||||
|
||||
- name: Fetch flow execution config for 'idp-review-profile'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/config/{{ test_flow_executions.json[0].authenticationConfig }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_execution_idp_review_profile_config
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow execution config for 'idp-review-profile'
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_execution_idp_review_profile_config.json.alias == "Integration Test Flow - review profile config"
|
||||
- test_flow_execution_idp_review_profile_config.json.config is not none
|
||||
- test_flow_execution_idp_review_profile_config.json.config['update.profile.on.first.login'] == "missing"
|
||||
|
||||
- name: Fetch flow execution config for 'idp-create-user-if-unique'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/config/{{ test_flow_executions.json[2].authenticationConfig }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_execution_idp_create_user_if_unique
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow execution config for 'idp-create-user-if-unique'
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_execution_idp_create_user_if_unique.json.alias == "Integration Test Flow - create unique user config"
|
||||
- test_flow_execution_idp_create_user_if_unique.json.config is not none
|
||||
- test_flow_execution_idp_create_user_if_unique.json.config['require.password.update.after.registration'] == "false"
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Fetch all authentication flows
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: keycloak_flows_response
|
||||
no_log: true
|
||||
|
||||
- name: Extract flow id for alias 'Integration Test Flow'
|
||||
ansible.builtin.set_fact:
|
||||
test_flow_id: >-
|
||||
{{ keycloak_flows_response.json
|
||||
| selectattr('alias', 'equalto', 'Integration Test Flow')
|
||||
| map(attribute='id')
|
||||
| first }}
|
||||
no_log: true
|
||||
|
||||
- name: Fetch basic flow data for 'Integration Test Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/{{ test_flow_id }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_top_level_data
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow attributes
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_top_level_data.json.alias == "Integration Test Flow"
|
||||
- test_flow_top_level_data.json.providerId == "basic-flow"
|
||||
- test_flow_top_level_data.json.topLevel == true
|
||||
- test_flow_top_level_data.json.builtIn == false
|
||||
|
||||
- name: Fetch flow executions for 'Integration Test Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_executions
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow executions
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_executions.json | length == 7
|
||||
- test_flow_executions.json[0].providerId == "idp-review-profile"
|
||||
- test_flow_executions.json[0].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[0].index == 0
|
||||
- test_flow_executions.json[0].priority == 0
|
||||
- test_flow_executions.json[0].level == 0
|
||||
- test_flow_executions.json[0].authenticationConfig is not none
|
||||
- test_flow_executions.json[0]['authenticationFlow'] is not defined or test_flow_executions.json[0].authenticationFlow == false
|
||||
- test_flow_executions.json[1].displayName == "Integration Test Flow - User creation or linking"
|
||||
- test_flow_executions.json[1].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[1].index == 1
|
||||
- test_flow_executions.json[1].priority == 1
|
||||
- test_flow_executions.json[1].level == 0
|
||||
- test_flow_executions.json[1]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[1].authenticationFlow == true
|
||||
- test_flow_executions.json[2].providerId == "idp-create-user-if-unique"
|
||||
- test_flow_executions.json[2].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[2].index == 0
|
||||
- test_flow_executions.json[2].priority == 0
|
||||
- test_flow_executions.json[2].level == 1
|
||||
- test_flow_executions.json[2].authenticationConfig is not none
|
||||
- test_flow_executions.json[2]['authenticationFlow'] is not defined or test_flow_executions.json[2].authenticationFlow == false
|
||||
- test_flow_executions.json[3].providerId == "auth-cookie"
|
||||
- test_flow_executions.json[3].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[3].index == 1
|
||||
- test_flow_executions.json[3].priority == 1
|
||||
- test_flow_executions.json[3].level == 1
|
||||
- test_flow_executions.json[3]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[3]['authenticationFlow'] is not defined or test_flow_executions.json[3].authenticationFlow == false
|
||||
- test_flow_executions.json[4].displayName == "Integration Test Flow - Handle Existing Account"
|
||||
- test_flow_executions.json[4].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[4].index == 2
|
||||
- test_flow_executions.json[4].priority == 2
|
||||
- test_flow_executions.json[4].level == 1
|
||||
- test_flow_executions.json[4]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[4].authenticationFlow == true
|
||||
- test_flow_executions.json[5].providerId == "idp-confirm-link"
|
||||
- test_flow_executions.json[5].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[5].index == 0
|
||||
- test_flow_executions.json[5].priority == 0
|
||||
- test_flow_executions.json[5].level == 2
|
||||
- test_flow_executions.json[5]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[5]['authenticationFlow'] is not defined or test_flow_executions.json[5].authenticationFlow == false
|
||||
- test_flow_executions.json[6].providerId == "auth-cookie"
|
||||
- test_flow_executions.json[6].requirement == "DISABLED"
|
||||
- test_flow_executions.json[6].index == 2
|
||||
- test_flow_executions.json[6].priority == 2
|
||||
- test_flow_executions.json[6].level == 0
|
||||
- test_flow_executions.json[6]['authenticationConfig'] is not defined
|
||||
- test_flow_executions.json[6]['authenticationFlow'] is not defined or test_flow_executions.json[6].authenticationFlow == false
|
||||
|
||||
- name: Fetch flow execution config for 'idp-review-profile'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/config/{{ test_flow_executions.json[0].authenticationConfig }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_execution_idp_review_profile_config
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow execution config for 'idp-review-profile'
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_execution_idp_review_profile_config.json.alias == "Integration Test Flow - review profile config"
|
||||
- test_flow_execution_idp_review_profile_config.json.config is not none
|
||||
- test_flow_execution_idp_review_profile_config.json.config['update.profile.on.first.login'] == "missing"
|
||||
|
||||
- name: Fetch flow execution config for 'idp-create-user-if-unique'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/config/{{ test_flow_executions.json[2].authenticationConfig }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_execution_idp_create_user_if_unique
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow execution config for 'idp-create-user-if-unique'
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_execution_idp_create_user_if_unique.json.alias == "Integration Test Flow - create unique user config"
|
||||
- test_flow_execution_idp_create_user_if_unique.json.config is not none
|
||||
- test_flow_execution_idp_create_user_if_unique.json.config['require.password.update.after.registration'] == "true"
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Fetch all authentication flows
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: keycloak_flows_response
|
||||
no_log: true
|
||||
|
||||
- name: Extract flow id for alias 'Integration Test Flow - Client Flow'
|
||||
ansible.builtin.set_fact:
|
||||
test_flow_id: >-
|
||||
{{ keycloak_flows_response.json
|
||||
| selectattr('alias', 'equalto', 'Integration Test Flow - Client Flow')
|
||||
| map(attribute='id')
|
||||
| first }}
|
||||
no_log: true
|
||||
|
||||
- name: Fetch basic flow data for 'Integration Test Flow - Client Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/{{ test_flow_id }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_top_level_data
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow attributes
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_top_level_data.json.alias == "Integration Test Flow - Client Flow"
|
||||
- test_flow_top_level_data.json.providerId == "client-flow"
|
||||
- test_flow_top_level_data.json.topLevel == true
|
||||
- test_flow_top_level_data.json.builtIn == false
|
||||
|
||||
- name: Fetch flow executions for 'Integration Test Flow - Client Flow'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow%20-%20Client%20Flow/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_executions
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow executions
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_executions.json | length == 4
|
||||
- test_flow_executions.json[0].providerId == "client-secret"
|
||||
- test_flow_executions.json[0].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[0].index == 0
|
||||
- test_flow_executions.json[0].level == 0
|
||||
- test_flow_executions.json[1].providerId == "client-jwt"
|
||||
- test_flow_executions.json[1].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[1].index == 1
|
||||
- test_flow_executions.json[1].level == 0
|
||||
- test_flow_executions.json[2].providerId == "client-secret-jwt"
|
||||
- test_flow_executions.json[2].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[2].index == 2
|
||||
- test_flow_executions.json[2].level == 0
|
||||
- test_flow_executions.json[3].providerId == "client-x509"
|
||||
- test_flow_executions.json[3].requirement == "ALTERNATIVE"
|
||||
- test_flow_executions.json[3].index == 3
|
||||
- test_flow_executions.json[3].level == 0
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Fetch all authentication flows
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: keycloak_flows_response
|
||||
no_log: true
|
||||
|
||||
- name: Extract flow id for alias 'Integration Test Flow - Form Actions'
|
||||
ansible.builtin.set_fact:
|
||||
test_flow_id: >-
|
||||
{{ keycloak_flows_response.json
|
||||
| selectattr('alias', 'equalto', 'Integration Test Flow - Form Actions')
|
||||
| map(attribute='id')
|
||||
| first }}
|
||||
no_log: true
|
||||
|
||||
- name: Fetch basic flow data for 'Integration Test Flow - Form Actions'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/{{ test_flow_id }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_top_level_data
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow attributes
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_top_level_data.json.alias == "Integration Test Flow - Form Actions"
|
||||
- test_flow_top_level_data.json.providerId == "basic-flow"
|
||||
- test_flow_top_level_data.json.topLevel == true
|
||||
- test_flow_top_level_data.json.builtIn == false
|
||||
|
||||
- name: Fetch flow executions for 'Integration Test Flow - Form Actions'
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow%20-%20Form%20Actions/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: test_flow_executions
|
||||
no_log: true
|
||||
|
||||
- name: Assert flow executions
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- test_flow_executions.json | length == 5
|
||||
- test_flow_executions.json[0].displayName == "Integration Test Flow - Form Actions - registration form"
|
||||
- test_flow_executions.json[0].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[0].index == 0
|
||||
- test_flow_executions.json[0].level == 0
|
||||
- test_flow_executions.json[0].authenticationFlow == true
|
||||
- test_flow_executions.json[1].providerId == "registration-user-creation"
|
||||
- test_flow_executions.json[1].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[1].index == 0
|
||||
- test_flow_executions.json[1].level == 1
|
||||
- test_flow_executions.json[1]['authenticationFlow'] is not defined or test_flow_executions.json[1].authenticationFlow == false
|
||||
- test_flow_executions.json[2].providerId == "registration-password-action"
|
||||
- test_flow_executions.json[2].requirement == "REQUIRED"
|
||||
- test_flow_executions.json[2].index == 1
|
||||
- test_flow_executions.json[2].level == 1
|
||||
- test_flow_executions.json[3].providerId == "registration-recaptcha-action"
|
||||
- test_flow_executions.json[3].requirement == "DISABLED"
|
||||
- test_flow_executions.json[3].index == 2
|
||||
- test_flow_executions.json[3].level == 1
|
||||
- test_flow_executions.json[4].providerId == "registration-terms-and-conditions"
|
||||
- test_flow_executions.json[4].requirement == "DISABLED"
|
||||
- test_flow_executions.json[4].index == 3
|
||||
- test_flow_executions.json[4].level == 1
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow - Client Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2_client_flow.yml
|
||||
|
||||
- name: Assert the flow creation result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_client_flow_result is changed
|
||||
- flow_v2_client_flow_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_client_flow_result.changed }}, diff={{ flow_v2_client_flow_result.get('diff') }}"
|
||||
|
||||
- name: Assert the created flow <Integration Test Flow - Client Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2_client_flow.yml
|
||||
|
||||
# Check idempotency, by trying to create the existing flow again
|
||||
- name: Trying to create the <Integration Test Flow - Client Flow> again, although nothing changed
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2_client_flow.yml
|
||||
|
||||
- name: Assert that the task didn't re-create the flow, because the flow didn't change
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_client_flow_result is not changed
|
||||
- flow_v2_client_flow_result.diff is not defined
|
||||
msg: "Expected no changes and no diff but got: changed={{ flow_v2_client_flow_result.changed }}, diff={{ flow_v2_client_flow_result.get('diff') }}"
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Create a client with browser override <Integration Test Flow>
|
||||
middleware_automation.keycloak.keycloak_client:
|
||||
realm: "{{ target_realm }}"
|
||||
client_id: "test_client"
|
||||
state: present
|
||||
authentication_flow_binding_overrides:
|
||||
browser_name: "Integration Test Flow"
|
||||
|
||||
- name: Modify the flow <Integration Test Flow> although it is bound as client override flow
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2.yml
|
||||
|
||||
- name: Assert the flow modification result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_result is changed
|
||||
- flow_v2_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_result.changed }}, diff={{ flow_v2_result.get('diff') }}"
|
||||
|
||||
- name: Assert the flow <Integration Test Flow> after the modifications
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2.yml
|
||||
|
||||
- name: Fetch client data
|
||||
middleware_automation.keycloak.keycloak_client:
|
||||
realm: "{{ target_realm }}"
|
||||
client_id: "test_client"
|
||||
state: present
|
||||
register: client_result
|
||||
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Fetch authentication flow (browser override={{ client_result.end_state.authenticationFlowBindingOverrides.browser }})
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/{{ client_result.end_state.authenticationFlowBindingOverrides.browser }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
register: flow_response
|
||||
|
||||
- name: Assert client flow override binding
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_response.json is defined
|
||||
- flow_response.json.alias == "Integration Test Flow"
|
||||
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Assert the flow creation result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v1_result is changed
|
||||
- flow_v1_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v1_result.changed }}, diff={{ flow_v1_result.get('diff') }}"
|
||||
|
||||
- name: Assert the created flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v1.yml
|
||||
|
||||
# Check idempotency, by trying to create the existing flow again
|
||||
- name: Trying to create the <Integration Test Flow> again, although nothing changed
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Assert that the task didn't re-create the flow, because the flow didn't change
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v1_result is not changed
|
||||
- flow_v1_result.diff is not defined
|
||||
msg: "Expected no changes and no diff but got: changed={{ flow_v1_result.changed }}, diff={{ flow_v1_result.get('diff') }}"
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Delete the flow <Integration Test Flow>
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow
|
||||
state: absent
|
||||
register: flow_deletion_result
|
||||
|
||||
- name: Assert that the flow deletion result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_deletion_result is changed
|
||||
- flow_deletion_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_deletion_result.changed }}, diff={{ flow_deletion_result.get('diff') }}"
|
||||
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Assert that the flow does not exist anymore
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
status_code: 404
|
||||
register: flow_response
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow - Form Actions>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2_form_action.yml
|
||||
|
||||
- name: Assert the flow creation result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_form_action_result is changed
|
||||
- flow_v2_form_action_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_form_action_result.changed }}, diff={{ flow_v2_form_action_result.get('diff') }}"
|
||||
|
||||
- name: Assert the created flow <Integration Test Flow - Form Actions>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2_form_action.yml
|
||||
|
||||
# Check idempotency, by trying to create the existing flow again
|
||||
- name: Trying to create the <Integration Test Flow - Form Actions> again, although nothing changed
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2_form_action.yml
|
||||
|
||||
- name: Assert that the task didn't re-create the flow, because the flow didn't change
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_form_action_result is not changed
|
||||
- flow_v2_form_action_result.diff is not defined
|
||||
msg: "Expected no changes and no diff but got: changed={{ flow_v2_form_action_result.changed }}, diff={{ flow_v2_form_action_result.get('diff') }}"
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Create an identity-provider with first and post login flow override <Integration Test Flow>
|
||||
middleware_automation.keycloak.keycloak_identity_provider:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: oidc-idp-integration-test
|
||||
state: present
|
||||
display_name: OpenID Connect IdP - Integration Test
|
||||
enabled: true
|
||||
provider_id: oidc
|
||||
first_broker_login_flow_alias: Integration Test Flow
|
||||
post_broker_login_flow_alias: Integration Test Flow
|
||||
config:
|
||||
issuer: https://idp.example.com
|
||||
authorizationUrl: https://idp.example.com/auth
|
||||
tokenUrl: https://idp.example.com/token
|
||||
userInfoUrl: https://idp.example.com/userinfo
|
||||
clientAuthMethod: client_secret_post
|
||||
clientId: my-client
|
||||
clientSecret: secret
|
||||
syncMode: FORCE
|
||||
|
||||
- name: Modify the flow <Integration Test Flow> although it is bound as identity-provider first and post login flow
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2.yml
|
||||
|
||||
- name: Assert the flow modification result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_result is changed
|
||||
- flow_v2_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_result.changed }}, diff={{ flow_v2_result.get('diff') }}"
|
||||
|
||||
- name: Assert the flow <Integration Test Flow> after the modifications
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2.yml
|
||||
|
||||
- name: Fetch identity-provider data
|
||||
middleware_automation.keycloak.keycloak_identity_provider:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: oidc-idp-integration-test
|
||||
state: present
|
||||
register: identity_provider_result
|
||||
|
||||
- name: Assert identity-provider first and post flow binding
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- identity_provider_result.end_state.firstBrokerLoginFlowAlias == "Integration Test Flow"
|
||||
- identity_provider_result.end_state.postBrokerLoginFlowAlias == "Integration Test Flow"
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
---
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Flow Creation/Update <Integration Test Flow with invalid providerid in execution>
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow with invalid providerid in execution
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- providerId: idp-review-profile
|
||||
requirement: REQUIRED
|
||||
authenticationConfig:
|
||||
alias: Integration Test Flow - review profile config
|
||||
config:
|
||||
update.profile.on.first.login: "missing"
|
||||
- subFlow: Integration Test Flow - User creation or linking
|
||||
requirement: REQUIRED
|
||||
authenticationExecutions:
|
||||
- providerId: invalid-providerid
|
||||
requirement: ALTERNATIVE
|
||||
- subFlow: Integration Test Flow - Handle Existing Account
|
||||
requirement: ALTERNATIVE
|
||||
authenticationExecutions:
|
||||
- providerId: another-invalid-providerid
|
||||
requirement: REQUIRED
|
||||
- providerId: auth-cookie
|
||||
requirement: REQUIRED
|
||||
ignore_errors: true
|
||||
register: invalid_providerid_in_flow_result
|
||||
|
||||
- name: Verify that invalid providerId causes failure
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- invalid_providerid_in_flow_result is failed
|
||||
- invalid_providerid_in_flow_result is not changed
|
||||
- >-
|
||||
invalid_providerid_in_flow_result.msg == "Validation of executions failed: Error(s) while validating flow: Unknown providerId 'invalid-providerid', Unknown providerId 'another-invalid-providerid'"
|
||||
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Assert that the flow did not get created
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow%20with%20invalid%20providerid%20in%20execution/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
status_code: 404
|
||||
register: flow_response
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
# form-action providers are valid for form-flow, but not for basic-flow.
|
||||
# This test ensures that validate_executions() correctly rejects them when used in a basic-flow context.
|
||||
# Same for authentication providers (e.g auth-cookie) in a form-flow context.
|
||||
- name: Flow Creation/Update <Integration Test Flow - Mismatched Flow Type> with providerIds mismatched to their parent flow type
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Mismatched Flow Type
|
||||
state: present
|
||||
authenticationExecutions:
|
||||
- providerId: registration-user-creation
|
||||
requirement: REQUIRED
|
||||
- subFlow: Integration Test Flow - Mismatched Flow Type - form
|
||||
subFlowType: form-flow
|
||||
requirement: REQUIRED
|
||||
authenticationExecutions:
|
||||
- providerId: auth-cookie
|
||||
requirement: REQUIRED
|
||||
ignore_errors: true
|
||||
register: mismatched_flow_type_result
|
||||
|
||||
- name: Assert providerIds mismatched with their parent flow type are rejected
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mismatched_flow_type_result is failed
|
||||
- mismatched_flow_type_result is not changed
|
||||
- "'registration-user-creation' in mismatched_flow_type_result.msg"
|
||||
- "'auth-cookie' in mismatched_flow_type_result.msg"
|
||||
|
||||
- name: Retrieve access token
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/fetch_access_token.yml
|
||||
|
||||
- name: Assert that the flow did not get created
|
||||
ansible.builtin.uri:
|
||||
url: "{{ auth_keycloak_url }}/admin/realms/{{ target_realm }}/authentication/flows/Integration%20Test%20Flow%20-%20Mismatched%20Flow%20Type/executions"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: application/json
|
||||
User-agent: Ansible
|
||||
Authorization: "Bearer {{ access_token }}"
|
||||
return_content: true
|
||||
status_code: 404
|
||||
register: flow_response
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Delete identity-provider <oidc-idp-integration-test> if it exists
|
||||
middleware_automation.keycloak.keycloak_identity_provider:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: oidc-idp-integration-test
|
||||
state: absent
|
||||
|
||||
- name: Delete client <test_client> if it exists
|
||||
middleware_automation.keycloak.keycloak_client:
|
||||
realm: "{{ target_realm }}"
|
||||
client_id: "test_client"
|
||||
state: absent
|
||||
|
||||
- name: Unassign the flow <Integration Test Flow> as default browser flow
|
||||
middleware_automation.keycloak.keycloak_realm:
|
||||
id: "{{ target_realm }}"
|
||||
realm: "{{ target_realm }}"
|
||||
state: present
|
||||
browser_flow: browser
|
||||
|
||||
- name: Delete <Integration Test Flow> flow if it exists
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow
|
||||
state: absent
|
||||
|
||||
- name: Delete <Integration Test Flow - Form Actions> flow if it exists
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Form Actions
|
||||
state: absent
|
||||
|
||||
- name: Delete <Integration Test Flow - Mismatched Flow Type> flow if it exists
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Mismatched Flow Type
|
||||
state: absent
|
||||
|
||||
- name: Delete <Integration Test Flow - Client Flow> flow if it exists
|
||||
middleware_automation.keycloak.keycloak_authentication_v2:
|
||||
realm: "{{ target_realm }}"
|
||||
alias: Integration Test Flow - Client Flow
|
||||
state: absent
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Modify the flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2.yml
|
||||
|
||||
- name: Assert the flow creation modification result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_result is changed
|
||||
- flow_v2_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_result.changed }}, diff={{ flow_v2_result.get('diff') }}"
|
||||
|
||||
- name: Assert the modified flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2.yml
|
||||
|
||||
# Revert the modifications from the previous step
|
||||
- name: Revert the modifications the flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Assert the flow modification result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v1_result is changed
|
||||
- flow_v1_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v1_result.changed }}, diff={{ flow_v1_result.get('diff') }}"
|
||||
|
||||
- name: Assert the flow <Integration Test Flow> after reverting the modifications
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v1.yml
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
- name: Setup Test
|
||||
ansible.builtin.include_tasks:
|
||||
file: test_setup.yml
|
||||
|
||||
- name: Create the new flow <Integration Test Flow>
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v1.yml
|
||||
|
||||
- name: Assign the flow <Integration Test Flow> as default browser flow
|
||||
middleware_automation.keycloak.keycloak_realm:
|
||||
id: "{{ target_realm }}"
|
||||
realm: "{{ target_realm }}"
|
||||
state: present
|
||||
browser_flow: Integration Test Flow
|
||||
|
||||
- name: Modify the flow <Integration Test Flow> although it is bound as realm browser flow
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../actions/flow_v2.yml
|
||||
|
||||
- name: Assert the flow modification result
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- flow_v2_result is changed
|
||||
- flow_v2_result.diff is defined
|
||||
msg: "Expected changes and a diff but got: changed={{ flow_v2_result.changed }}, diff={{ flow_v2_result.get('diff') }}"
|
||||
|
||||
- name: Assert the flow <Integration Test Flow> after the modifications
|
||||
ansible.builtin.include_tasks:
|
||||
file: ../assertions/assertion_flow_v2.yml
|
||||
|
||||
- name: Fetch realm data to validate if the browser flow is still set to <Integration Test Flow>
|
||||
middleware_automation.keycloak.keycloak_realm:
|
||||
id: "{{ target_realm }}"
|
||||
realm: "{{ target_realm }}"
|
||||
state: present
|
||||
register: realm_result
|
||||
|
||||
- name: Assert realm browser flow binding
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- realm_result.end_state.browserFlow == "Integration Test Flow"
|
||||
@@ -0,0 +1,39 @@
|
||||
- name: Executing flow creation tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_flow_creation.yml
|
||||
|
||||
- name: Executing unused flow modification tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_unused_flow_modification.yml
|
||||
|
||||
- name: Executing used default browser flow modification tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_used_default_browser_flow_modification.yml
|
||||
|
||||
- name: Executing client flow override flow modification tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_client_flow_override_flow_modification.yml
|
||||
|
||||
- name: Executing identity provider first and post flow override flow modification tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_identity_provider_flow_overrides_flow_modification.yml
|
||||
|
||||
- name: Executing flow deletion tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_flow_deletion.yml
|
||||
|
||||
- name: Invalid providerIds in execution tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_invalid_providerid_flow_creation.yml
|
||||
|
||||
- name: Executing form action flow creation tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_form_action_flow_creation.yml
|
||||
|
||||
- name: Mismatched flow type providerIds in execution tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_mismatched_flow_type_flow_creation.yml
|
||||
|
||||
- name: Executing client flow creation tests
|
||||
ansible.builtin.include_tasks:
|
||||
file: tests/test_client_flow_creation.yml
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
- "9000/tcp"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
interpreter_python: auto_silent
|
||||
roles_path: ../../roles
|
||||
ssh_connection:
|
||||
pipelining: false
|
||||
playbooks:
|
||||
prepare: prepare.yml
|
||||
converge: converge.yml
|
||||
verify: verify.yml
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
keycloak_install_requires_become: true
|
||||
host_vars:
|
||||
localhost:
|
||||
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||
env:
|
||||
ANSIBLE_FORCE_COLOR: "true"
|
||||
PROXY: "${PROXY}"
|
||||
NO_PROXY: "${NO_PROXY}"
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
test_sequence:
|
||||
- cleanup
|
||||
- destroy
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- import_playbook: ../default/prepare.yml
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
||||
---
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
- "9000/tcp"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
interpreter_python: auto_silent
|
||||
roles_path: ../../roles
|
||||
ssh_connection:
|
||||
pipelining: false
|
||||
playbooks:
|
||||
prepare: ../default/prepare.yml
|
||||
converge: ../default/converge.yml
|
||||
verify: verify.yml
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
keycloak_install_requires_become: true
|
||||
host_vars:
|
||||
localhost:
|
||||
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||
env:
|
||||
ANSIBLE_FORCE_COLOR: "true"
|
||||
PROXY: "${PROXY}"
|
||||
NO_PROXY: "${NO_PROXY}"
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
test_sequence:
|
||||
- cleanup
|
||||
- destroy
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../roles
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
- name: Verify use_netrc option prevents .netrc from overriding bearer token (issue 403)
|
||||
hosts: all
|
||||
vars:
|
||||
auth_keycloak_url: http://instance:8080
|
||||
auth_realm: master
|
||||
auth_username: remembertochangeme
|
||||
auth_password: remembertochangeme
|
||||
target_realm: TestRealm
|
||||
module_defaults:
|
||||
group/middleware_automation.keycloak.keycloak:
|
||||
auth_keycloak_url: "{{ auth_keycloak_url }}"
|
||||
auth_realm: "{{ auth_realm }}"
|
||||
auth_username: "{{ auth_username }}"
|
||||
auth_password: "{{ auth_password }}"
|
||||
validate_certs: false
|
||||
tasks:
|
||||
- name: Populate service facts
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: Check if keycloak service started
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts.services["keycloak.service"]["state"] == "running"
|
||||
- ansible_facts.services["keycloak.service"]["status"] == "enabled"
|
||||
fail_msg: Keycloak service is not running
|
||||
|
||||
- name: Verify netrc handling
|
||||
block:
|
||||
- name: Create .netrc with bogus credentials matching the Keycloak host
|
||||
ansible.builtin.copy:
|
||||
dest: ~/.netrc
|
||||
mode: "0600"
|
||||
content: |
|
||||
machine instance
|
||||
login netrc_user
|
||||
password netrc_password
|
||||
|
||||
- name: API call with default use_netrc (false) ignores .netrc
|
||||
middleware_automation.keycloak.keycloak_realm_keys_metadata_info:
|
||||
realm: "{{ target_realm }}"
|
||||
register: netrc_default_result
|
||||
|
||||
- name: Assert API call succeeds with default use_netrc despite .netrc
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- netrc_default_result is not failed
|
||||
|
||||
- name: API call with use_netrc true picks up .netrc credentials
|
||||
middleware_automation.keycloak.keycloak_realm_keys_metadata_info:
|
||||
realm: "{{ target_realm }}"
|
||||
use_netrc: true
|
||||
register: netrc_true_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Assert API call fails when use_netrc is true and .netrc has credentials
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- netrc_true_result is failed
|
||||
always:
|
||||
- name: Remove .netrc test file
|
||||
ansible.builtin.file:
|
||||
path: ~/.netrc
|
||||
state: absent
|
||||
@@ -4,7 +4,9 @@
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
vars:
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_hostname: "http://instance:8080"
|
||||
keycloak_config_override_template: custom.xml.j2
|
||||
keycloak_http_port: 8081
|
||||
keycloak_management_http_port: 19990
|
||||
|
||||
@@ -7,7 +7,7 @@ platforms:
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
ansible.builtin.set_fact:
|
||||
assets_server: "{{ lookup('env', 'MIDDLEWARE_DOWNLOAD_RELEASE_SERVER_URL') }}"
|
||||
|
||||
- name: "Download artefacts only if assets_server is set"
|
||||
- name: "Download artifacts only if assets_server is set"
|
||||
when:
|
||||
- assets_server is defined
|
||||
- assets_server | length > 0
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
keycloak_quarkus_show_deprecation_warnings: false
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_quarkus_hostname: https://instance:8443
|
||||
keycloak_quarkus_log: file
|
||||
keycloak_quarkus_log_level: debug # needed for the verify step
|
||||
@@ -25,7 +25,7 @@
|
||||
keycloak_quarkus_systemd_wait_for_delay: 2
|
||||
keycloak_quarkus_systemd_wait_for_log: true
|
||||
keycloak_quarkus_restart_health_check: false # would fail because of self-signed cert
|
||||
keycloak_quarkus_version: 26.4.7
|
||||
keycloak_quarkus_version: 26.6.2
|
||||
keycloak_quarkus_java_heap_opts: "-Xms1024m -Xmx1024m"
|
||||
keycloak_quarkus_additional_env_vars:
|
||||
- key: KC_FEATURES_DISABLED
|
||||
@@ -39,16 +39,16 @@
|
||||
- key: default-connection-pool-size
|
||||
value: 10
|
||||
- id: spid-saml
|
||||
url: https://github.com/italia/spid-keycloak-provider/releases/download/24.0.2/spid-provider.jar
|
||||
url: https://github.com/italia/spid-keycloak-provider/releases/download/26.5.6/spid-provider.jar
|
||||
- id: spid-saml-w-checksum
|
||||
url: https://github.com/italia/spid-keycloak-provider/releases/download/24.0.2/spid-provider.jar
|
||||
checksum: sha256:fbb50e73739d7a6d35b5bff611b1c01668b29adf6f6259624b95e466a305f377
|
||||
url: https://github.com/italia/spid-keycloak-provider/releases/download/26.5.6/spid-provider.jar
|
||||
checksum: sha256:2ddafc389a5f017d8665bfdfa2f72b3784fc74b9f3a482e796fa89a5ba5cc95b
|
||||
- id: keycloak-kerberos-federation
|
||||
maven:
|
||||
repository_url: https://repo1.maven.org/maven2/ # https://mvnrepository.com/artifact/org.keycloak/keycloak-kerberos-federation/24.0.4
|
||||
group_id: org.keycloak
|
||||
artifact_id: keycloak-kerberos-federation
|
||||
version: 26.4.7 # optional
|
||||
version: 26.6.3 # optional
|
||||
# username: myUser # optional
|
||||
# password: myPAT # optional
|
||||
# - id: my-static-theme
|
||||
@@ -62,34 +62,34 @@
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
- role: keycloak_realm
|
||||
keycloak_url: http://instance:8080
|
||||
keycloak_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_client_default_roles:
|
||||
keycloak_realm_url: http://instance:8080
|
||||
keycloak_realm_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_realm_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_realm_client_default_roles:
|
||||
- TestRoleAdmin
|
||||
- TestRoleUser
|
||||
keycloak_client_users:
|
||||
keycloak_realm_client_users:
|
||||
- username: TestUser
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- username: TestAdmin
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- client: TestClient
|
||||
role: TestRoleAdmin
|
||||
realm: "{{ keycloak_realm }}"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_clients:
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient
|
||||
roles: "{{ keycloak_client_default_roles }}"
|
||||
realm: "{{ keycloak_realm }}"
|
||||
public_client: "{{ keycloak_client_public }}"
|
||||
web_origins: "{{ keycloak_client_web_origins }}"
|
||||
users: "{{ keycloak_client_users }}"
|
||||
roles: "{{ keycloak_realm_client_default_roles }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: "{{ keycloak_realm_client_public }}"
|
||||
web_origins: "{{ keycloak_realm_client_web_origins }}"
|
||||
users: "{{ keycloak_realm_client_users }}"
|
||||
client_id: TestClient
|
||||
|
||||
@@ -7,7 +7,7 @@ platforms:
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
keycloak_quarkus_show_deprecation_warnings: false
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_quarkus_log: file
|
||||
keycloak_quarkus_hostname: 'http://localhost:8080'
|
||||
keycloak_quarkus_start_dev: True
|
||||
@@ -18,34 +18,34 @@
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
- role: keycloak_realm
|
||||
keycloak_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_client_default_roles:
|
||||
keycloak_realm_url: "{{ keycloak_quarkus_hostname }}"
|
||||
keycloak_realm_admin_user: "{{ keycloak_quarkus_bootstrap_admin_user }}"
|
||||
keycloak_realm_admin_password: "{{ keycloak_quarkus_bootstrap_admin_password }}"
|
||||
keycloak_realm_client_default_roles:
|
||||
- TestRoleAdmin
|
||||
- TestRoleUser
|
||||
keycloak_client_users:
|
||||
keycloak_realm_client_users:
|
||||
- username: TestUser
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- username: TestAdmin
|
||||
password: password
|
||||
client_roles:
|
||||
- client: TestClient
|
||||
role: TestRoleUser
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
- client: TestClient
|
||||
role: TestRoleAdmin
|
||||
realm: "{{ keycloak_realm }}"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_clients:
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient
|
||||
roles: "{{ keycloak_client_default_roles }}"
|
||||
realm: "{{ keycloak_realm }}"
|
||||
public_client: "{{ keycloak_client_public }}"
|
||||
web_origins: "{{ keycloak_client_web_origins }}"
|
||||
users: "{{ keycloak_client_users }}"
|
||||
roles: "{{ keycloak_realm_client_default_roles }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: "{{ keycloak_realm_client_public }}"
|
||||
web_origins: "{{ keycloak_realm_client_web_origins }}"
|
||||
users: "{{ keycloak_realm_client_users }}"
|
||||
client_id: TestClient
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
driver:
|
||||
name: podman
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8009/tcp"
|
||||
- "9000/tcp"
|
||||
|
||||
@@ -11,7 +11,7 @@ platforms:
|
||||
- keycloak
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "9000/tcp"
|
||||
@@ -24,7 +24,7 @@ platforms:
|
||||
- keycloak
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "9000/tcp"
|
||||
@@ -37,7 +37,7 @@ platforms:
|
||||
- database
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "5432/tcp"
|
||||
mounts:
|
||||
- type: bind
|
||||
|
||||
@@ -11,7 +11,7 @@ platforms:
|
||||
- keycloak
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "9000/tcp"
|
||||
@@ -24,7 +24,7 @@ platforms:
|
||||
- keycloak
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "9000/tcp"
|
||||
@@ -37,7 +37,7 @@ platforms:
|
||||
- database
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "5432/tcp"
|
||||
mounts:
|
||||
- type: bind
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
infinispan_supervisor_password: remembertochangeme
|
||||
infinispan_keycloak_caches: true
|
||||
infinispan_keycloak_persistence: False
|
||||
infinispan_jgroups_discovery: TCPPING
|
||||
infinispan_jdbc_engine: postgres
|
||||
infinispan_jdbc_url: jdbc:postgresql://postgres:5432/keycloak
|
||||
infinispan_jdbc_driver_version: 9.4.1212
|
||||
infinispan_jdbc_user: keycloak
|
||||
infinispan_jdbc_pass: mysecretpass
|
||||
infinispan_bind_address: "{{ ansible_default_ipv4.address }}"
|
||||
infinispan_bind_address: 0.0.0.0
|
||||
infinispan_users:
|
||||
- { name: 'testuser', password: 'test', roles: 'observer' }
|
||||
|
||||
@@ -24,6 +25,12 @@
|
||||
hosts: keycloak
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
pre_tasks:
|
||||
- name: Wait for Infinispan Hot Rod port before starting Keycloak
|
||||
ansible.builtin.wait_for:
|
||||
host: infinispan1
|
||||
port: 11222
|
||||
timeout: 120
|
||||
vars:
|
||||
keycloak_quarkus_show_deprecation_warnings: false
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
@@ -40,7 +47,7 @@
|
||||
keycloak_quarkus_ks_vault_file: "/opt/keycloak/vault/keystore.p12"
|
||||
keycloak_quarkus_ks_vault_pass: keystorepassword
|
||||
keycloak_quarkus_systemd_wait_for_port: true
|
||||
keycloak_quarkus_systemd_wait_for_timeout: 20
|
||||
keycloak_quarkus_systemd_wait_for_timeout: 120
|
||||
keycloak_quarkus_systemd_wait_for_delay: 2
|
||||
keycloak_quarkus_systemd_wait_for_log: true
|
||||
keycloak_quarkus_ha_enabled: true
|
||||
|
||||
@@ -11,7 +11,7 @@ platforms:
|
||||
- keycloak
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "9000/tcp"
|
||||
@@ -24,7 +24,7 @@ platforms:
|
||||
- infinispan
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "11222/tcp"
|
||||
- name: postgres
|
||||
image: ubuntu/postgres:14-22.04_beta
|
||||
@@ -35,12 +35,12 @@ platforms:
|
||||
- database
|
||||
networks:
|
||||
- name: rhbk
|
||||
port_bindings:
|
||||
exposed_ports:
|
||||
- "5432/tcp"
|
||||
mounts:
|
||||
- type: bind
|
||||
target: /etc/postgresql/postgresql.conf
|
||||
source: ${MOLECULE_PROJECT_DIRECTORY}/molecule/quarkus_ha/postgresql/postgresql.conf
|
||||
source: ${MOLECULE_PROJECT_DIRECTORY}/molecule/quarkus_ha_remote/postgresql/postgresql.conf
|
||||
env:
|
||||
POSTGRES_USER: keycloak
|
||||
POSTGRES_PASSWORD: mysecretpass
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
vars:
|
||||
keycloak_quarkus_show_deprecation_warnings: false
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
||||
keycloak_quarkus_hostname: http://instance:8080/auth
|
||||
keycloak_quarkus_http_relative_path: /auth
|
||||
keycloak_quarkus_log: file
|
||||
keycloak_quarkus_log_level: debug
|
||||
keycloak_quarkus_log_target: /tmp/keycloak
|
||||
keycloak_quarkus_start_dev: true
|
||||
keycloak_quarkus_proxy_mode: none
|
||||
keycloak_quarkus_offline_install: true
|
||||
keycloak_quarkus_download_path: /tmp/keycloak/
|
||||
keycloak_quarkus_java_heap_opts: "-Xms640m -Xmx640m "
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
command: "/usr/sbin/init"
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "8443/tcp"
|
||||
- "8009/tcp"
|
||||
- "9000/tcp"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
interpreter_python: auto_silent
|
||||
ssh_connection:
|
||||
pipelining: false
|
||||
playbooks:
|
||||
prepare: prepare.yml
|
||||
converge: converge.yml
|
||||
verify: verify.yml
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
keycloak_install_requires_become: true
|
||||
host_vars:
|
||||
localhost:
|
||||
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||
env:
|
||||
ANSIBLE_FORCE_COLOR: "true"
|
||||
PROXY: "${PROXY}"
|
||||
NO_PROXY: "${NO_PROXY}"
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
test_sequence:
|
||||
- cleanup
|
||||
- destroy
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
gather_facts: yes
|
||||
vars:
|
||||
sudo_pkg_name: sudo
|
||||
tasks:
|
||||
- name: "Run preparation common to all scenario"
|
||||
ansible.builtin.include_tasks: ../prepare.yml
|
||||
|
||||
- name: Create controller directory for downloads
|
||||
ansible.builtin.file: # noqa risky-file-permissions delegated, uses controller host user
|
||||
path: /tmp/keycloak
|
||||
state: directory
|
||||
mode: '0750'
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
|
||||
- name: Download keycloak archive to controller directory
|
||||
ansible.builtin.get_url: # noqa risky-file-permissions delegated, uses controller host user
|
||||
url: https://github.com/keycloak/keycloak/releases/download/26.6.2/keycloak-26.6.2.zip
|
||||
dest: /tmp/keycloak
|
||||
mode: '0640'
|
||||
validate_certs: false
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
ignore_errors: true
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../roles
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
vars:
|
||||
keycloak_quarkus_bootstrap_admin_password: "remembertochangeme"
|
||||
keycloak_quarkus_bootstrap_admin_user: "remembertochangeme"
|
||||
keycloak_uri: "http://localhost:8080/auth"
|
||||
tasks:
|
||||
- name: Populate service facts
|
||||
ansible.builtin.service_facts:
|
||||
- name: Check if keycloak service started
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts.services["keycloak.service"]["state"] == "running"
|
||||
- ansible_facts.services["keycloak.service"]["status"] == "enabled"
|
||||
- name: Verify openid endpoint with relative path
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_uri }}/realms/master/.well-known/openid-configuration"
|
||||
method: GET
|
||||
validate_certs: no
|
||||
register: keycloak_openid_response
|
||||
until: keycloak_openid_response.status == 200
|
||||
retries: 5
|
||||
delay: 5
|
||||
@@ -9,6 +9,6 @@
|
||||
keycloak_quarkus_additional_env_vars:
|
||||
- key: KC_FEATURES_DISABLED
|
||||
value: ciba,device-flow,impersonation,kerberos,docker
|
||||
keycloak_quarkus_version: 26.0.7
|
||||
keycloak_quarkus_version: 26.6.2
|
||||
roles:
|
||||
- role: keycloak_quarkus
|
||||
|
||||
@@ -4,15 +4,15 @@ dependency:
|
||||
options:
|
||||
requirements-file: molecule/requirements.yml
|
||||
driver:
|
||||
name: podman
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
command: "/usr/sbin/init"
|
||||
pre_build_image: true
|
||||
privileged: true
|
||||
port_bindings:
|
||||
- 8080:8080
|
||||
exposed_ports:
|
||||
- "8080/tcp"
|
||||
- "9000/tcp"
|
||||
published_ports:
|
||||
- 0.0.0.0:8080:8080/TCP
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- vars.yml
|
||||
vars:
|
||||
sudo_pkg_name: sudo
|
||||
keycloak_quarkus_version: 26.0.4
|
||||
keycloak_quarkus_version: 26.6.1
|
||||
keycloak_quarkus_additional_env_vars:
|
||||
- key: KC_FEATURES_DISABLED
|
||||
value: impersonation,kerberos
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
vars:
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_enable: true
|
||||
keycloak_offline_install: false
|
||||
roles:
|
||||
- role: keycloak
|
||||
- role: keycloak_realm
|
||||
keycloak_realm_url: "http://instance:8080"
|
||||
keycloak_realm_context: "/auth"
|
||||
keycloak_realm_admin_user: "admin"
|
||||
keycloak_realm_admin_password: "remembertochangeme"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: true
|
||||
client_id: TestClient
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: registry.access.redhat.com/ubi9/ubi-init:latest
|
||||
command: /usr/sbin/init
|
||||
privileged: true
|
||||
pre_build_image: true
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
interpreter_python: auto_silent
|
||||
callbacks_enabled: profile_tasks, timer
|
||||
callback_result_format: yaml
|
||||
ssh_connection:
|
||||
pipelining: false
|
||||
playbooks:
|
||||
prepare: prepare.yml
|
||||
converge: converge.yml
|
||||
verify: verify.yml
|
||||
env:
|
||||
ANSIBLE_ROLES_PATH: "../../roles"
|
||||
inventory:
|
||||
host_vars:
|
||||
instance:
|
||||
ansible_user: root
|
||||
verifier:
|
||||
name: ansible
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
vars_files:
|
||||
- ../group_vars/all/vars.yml
|
||||
gather_facts: yes
|
||||
vars:
|
||||
sudo_pkg_name: sudo
|
||||
tasks:
|
||||
- name: "Run preparation common to all scenario"
|
||||
ansible.builtin.include_tasks: ../prepare.yml
|
||||
@@ -0,0 +1,78 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
vars:
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_admin_user: "admin"
|
||||
keycloak_uri: "http://localhost:8080"
|
||||
keycloak_context: "/auth"
|
||||
parent_group: molecule-parent-group
|
||||
child_group: molecule-child-group
|
||||
tasks:
|
||||
- name: Populate service facts
|
||||
ansible.builtin.service_facts:
|
||||
- name: Check if keycloak service started
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts.services["keycloak.service"]["state"] == "running"
|
||||
- ansible_facts.services["keycloak.service"]["status"] == "enabled"
|
||||
- name: Verify token api call
|
||||
ansible.builtin.uri:
|
||||
url: "{{ keycloak_uri }}{{ keycloak_context }}/realms/master/protocol/openid-connect/token"
|
||||
method: POST
|
||||
body: "client_id=admin-cli&username={{ keycloak_admin_user }}&password={{ keycloak_admin_password }}&grant_type=password"
|
||||
validate_certs: no
|
||||
register: keycloak_auth_response
|
||||
until: keycloak_auth_response.status == 200
|
||||
retries: 2
|
||||
delay: 2
|
||||
|
||||
# This Keycloak is older than 23, so its group children endpoint accepts no
|
||||
# GET request and the subgroup lookup has to fall back to the subgroups
|
||||
# inlined in the parent group representation.
|
||||
- name: Verify subgroup handling on a pre-23 Keycloak
|
||||
module_defaults:
|
||||
group/middleware_automation.keycloak.keycloak:
|
||||
auth_keycloak_url: "{{ keycloak_uri }}{{ keycloak_context }}"
|
||||
auth_realm: master
|
||||
auth_username: "{{ keycloak_admin_user }}"
|
||||
auth_password: "{{ keycloak_admin_password }}"
|
||||
validate_certs: false
|
||||
realm: master
|
||||
block:
|
||||
- name: keycloak_group — create parent group
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ parent_group }}"
|
||||
state: present
|
||||
|
||||
- name: keycloak_group — create subgroup below the parent group
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ child_group }}"
|
||||
parents:
|
||||
- name: "{{ parent_group }}"
|
||||
state: present
|
||||
register: subgroup_result
|
||||
|
||||
- name: Assert subgroup was created below the parent group
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_result is changed
|
||||
- subgroup_result.end_state.path == '/' ~ parent_group ~ '/' ~ child_group
|
||||
|
||||
- name: keycloak_group — look the subgroup up through parents again
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ child_group }}"
|
||||
parents:
|
||||
- name: "{{ parent_group }}"
|
||||
state: present
|
||||
register: subgroup_lookup_result
|
||||
|
||||
- name: Assert the existing subgroup was found instead of re-created
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- subgroup_lookup_result is not changed
|
||||
always:
|
||||
- name: keycloak_group — remove parent group and its subtree
|
||||
middleware_automation.keycloak.keycloak_group:
|
||||
name: "{{ parent_group }}"
|
||||
state: absent
|
||||
@@ -6,9 +6,9 @@
|
||||
ansible.builtin.include_role:
|
||||
name: keycloak_realm
|
||||
vars:
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_user_federation:
|
||||
keycloak_realm_admin_password: "remembertochangeme"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_user_federation:
|
||||
- realm: TestRealm
|
||||
name: my-ldap
|
||||
provider_id: ldap
|
||||
@@ -48,13 +48,13 @@
|
||||
ldap.full.name.attribute: cn
|
||||
read.only: true
|
||||
write.only: false
|
||||
keycloak_clients:
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient1
|
||||
client_id: TestClient1
|
||||
roles:
|
||||
- TestClient1Admin
|
||||
- TestClient1User
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
public_client: true
|
||||
web_origins:
|
||||
- http://testclient1origin/application
|
||||
@@ -65,4 +65,4 @@
|
||||
client_roles:
|
||||
- client: TestClient1
|
||||
role: TestClient1User
|
||||
realm: "{{ keycloak_realm }}"
|
||||
realm: "{{ keycloak_realm_realm }}"
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
- name: Playbook for Keycloak Hosts
|
||||
hosts: all
|
||||
vars:
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_clients:
|
||||
keycloak_realm_admin_password: "remembertochangeme"
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient1
|
||||
client_id: TestClient1
|
||||
roles:
|
||||
@@ -23,4 +23,4 @@
|
||||
realm: TestRealm
|
||||
roles:
|
||||
- role: middleware_automation.keycloak.keycloak_realm
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_realm_realm: TestRealm
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
ansible.builtin.include_role:
|
||||
name: middleware_automation.keycloak.keycloak_realm
|
||||
vars:
|
||||
keycloak_admin_password: "remembertochangeme"
|
||||
keycloak_realm: TestRealm
|
||||
keycloak_client_default_roles:
|
||||
keycloak_realm_admin_password: "remembertochangeme"
|
||||
keycloak_realm_realm: TestRealm
|
||||
keycloak_realm_client_default_roles:
|
||||
- TestRoleAdmin
|
||||
- TestRoleUser
|
||||
keycloak_client_users:
|
||||
keycloak_realm_client_users:
|
||||
- username: TestUser
|
||||
password: password
|
||||
client_roles:
|
||||
@@ -27,13 +27,13 @@
|
||||
- client: TestClient1
|
||||
role: TestRoleAdmin
|
||||
realm: TestRealm
|
||||
keycloak_clients:
|
||||
keycloak_realm_clients:
|
||||
- name: TestClient1
|
||||
client_id: TestClient1
|
||||
roles: "{{ keycloak_client_default_roles }}"
|
||||
roles: "{{ keycloak_realm_client_default_roles }}"
|
||||
realm: TestRealm
|
||||
public_client: true
|
||||
web_origins:
|
||||
- http://testclient1origin/application
|
||||
- http://testclient1origin/other
|
||||
users: "{{ keycloak_client_users }}"
|
||||
users: "{{ keycloak_realm_client_users }}"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class ModuleDocFragment(object):
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
options: {}
|
||||
attributes:
|
||||
action_group:
|
||||
description: Use C(group/middleware_automation.keycloak.keycloak) in C(module_defaults) to set defaults for this module.
|
||||
support: full
|
||||
membership:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
'''
|
||||
@@ -5,6 +5,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
@@ -55,7 +56,11 @@ options:
|
||||
description:
|
||||
- Authentication token for Keycloak API.
|
||||
type: str
|
||||
version_added: 3.0.0
|
||||
|
||||
refresh_token:
|
||||
description:
|
||||
- Authentication refresh token for Keycloak API.
|
||||
type: str
|
||||
|
||||
validate_certs:
|
||||
description:
|
||||
@@ -68,11 +73,17 @@ options:
|
||||
- Controls the HTTP connections timeout period (in seconds) to Keycloak API.
|
||||
type: int
|
||||
default: 10
|
||||
version_added: 4.5.0
|
||||
http_agent:
|
||||
description:
|
||||
- Configures the HTTP User-Agent header.
|
||||
type: str
|
||||
default: Ansible
|
||||
version_added: 5.4.0
|
||||
use_netrc:
|
||||
description:
|
||||
- Whether to use credentials from C(~/.netrc) file.
|
||||
- By default, C(~/.netrc) is not used because these modules authenticate via
|
||||
explicit OIDC credentials/token. A matching C(~/.netrc) entry would silently
|
||||
override the Bearer token with Basic authentication, causing 401 errors.
|
||||
type: bool
|
||||
default: false
|
||||
'''
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||
# Do not use this from other collections or standalone plugins/modules!
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
import typing as t
|
||||
|
||||
|
||||
def merge_settings_without_absent_nulls(
|
||||
existing_settings: dict[str, t.Any], desired_settings: dict[str, t.Any]
|
||||
) -> dict[str, t.Any]:
|
||||
"""
|
||||
Merges existing and desired settings into a new dictionary while excluding null values in desired settings that are absent in the existing settings.
|
||||
This ensures idempotency by treating absent keys in existing settings and null values in desired settings as equivalent, preventing unnecessary updates.
|
||||
|
||||
Args:
|
||||
existing_settings (dict): Dictionary representing the current settings in Keycloak
|
||||
desired_settings (dict): Dictionary representing the desired settings
|
||||
|
||||
Returns:
|
||||
dict: A new dictionary containing all entries from existing_settings and desired_settings,
|
||||
excluding null values in desired_settings whose corresponding keys are not present in existing_settings
|
||||
"""
|
||||
|
||||
existing = existing_settings or {}
|
||||
desired = desired_settings or {}
|
||||
|
||||
return {**existing, **{k: v for k, v in desired.items() if v is not None or k in existing}}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
# Copyright (c) 2022, John Cant <a.johncant@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
import typing as t
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def keycloak_clientsecret_module() -> AnsibleModule:
|
||||
"""
|
||||
Returns an AnsibleModule definition for modules that interact with a client
|
||||
secret.
|
||||
|
||||
:return: argument_spec dict
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
realm=dict(default="master"),
|
||||
id=dict(type="str"),
|
||||
client_id=dict(type="str", aliases=["clientId"]),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[
|
||||
["id", "client_id"],
|
||||
["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"],
|
||||
]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
mutually_exclusive=[["token", "auth_realm"], ["token", "auth_username"], ["token", "auth_password"]],
|
||||
)
|
||||
|
||||
return module
|
||||
|
||||
|
||||
def keycloak_clientsecret_module_resolve_params(module: AnsibleModule, kc: KeycloakAPI) -> tuple[str, dict[str, t.Any]]:
|
||||
"""
|
||||
Given an AnsibleModule definition for keycloak_clientsecret_*, and a
|
||||
KeycloakAPI client, resolve the params needed to interact with the Keycloak
|
||||
client secret, looking up the client by clientId if necessary via an API
|
||||
call.
|
||||
|
||||
:return: tuple of id, realm
|
||||
"""
|
||||
|
||||
realm = module.params.get("realm")
|
||||
id = module.params.get("id")
|
||||
client_id = module.params.get("client_id")
|
||||
|
||||
# only lookup the client_id if id isn't provided.
|
||||
# in the case that both are provided, prefer the ID, since it is one
|
||||
# less lookup.
|
||||
if id is None:
|
||||
# Due to the required_one_of spec, client_id is guaranteed to not be None
|
||||
client = kc.get_client_by_client_id(client_id, realm=realm)
|
||||
|
||||
if client is None:
|
||||
module.fail_json(msg=f"Client does not exist {client_id}")
|
||||
|
||||
id = client["id"]
|
||||
|
||||
return id, realm
|
||||
@@ -0,0 +1,520 @@
|
||||
# Copyright (c) 2019, INSPQ <philippe.gauthier@inspq.qc.ca>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authentication
|
||||
|
||||
short_description: Configure authentication in Keycloak
|
||||
|
||||
description:
|
||||
- This module actually can only make a copy of an existing authentication flow, add an execution to it and configure it.
|
||||
- It can also delete the flow.
|
||||
# Originally added in community.general 3.3.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: full
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
realm:
|
||||
description:
|
||||
- The name of the realm in which is the authentication.
|
||||
required: true
|
||||
type: str
|
||||
alias:
|
||||
description:
|
||||
- Alias for the authentication flow.
|
||||
required: true
|
||||
type: str
|
||||
description:
|
||||
description:
|
||||
- Description of the flow.
|
||||
type: str
|
||||
providerId:
|
||||
description:
|
||||
- C(providerId) for the new flow when not copied from an existing flow.
|
||||
choices: ["basic-flow", "client-flow"]
|
||||
type: str
|
||||
copyFrom:
|
||||
description:
|
||||
- C(flowAlias) of the authentication flow to use for the copy.
|
||||
type: str
|
||||
authenticationExecutions:
|
||||
description:
|
||||
- Configuration structure for the executions.
|
||||
type: list
|
||||
elements: dict
|
||||
suboptions:
|
||||
providerId:
|
||||
description:
|
||||
- C(providerID) for the new flow when not copied from an existing flow.
|
||||
type: str
|
||||
displayName:
|
||||
description:
|
||||
- Name of the execution or subflow to create or update.
|
||||
type: str
|
||||
requirement:
|
||||
description:
|
||||
- Control status of the subflow or execution.
|
||||
choices: ["REQUIRED", "ALTERNATIVE", "DISABLED", "CONDITIONAL"]
|
||||
type: str
|
||||
flowAlias:
|
||||
description:
|
||||
- Alias of parent flow.
|
||||
type: str
|
||||
authenticationConfig:
|
||||
description:
|
||||
- Describe the config of the authentication.
|
||||
type: dict
|
||||
index:
|
||||
description:
|
||||
- Priority order of the execution.
|
||||
type: int
|
||||
subFlowType:
|
||||
description:
|
||||
- For new subflows, optionally specify the type.
|
||||
- Is only used at creation.
|
||||
choices: ["basic-flow", "form-flow"]
|
||||
default: "basic-flow"
|
||||
type: str
|
||||
state:
|
||||
description:
|
||||
- Control if the authentication flow must exists or not.
|
||||
choices: ["present", "absent"]
|
||||
default: present
|
||||
type: str
|
||||
force:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- If V(true), allows to remove the authentication flow and recreate it.
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Philippe Gauthier (@elfelip)
|
||||
- Gaëtan Daubresse (@Gaetan2907)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Create an authentication flow from first broker login and add an execution to it.
|
||||
middleware_automation.keycloak.keycloak_authentication:
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_realm: master
|
||||
auth_username: admin
|
||||
auth_password: password
|
||||
realm: master
|
||||
alias: "Copy of first broker login"
|
||||
copyFrom: "first broker login"
|
||||
authenticationExecutions:
|
||||
- providerId: "test-execution1"
|
||||
requirement: "REQUIRED"
|
||||
authenticationConfig:
|
||||
alias: "test.execution1.property"
|
||||
config:
|
||||
test1.property: "value"
|
||||
- providerId: "test-execution2"
|
||||
requirement: "REQUIRED"
|
||||
authenticationConfig:
|
||||
alias: "test.execution2.property"
|
||||
config:
|
||||
test2.property: "value"
|
||||
state: present
|
||||
|
||||
- name: Re-create the authentication flow
|
||||
middleware_automation.keycloak.keycloak_authentication:
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_realm: master
|
||||
auth_username: admin
|
||||
auth_password: password
|
||||
realm: master
|
||||
alias: "Copy of first broker login"
|
||||
copyFrom: "first broker login"
|
||||
authenticationExecutions:
|
||||
- providerId: "test-provisioning"
|
||||
requirement: "REQUIRED"
|
||||
authenticationConfig:
|
||||
alias: "test.provisioning.property"
|
||||
config:
|
||||
test.provisioning.property: "value"
|
||||
state: present
|
||||
force: true
|
||||
|
||||
- name: Create an authentication flow with subflow containing an execution.
|
||||
middleware_automation.keycloak.keycloak_authentication:
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_realm: master
|
||||
auth_username: admin
|
||||
auth_password: password
|
||||
realm: master
|
||||
alias: "Copy of first broker login"
|
||||
copyFrom: "first broker login"
|
||||
authenticationExecutions:
|
||||
- providerId: "test-execution1"
|
||||
requirement: "REQUIRED"
|
||||
- displayName: "New Subflow"
|
||||
requirement: "REQUIRED"
|
||||
- providerId: "auth-cookie"
|
||||
requirement: "REQUIRED"
|
||||
flowAlias: "New Sublow"
|
||||
state: present
|
||||
|
||||
- name: Remove authentication.
|
||||
middleware_automation.keycloak.keycloak_authentication:
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_realm: master
|
||||
auth_username: admin
|
||||
auth_password: password
|
||||
realm: master
|
||||
alias: "Copy of first broker login"
|
||||
state: absent
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
end_state:
|
||||
description: Representation of the authentication after module execution.
|
||||
returned: on success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"alias": "Copy of first broker login",
|
||||
"authenticationExecutions": [
|
||||
{
|
||||
"alias": "review profile config",
|
||||
"authenticationConfig": {
|
||||
"alias": "review profile config",
|
||||
"config": {
|
||||
"update.profile.on.first.login": "missing"
|
||||
},
|
||||
"id": "6f09e4fb-aad4-496a-b873-7fa9779df6d7"
|
||||
},
|
||||
"configurable": true,
|
||||
"displayName": "Review Profile",
|
||||
"id": "8f77dab8-2008-416f-989e-88b09ccf0b4c",
|
||||
"index": 0,
|
||||
"level": 0,
|
||||
"providerId": "idp-review-profile",
|
||||
"requirement": "REQUIRED",
|
||||
"requirementChoices": [
|
||||
"REQUIRED",
|
||||
"ALTERNATIVE",
|
||||
"DISABLED"
|
||||
]
|
||||
}
|
||||
],
|
||||
"builtIn": false,
|
||||
"description": "Actions taken after first broker login with identity provider account, which is not yet linked to any Keycloak account",
|
||||
"id": "bc228863-5887-4297-b898-4d988f8eaa5c",
|
||||
"providerId": "basic-flow",
|
||||
"topLevel": true
|
||||
}
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
is_struct_included,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def find_exec_in_executions(searched_exec, executions):
|
||||
"""
|
||||
Search if exec is contained in the executions.
|
||||
:param searched_exec: Execution to search for.
|
||||
:param executions: List of executions.
|
||||
:return: Index of the execution, -1 if not found..
|
||||
"""
|
||||
for i, existing_exec in enumerate(executions, start=0):
|
||||
if (
|
||||
"providerId" in existing_exec
|
||||
and "providerId" in searched_exec
|
||||
and existing_exec["providerId"] == searched_exec["providerId"]
|
||||
or "displayName" in existing_exec
|
||||
and "displayName" in searched_exec
|
||||
and existing_exec["displayName"] == searched_exec["displayName"]
|
||||
):
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
def create_or_update_executions(kc, config, realm="master"):
|
||||
"""
|
||||
Create or update executions for an authentication flow.
|
||||
:param kc: Keycloak API access.
|
||||
:param config: Representation of the authentication flow including its executions.
|
||||
:param realm: Realm
|
||||
:return: tuple (changed, dict(before, after)
|
||||
WHERE
|
||||
bool changed indicates if changes have been made
|
||||
dict(str, str) shows state before and after creation/update
|
||||
"""
|
||||
try:
|
||||
changed = False
|
||||
after = ""
|
||||
before = ""
|
||||
execution = None
|
||||
if config.get("authenticationExecutions") is not None:
|
||||
# Get existing executions on the Keycloak server for this alias
|
||||
existing_executions = kc.get_executions_representation(config, realm=realm)
|
||||
for new_exec_index, new_exec in enumerate(config["authenticationExecutions"], start=0):
|
||||
if new_exec["index"] is not None:
|
||||
new_exec_index = new_exec["index"]
|
||||
exec_found = False
|
||||
# Get flowalias parent if given
|
||||
if new_exec["flowAlias"] is not None:
|
||||
flow_alias_parent = new_exec["flowAlias"]
|
||||
else:
|
||||
flow_alias_parent = config["alias"]
|
||||
# Check if same providerId or displayName name between existing and new execution
|
||||
exec_index = find_exec_in_executions(new_exec, existing_executions)
|
||||
if exec_index != -1:
|
||||
# Remove key that doesn't need to be compared with existing_exec
|
||||
exclude_key = ["flowAlias", "subFlowType"]
|
||||
for key in new_exec:
|
||||
if new_exec[key] is None:
|
||||
exclude_key.append(key)
|
||||
# Compare the executions to see if it need changes
|
||||
if (
|
||||
not is_struct_included(new_exec, existing_executions[exec_index], exclude_key)
|
||||
or exec_index != new_exec_index
|
||||
):
|
||||
exec_found = True
|
||||
if new_exec["index"] is None:
|
||||
new_exec_index = exec_index
|
||||
before += f"{existing_executions[exec_index]}\n"
|
||||
execution = existing_executions[exec_index].copy()
|
||||
# Remove exec from list in case 2 exec with same name
|
||||
existing_executions[exec_index].clear()
|
||||
elif new_exec["providerId"] is not None:
|
||||
kc.create_execution(new_exec, flowAlias=flow_alias_parent, realm=realm)
|
||||
execution = kc.get_executions_representation(config, realm=realm)[exec_index]
|
||||
exec_found = True
|
||||
exec_index = new_exec_index
|
||||
after += f"{new_exec}\n"
|
||||
elif new_exec["displayName"] is not None:
|
||||
kc.create_subflow(
|
||||
new_exec["displayName"], flow_alias_parent, realm=realm, flowType=new_exec["subFlowType"]
|
||||
)
|
||||
execution = kc.get_executions_representation(config, realm=realm)[exec_index]
|
||||
exec_found = True
|
||||
exec_index = new_exec_index
|
||||
after += f"{new_exec}\n"
|
||||
if exec_found:
|
||||
changed = True
|
||||
if exec_index != -1:
|
||||
# Update the existing execution
|
||||
updated_exec = {"id": execution["id"]}
|
||||
# add the execution configuration
|
||||
if new_exec["authenticationConfig"] is not None:
|
||||
if "authenticationConfig" in execution and "id" in execution["authenticationConfig"]:
|
||||
kc.delete_authentication_config(execution["authenticationConfig"]["id"], realm=realm)
|
||||
kc.add_authenticationConfig_to_execution(
|
||||
updated_exec["id"], new_exec["authenticationConfig"], realm=realm
|
||||
)
|
||||
for key in new_exec:
|
||||
# remove unwanted key for the next API call
|
||||
if key not in ("flowAlias", "authenticationConfig", "subFlowType"):
|
||||
updated_exec[key] = new_exec[key]
|
||||
if new_exec["requirement"] is not None:
|
||||
if "priority" in execution:
|
||||
updated_exec["priority"] = execution["priority"]
|
||||
kc.update_authentication_executions(flow_alias_parent, updated_exec, realm=realm)
|
||||
diff = exec_index - new_exec_index
|
||||
kc.change_execution_priority(updated_exec["id"], diff, realm=realm)
|
||||
after += f"{kc.get_executions_representation(config, realm=realm)[new_exec_index]}\n"
|
||||
return changed, dict(before=before, after=after)
|
||||
except Exception as e:
|
||||
kc.module.fail_json(
|
||||
msg=f"Could not create or update executions for authentication flow {config['alias']} in realm {realm}: {e}"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
realm=dict(type="str", required=True),
|
||||
alias=dict(type="str", required=True),
|
||||
providerId=dict(type="str", choices=["basic-flow", "client-flow"]),
|
||||
description=dict(type="str"),
|
||||
copyFrom=dict(type="str"),
|
||||
authenticationExecutions=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
options=dict(
|
||||
providerId=dict(type="str"),
|
||||
displayName=dict(type="str"),
|
||||
requirement=dict(choices=["REQUIRED", "ALTERNATIVE", "DISABLED", "CONDITIONAL"], type="str"),
|
||||
flowAlias=dict(type="str"),
|
||||
authenticationConfig=dict(type="dict"),
|
||||
index=dict(type="int"),
|
||||
subFlowType=dict(choices=["basic-flow", "form-flow"], default="basic-flow", type="str"),
|
||||
),
|
||||
),
|
||||
state=dict(choices=["absent", "present"], default="present"),
|
||||
force=dict(type="bool", default=False),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg="", flow={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
realm = module.params.get("realm")
|
||||
state = module.params.get("state")
|
||||
force = module.params.get("force")
|
||||
|
||||
new_auth_repr = {
|
||||
"alias": module.params.get("alias"),
|
||||
"copyFrom": module.params.get("copyFrom"),
|
||||
"providerId": module.params.get("providerId"),
|
||||
"authenticationExecutions": module.params.get("authenticationExecutions"),
|
||||
"description": module.params.get("description"),
|
||||
"builtIn": module.params.get("builtIn"),
|
||||
"subflow": module.params.get("subflow"),
|
||||
}
|
||||
|
||||
auth_repr = kc.get_authentication_flow_by_alias(alias=new_auth_repr["alias"], realm=realm)
|
||||
|
||||
# Cater for when it doesn't exist (an empty dict)
|
||||
if not auth_repr:
|
||||
if state == "absent":
|
||||
# Do nothing and exit
|
||||
if module._diff:
|
||||
result["diff"] = dict(before="", after="")
|
||||
result["changed"] = False
|
||||
result["end_state"] = {}
|
||||
result["msg"] = f"{new_auth_repr['alias']} absent"
|
||||
module.exit_json(**result)
|
||||
|
||||
elif state == "present":
|
||||
# Process a creation
|
||||
result["changed"] = True
|
||||
|
||||
if module._diff:
|
||||
result["diff"] = dict(before="", after=new_auth_repr)
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
|
||||
# If copyFrom is defined, create authentication flow from a copy
|
||||
if "copyFrom" in new_auth_repr and new_auth_repr["copyFrom"] is not None:
|
||||
auth_repr = kc.copy_auth_flow(config=new_auth_repr, realm=realm)
|
||||
else: # Create an empty authentication flow
|
||||
auth_repr = kc.create_empty_auth_flow(config=new_auth_repr, realm=realm)
|
||||
|
||||
# If the authentication still not exist on the server, raise an exception.
|
||||
if auth_repr is None:
|
||||
result["msg"] = f"Authentication just created not found: {new_auth_repr}"
|
||||
module.fail_json(**result)
|
||||
|
||||
# Configure the executions for the flow
|
||||
create_or_update_executions(kc=kc, config=new_auth_repr, realm=realm)
|
||||
|
||||
# Get executions created
|
||||
exec_repr = kc.get_executions_representation(config=new_auth_repr, realm=realm)
|
||||
if exec_repr is not None:
|
||||
auth_repr["authenticationExecutions"] = exec_repr
|
||||
result["end_state"] = auth_repr
|
||||
|
||||
else:
|
||||
if state == "present":
|
||||
# Process an update
|
||||
|
||||
if force: # If force option is true
|
||||
# Delete the actual authentication flow
|
||||
result["changed"] = True
|
||||
if module._diff:
|
||||
result["diff"] = dict(before=auth_repr, after=new_auth_repr)
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
kc.delete_authentication_flow_by_id(id=auth_repr["id"], realm=realm)
|
||||
# If copyFrom is defined, create authentication flow from a copy
|
||||
if "copyFrom" in new_auth_repr and new_auth_repr["copyFrom"] is not None:
|
||||
auth_repr = kc.copy_auth_flow(config=new_auth_repr, realm=realm)
|
||||
else: # Create an empty authentication flow
|
||||
auth_repr = kc.create_empty_auth_flow(config=new_auth_repr, realm=realm)
|
||||
# If the authentication still not exist on the server, raise an exception.
|
||||
if auth_repr is None:
|
||||
result["msg"] = f"Authentication just created not found: {new_auth_repr}"
|
||||
module.fail_json(**result)
|
||||
# Configure the executions for the flow
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
changed, diff = create_or_update_executions(kc=kc, config=new_auth_repr, realm=realm)
|
||||
result["changed"] |= changed
|
||||
|
||||
if module._diff:
|
||||
result["diff"] = diff
|
||||
|
||||
# Get executions created
|
||||
exec_repr = kc.get_executions_representation(config=new_auth_repr, realm=realm)
|
||||
if exec_repr is not None:
|
||||
auth_repr["authenticationExecutions"] = exec_repr
|
||||
result["end_state"] = auth_repr
|
||||
|
||||
else:
|
||||
# Process a deletion (because state was not 'present')
|
||||
result["changed"] = True
|
||||
|
||||
if module._diff:
|
||||
result["diff"] = dict(before=auth_repr, after="")
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
|
||||
# delete it
|
||||
kc.delete_authentication_flow_by_id(id=auth_repr["id"], realm=realm)
|
||||
|
||||
result["msg"] = f"Authentication flow: {new_auth_repr['alias']} id: {auth_repr['id']} is deleted"
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -5,7 +5,8 @@
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
@@ -14,6 +15,8 @@ module: keycloak_authentication_flow
|
||||
|
||||
short_description: Allows administration of Keycloak authentication flows via Keycloak API
|
||||
|
||||
version_added: "3.0.0"
|
||||
|
||||
description:
|
||||
- This module allows you to add, remove or modify Keycloak authentication flows via the Keycloak REST API.
|
||||
It requires access to the REST API via OpenID Connect; the user connecting and the client being
|
||||
@@ -105,6 +108,7 @@ options:
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# Copyright (c) 2021, Christophe Gilles <christophe.gilles54@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
|
||||
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authentication_required_actions
|
||||
|
||||
short_description: Allows administration of Keycloak authentication required actions
|
||||
|
||||
description:
|
||||
- This module can register, update and delete required actions.
|
||||
- It also filters out any duplicate required actions by their alias. The first occurrence is preserved.
|
||||
# Originally added in community.general 7.1.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: full
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
realm:
|
||||
description:
|
||||
- The name of the realm in which are the authentication required actions.
|
||||
required: true
|
||||
type: str
|
||||
required_actions:
|
||||
elements: dict
|
||||
description:
|
||||
- Authentication required action.
|
||||
suboptions:
|
||||
alias:
|
||||
description:
|
||||
- Unique name of the required action.
|
||||
required: true
|
||||
type: str
|
||||
config:
|
||||
description:
|
||||
- Configuration for the required action.
|
||||
type: dict
|
||||
defaultAction:
|
||||
description:
|
||||
- Indicates whether new users have the required action assigned to them.
|
||||
type: bool
|
||||
enabled:
|
||||
description:
|
||||
- Indicates, if the required action is enabled or not.
|
||||
type: bool
|
||||
name:
|
||||
description:
|
||||
- Displayed name of the required action. Required for registration.
|
||||
type: str
|
||||
priority:
|
||||
description:
|
||||
- Priority of the required action.
|
||||
type: int
|
||||
providerId:
|
||||
description:
|
||||
- Provider ID of the required action. Required for registration.
|
||||
type: str
|
||||
type: list
|
||||
state:
|
||||
choices: ["absent", "present"]
|
||||
description:
|
||||
- Control if the realm authentication required actions are going to be registered/updated (V(present)) or deleted (V(absent)).
|
||||
required: true
|
||||
type: str
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Skrekulko (@Skrekulko)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Register a new required action.
|
||||
middleware_automation.keycloak.keycloak_authentication_required_actions:
|
||||
auth_client_id: "admin-cli"
|
||||
auth_keycloak_url: "http://localhost:8080"
|
||||
auth_password: "password"
|
||||
auth_realm: "master"
|
||||
auth_username: "admin"
|
||||
realm: "master"
|
||||
required_actions:
|
||||
- alias: "TERMS_AND_CONDITIONS"
|
||||
name: "Terms and conditions"
|
||||
providerId: "TERMS_AND_CONDITIONS"
|
||||
enabled: true
|
||||
state: "present"
|
||||
|
||||
- name: Update the newly registered required action.
|
||||
middleware_automation.keycloak.keycloak_authentication_required_actions:
|
||||
auth_client_id: "admin-cli"
|
||||
auth_keycloak_url: "http://localhost:8080"
|
||||
auth_password: "password"
|
||||
auth_realm: "master"
|
||||
auth_username: "admin"
|
||||
realm: "master"
|
||||
required_actions:
|
||||
- alias: "TERMS_AND_CONDITIONS"
|
||||
enabled: false
|
||||
state: "present"
|
||||
|
||||
- name: Delete the updated registered required action.
|
||||
middleware_automation.keycloak.keycloak_authentication_required_actions:
|
||||
auth_client_id: "admin-cli"
|
||||
auth_keycloak_url: "http://localhost:8080"
|
||||
auth_password: "password"
|
||||
auth_realm: "master"
|
||||
auth_username: "admin"
|
||||
realm: "master"
|
||||
required_actions:
|
||||
- alias: "TERMS_AND_CONDITIONS"
|
||||
state: "absent"
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
end_state:
|
||||
description: Representation of the authentication required actions after module execution.
|
||||
returned: on success
|
||||
type: complex
|
||||
contains:
|
||||
alias:
|
||||
description:
|
||||
- Unique name of the required action.
|
||||
sample: test-provider-id
|
||||
type: str
|
||||
config:
|
||||
description:
|
||||
- Configuration for the required action.
|
||||
sample: {}
|
||||
type: dict
|
||||
defaultAction:
|
||||
description:
|
||||
- Indicates whether new users have the required action assigned to them.
|
||||
sample: false
|
||||
type: bool
|
||||
enabled:
|
||||
description:
|
||||
- Indicates, if the required action is enabled or not.
|
||||
sample: false
|
||||
type: bool
|
||||
name:
|
||||
description:
|
||||
- Displayed name of the required action. Required for registration.
|
||||
sample: Test provider ID
|
||||
type: str
|
||||
priority:
|
||||
description:
|
||||
- Priority of the required action.
|
||||
sample: 90
|
||||
type: int
|
||||
providerId:
|
||||
description:
|
||||
- Provider ID of the required action. Required for registration.
|
||||
sample: test-provider-id
|
||||
type: str
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def sanitize_required_actions(objects):
|
||||
for obj in objects:
|
||||
alias = obj["alias"]
|
||||
name = obj["name"]
|
||||
provider_id = obj["providerId"]
|
||||
|
||||
if not name:
|
||||
obj["name"] = alias
|
||||
|
||||
if provider_id != alias:
|
||||
obj["providerId"] = alias
|
||||
|
||||
return objects
|
||||
|
||||
|
||||
def filter_duplicates(objects):
|
||||
filtered_objects = {}
|
||||
|
||||
for obj in objects:
|
||||
alias = obj["alias"]
|
||||
|
||||
if alias not in filtered_objects:
|
||||
filtered_objects[alias] = obj
|
||||
|
||||
return list(filtered_objects.values())
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
realm=dict(type="str", required=True),
|
||||
required_actions=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
options=dict(
|
||||
alias=dict(type="str", required=True),
|
||||
config=dict(type="dict"),
|
||||
defaultAction=dict(type="bool"),
|
||||
enabled=dict(type="bool"),
|
||||
name=dict(type="str"),
|
||||
priority=dict(type="int"),
|
||||
providerId=dict(type="str"),
|
||||
),
|
||||
),
|
||||
state=dict(type="str", choices=["present", "absent"], required=True),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg="", end_state={}, diff=dict(before={}, after={}))
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
# Convenience variables
|
||||
realm = module.params.get("realm")
|
||||
desired_required_actions = module.params.get("required_actions")
|
||||
state = module.params.get("state")
|
||||
|
||||
# Sanitize required actions
|
||||
desired_required_actions = sanitize_required_actions(desired_required_actions)
|
||||
|
||||
# Filter out duplicate required actions
|
||||
desired_required_actions = filter_duplicates(desired_required_actions)
|
||||
|
||||
# Get required actions
|
||||
before_required_actions = kc.get_required_actions(realm=realm)
|
||||
|
||||
if state == "present":
|
||||
# Initialize empty lists to hold the required actions that need to be
|
||||
# registered, updated, and original ones of the updated one
|
||||
register_required_actions = []
|
||||
before_updated_required_actions = []
|
||||
updated_required_actions = []
|
||||
|
||||
# Loop through the desired required actions and check if they exist in the before required actions
|
||||
for desired_required_action in desired_required_actions:
|
||||
found = False
|
||||
|
||||
# Loop through the before required actions and check if the aliases match
|
||||
for before_required_action in before_required_actions:
|
||||
if desired_required_action["alias"] == before_required_action["alias"]:
|
||||
update_required = False
|
||||
|
||||
# Fill in the parameters
|
||||
for k, v in before_required_action.items():
|
||||
if k not in desired_required_action or desired_required_action[k] is None:
|
||||
desired_required_action[k] = v
|
||||
|
||||
# Loop through the keys of the desired and before required actions
|
||||
# and check if there are any differences between them
|
||||
for key in desired_required_action.keys():
|
||||
if (
|
||||
key in before_required_action
|
||||
and desired_required_action[key] != before_required_action[key]
|
||||
):
|
||||
update_required = True
|
||||
break
|
||||
|
||||
# If there are differences, add the before and desired required actions
|
||||
# to their respective lists for updating
|
||||
if update_required:
|
||||
before_updated_required_actions.append(before_required_action)
|
||||
updated_required_actions.append(desired_required_action)
|
||||
found = True
|
||||
break
|
||||
# If the desired required action is not found in the before required actions,
|
||||
# add it to the list of required actions to register
|
||||
if not found:
|
||||
# Check if name is provided
|
||||
if "name" not in desired_required_action or desired_required_action["name"] is None:
|
||||
module.fail_json(
|
||||
msg=f"Unable to register required action {desired_required_action['alias']} in realm {realm}: name not included"
|
||||
)
|
||||
|
||||
# Check if provider ID is provided
|
||||
if "providerId" not in desired_required_action or desired_required_action["providerId"] is None:
|
||||
module.fail_json(
|
||||
msg=f"Unable to register required action {desired_required_action['alias']} in realm {realm}: providerId not included"
|
||||
)
|
||||
|
||||
register_required_actions.append(desired_required_action)
|
||||
|
||||
# Handle diff
|
||||
if module._diff:
|
||||
diff_required_actions = updated_required_actions.copy()
|
||||
diff_required_actions.extend(register_required_actions)
|
||||
|
||||
result["diff"] = dict(before=before_updated_required_actions, after=diff_required_actions)
|
||||
|
||||
# Handle changed
|
||||
if register_required_actions or updated_required_actions:
|
||||
result["changed"] = True
|
||||
|
||||
# Handle check mode
|
||||
if module.check_mode:
|
||||
if register_required_actions or updated_required_actions:
|
||||
result["change"] = True
|
||||
result["msg"] = "Required actions would be registered/updated"
|
||||
else:
|
||||
result["change"] = False
|
||||
result["msg"] = "Required actions would not be registered/updated"
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
# Register required actions
|
||||
if register_required_actions:
|
||||
for register_required_action in register_required_actions:
|
||||
kc.register_required_action(realm=realm, rep=register_required_action)
|
||||
kc.update_required_action(
|
||||
alias=register_required_action["alias"], realm=realm, rep=register_required_action
|
||||
)
|
||||
|
||||
# Update required actions
|
||||
if updated_required_actions:
|
||||
for updated_required_action in updated_required_actions:
|
||||
kc.update_required_action(
|
||||
alias=updated_required_action["alias"], realm=realm, rep=updated_required_action
|
||||
)
|
||||
|
||||
# Initialize the final list of required actions
|
||||
final_required_actions = []
|
||||
|
||||
# Iterate over the before_required_actions
|
||||
for before_required_action in before_required_actions:
|
||||
# Check if there is an updated_required_action with the same alias
|
||||
updated_required_action_found = False
|
||||
|
||||
for updated_required_action in updated_required_actions:
|
||||
if updated_required_action["alias"] == before_required_action["alias"]:
|
||||
# Merge the two dictionaries, favoring the values from updated_required_action
|
||||
merged_dict = {}
|
||||
for key in before_required_action.keys():
|
||||
if key in updated_required_action:
|
||||
merged_dict[key] = updated_required_action[key]
|
||||
else:
|
||||
merged_dict[key] = before_required_action[key]
|
||||
|
||||
for key in updated_required_action.keys():
|
||||
if key not in before_required_action:
|
||||
merged_dict[key] = updated_required_action[key]
|
||||
|
||||
# Add the merged dictionary to the final list of required actions
|
||||
final_required_actions.append(merged_dict)
|
||||
|
||||
# Mark the updated_required_action as found
|
||||
updated_required_action_found = True
|
||||
|
||||
# Stop looking for updated_required_action
|
||||
break
|
||||
|
||||
# If no matching updated_required_action was found, add the before_required_action to the final list of required actions
|
||||
if not updated_required_action_found:
|
||||
final_required_actions.append(before_required_action)
|
||||
|
||||
# Append any remaining updated_required_actions that were not merged
|
||||
for updated_required_action in updated_required_actions:
|
||||
if not any(updated_required_action["alias"] == action["alias"] for action in final_required_actions):
|
||||
final_required_actions.append(updated_required_action)
|
||||
|
||||
# Append newly registered required actions
|
||||
final_required_actions.extend(register_required_actions)
|
||||
|
||||
# Handle message and end state
|
||||
result["msg"] = "Required actions registered/updated"
|
||||
result["end_state"] = final_required_actions
|
||||
else:
|
||||
# Filter out the deleted required actions
|
||||
final_required_actions = []
|
||||
delete_required_actions = []
|
||||
|
||||
for before_required_action in before_required_actions:
|
||||
delete_action = False
|
||||
|
||||
for desired_required_action in desired_required_actions:
|
||||
if before_required_action["alias"] == desired_required_action["alias"]:
|
||||
delete_action = True
|
||||
break
|
||||
|
||||
if not delete_action:
|
||||
final_required_actions.append(before_required_action)
|
||||
else:
|
||||
delete_required_actions.append(before_required_action)
|
||||
|
||||
# Handle diff
|
||||
if module._diff:
|
||||
result["diff"] = dict(before=before_required_actions, after=final_required_actions)
|
||||
|
||||
# Handle changed
|
||||
if delete_required_actions:
|
||||
result["changed"] = True
|
||||
|
||||
# Handle check mode
|
||||
if module.check_mode:
|
||||
if final_required_actions:
|
||||
result["change"] = True
|
||||
result["msg"] = "Required actions would be deleted"
|
||||
else:
|
||||
result["change"] = False
|
||||
result["msg"] = "Required actions would not be deleted"
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
# Delete required actions
|
||||
if delete_required_actions:
|
||||
for delete_required_action in delete_required_actions:
|
||||
kc.delete_required_action(alias=delete_required_action["alias"], realm=realm)
|
||||
|
||||
# Handle message and end state
|
||||
result["msg"] = "Required actions deleted"
|
||||
result["end_state"] = final_required_actions
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,282 @@
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# Copyright (c) 2021, Christophe Gilles <christophe.gilles54@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
|
||||
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authz_authorization_scope
|
||||
|
||||
short_description: Allows administration of Keycloak client authorization scopes using Keycloak API
|
||||
|
||||
# Originally added in community.general 6.6.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
description:
|
||||
- This module allows the administration of Keycloak client Authorization Scopes using the Keycloak REST API. Authorization
|
||||
Scopes are only available if a client has Authorization enabled.
|
||||
- This module requires access to the REST API using OpenID Connect; the user connecting and the realm 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
|
||||
realm 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 options used by Keycloak. The Authorization Services
|
||||
paths and payloads have not officially been documented by the Keycloak project.
|
||||
U(https://www.puppeteers.net/blog/keycloak-authorization-services-rest-api-paths-and-payload/).
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: full
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- State of the authorization scope.
|
||||
- On V(present), the authorization scope is created (or updated if it exists already).
|
||||
- On V(absent), the authorization scope is removed if it exists.
|
||||
choices: ['present', 'absent']
|
||||
default: 'present'
|
||||
type: str
|
||||
name:
|
||||
description:
|
||||
- Name of the authorization scope to create.
|
||||
type: str
|
||||
required: true
|
||||
display_name:
|
||||
description:
|
||||
- The display name of the authorization scope.
|
||||
type: str
|
||||
icon_uri:
|
||||
description:
|
||||
- The icon URI for the authorization scope.
|
||||
type: str
|
||||
client_id:
|
||||
description:
|
||||
- The C(clientId) of the Keycloak client that should have the authorization scope.
|
||||
- This is usually a human-readable name of the Keycloak client.
|
||||
type: str
|
||||
required: true
|
||||
realm:
|
||||
description:
|
||||
- The name of the Keycloak realm the Keycloak client is in.
|
||||
type: str
|
||||
required: true
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Samuli Seppänen (@mattock)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Manage Keycloak file:delete authorization scope
|
||||
keycloak_authz_authorization_scope:
|
||||
name: file:delete
|
||||
state: present
|
||||
display_name: File delete
|
||||
client_id: myclient
|
||||
realm: myrealm
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_username: keycloak
|
||||
auth_password: keycloak
|
||||
auth_realm: master
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
end_state:
|
||||
description: Representation of the authorization scope after module execution.
|
||||
returned: on success
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: ID of the authorization scope.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: a6ab1cf2-1001-40ec-9f39-48f23b6a0a41
|
||||
name:
|
||||
description: Name of the authorization scope.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: file:delete
|
||||
display_name:
|
||||
description: Display name of the authorization scope.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: File delete
|
||||
icon_uri:
|
||||
description: Icon URI for the authorization scope.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: http://localhost/icon.png
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
state=dict(type="str", default="present", choices=["present", "absent"]),
|
||||
name=dict(type="str", required=True),
|
||||
display_name=dict(type="str"),
|
||||
icon_uri=dict(type="str"),
|
||||
client_id=dict(type="str", required=True),
|
||||
realm=dict(type="str", required=True),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg="", end_state={}, diff=dict(before={}, after={}))
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
# Convenience variables
|
||||
state = module.params.get("state")
|
||||
name = module.params.get("name")
|
||||
display_name = module.params.get("display_name")
|
||||
icon_uri = module.params.get("icon_uri")
|
||||
client_id = module.params.get("client_id")
|
||||
realm = module.params.get("realm")
|
||||
|
||||
# Get the "id" of the client based on the usually more human-readable
|
||||
# "clientId"
|
||||
cid = kc.get_client_id(client_id, realm=realm)
|
||||
if not cid:
|
||||
module.fail_json(msg=f"Invalid client {client_id} for realm {realm}")
|
||||
|
||||
# Get current state of the Authorization Scope using its name as the search
|
||||
# filter. This returns False if it is not found.
|
||||
before_authz_scope = kc.get_authz_authorization_scope_by_name(name=name, client_id=cid, realm=realm)
|
||||
|
||||
# Generate a JSON payload for Keycloak Admin API. This is needed for
|
||||
# "create" and "update" operations.
|
||||
desired_authz_scope = {}
|
||||
desired_authz_scope["name"] = name
|
||||
desired_authz_scope["displayName"] = display_name
|
||||
desired_authz_scope["iconUri"] = icon_uri
|
||||
|
||||
# Add "id" to payload for modify operations
|
||||
if before_authz_scope:
|
||||
desired_authz_scope["id"] = before_authz_scope["id"]
|
||||
|
||||
# Ensure that undefined (null) optional parameters are presented as empty
|
||||
# strings in the desired state. This makes comparisons with current state
|
||||
# much easier.
|
||||
for k, v in desired_authz_scope.items():
|
||||
if not v:
|
||||
desired_authz_scope[k] = ""
|
||||
|
||||
# Do the above for the current state
|
||||
if before_authz_scope:
|
||||
for k in ["displayName", "iconUri"]:
|
||||
if k not in before_authz_scope:
|
||||
before_authz_scope[k] = ""
|
||||
|
||||
if before_authz_scope and state == "present":
|
||||
changes = False
|
||||
for k, v in desired_authz_scope.items():
|
||||
if before_authz_scope[k] != v:
|
||||
changes = True
|
||||
# At this point we know we have to update the object anyways,
|
||||
# so there's no need to do more work.
|
||||
break
|
||||
|
||||
if changes:
|
||||
if module._diff:
|
||||
result["diff"] = dict(before=before_authz_scope, after=desired_authz_scope)
|
||||
|
||||
if module.check_mode:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope would be updated"
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
kc.update_authz_authorization_scope(
|
||||
payload=desired_authz_scope, id=before_authz_scope["id"], client_id=cid, realm=realm
|
||||
)
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope updated"
|
||||
else:
|
||||
result["changed"] = False
|
||||
result["msg"] = "Authorization scope not updated"
|
||||
|
||||
result["end_state"] = desired_authz_scope
|
||||
elif not before_authz_scope and state == "present":
|
||||
if module._diff:
|
||||
result["diff"] = dict(before={}, after=desired_authz_scope)
|
||||
|
||||
if module.check_mode:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope would be created"
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
kc.create_authz_authorization_scope(payload=desired_authz_scope, client_id=cid, realm=realm)
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope created"
|
||||
result["end_state"] = desired_authz_scope
|
||||
elif before_authz_scope and state == "absent":
|
||||
if module._diff:
|
||||
result["diff"] = dict(before=before_authz_scope, after={})
|
||||
|
||||
if module.check_mode:
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope would be removed"
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
kc.remove_authz_authorization_scope(id=before_authz_scope["id"], client_id=cid, realm=realm)
|
||||
result["changed"] = True
|
||||
result["msg"] = "Authorization scope removed"
|
||||
elif not before_authz_scope and state == "absent":
|
||||
result["changed"] = False
|
||||
else:
|
||||
module.fail_json(
|
||||
msg=f"Unable to determine what to do with authorization scope {name} of client {client_id} in realm {realm}"
|
||||
)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,215 @@
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# Copyright (c) 2021, Christophe Gilles <christophe.gilles54@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
|
||||
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authz_custom_policy
|
||||
|
||||
short_description: Allows administration of Keycloak client custom Javascript policies using Keycloak API
|
||||
|
||||
# Originally added in community.general 7.5.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
description:
|
||||
- This module allows the administration of Keycloak client custom Javascript using the Keycloak REST API. Custom Javascript
|
||||
policies are only available if a client has Authorization enabled and if they have been deployed to the Keycloak server
|
||||
as JAR files.
|
||||
- This module requires access to the REST API using OpenID Connect; the user connecting and the realm 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
|
||||
realm 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 options used by Keycloak. The Authorization Services
|
||||
paths and payloads have not officially been documented by the Keycloak project.
|
||||
U(https://www.puppeteers.net/blog/keycloak-authorization-services-rest-api-paths-and-payload/).
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- State of the custom policy.
|
||||
- On V(present), the custom policy is created (or updated if it exists already).
|
||||
- On V(absent), the custom policy is removed if it exists.
|
||||
choices: ['present', 'absent']
|
||||
default: 'present'
|
||||
type: str
|
||||
name:
|
||||
description:
|
||||
- Name of the custom policy to create.
|
||||
type: str
|
||||
required: true
|
||||
policy_type:
|
||||
description:
|
||||
- The type of the policy. This must match the name of the custom policy deployed to the server.
|
||||
- Multiple policies pointing to the same policy type can be created, but their names have to differ.
|
||||
type: str
|
||||
required: true
|
||||
client_id:
|
||||
description:
|
||||
- The V(clientId) of the Keycloak client that should have the custom policy attached to it.
|
||||
- This is usually a human-readable name of the Keycloak client.
|
||||
type: str
|
||||
required: true
|
||||
realm:
|
||||
description:
|
||||
- The name of the Keycloak realm the Keycloak client is in.
|
||||
type: str
|
||||
required: true
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Samuli Seppänen (@mattock)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Manage Keycloak custom authorization policy
|
||||
middleware_automation.keycloak.keycloak_authz_custom_policy:
|
||||
name: OnlyOwner
|
||||
state: present
|
||||
policy_type: script-policy.js
|
||||
client_id: myclient
|
||||
realm: myrealm
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_username: keycloak
|
||||
auth_password: keycloak
|
||||
auth_realm: master
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
end_state:
|
||||
description: Representation of the custom policy after module execution.
|
||||
returned: on success
|
||||
type: dict
|
||||
contains:
|
||||
name:
|
||||
description: Name of the custom policy.
|
||||
type: str
|
||||
returned: when I(state=present)
|
||||
sample: file:delete
|
||||
policy_type:
|
||||
description: Type of custom policy.
|
||||
type: str
|
||||
returned: when I(state=present)
|
||||
sample: File delete
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
state=dict(type="str", default="present", choices=["present", "absent"]),
|
||||
name=dict(type="str", required=True),
|
||||
policy_type=dict(type="str", required=True),
|
||||
client_id=dict(type="str", required=True),
|
||||
realm=dict(type="str", required=True),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg="", end_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
# Convenience variables
|
||||
state = module.params.get("state")
|
||||
name = module.params.get("name")
|
||||
policy_type = module.params.get("policy_type")
|
||||
client_id = module.params.get("client_id")
|
||||
realm = module.params.get("realm")
|
||||
|
||||
cid = kc.get_client_id(client_id, realm=realm)
|
||||
if not cid:
|
||||
module.fail_json(msg=f"Invalid client {client_id} for realm {realm}")
|
||||
|
||||
before_authz_custom_policy = kc.get_authz_policy_by_name(name=name, client_id=cid, realm=realm)
|
||||
|
||||
desired_authz_custom_policy = {}
|
||||
desired_authz_custom_policy["name"] = name
|
||||
desired_authz_custom_policy["type"] = policy_type
|
||||
|
||||
# Modifying existing custom policies is not possible
|
||||
if before_authz_custom_policy and state == "present":
|
||||
result["msg"] = f"Custom policy {name} already exists"
|
||||
result["changed"] = False
|
||||
result["end_state"] = desired_authz_custom_policy
|
||||
elif not before_authz_custom_policy and state == "present":
|
||||
if module.check_mode:
|
||||
result["msg"] = f"Would create custom policy {name}"
|
||||
else:
|
||||
kc.create_authz_custom_policy(
|
||||
payload=desired_authz_custom_policy, policy_type=policy_type, client_id=cid, realm=realm
|
||||
)
|
||||
result["msg"] = f"Custom policy {name} created"
|
||||
|
||||
result["changed"] = True
|
||||
result["end_state"] = desired_authz_custom_policy
|
||||
elif before_authz_custom_policy and state == "absent":
|
||||
if module.check_mode:
|
||||
result["msg"] = f"Would remove custom policy {name}"
|
||||
else:
|
||||
kc.remove_authz_custom_policy(policy_id=before_authz_custom_policy["id"], client_id=cid, realm=realm)
|
||||
result["msg"] = f"Custom policy {name} removed"
|
||||
|
||||
result["changed"] = True
|
||||
result["end_state"] = {}
|
||||
elif not before_authz_custom_policy and state == "absent":
|
||||
result["msg"] = f"Custom policy {name} does not exist"
|
||||
result["changed"] = False
|
||||
result["end_state"] = {}
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,445 @@
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# Copyright (c) 2021, Christophe Gilles <christophe.gilles54@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
|
||||
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authz_permission
|
||||
|
||||
# Originally added in community.general 7.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
short_description: Allows administration of Keycloak client authorization permissions using Keycloak API
|
||||
|
||||
description:
|
||||
- This module allows the administration of Keycloak client authorization permissions using the Keycloak REST API. Authorization
|
||||
permissions are only available if a client has Authorization enabled.
|
||||
- There are some peculiarities in JSON paths and payloads for authorization permissions. In particular POST and PUT operations
|
||||
are targeted at permission endpoints, whereas GET requests go to policies endpoint. To make matters more interesting the
|
||||
JSON responses from GET requests return data in a different format than what is expected for POST and PUT. The end result
|
||||
is that it is not possible to detect changes to things like policies, scopes or resources - at least not without a large
|
||||
number of additional API calls. Therefore this module always updates authorization permissions instead of attempting to
|
||||
determine if changes are truly needed.
|
||||
- This module requires access to the REST API using OpenID Connect; the user connecting and the realm 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
|
||||
realm 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 options used by Keycloak. The Authorization Services
|
||||
paths and payloads have not officially been documented by the Keycloak project.
|
||||
U(https://www.puppeteers.net/blog/keycloak-authorization-services-rest-api-paths-and-payload/).
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- State of the authorization permission.
|
||||
- On V(present), the authorization permission is created (or updated if it exists already).
|
||||
- On V(absent), the authorization permission is removed if it exists.
|
||||
choices: ['present', 'absent']
|
||||
default: 'present'
|
||||
type: str
|
||||
name:
|
||||
description:
|
||||
- Name of the authorization permission to create.
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
description:
|
||||
- The description of the authorization permission.
|
||||
type: str
|
||||
permission_type:
|
||||
description:
|
||||
- The type of authorization permission.
|
||||
- On V(scope) create a scope-based permission.
|
||||
- On V(resource) create a resource-based permission.
|
||||
type: str
|
||||
required: true
|
||||
choices:
|
||||
- resource
|
||||
- scope
|
||||
decision_strategy:
|
||||
description:
|
||||
- The decision strategy to use with this permission.
|
||||
type: str
|
||||
default: UNANIMOUS
|
||||
choices:
|
||||
- UNANIMOUS
|
||||
- AFFIRMATIVE
|
||||
- CONSENSUS
|
||||
resources:
|
||||
description:
|
||||
- Resource names to attach to this permission.
|
||||
- Scope-based permissions can only include one resource.
|
||||
- Resource-based permissions can include multiple resources.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
scopes:
|
||||
description:
|
||||
- Scope names to attach to this permission.
|
||||
- Resource-based permissions cannot have scopes attached to them.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
policies:
|
||||
description:
|
||||
- Policy names to attach to this permission.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
client_id:
|
||||
description:
|
||||
- The clientId of the keycloak client that should have the authorization scope.
|
||||
- This is usually a human-readable name of the Keycloak client.
|
||||
type: str
|
||||
required: true
|
||||
realm:
|
||||
description:
|
||||
- The name of the Keycloak realm the Keycloak client is in.
|
||||
type: str
|
||||
required: true
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Samuli Seppänen (@mattock)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Manage scope-based Keycloak authorization permission
|
||||
middleware_automation.keycloak.keycloak_authz_permission:
|
||||
name: ScopePermission
|
||||
state: present
|
||||
description: Scope permission
|
||||
permission_type: scope
|
||||
scopes:
|
||||
- file:delete
|
||||
policies:
|
||||
- Default Policy
|
||||
client_id: myclient
|
||||
realm: myrealm
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_username: keycloak
|
||||
auth_password: keycloak
|
||||
auth_realm: master
|
||||
|
||||
- name: Manage resource-based Keycloak authorization permission
|
||||
middleware_automation.keycloak.keycloak_authz_permission:
|
||||
name: ResourcePermission
|
||||
state: present
|
||||
description: Resource permission
|
||||
permission_type: resource
|
||||
resources:
|
||||
- Default Resource
|
||||
policies:
|
||||
- Default Policy
|
||||
client_id: myclient
|
||||
realm: myrealm
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_username: keycloak
|
||||
auth_password: keycloak
|
||||
auth_realm: master
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
end_state:
|
||||
description: Representation of the authorization permission after module execution.
|
||||
returned: on success
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: ID of the authorization permission.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: 9da05cd2-b273-4354-bbd8-0c133918a454
|
||||
name:
|
||||
description: Name of the authorization permission.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: ResourcePermission
|
||||
description:
|
||||
description: Description of the authorization permission.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: Resource Permission
|
||||
type:
|
||||
description: Type of the authorization permission.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: resource
|
||||
decisionStrategy:
|
||||
description: The decision strategy to use.
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: UNANIMOUS
|
||||
logic:
|
||||
description: The logic used for the permission (part of the payload, but has a fixed value).
|
||||
type: str
|
||||
returned: when O(state=present)
|
||||
sample: POSITIVE
|
||||
resources:
|
||||
description: IDs of resources attached to this permission.
|
||||
type: list
|
||||
returned: when O(state=present)
|
||||
sample:
|
||||
- 49e052ff-100d-4b79-a9dd-52669ed3c11d
|
||||
scopes:
|
||||
description: IDs of scopes attached to this permission.
|
||||
type: list
|
||||
returned: when O(state=present)
|
||||
sample:
|
||||
- 9da05cd2-b273-4354-bbd8-0c133918a454
|
||||
policies:
|
||||
description: IDs of policies attached to this permission.
|
||||
type: list
|
||||
returned: when O(state=present)
|
||||
sample:
|
||||
- 9da05cd2-b273-4354-bbd8-0c133918a454
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
state=dict(type="str", default="present", choices=["present", "absent"]),
|
||||
name=dict(type="str", required=True),
|
||||
description=dict(type="str"),
|
||||
permission_type=dict(type="str", choices=["scope", "resource"], required=True),
|
||||
decision_strategy=dict(type="str", default="UNANIMOUS", choices=["UNANIMOUS", "AFFIRMATIVE", "CONSENSUS"]),
|
||||
resources=dict(type="list", elements="str", default=[]),
|
||||
scopes=dict(type="list", elements="str", default=[]),
|
||||
policies=dict(type="list", elements="str", default=[]),
|
||||
client_id=dict(type="str", required=True),
|
||||
realm=dict(type="str", required=True),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
# Convenience variables
|
||||
state = module.params.get("state")
|
||||
name = module.params.get("name")
|
||||
description = module.params.get("description")
|
||||
permission_type = module.params.get("permission_type")
|
||||
decision_strategy = module.params.get("decision_strategy")
|
||||
realm = module.params.get("realm")
|
||||
client_id = module.params.get("client_id")
|
||||
realm = module.params.get("realm")
|
||||
resources = module.params.get("resources")
|
||||
scopes = module.params.get("scopes")
|
||||
policies = module.params.get("policies")
|
||||
|
||||
if permission_type == "scope" and state == "present":
|
||||
if scopes == []:
|
||||
module.fail_json(msg="Scopes need to defined when permission type is set to scope!")
|
||||
if len(resources) > 1:
|
||||
module.fail_json(msg="Only one resource can be defined for a scope permission!")
|
||||
|
||||
if permission_type == "resource" and state == "present":
|
||||
if resources == []:
|
||||
module.fail_json(msg="A resource need to defined when permission type is set to resource!")
|
||||
if scopes != []:
|
||||
module.fail_json(msg="Scopes cannot be defined when permission type is set to resource!")
|
||||
|
||||
result = dict(changed=False, msg="", end_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
# Get id of the client based on client_id
|
||||
cid = kc.get_client_id(client_id, realm=realm)
|
||||
if not cid:
|
||||
module.fail_json(msg=f"Invalid client {client_id} for realm {realm}")
|
||||
|
||||
# Get current state of the permission using its name as the search
|
||||
# filter. This returns False if it is not found.
|
||||
permission = kc.get_authz_permission_by_name(name=name, client_id=cid, realm=realm)
|
||||
|
||||
# Generate a JSON payload for Keycloak Admin API. This is needed for
|
||||
# "create" and "update" operations.
|
||||
payload = {}
|
||||
payload["name"] = name
|
||||
payload["description"] = description
|
||||
payload["type"] = permission_type
|
||||
payload["decisionStrategy"] = decision_strategy
|
||||
payload["logic"] = "POSITIVE"
|
||||
payload["scopes"] = []
|
||||
payload["resources"] = []
|
||||
payload["policies"] = []
|
||||
|
||||
if permission_type == "scope":
|
||||
# Add the resource id, if any, to the payload. While the data type is a
|
||||
# list, it is only possible to have one entry in it based on what Keycloak
|
||||
# Admin Console does.
|
||||
r = False
|
||||
resource_scopes = []
|
||||
|
||||
if resources:
|
||||
r = kc.get_authz_resource_by_name(resources[0], cid, realm)
|
||||
if not r:
|
||||
module.fail_json(
|
||||
msg=f"Unable to find authorization resource with name {resources[0]} for client {cid} in realm {realm}"
|
||||
)
|
||||
else:
|
||||
payload["resources"].append(r["_id"])
|
||||
|
||||
for rs in r["scopes"]:
|
||||
resource_scopes.append(rs["id"])
|
||||
|
||||
# Generate a list of scope ids based on scope names. Fail if the
|
||||
# defined resource does not include all those scopes.
|
||||
for scope in scopes:
|
||||
s = kc.get_authz_authorization_scope_by_name(scope, cid, realm)
|
||||
if r and s["id"] not in resource_scopes:
|
||||
module.fail_json(
|
||||
msg=f"Resource {resources[0]} does not include scope {scope} for client {client_id} in realm {realm}"
|
||||
)
|
||||
else:
|
||||
payload["scopes"].append(s["id"])
|
||||
|
||||
elif permission_type == "resource":
|
||||
if resources:
|
||||
for resource in resources:
|
||||
r = kc.get_authz_resource_by_name(resource, cid, realm)
|
||||
if not r:
|
||||
module.fail_json(
|
||||
msg=f"Unable to find authorization resource with name {resource} for client {cid} in realm {realm}"
|
||||
)
|
||||
else:
|
||||
payload["resources"].append(r["_id"])
|
||||
|
||||
# Add policy ids, if any, to the payload.
|
||||
if policies:
|
||||
for policy in policies:
|
||||
p = kc.get_authz_policy_by_name(policy, cid, realm)
|
||||
|
||||
if p:
|
||||
payload["policies"].append(p["id"])
|
||||
else:
|
||||
module.fail_json(
|
||||
msg=f"Unable to find authorization policy with name {policy} for client {client_id} in realm {realm}"
|
||||
)
|
||||
|
||||
# Add "id" to payload for update operations
|
||||
if permission:
|
||||
payload["id"] = permission["id"]
|
||||
|
||||
# Handle the special case where the user attempts to change an already
|
||||
# existing permission's type - something that can't be done without a
|
||||
# full delete -> (re)create cycle.
|
||||
if permission["type"] != payload["type"]:
|
||||
module.fail_json(
|
||||
msg=(
|
||||
f"Modifying the type of permission (scope/resource) is not supported: "
|
||||
f"permission {permission['id']} of client {cid} in realm {realm} unchanged"
|
||||
)
|
||||
)
|
||||
|
||||
# Updating an authorization permission is tricky for several reasons.
|
||||
# Firstly, the current permission is retrieved using a _policy_ endpoint,
|
||||
# not from a permission endpoint. Also, the data that is returned is in a
|
||||
# different format than what is expected by the payload. So, comparing the
|
||||
# current state attribute by attribute to the payload is not possible. For
|
||||
# example the data contains a JSON object "config" which may contain the
|
||||
# authorization type, but which is no required in the payload. Moreover,
|
||||
# information about resources, scopes and policies is _not_ present in the
|
||||
# data. So, there is no way to determine if any of those fields have
|
||||
# changed. Therefore the best options we have are
|
||||
#
|
||||
# a) Always apply the payload without checking the current state
|
||||
# b) Refuse to make any changes to any settings (only support create and delete)
|
||||
#
|
||||
# The approach taken here is a).
|
||||
#
|
||||
if permission and state == "present":
|
||||
if module.check_mode:
|
||||
result["msg"] = "Notice: unable to check current resources, scopes and policies for permission. \
|
||||
Would apply desired state without checking the current state."
|
||||
else:
|
||||
kc.update_authz_permission(
|
||||
payload=payload, permission_type=permission_type, id=permission["id"], client_id=cid, realm=realm
|
||||
)
|
||||
result["msg"] = "Notice: unable to check current resources, scopes and policies for permission. \
|
||||
Applying desired state without checking the current state."
|
||||
|
||||
# Assume that something changed, although we don't know if that is the case.
|
||||
result["changed"] = True
|
||||
result["end_state"] = payload
|
||||
elif not permission and state == "present":
|
||||
if module.check_mode:
|
||||
result["msg"] = "Would create permission"
|
||||
else:
|
||||
kc.create_authz_permission(payload=payload, permission_type=permission_type, client_id=cid, realm=realm)
|
||||
result["msg"] = "Permission created"
|
||||
|
||||
result["changed"] = True
|
||||
result["end_state"] = payload
|
||||
elif permission and state == "absent":
|
||||
if module.check_mode:
|
||||
result["msg"] = "Would remove permission"
|
||||
else:
|
||||
kc.remove_authz_permission(id=permission["id"], client_id=cid, realm=realm)
|
||||
result["msg"] = "Permission removed"
|
||||
|
||||
result["changed"] = True
|
||||
|
||||
elif not permission and state == "absent":
|
||||
result["changed"] = False
|
||||
else:
|
||||
module.fail_json(
|
||||
msg=f"Unable to determine what to do with permission {name} of client {client_id} in realm {realm}"
|
||||
)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,180 @@
|
||||
|
||||
# Copyright (c) 2017, Eike Frost <ei@kefro.st>
|
||||
# Copyright (c) 2021, Christophe Gilles <christophe.gilles54@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
|
||||
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_authz_permission_info
|
||||
|
||||
# Originally added in community.general 7.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
short_description: Query Keycloak client authorization permissions information
|
||||
|
||||
description:
|
||||
- This module allows querying information about Keycloak client authorization permissions from the resources endpoint using
|
||||
the Keycloak REST API. Authorization permissions are only available if a client has Authorization enabled.
|
||||
- This module requires access to the REST API using OpenID Connect; the user connecting and the realm 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
|
||||
realm 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 options used by Keycloak. The Authorization Services
|
||||
paths and payloads have not officially been documented by the Keycloak project.
|
||||
U(https://www.puppeteers.net/blog/keycloak-authorization-services-rest-api-paths-and-payload/).
|
||||
attributes:
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- Name of the authorization permission to create.
|
||||
type: str
|
||||
required: true
|
||||
client_id:
|
||||
description:
|
||||
- The clientId of the keycloak client that should have the authorization scope.
|
||||
- This is usually a human-readable name of the Keycloak client.
|
||||
type: str
|
||||
required: true
|
||||
realm:
|
||||
description:
|
||||
- The name of the Keycloak realm the Keycloak client is in.
|
||||
type: str
|
||||
required: true
|
||||
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
- middleware_automation.keycloak.attributes.info_module
|
||||
|
||||
author:
|
||||
- Samuli Seppänen (@mattock)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Query Keycloak authorization permission
|
||||
middleware_automation.keycloak.keycloak_authz_permission_info:
|
||||
name: ScopePermission
|
||||
client_id: myclient
|
||||
realm: myrealm
|
||||
auth_keycloak_url: http://localhost:8080
|
||||
auth_username: keycloak
|
||||
auth_password: keycloak
|
||||
auth_realm: master
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
queried_state:
|
||||
description: State of the resource (a policy) as seen by Keycloak.
|
||||
returned: on success
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: ID of the authorization permission.
|
||||
type: str
|
||||
sample: 9da05cd2-b273-4354-bbd8-0c133918a454
|
||||
name:
|
||||
description: Name of the authorization permission.
|
||||
type: str
|
||||
sample: ResourcePermission
|
||||
description:
|
||||
description: Description of the authorization permission.
|
||||
type: str
|
||||
sample: Resource Permission
|
||||
type:
|
||||
description: Type of the authorization permission.
|
||||
type: str
|
||||
sample: resource
|
||||
decisionStrategy:
|
||||
description: The decision strategy.
|
||||
type: str
|
||||
sample: UNANIMOUS
|
||||
logic:
|
||||
description: The logic used for the permission (part of the payload, but has a fixed value).
|
||||
type: str
|
||||
sample: POSITIVE
|
||||
config:
|
||||
description: Configuration of the permission (empty in all observed cases).
|
||||
type: dict
|
||||
sample: {}
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
name=dict(type="str", required=True),
|
||||
client_id=dict(type="str", required=True),
|
||||
realm=dict(type="str", required=True),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
# Convenience variables
|
||||
name = module.params.get("name")
|
||||
client_id = module.params.get("client_id")
|
||||
realm = module.params.get("realm")
|
||||
|
||||
result = dict(changed=False, msg="", queried_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
# Get id of the client based on client_id
|
||||
cid = kc.get_client_id(client_id, realm=realm)
|
||||
if not cid:
|
||||
module.fail_json(msg=f"Invalid client {client_id} for realm {realm}")
|
||||
|
||||
# Get current state of the permission using its name as the search
|
||||
# filter. This returns False if it is not found.
|
||||
permission = kc.get_authz_permission_by_name(name=name, client_id=cid, realm=realm)
|
||||
|
||||
result["queried_state"] = permission
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+1122
-740
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,421 @@
|
||||
|
||||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_client_rolemapping
|
||||
|
||||
short_description: Allows administration of Keycloak client_rolemapping with the Keycloak API
|
||||
|
||||
# Originally added in community.general 3.5.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
description:
|
||||
- This module allows you to add, remove or modify Keycloak client_rolemapping with the Keycloak REST API. It requires access
|
||||
to the REST API using 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/latest/rest-api/index.html).
|
||||
- Attributes are multi-valued in the Keycloak API. All attributes are lists of individual values and are returned that way
|
||||
by this module. You may pass single values for attributes when calling the module, and this is translated into a list
|
||||
suitable for the API.
|
||||
- When updating a client_rolemapping, where possible provide the role ID to the module. This removes a lookup to the API
|
||||
to translate the name into the role ID.
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: full
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- State of the client_rolemapping.
|
||||
- On V(present), the client_rolemapping is created if it does not yet exist, or updated with the parameters
|
||||
you provide.
|
||||
- On V(absent), the client_rolemapping is removed if it exists.
|
||||
default: 'present'
|
||||
type: str
|
||||
choices:
|
||||
- present
|
||||
- absent
|
||||
|
||||
realm:
|
||||
type: str
|
||||
description:
|
||||
- They Keycloak realm under which this role_representation resides.
|
||||
default: 'master'
|
||||
|
||||
group_name:
|
||||
type: str
|
||||
description:
|
||||
- Name of the group to be mapped.
|
||||
- This parameter is required (can be replaced by gid for less API call).
|
||||
parents:
|
||||
type: list
|
||||
description:
|
||||
- List of parent groups for the group to handle sorted top to bottom.
|
||||
- Set this if your group is a subgroup and you do not provide the GID in O(gid).
|
||||
elements: dict
|
||||
suboptions:
|
||||
id:
|
||||
type: str
|
||||
description:
|
||||
- Identify parent by ID.
|
||||
- Needs less API calls than using O(parents[].name).
|
||||
- A deep parent chain can be started at any point when first given parent is given as ID.
|
||||
- Note that in principle both ID and name can be specified at the same time but current implementation only always
|
||||
use just one of them, with ID being preferred.
|
||||
name:
|
||||
type: str
|
||||
description:
|
||||
- Identify parent by name.
|
||||
- Needs more internal API calls than using O(parents[].id) to map names to ID's under the hood.
|
||||
- When giving a parent chain with only names it must be complete up to the top.
|
||||
- Note that in principle both ID and name can be specified at the same time but current implementation only always
|
||||
use just one of them, with ID being preferred.
|
||||
gid:
|
||||
type: str
|
||||
description:
|
||||
- ID of the group to be mapped.
|
||||
- This parameter is not required for updating or deleting the rolemapping but providing it reduces the number of API
|
||||
calls required.
|
||||
client_id:
|
||||
type: str
|
||||
description:
|
||||
- Name of the client to be mapped (different than O(cid)).
|
||||
- This parameter is required (can be replaced by cid for less API call).
|
||||
cid:
|
||||
type: str
|
||||
description:
|
||||
- ID of the client to be mapped.
|
||||
- This parameter is not required for updating or deleting the rolemapping but providing it reduces the number of API
|
||||
calls required.
|
||||
roles:
|
||||
description:
|
||||
- Roles to be mapped to the group.
|
||||
type: list
|
||||
elements: dict
|
||||
suboptions:
|
||||
name:
|
||||
type: str
|
||||
description:
|
||||
- Name of the role_representation.
|
||||
- This parameter is required only when creating or updating the role_representation.
|
||||
id:
|
||||
type: str
|
||||
description:
|
||||
- The unique identifier for this role_representation.
|
||||
- This parameter is not required for updating or deleting a role_representation but providing it reduces the number
|
||||
of API calls required.
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Gaëtan Daubresse (@Gaetan2907)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Map a client role to a group, authentication with credentials
|
||||
middleware_automation.keycloak.keycloak_client_rolemapping:
|
||||
realm: MyCustomRealm
|
||||
auth_client_id: admin-cli
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
auth_realm: master
|
||||
auth_username: USERNAME
|
||||
auth_password: PASSWORD
|
||||
state: present
|
||||
client_id: client1
|
||||
group_name: group1
|
||||
roles:
|
||||
- name: role_name1
|
||||
id: role_id1
|
||||
- name: role_name2
|
||||
id: role_id2
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Map a client role to a group, authentication with token
|
||||
middleware_automation.keycloak.keycloak_client_rolemapping:
|
||||
realm: MyCustomRealm
|
||||
auth_client_id: admin-cli
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
token: TOKEN
|
||||
state: present
|
||||
client_id: client1
|
||||
group_name: group1
|
||||
roles:
|
||||
- name: role_name1
|
||||
id: role_id1
|
||||
- name: role_name2
|
||||
id: role_id2
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Map a client role to a subgroup, authentication with token
|
||||
middleware_automation.keycloak.keycloak_client_rolemapping:
|
||||
realm: MyCustomRealm
|
||||
auth_client_id: admin-cli
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
token: TOKEN
|
||||
state: present
|
||||
client_id: client1
|
||||
group_name: subgroup1
|
||||
parents:
|
||||
- name: parent-group
|
||||
roles:
|
||||
- name: role_name1
|
||||
id: role_id1
|
||||
- name: role_name2
|
||||
id: role_id2
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Unmap client role from a group
|
||||
middleware_automation.keycloak.keycloak_client_rolemapping:
|
||||
realm: MyCustomRealm
|
||||
auth_client_id: admin-cli
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
auth_realm: master
|
||||
auth_username: USERNAME
|
||||
auth_password: PASSWORD
|
||||
state: absent
|
||||
client_id: client1
|
||||
group_name: group1
|
||||
roles:
|
||||
- name: role_name1
|
||||
id: role_id1
|
||||
- name: role_name2
|
||||
id: role_id2
|
||||
delegate_to: localhost
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Role role1 assigned to group group1."
|
||||
|
||||
proposed:
|
||||
description: Representation of proposed client role mapping.
|
||||
returned: always
|
||||
type: dict
|
||||
sample: {"clientId": "test"}
|
||||
|
||||
existing:
|
||||
description:
|
||||
- Representation of existing client role mapping.
|
||||
- The sample is truncated.
|
||||
returned: always
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"adminUrl": "http://www.example.com/admin_url",
|
||||
"attributes": {
|
||||
"request.object.signature.alg": "RS256"
|
||||
}
|
||||
}
|
||||
|
||||
end_state:
|
||||
description:
|
||||
- Representation of client role mapping after module execution.
|
||||
- The sample is truncated.
|
||||
returned: on success
|
||||
type: dict
|
||||
sample:
|
||||
{
|
||||
"adminUrl": "http://www.example.com/admin_url",
|
||||
"attributes": {
|
||||
"request.object.signature.alg": "RS256"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
roles_spec = dict(
|
||||
name=dict(type="str"),
|
||||
id=dict(type="str"),
|
||||
)
|
||||
|
||||
meta_args = dict(
|
||||
state=dict(default="present", choices=["present", "absent"]),
|
||||
realm=dict(default="master"),
|
||||
gid=dict(type="str"),
|
||||
group_name=dict(type="str"),
|
||||
parents=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
options=dict(id=dict(type="str"), name=dict(type="str")),
|
||||
),
|
||||
cid=dict(type="str"),
|
||||
client_id=dict(type="str"),
|
||||
roles=dict(type="list", elements="dict", options=roles_spec),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"]]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg="", diff={}, proposed={}, existing={}, end_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
realm = module.params.get("realm")
|
||||
state = module.params.get("state")
|
||||
cid = module.params.get("cid")
|
||||
client_id = module.params.get("client_id")
|
||||
gid = module.params.get("gid")
|
||||
group_name = module.params.get("group_name")
|
||||
roles = module.params.get("roles")
|
||||
parents = module.params.get("parents")
|
||||
|
||||
# Check the parameters
|
||||
if cid is None and client_id is None:
|
||||
module.fail_json(msg="Either the `client_id` or `cid` has to be specified.")
|
||||
if gid is None and group_name is None:
|
||||
module.fail_json(msg="Either the `group_name` or `gid` has to be specified.")
|
||||
|
||||
# Get the potential missing parameters
|
||||
if gid is None:
|
||||
group_rep = kc.get_group_by_name(group_name, realm=realm, parents=parents)
|
||||
if group_rep is not None:
|
||||
gid = group_rep["id"]
|
||||
else:
|
||||
module.fail_json(msg=f"Could not fetch group {group_name}:")
|
||||
if cid is None:
|
||||
cid = kc.get_client_id(client_id, realm=realm)
|
||||
if cid is None:
|
||||
module.fail_json(msg=f"Could not fetch client {client_id}:")
|
||||
if roles is None:
|
||||
module.exit_json(msg="Nothing to do (no roles specified).")
|
||||
else:
|
||||
for role in roles:
|
||||
if role["name"] is None and role["id"] is None:
|
||||
module.fail_json(msg="Either the `name` or `id` has to be specified on each role.")
|
||||
# Fetch missing role_id
|
||||
if role["id"] is None:
|
||||
role_id = kc.get_client_role_id_by_name(cid, role["name"], realm=realm)
|
||||
if role_id is not None:
|
||||
role["id"] = role_id
|
||||
else:
|
||||
module.fail_json(msg=f"Could not fetch role {role['name']}:")
|
||||
# Fetch missing role_name from the client's roles, not from existing group mappings
|
||||
elif role["name"] is None:
|
||||
role_rep = kc.get_role_by_id(role["id"], realm=realm)
|
||||
role["name"] = role_rep["name"]
|
||||
|
||||
# Get effective client-level role mappings
|
||||
available_roles_before = kc.get_client_group_available_rolemappings(gid, cid, realm=realm)
|
||||
assigned_roles_before = kc.get_client_group_composite_rolemappings(gid, cid, realm=realm)
|
||||
|
||||
result["existing"] = assigned_roles_before
|
||||
result["proposed"] = list(assigned_roles_before) if assigned_roles_before else []
|
||||
|
||||
update_roles = []
|
||||
for role in roles:
|
||||
# Fetch roles to assign if state present
|
||||
if state == "present":
|
||||
for available_role in available_roles_before:
|
||||
if role["name"] == available_role["name"]:
|
||||
update_roles.append(
|
||||
{
|
||||
"id": role["id"],
|
||||
"name": role["name"],
|
||||
}
|
||||
)
|
||||
result["proposed"].append(available_role)
|
||||
# Fetch roles to remove if state absent
|
||||
else:
|
||||
for assigned_role in assigned_roles_before:
|
||||
if role["name"] == assigned_role["name"]:
|
||||
update_roles.append(
|
||||
{
|
||||
"id": role["id"],
|
||||
"name": role["name"],
|
||||
}
|
||||
)
|
||||
if assigned_role in result["proposed"]: # Handle double removal
|
||||
result["proposed"].remove(assigned_role)
|
||||
|
||||
if len(update_roles):
|
||||
if state == "present":
|
||||
# Assign roles
|
||||
result["changed"] = True
|
||||
if module._diff:
|
||||
result["diff"] = dict(
|
||||
before={"roles": assigned_roles_before or []},
|
||||
after={"roles": result["proposed"]},
|
||||
)
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
kc.add_group_rolemapping(gid, cid, update_roles, realm=realm)
|
||||
result["msg"] = f"Roles {update_roles} assigned to group {group_name}."
|
||||
assigned_roles_after = kc.get_client_group_composite_rolemappings(gid, cid, realm=realm)
|
||||
result["end_state"] = assigned_roles_after
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
# Remove mapping of role
|
||||
result["changed"] = True
|
||||
if module._diff:
|
||||
result["diff"] = dict(
|
||||
before={"roles": assigned_roles_before or []},
|
||||
after={"roles": result["proposed"]},
|
||||
)
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
kc.delete_group_rolemapping(gid, cid, update_roles, realm=realm)
|
||||
result["msg"] = f"Roles {update_roles} removed from group {group_name}."
|
||||
assigned_roles_after = kc.get_client_group_composite_rolemappings(gid, cid, realm=realm)
|
||||
result["end_state"] = assigned_roles_after
|
||||
module.exit_json(**result)
|
||||
# Do nothing
|
||||
else:
|
||||
result["changed"] = False
|
||||
result["msg"] = (
|
||||
f"Nothing to do, roles {roles} are {'mapped' if state == 'present' else 'not mapped'} with group {group_name}."
|
||||
)
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,289 @@
|
||||
|
||||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from __future__ import annotations
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: keycloak_client_rolescope
|
||||
|
||||
short_description: Allows administration of Keycloak client roles scope to restrict the usage of certain roles to a other
|
||||
specific client applications
|
||||
|
||||
# Originally added in community.general 8.6.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
description:
|
||||
- This module allows you to add or remove Keycloak roles from clients scope using the Keycloak REST API. It requires access
|
||||
to the REST API using 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.
|
||||
- Client O(target_client_id) must have O(middleware_automation.keycloak.keycloak_client#module:full_scope_allowed) set to V(false).
|
||||
- Attributes are multi-valued in the Keycloak API. All attributes are lists of individual values and are returned that way
|
||||
by this module. You may pass single values for attributes when calling the module, and this is translated into a list
|
||||
suitable for the API.
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: full
|
||||
action_group:
|
||||
# Originally added in community.general 10.2.0
|
||||
version_added: "3.0.0"
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- State of the role mapping.
|
||||
- On V(present), all roles in O(role_names) are mapped if not exist yet.
|
||||
- On V(absent), all roles mapping in O(role_names) are removed if it exists.
|
||||
default: 'present'
|
||||
type: str
|
||||
choices:
|
||||
- present
|
||||
- absent
|
||||
|
||||
realm:
|
||||
type: str
|
||||
description:
|
||||
- The Keycloak realm under which clients resides.
|
||||
default: 'master'
|
||||
|
||||
target_client_id:
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
- Roles provided in O(role_names) while be added to this client scope.
|
||||
role_owner_client_id:
|
||||
type: str
|
||||
description:
|
||||
- If the O(role_names) are client role, the client ID under which it resides.
|
||||
- If this parameter is absent, the roles are considered a realm role.
|
||||
role_names:
|
||||
required: true
|
||||
type: list
|
||||
elements: str
|
||||
description:
|
||||
- Names of roles to manipulate.
|
||||
- If O(role_owner_client_id) is present, all roles must be under this client.
|
||||
- If O(role_owner_client_id) is absent, all roles must be under the realm.
|
||||
extends_documentation_fragment:
|
||||
- middleware_automation.keycloak.keycloak
|
||||
- middleware_automation.keycloak.actiongroup_keycloak
|
||||
- middleware_automation.keycloak.attributes
|
||||
|
||||
author:
|
||||
- Andre Desrosiers (@desand01)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Add roles to public client scope
|
||||
middleware_automation.keycloak.keycloak_client_rolescope:
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
auth_realm: master
|
||||
auth_username: USERNAME
|
||||
auth_password: PASSWORD
|
||||
realm: MyCustomRealm
|
||||
target_client_id: frontend-client-public
|
||||
role_owner_client_id: backend-client-private
|
||||
role_names:
|
||||
- backend-role-admin
|
||||
- backend-role-user
|
||||
|
||||
- name: Remove roles from public client scope
|
||||
middleware_automation.keycloak.keycloak_client_rolescope:
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
auth_realm: master
|
||||
auth_username: USERNAME
|
||||
auth_password: PASSWORD
|
||||
realm: MyCustomRealm
|
||||
target_client_id: frontend-client-public
|
||||
role_owner_client_id: backend-client-private
|
||||
role_names:
|
||||
- backend-role-admin
|
||||
state: absent
|
||||
|
||||
- name: Add realm roles to public client scope
|
||||
middleware_automation.keycloak.keycloak_client_rolescope:
|
||||
auth_keycloak_url: https://auth.example.com
|
||||
auth_realm: master
|
||||
auth_username: USERNAME
|
||||
auth_password: PASSWORD
|
||||
realm: MyCustomRealm
|
||||
target_client_id: frontend-client-public
|
||||
role_names:
|
||||
- realm-role-admin
|
||||
- realm-role-user
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
msg:
|
||||
description: Message as to what action was taken.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Client role scope for frontend-client-public has been updated"
|
||||
|
||||
end_state:
|
||||
description: Representation of role role scope after module execution.
|
||||
returned: on success
|
||||
type: list
|
||||
elements: dict
|
||||
sample:
|
||||
[
|
||||
{
|
||||
"clientRole": false,
|
||||
"composite": false,
|
||||
"containerId": "MyCustomRealm",
|
||||
"id": "47293104-59a6-46f0-b460-2e9e3c9c424c",
|
||||
"name": "backend-role-admin"
|
||||
},
|
||||
{
|
||||
"clientRole": false,
|
||||
"composite": false,
|
||||
"containerId": "MyCustomRealm",
|
||||
"id": "39c62a6d-542c-4715-92d2-41021eb33967",
|
||||
"name": "backend-role-user"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.middleware_automation.keycloak.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
KeycloakError,
|
||||
get_token,
|
||||
keycloak_argument_spec,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Module execution
|
||||
|
||||
:return:
|
||||
"""
|
||||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
meta_args = dict(
|
||||
target_client_id=dict(type="str", required=True),
|
||||
role_owner_client_id=dict(type="str"),
|
||||
realm=dict(type="str", default="master"),
|
||||
role_names=dict(type="list", elements="str", required=True),
|
||||
state=dict(type="str", default="present", choices=["present", "absent"]),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
result = dict(changed=False, msg="", diff={}, end_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
connection_header = get_token(module.params)
|
||||
except KeycloakError as e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
realm = module.params.get("realm")
|
||||
target_client_id = module.params.get("target_client_id")
|
||||
role_owner_client_id = module.params.get("role_owner_client_id")
|
||||
role_names = module.params.get("role_names")
|
||||
state = module.params.get("state")
|
||||
|
||||
objRealm = kc.get_realm_by_id(realm)
|
||||
if not objRealm:
|
||||
module.fail_json(msg=f"Failed to retrive realm '{realm}'")
|
||||
|
||||
objClient = kc.get_client_by_client_id(target_client_id, realm)
|
||||
if not objClient:
|
||||
module.fail_json(msg=f"Failed to retrive client '{realm}.{target_client_id}'")
|
||||
if objClient["fullScopeAllowed"] and state == "present":
|
||||
module.fail_json(msg=f"FullScopeAllowed is active for Client '{realm}.{target_client_id}'")
|
||||
|
||||
if role_owner_client_id:
|
||||
role_owner_client = kc.get_client_by_client_id(role_owner_client_id, realm)
|
||||
if not role_owner_client:
|
||||
module.fail_json(msg=f"Failed to retrive client '{realm}.{role_owner_client_id}'")
|
||||
before_role_mapping = kc.get_client_role_scope_from_client(objClient["id"], role_owner_client["id"], realm)
|
||||
else:
|
||||
before_role_mapping = kc.get_client_role_scope_from_realm(objClient["id"], realm)
|
||||
|
||||
if role_owner_client_id:
|
||||
# retrive all role from client_scope
|
||||
client_scope_roles_by_name = kc.get_client_roles_by_id(role_owner_client["id"], realm)
|
||||
else:
|
||||
# retrive all role from realm
|
||||
client_scope_roles_by_name = kc.get_realm_roles(realm)
|
||||
|
||||
# convert to indexed Dict by name
|
||||
client_scope_roles_by_name = {role["name"]: role for role in client_scope_roles_by_name}
|
||||
role_mapping_by_name = {role["name"]: role for role in before_role_mapping}
|
||||
role_mapping_to_manipulate = []
|
||||
|
||||
if state == "present":
|
||||
# update desired
|
||||
for role_name in role_names:
|
||||
if role_name not in client_scope_roles_by_name:
|
||||
if role_owner_client_id:
|
||||
module.fail_json(msg=f"Failed to retrive role '{realm}.{role_owner_client_id}.{role_name}'")
|
||||
else:
|
||||
module.fail_json(msg=f"Failed to retrive role '{realm}.{role_name}'")
|
||||
if role_name not in role_mapping_by_name:
|
||||
role_mapping_to_manipulate.append(client_scope_roles_by_name[role_name])
|
||||
role_mapping_by_name[role_name] = client_scope_roles_by_name[role_name]
|
||||
else:
|
||||
# remove role if present
|
||||
for role_name in role_names:
|
||||
if role_name in role_mapping_by_name:
|
||||
role_mapping_to_manipulate.append(role_mapping_by_name[role_name])
|
||||
del role_mapping_by_name[role_name]
|
||||
|
||||
before_role_mapping = sorted(before_role_mapping, key=lambda d: d["name"])
|
||||
desired_role_mapping = sorted(role_mapping_by_name.values(), key=lambda d: d["name"])
|
||||
|
||||
result["changed"] = len(role_mapping_to_manipulate) > 0
|
||||
|
||||
if result["changed"]:
|
||||
result["diff"] = dict(before=before_role_mapping, after=desired_role_mapping)
|
||||
|
||||
if not result["changed"]:
|
||||
# no changes
|
||||
result["end_state"] = before_role_mapping
|
||||
result["msg"] = f"No changes required for client role scope {target_client_id}."
|
||||
elif state == "present":
|
||||
# doing update
|
||||
if module.check_mode:
|
||||
result["end_state"] = desired_role_mapping
|
||||
elif role_owner_client_id:
|
||||
result["end_state"] = kc.update_client_role_scope_from_client(
|
||||
role_mapping_to_manipulate, objClient["id"], role_owner_client["id"], realm
|
||||
)
|
||||
else:
|
||||
result["end_state"] = kc.update_client_role_scope_from_realm(
|
||||
role_mapping_to_manipulate, objClient["id"], realm
|
||||
)
|
||||
result["msg"] = f"Client role scope for {target_client_id} has been updated"
|
||||
else:
|
||||
# doing delete
|
||||
if module.check_mode:
|
||||
result["end_state"] = desired_role_mapping
|
||||
elif role_owner_client_id:
|
||||
result["end_state"] = kc.delete_client_role_scope_from_client(
|
||||
role_mapping_to_manipulate, objClient["id"], role_owner_client["id"], realm
|
||||
)
|
||||
else:
|
||||
result["end_state"] = kc.delete_client_role_scope_from_realm(
|
||||
role_mapping_to_manipulate, objClient["id"], realm
|
||||
)
|
||||
result["msg"] = f"Client role scope for {target_client_id} has been deleted"
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user