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

Add new type 'mode' for Unix permissions/umask #50035

Closed
wants to merge 1 commit into from

Conversation

dagwieers
Copy link
Contributor

@dagwieers dagwieers commented Dec 17, 2018

SUMMARY

To avoid any dangerous situations with octal or integer values as Unix mode, it is better to always rely on using strings for Unix permissions or umasks. It adds clarity and uniformity, as the current ambiguous situation leads to unforeseen consequences (e.g. with indirected values being converted to integers). It would have been better if we always had only accepted string octal representation IMO.

This implements a deprecation warning if a string was not provided, but by Ansible v2.12 we will only accept string values for type mode. As a temporary measure we introduced a mode_str type to cover old str-type modes (whereas mode is using raw-type modes instead).

This PR also:

  • fix all examples doing it wrong

This fixes #43256

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

apt_repository, copy, file, get_url, htpasswd, ini_file, java_keystore, jenkins_plugin, lineinfile, openssl_pkcs12, replace, stat, template, udm_share

@ansibot
Copy link
Contributor

ansibot commented Dec 17, 2018

cc @ptux
click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Dec 17, 2018
@dagwieers dagwieers force-pushed the mode-type branch 2 times, most recently from 5f74734 to 22d01bc Compare December 17, 2018 17:42
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. net_tools Net-tools category stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. test This PR relates to tests. labels Dec 17, 2018
@ansibot

This comment has been minimized.

@ansibot ansibot added cloud and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Dec 17, 2018
@ansibot
Copy link
Contributor

ansibot commented Dec 17, 2018

@dagwieers dagwieers force-pushed the mode-type branch 3 times, most recently from e6c81de to 42fe72f Compare December 17, 2018 18:31
@felixfontein
Copy link
Contributor

Why not simply changing https://github.com/ansible/ansible/blob/devel/docs/bin/plugin_formatter.py#L150-L163 to output mode when it encounters mode_str? Then the modules don't have to end up on the ignore list.

@mattclay
Copy link
Member

@sivel Do you have any thoughts on #50035 (comment) ?

@dagwieers
Copy link
Contributor Author

dagwieers commented Feb 26, 2019

@felixfontein A possibility as well. It's only two three files so I didn't want to make it more complex than it already is for two three files.

This PR alse fixes existing modules and examples.
@thaumos
Copy link
Contributor

thaumos commented Feb 26, 2019

I want to make sure I understand this correctly. Please forgive me for any misunderstanding up front.

This change will be introducing a warning to a user who may be using an int in their playbooks for mode. So we suggest moving to a string as the new recommendation?

I'd also like to see a porting guide addition for this change. Also, @kustodian, we do need a lint rule change for this.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 27, 2019
@dagwieers
Copy link
Contributor Author

This change will be introducing a warning to a user who may be using an int in their playbooks for mode. So we suggest moving to a string as the new recommendation?

The documentation of the mode-parameter usually recommends using strings for various reasons. Rather than giving users insights in how YAML and Ansible work together to make this a big problem, requiring a string takes away most of the pain.

This is what we have in the documentation currently:

For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777) or quote it (like '644' or '1777') so Ansible receives a string and can do its own conversion from string into number. Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results

@ansibot ansibot added files Files category stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Mar 8, 2019
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 16, 2019
Copy link
Contributor

@acozine acozine left a comment

Choose a reason for hiding this comment

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

Overall I think this change promotes consistency and clarity. I did find a couple of points of confusion, noted below.

@@ -477,7 +477,7 @@ def main():
backup=dict(type='bool', default=False),
force=dict(type='bool', default=True, aliases=['thirsty']),
validate=dict(type='str'),
directory_mode=dict(type='raw'),
directory_mode=dict(type='mode'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't the parameter mode also defined here in the argspec? It's listed in the docs but not here.

Copy link
Contributor

Choose a reason for hiding this comment

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

AnsibleModule() has an argument add_file_common_args, which will add common parameters such as mode to the argspec. The parametes which are added are the ones in FILE_COMMON_ARGUMENTS defined in module_utils/basic.py, which includes this change.

@@ -155,8 +155,8 @@
mode:
description: Unix permissions of the file in octal
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to change as well.

@@ -36,6 +36,7 @@
mode:
description:
- The octal mode for newly created files in sources.list.d
Copy link
Contributor

Choose a reason for hiding this comment

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

This one too.

@gundalow
Copy link
Contributor

We've passed Core feature freeze for 2.8.
So how about we get this early in 2.9 and get feedback?

@ansibot
Copy link
Contributor

ansibot commented May 30, 2019

@ansibot
Copy link
Contributor

ansibot commented Sep 17, 2019

@ansibot ansibot added collection Related to Ansible Collections work collection:community.general labels Apr 29, 2020
@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Dec 6, 2020
@jborean93
Copy link
Contributor

When discussing this in the backlog meeting it seems like these changes here have been implemented by various other features over time and the changes here may not be needed anymore (or at least aren't needed to the same extent). Due to the age and the conflicts in the files we are going to close this PR.

@jborean93 jborean93 closed this Jan 26, 2022
@ansible ansible locked and limited conversation to collaborators Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 cloud collection:community.general collection Related to Ansible Collections work crypto Crypto community (ACME, openssl, letsencrypt) feature This issue/PR relates to a feature request. files Files category has_issue module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. net_tools Net-tools category packaging Packaging category pre_azp This PR was last tested before migration to Azure Pipelines. source_control Source-control category support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. system System category test This PR relates to tests. web_infrastructure Web-infrastructure category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip umask parameter does not work with octal (int) umask values