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

get_url checksum does not support checksum files containing *just* the checksum #54390

Closed
DanHam opened this issue Mar 26, 2019 · 7 comments · Fixed by #77948
Closed

get_url checksum does not support checksum files containing *just* the checksum #54390

DanHam opened this issue Mar 26, 2019 · 7 comments · Fixed by #77948
Assignees
Labels
affects_2.11 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. has_pr This issue has an associated PR. module This issue/PR relates to a module. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@DanHam
Copy link

DanHam commented Mar 26, 2019

SUMMARY

get_url fails to parse a checksum file when the file contains just the checksum

ISSUE TYPE
  • Bug Report
COMPONENT NAME

get_url

ANSIBLE VERSION
ansible 2.8.0.dev0
  config file = /Users/dan/.ansible.cfg
  configured module search path = ['/Users/dan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/dan/.venv-ansible/lib/python3.7/site-packages/ansible
  executable location = /Users/dan/.venv-ansible/bin/ansible
  python version = 3.7.2 (default, Dec 30 2018, 08:55:50) [Clang 10.0.0 (clang-1000.11.45.5)]
CONFIGURATION
HOST_KEY_CHECKING(/Users/dan/.ansible.cfg) = False
INVENTORY_ENABLED(/Users/dan/.ansible.cfg) = ['host_list', 'script', 'yaml', 'ini', 'auto', 'gcp_compute']
OS / ENVIRONMENT
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.3
BuildVersion:   18D109
STEPS TO REPRODUCE
- name: Demo error with plain checksum file
  get_url:
    checksum: sha512:https://dl.k8s.io/v1.13.0/bin/linux/amd64/kube-scheduler.sha512
    dest: /usr/bin/kube-scheduler
    mode: 0755
    url: https://dl.k8s.io/v1.13.0/bin/linux/amd64/kube-scheduler

For easy reference, the contents of the checksum file is as follows:

f400eedaef4aa277ba9ffbc17d1937fe2e200f5b4886930ae2c34e5a1a4ee14aee5d26c45b3babf7e791ba292787c950f55f4b9a32294472c73ec7b62af45858
EXPECTED RESULTS

get_url should be able to obtain the checksum from a file containing just the checksum.

At present get_url is able to handle the more complex case of parsing out the correct checksum from a file containing multiple checksums.

With the example shown above, there is no need to parse out the correct checksum. Here the checksum makes up the entirety of the file contents and all that is needed is to simply read the file.

ping @sivel as this was worked on recently in #53685

ACTUAL RESULTS

get_url fails and returns the following error

"msg": "The checksum parameter has to be in format <algorithm>:<checksum>"
@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Mar 26, 2019
@sivel
Copy link
Member

sivel commented Mar 26, 2019

I think I would consider this a feature request.

In any case, for now you can do the following:

- name: Demo error with plain checksum file
  get_url:
    checksum: "sha512:{{ lookup('url', 'https://dl.k8s.io/v1.13.0/bin/linux/amd64/kube-scheduler.sha512') }}"
    dest: /usr/bin/kube-scheduler
    mode: 0755
    url: https://dl.k8s.io/v1.13.0/bin/linux/amd64/kube-scheduler

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Mar 26, 2019
@DanHam
Copy link
Author

DanHam commented Mar 26, 2019

@sivel OK. In the meantime it would be great if the docs could specify exactly what the expected format of the checksum file should be - this one had me scratching my head for a while as I just assumed this would be supported.

Many thanks for the workaround in the interim.

@sivel
Copy link
Member

sivel commented Apr 2, 2020

I've had a few minutes to play with a solution, but haven't tested it extensively.

diff --git a/lib/ansible/modules/net_tools/basics/get_url.py b/lib/ansible/modules/net_tools/basics/get_url.py
index ea033d9cfe..d25ae0c39c 100644
--- a/lib/ansible/modules/net_tools/basics/get_url.py
+++ b/lib/ansible/modules/net_tools/basics/get_url.py
@@ -495,12 +495,19 @@ def main():
             with open(checksum_tmpsrc) as f:
                 lines = [line.rstrip('\n') for line in f]
             os.remove(checksum_tmpsrc)
-            checksum_map = {}
-            for line in lines:
-                parts = line.split(None, 1)
-                if len(parts) == 2:
-                    checksum_map[parts[0]] = parts[1]
             filename = url_filename(url)
+            checksum_map = {}
+            if len(lines) == 1 and len(lines[0].split()) == 1:
+                # Only a single line with a single string
+                # treat it as a checksum only file
+                checksum_map[lines[0]] = filename
+            else:
+                # The assumption here is the file is in the format of
+                # filename checksum
+                for line in lines:
+                    parts = line.split(None, 1)
+                    if len(parts) == 2:
+                        checksum_map[parts[0]] = parts[1]
 
             # Look through each line in the checksum file for a hash corresponding to
             # the filename in the url, returning the first hash that is found.

If anyone wants to take that patch, and get together a PR with a changelog fragment, and tests, please feel free to do so. I am not actively pursuing this further.

@sivel sivel added the easyfix This issue is considered easy to fix by aspiring contributors. label Apr 2, 2020
@ansibot
Copy link
Contributor

ansibot commented May 16, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added the has_pr This issue has an associated PR. label May 18, 2020
@s-hertel s-hertel added affects_2.11 and removed affects_2.8 This issue/PR affects Ansible v2.8 labels Jul 9, 2021
@s-hertel s-hertel self-assigned this Jul 9, 2021
adam-stokes added a commit to elastic/beats-tester that referenced this issue Jul 22, 2021
Attempt to fix issue where `get_url` doesn't properly read a checksum value out of a checksum file:

ansible/ansible#54390
adam-stokes added a commit to elastic/beats-tester that referenced this issue Jul 26, 2021
* Fix checksum validation 

Attempt to fix issue where `get_url` doesn't properly read a checksum value out of a checksum file:

ansible/ansible#54390
@muellert
Copy link

muellert commented Feb 7, 2022

It would be great if the module's documentation would specify the format the checksum file needs to be in, and if one could have more than one checkum in one file, for a number of algorithms or files. So far, I tried "xxxxx" (the sha256sum checksum), "xxxxx filename", "sha256:xxxxx" and also "SHA256:xxxxx filename", all without success.

s-hertel pushed a commit to s-hertel/ansible that referenced this issue Jun 1, 2022
checksum can also accept a checksum only file (no filename beside the checksum).
fixes ansible#54390
jborean93 pushed a commit that referenced this issue Jun 2, 2022
checksum can also accept a checksum only file (no filename beside the checksum).
fixes #54390

Co-authored-by: Baptiste Mille-Mathias <baptiste.millemathias@gmail.com>
@ansible ansible locked and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. has_pr This issue has an associated PR. module This issue/PR relates to a module. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
5 participants