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

Calculating md5 for the local s3 file uses filename instead of file content #861

Closed
1 task done
stefangluszek opened this issue Jun 3, 2022 · 2 comments
Closed
1 task done
Assignees
Labels
bug This issue/PR relates to a bug jira module_utils module_utils plugins plugin (any type) waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@stefangluszek
Copy link

Summary

The filename string literal is used instead of the file content when calculating the MD5 checksum of the local file in:

return '"{0}"'.format(module.md5(filename))

This should be:

return '"{0}"'.format(md5(open(filename,'rb').read()).hexdigest())

This only happens if the ETAG is not Multi-part.

Issue Type

Bug Report

Component Name

s3

Ansible Version

$ ansible --version

Collection Versions

$ ansible-galaxy collection list
amazon.aws        3.1.1

AWS SDK versions

$ pip show boto boto3 botocore
Name: boto3
Version: 1.21.35
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.24.35
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed

OS / Environment

No response

Steps to Reproduce

Expected Results

Checksum to be calculated correctly

Actual Results

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

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

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module_utils module_utils needs_triage plugins plugin (any type) labels Jun 3, 2022
@jillr jillr added jira waiting_on_contributor Needs help. Feel free to engage to get things unblocked and removed needs_triage labels Jun 28, 2022
@goneri goneri self-assigned this Sep 7, 2022
@goneri
Copy link
Member

goneri commented Sep 12, 2022

Hi @stefangluszek,

The module.md5() call triggers AnsibleModule.digest_from_file(filename, 'md5')
See: https://github.com/ansible/ansible/blob/a26c325bd8f6e2822d9d7e62f77a424c1db4fbf6/lib/ansible/module_utils/basic.py#L1544

I opened a PR to cover the calculate_etag() function with unit-tests. #1015

I close the issue, feel free to reopen if you've got a test-case to produce your original problem.

@goneri goneri closed this as completed Sep 12, 2022
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 jira module_utils module_utils plugins plugin (any type) waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
Development

No branches or pull requests

4 participants