Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/keycloak userfed idempotency #5732

Conversation

morco
Copy link
Contributor

@morco morco commented Dec 23, 2022

SUMMARY

Current version of keycloak_user_federation has some idempotency problems in some situations where an already existing user federation is not correctly recognized (detected) which then leads to the module falsely creating a new federation
again and again on each consequent playbook run.
One contributing factor seems to be the optional query param parent=<realm-name> which is momentarely always set when checking the server for existing user federations. This param seems to be buggy in upstream keycloak rest api working sometimes as expected while other times not (when parent realm is for example master).

Although this is fundamentally an upstream issue fpr keycloak rest api I would still argue that there is something which can and should be done inside this ansible module. As the parent realm (name) is already part of the url-path specifying them again as query param seems superfluous. So simply not setting them as query param seems to have no disadvantadges while insulating against these kind of api flukes.

Fixes #4664: at least for some cases
Fixes #5286: not totally sure here but this might be related to issue above

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

plugins/modules/keycloak_user_federation.py

ADDITIONAL INFORMATION

Tested with recent keycloak (api) version: 20.0.2.

Mirko Wilhelmi added 2 commits December 22, 2022 21:16
... federation read call not finding already existing federations
properly because of bad parametrisation
... new integration test for module idempotency bugfix
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress bug This issue/PR relates to a bug identity integration tests/integration module module plugins plugin (any type) tests tests labels Dec 23, 2022
@github-actions
Copy link

github-actions bot commented Dec 23, 2022

Docs Build 📝

Thank you for contribution!✨

The docsite for this PR is available for download as an artifact from this run:
https://github.com/ansible-collections/community.general/actions/runs/3821360870

File changes:

  • M collections/community/general/htpasswd_module.html
  • M collections/community/general/keycloak_user_federation_module.html
  • M collections/community/general/proxmox_module.html
Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/htpasswd_module.html b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/htpasswd_module.html
index 9870ce5..13f1d52 100644
--- a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/htpasswd_module.html
+++ b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/htpasswd_module.html
@@ -205,8 +205,9 @@ see <a class="reference internal" href="#ansible-collections-community-general-h
 <div class="ansibleOptionAnchor" id="parameter-crypt_scheme"></div><p class="ansible-option-title" id="ansible-collections-community-general-htpasswd-module-parameter-crypt-scheme"><strong>crypt_scheme</strong></p>
 <a class="ansibleOptionLink" href="#parameter-crypt_scheme" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
-<td><div class="ansible-option-cell"><p>Encryption scheme to be used.  As well as the four choices listed here, you can also use any other hash supported by passlib, such as md5_crypt and sha256_crypt, which are linux passwd hashes.  If you do so the password file will not be compatible with Apache or Nginx</p>
-<p>Some of the available choices might be: <code class="docutils literal notranslate"><span class="pre">apr_md5_crypt</span></code>, <code class="docutils literal notranslate"><span class="pre">des_crypt</span></code>, <code class="docutils literal notranslate"><span class="pre">ldap_sha1</span></code>, <code class="docutils literal notranslate"><span class="pre">plaintext</span></code></p>
+<td><div class="ansible-option-cell"><p>Encryption scheme to be used.  As well as the four choices listed here, you can also use any other hash supported by passlib, such as <code class="docutils literal notranslate"><span class="pre">portable_apache22</span></code> and <code class="docutils literal notranslate"><span class="pre">host_apache24</span></code>; or <code class="docutils literal notranslate"><span class="pre">md5_crypt</span></code> and <code class="docutils literal notranslate"><span class="pre">sha256_crypt</span></code>, which are Linux passwd hashes.  Only some schemes in addition to the four choices below will be compatible with Apache or Nginx, and supported schemes depend on passlib version and its dependencies.</p>
+<p>See <a class="reference external" href="https://passlib.readthedocs.io/en/stable/lib/passlib.apache.html#passlib.apache.HtpasswdFile">https://passlib.readthedocs.io/en/stable/lib/passlib.apache.html#passlib.apache.HtpasswdFile</a> parameter <code class="docutils literal notranslate"><span class="pre">default_scheme</span></code>.</p>
+<p>Some of the available choices might be: <code class="docutils literal notranslate"><span class="pre">apr_md5_crypt</span></code>, <code class="docutils literal notranslate"><span class="pre">des_crypt</span></code>, <code class="docutils literal notranslate"><span class="pre">ldap_sha1</span></code>, <code class="docutils literal notranslate"><span class="pre">plaintext</span></code>.</p>
 <p class="ansible-option-line"><span class="ansible-option-default-bold">Default:</span> <code class="ansible-option-default docutils literal notranslate"><span class="pre">&quot;apr_md5_crypt&quot;</span></code></p>
 </div></td>
 </tr>
diff --git a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/keycloak_user_federation_module.html b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/keycloak_user_federation_module.html
index eaac1fd..af7b84f 100644
--- a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/keycloak_user_federation_module.html
+++ b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/keycloak_user_federation_module.html
@@ -156,7 +156,7 @@
 <h2><a class="toc-backref" href="#id1">Synopsis</a><a class="headerlink" href="#synopsis" title="Permalink to this heading"></a></h2>
 <ul class="simple">
 <li><p>This module allows you to add, remove or modify Keycloak user federations via the Keycloak REST API. It requires access to the REST API via OpenID Connect; the user connecting and the client being used must have the requisite access rights. In a default Keycloak installation, admin-cli and an admin user would work, as would a separate client definition with the scope tailored to your needs and a user having the expected roles.</p></li>
-<li><p>The names of module options are snake_cased versions of the camelCase ones found in the Keycloak API and its documentation at <a class="reference external" href="https://www.keycloak.org/docs-api/15.0/rest-api/index.html">https://www.keycloak.org/docs-api/15.0/rest-api/index.html</a>.</p></li>
+<li><p>The names of module options are snake_cased versions of the camelCase ones found in the Keycloak API and its documentation at <a class="reference external" href="https://www.keycloak.org/docs-api/20.0.2/rest-api/index.html">https://www.keycloak.org/docs-api/20.0.2/rest-api/index.html</a>.</p></li>
 </ul>
 </section>
 <section id="parameters">
diff --git a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/proxmox_module.html b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/proxmox_module.html
index db18ad4..1d63982 100644
--- a/home/runner/work/community.general/community.general/docsbuild/base/collections/community/general/proxmox_module.html
+++ b/home/runner/work/community.general/community.general/docsbuild/head/collections/community/general/proxmox_module.html
@@ -486,6 +486,16 @@ see <a class="reference internal" href="#ansible-collections-community-general-p
 </div></td>
 </tr>
 <tr class="row-odd"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-tags"></div><p class="ansible-option-title" id="ansible-collections-community-general-proxmox-module-parameter-tags"><strong>tags</strong></p>
+<a class="ansibleOptionLink" href="#parameter-tags" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">list</span> / <span class="ansible-option-elements">elements=string</span></p>
+<p><span class="ansible-option-versionadded">added in community.general 6.2.0</span></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>List of tags to apply to the container.</p>
+<p>Tags must start with <code class="docutils literal notranslate"><span class="pre">[a-z0-9_]</span></code> followed by zero or more of the following characters <code class="docutils literal notranslate"><span class="pre">[a-z0-9_-+.]</span></code>.</p>
+<p>Tags are only available in Proxmox 7+.</p>
+</div></td>
+</tr>
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-timeout"></div><p class="ansible-option-title" id="ansible-collections-community-general-proxmox-module-parameter-timeout"><strong>timeout</strong></p>
 <a class="ansibleOptionLink" href="#parameter-timeout" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>
@@ -493,7 +503,7 @@ see <a class="reference internal" href="#ansible-collections-community-general-p
 <p class="ansible-option-line"><span class="ansible-option-default-bold">Default:</span> <code class="ansible-option-default docutils literal notranslate"><span class="pre">30</span></code></p>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-unprivileged"></div><p class="ansible-option-title" id="ansible-collections-community-general-proxmox-module-parameter-unprivileged"><strong>unprivileged</strong></p>
 <a class="ansibleOptionLink" href="#parameter-unprivileged" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 </div></td>
@@ -506,7 +516,7 @@ see <a class="reference internal" href="#ansible-collections-community-general-p
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-validate_certs"></div><p class="ansible-option-title" id="ansible-collections-community-general-proxmox-module-parameter-validate-certs"><strong>validate_certs</strong></p>
 <a class="ansibleOptionLink" href="#parameter-validate_certs" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 </div></td>
@@ -519,7 +529,7 @@ see <a class="reference internal" href="#ansible-collections-community-general-p
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-vmid"></div><p class="ansible-option-title" id="ansible-collections-community-general-proxmox-module-parameter-vmid"><strong>vmid</strong></p>
 <a class="ansibleOptionLink" href="#parameter-vmid" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">integer</span></p>
 </div></td>

@morco morco marked this pull request as ready for review December 23, 2022 14:27
@ansibullbot ansibullbot removed the WIP Work in progress label Dec 23, 2022
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! Could you please add a changelog fragment? Thanks.

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Dec 23, 2022
@felixfontein
Copy link
Collaborator

@morco please note that this cannot be merged without a changelog fragment. Thanks.

@morco
Copy link
Contributor Author

morco commented Jan 2, 2023

Okay, added the changelog fragment now.

Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the Ansible perspective, not very familiar with keycloak myself.

@felixfontein
Copy link
Collaborator

Same from my POV. If nobody objects in the next two weeks, I'll merge this.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jan 15, 2023
@felixfontein felixfontein merged commit 0ca41de into ansible-collections:main Jan 22, 2023
@patchback
Copy link

patchback bot commented Jan 22, 2023

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/0ca41dedce083b34fe06faa84eb001c1d1f5a8bd/pr-5732

Backported as #5873

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jan 22, 2023
patchback bot pushed a commit that referenced this pull request Jan 22, 2023
* fix(modules/keycloak_user_federation): fixes ...

... federation read call not finding already existing federations
properly because of bad parametrisation

* fix(modules/keycloak_user_federation): added ...

... new integration test for module idempotency bugfix

* added changelog fragment for pr

Co-authored-by: Mirko Wilhelmi <Mirko.Wilhelmi@sma.de>
(cherry picked from commit 0ca41de)
@patchback
Copy link

patchback bot commented Jan 22, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/0ca41dedce083b34fe06faa84eb001c1d1f5a8bd/pr-5732

Backported as #5874

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@morco thanks for your contribution!
@russoz thanks for reviewing!

patchback bot pushed a commit that referenced this pull request Jan 22, 2023
* fix(modules/keycloak_user_federation): fixes ...

... federation read call not finding already existing federations
properly because of bad parametrisation

* fix(modules/keycloak_user_federation): added ...

... new integration test for module idempotency bugfix

* added changelog fragment for pr

Co-authored-by: Mirko Wilhelmi <Mirko.Wilhelmi@sma.de>
(cherry picked from commit 0ca41de)
felixfontein pushed a commit that referenced this pull request Jan 22, 2023
…tency (#5873)

Bugfix/keycloak userfed idempotency (#5732)

* fix(modules/keycloak_user_federation): fixes ...

... federation read call not finding already existing federations
properly because of bad parametrisation

* fix(modules/keycloak_user_federation): added ...

... new integration test for module idempotency bugfix

* added changelog fragment for pr

Co-authored-by: Mirko Wilhelmi <Mirko.Wilhelmi@sma.de>
(cherry picked from commit 0ca41de)

Co-authored-by: morco <thegreatwiper@web.de>
felixfontein pushed a commit that referenced this pull request Jan 22, 2023
…tency (#5874)

Bugfix/keycloak userfed idempotency (#5732)

* fix(modules/keycloak_user_federation): fixes ...

... federation read call not finding already existing federations
properly because of bad parametrisation

* fix(modules/keycloak_user_federation): added ...

... new integration test for module idempotency bugfix

* added changelog fragment for pr

Co-authored-by: Mirko Wilhelmi <Mirko.Wilhelmi@sma.de>
(cherry picked from commit 0ca41de)

Co-authored-by: morco <thegreatwiper@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug identity integration tests/integration module module plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

keycloak_user_federation duplicate mapper name community.general.keycloak_user_federation is not idempotent
4 participants