mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-05-07 05:43:26 +00:00
ipaidp: Fix validation and reset of parameters
The uri parameters auth_uri, dev_auth_uri, token_uri, userinfo_uri and keys_uri have not been validated before. Also the base_url was not normalized. The auth_uri, dev_auth_uri, token_uri and userinfo_uri need to be set for new entries, but might be empty or empty string for reset or updates. The ipaidpclientsecret needs to be decoded from binary string in find_idp result to not trigger no change ipd_mod calls. The code for validate_uri and base_url normalization has been copied from the ipaserver idp plugin. ansible_freeipa_module: urlparse from urllib.parse with a fallback to six.moves.urllib.parse is imported and also exported. urlparse is needed for validate_uri in ipaidp module. Resolves: RHEL-17954, RHEL-17955, RHEL-17957 and RHEL-17958
This commit is contained in:
@@ -185,7 +185,7 @@ RETURN = """
|
||||
|
||||
|
||||
from ansible.module_utils.ansible_freeipa_module import \
|
||||
IPAAnsibleModule, compare_args_ipa, template_str
|
||||
IPAAnsibleModule, compare_args_ipa, template_str, urlparse
|
||||
from ansible.module_utils import six
|
||||
from copy import deepcopy
|
||||
import string
|
||||
@@ -274,7 +274,14 @@ def find_idp(module, name):
|
||||
# An exception is raised if idp name is not found.
|
||||
return None
|
||||
|
||||
return _result["result"]
|
||||
res = _result["result"]
|
||||
|
||||
# Decode binary string secret
|
||||
if "ipaidpclientsecret" in res and len(res["ipaidpclientsecret"]) > 0:
|
||||
res["ipaidpclientsecret"][0] = \
|
||||
res["ipaidpclientsecret"][0].decode("ascii")
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def gen_args(auth_uri, dev_auth_uri, token_uri, userinfo_uri, keys_uri,
|
||||
@@ -333,6 +340,16 @@ def convert_provider_to_endpoints(module, _args, provider):
|
||||
_args.update(points)
|
||||
|
||||
|
||||
def validate_uri(module, uri):
|
||||
try:
|
||||
parsed = urlparse(uri, 'https')
|
||||
except Exception:
|
||||
module.fail_json(msg="Invalid URI '%s': not an https scheme" % uri)
|
||||
|
||||
if not parsed.netloc:
|
||||
module.fail_json(msg="Invalid URI '%s': missing netloc" % uri)
|
||||
|
||||
|
||||
def main():
|
||||
ansible_module = IPAAnsibleModule(
|
||||
argument_spec=dict(
|
||||
@@ -426,19 +443,6 @@ def main():
|
||||
if provider not in idp_providers:
|
||||
ansible_module.fail_json(
|
||||
msg="Provider '%s' is unknown" % provider)
|
||||
else:
|
||||
if not auth_uri:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "auth_uri")
|
||||
if not dev_auth_uri:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "dev_auth_uri")
|
||||
if not token_uri:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "token_uri")
|
||||
if not userinfo_uri:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "userinfo_uri")
|
||||
invalid = ["rename", "delete_continue"]
|
||||
else:
|
||||
# state renamed and absent
|
||||
@@ -459,6 +463,19 @@ def main():
|
||||
|
||||
ansible_module.params_fail_used_invalid(invalid, state)
|
||||
|
||||
# Empty client_id test
|
||||
if client_id is not None and client_id == "":
|
||||
ansible_module.fail_json(msg="'client_id' is required")
|
||||
|
||||
# Normalize base_url
|
||||
if base_url is not None and base_url.startswith('https://'):
|
||||
base_url = base_url[len('https://'):]
|
||||
|
||||
# Validate uris
|
||||
for uri in [auth_uri, dev_auth_uri, token_uri, userinfo_uri, keys_uri]:
|
||||
if uri is not None and uri != "":
|
||||
validate_uri(ansible_module, uri)
|
||||
|
||||
# Init
|
||||
|
||||
changed = False
|
||||
@@ -507,6 +524,19 @@ def main():
|
||||
res_find):
|
||||
commands.append([name, "idp_mod", args])
|
||||
else:
|
||||
if "ipaidpauthendpoint" not in args:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "auth_uri")
|
||||
if "ipaidpdevauthendpoint" not in args:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "dev_auth_uri")
|
||||
if "ipaidptokenendpoint" not in args:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "token_uri")
|
||||
if "ipaidpuserinfoendpoint" not in args:
|
||||
ansible_module.fail_json(
|
||||
msg="Parameter '%s' is missing" % "userinfo_uri")
|
||||
|
||||
commands.append([name, "idp_add", args])
|
||||
|
||||
elif state == "absent":
|
||||
|
||||
Reference in New Issue
Block a user