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

Make risky-file-permissions rule does not ignore FQCN #1563

Merged
merged 2 commits into from May 21, 2021

Conversation

ssato
Copy link
Contributor

@ssato ssato commented May 20, 2021

Address the bug that the risky-file-permissions rule ignores the modules passed as FQCN like ansible.builtin.copy.

Signed-Off-By: Satoru SATOH satoru.satoh@gmail.com
Fixes: #1528

@ssato ssato requested a review from ssbarnea as a code owner May 20, 2021 09:35
@ssato ssato added the bug label May 20, 2021
@ssbarnea
Copy link
Member

ssbarnea commented May 20, 2021

Why not just adding both short and long names to the same lists? The new configuration seems overly complicated. I am curious if others share my opinion on that matter.  🤔

Other than this, thanks for raising it, we clearly need to fix it.

@ssbarnea ssbarnea requested a review from tadeboro May 20, 2021 09:50
@ssato
Copy link
Contributor Author

ssato commented May 20, 2021

Why not just adding both short and long names to the same lists? The new configuration seems overly complicated. I am curious if others share my opinion on that matter. thinking

I thought that much simple way at first but re-thought there might be a possibility of need to add more modules to take care in this rule. Also, similar fix may be required in other rules listing only short names of modules currently and smarter way to list modules might be needed, I guess. ;-)

But, of course, I'll make change that if it's better to keep it simple other than taking care of future possibilities. I don't have strong opinion about it.

Copy link
Contributor

@tadeboro tadeboro left a comment

Choose a reason for hiding this comment

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

I like the idea behind the PR, but the implementation is a bit too convoluted for my taste. YAGNI wins for me here.

Comment on lines 37 to 81
_FQCN_MODS_MAP: List[Tuple[str, List[str]]] = [
(
# fqcn prefix:
'ansible.builtin',
# modules:
[
# _modules:
'assemble',
'copy',
'file',
'replace',
'template',
# _modules_with_create:
'blockinfile',
'lineinfile',
],
),
(
'community.general',
[
# _modules:
'archive',
# _modules_with_create:
'htpasswd',
'ini_file',
],
),
]
_MOD_FQCN_PREFIX_MAP: Dict[str, str] = dict(
itertools.chain.from_iterable(
((mod, prefix) for mod in modules) for prefix, modules in _FQCN_MODS_MAP
)
)

_MODULES = {
'archive',
'assemble',
'copy', # supports preserve
'file',
'replace', # implicit preserve behavior but mode: preserve is invalid
'template', # supports preserve
# 'unarchive', # disabled because .tar.gz files can have permissions inside
}
for mod in _MODULES.copy():
_MODULES.add(f'{_MOD_FQCN_PREFIX_MAP[mod]}.{mod}')
Copy link
Contributor

Choose a reason for hiding this comment

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

This is overly complex. _MODULES should be a (frozen) set with all available options and that is it.

Comment on lines 83 to 92
_MODULES_WITH_CREATE = {
'blockinfile': False,
'htpasswd': True,
'ini_file': True,
'lineinfile': False,
}
for mod in _MODULES_WITH_CREATE.copy():
_MODULES_WITH_CREATE[f'{_MOD_FQCN_PREFIX_MAP[mod]}.{mod}'] = _MODULES_WITH_CREATE[
mod
]
Copy link
Contributor

Choose a reason for hiding this comment

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

The same thing here. _MODULES_WITH_CREATE should be a plain dictionary with all options directly listed.

@ssato
Copy link
Contributor Author

ssato commented May 21, 2021

I like the idea behind the PR, but the implementation is a bit too convoluted for my taste. YAGNI wins for me here.

Thanks for your feedbacks!

I pushed the simple version for the issue.

@ssbarnea
Copy link
Member

@ssato oops, another merge would require more work for you :p

ssato and others added 2 commits May 21, 2021 13:54
Address the bug that the risky-file-permissions rule ignores the modules
passed as FQCN like ansible.builtin.copy.

Signed-Off-By: Satoru SATOH <satoru.satoh@gmail.com>
@ssbarnea
Copy link
Member

@ssato Now you have write access to the repository. This means you can create branches, perform reviews and even merge changes that received reviews.

I encourage you to start using branches instead of your fork because it allows other cores to collaborate on them, making easier to fix small things and merge things faster.

Again, thanks for helping with the linter!

@ssbarnea ssbarnea changed the title Make risky-file-permissions rule does not ignore FQCN (#1528) Make risky-file-permissions rule does not ignore FQCN May 21, 2021
@ssbarnea ssbarnea requested a review from tadeboro May 21, 2021 13:08
@ssbarnea ssbarnea merged commit e77fa10 into ansible:master May 21, 2021
@ssato
Copy link
Contributor Author

ssato commented May 22, 2021

@ssato Now you have write access to the repository. This means you can create branches, perform reviews and even merge changes that received reviews.

I encourage you to start using branches instead of your fork because it allows other cores to collaborate on them, making easier to fix small things and merge things faster.

Thanks a lot! I'll do so later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

risky-file-permissions rule ignores FQCN
3 participants