From 526f0454aba3fcdfe2b673915b9a427b693d0a7f Mon Sep 17 00:00:00 2001 From: Alessandro Rossi <4215912+kubealex@users.noreply.github.com> Date: Tue, 14 Dec 2021 23:08:35 +0100 Subject: [PATCH] Fix for common non-ASCII characters in CRDs (#308) Fix for common non-ASCII characters in CRDs This should keep the module safe from digesting non-ASCII chars like here (https://github.com/projectcalico/api/pull/46/files) SUMMARY Add support for non-ASCII chars in manifests. ISSUE TYPE Bugfix Pull Request COMPONENT NAME core.k8s module failing if resources contain non ascii chars Reviewed-by: Abhijeet Kasurde Reviewed-by: Mike Graves Reviewed-by: Alessandro Rossi Reviewed-by: None --- .../308-fix-for-common-non-ascii-characters-in-resources.yaml | 2 ++ plugins/module_utils/common.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/308-fix-for-common-non-ascii-characters-in-resources.yaml diff --git a/changelogs/fragments/308-fix-for-common-non-ascii-characters-in-resources.yaml b/changelogs/fragments/308-fix-for-common-non-ascii-characters-in-resources.yaml new file mode 100644 index 00000000..d9730f8f --- /dev/null +++ b/changelogs/fragments/308-fix-for-common-non-ascii-characters-in-resources.yaml @@ -0,0 +1,2 @@ +bugfixes: + - module_utils.common - change default opening mode to read-bytes to avoid bad interpretation of non ascii characters and strings, often present in 3rd party manifests. diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 1be5513c..c1579549 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -496,7 +496,7 @@ class K8sAnsibleMixin(object): if not os.path.exists(path): self.fail(msg="Error accessing {0}. Does the file exist?".format(path)) try: - with open(path, "r") as f: + with open(path, "rb") as f: result = list(yaml.safe_load_all(f)) except (IOError, yaml.YAMLError) as exc: self.fail(msg="Error loading resource_definition: {0}".format(exc))