-
Notifications
You must be signed in to change notification settings - Fork 23.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Targeted fix for installing roles with symlinks containing '..' (#82165)
Set the tarfile attribute to a normalized value from unfrackpath instead of validating path parts and omiting potentially invald parts Allow tarfile paths/links containing '..', '$', '~' as long as the normalized realpath is in the tarfile's role directory
- Loading branch information
Showing
6 changed files
with
229 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- ansible-galaxy role install - normalize tarfile paths and symlinks using ``ansible.utils.path.unfrackpath`` and consider them valid as long as the realpath is in the tarfile's role directory (https://github.com/ansible/ansible/issues/81965). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/integration/targets/ansible-galaxy-role/tasks/valid-role-symlinks.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
- name: create test directories | ||
file: | ||
path: '{{ remote_tmp_dir }}/dir-traversal/{{ item }}' | ||
state: directory | ||
loop: | ||
- source | ||
- target | ||
- roles | ||
|
||
- name: create subdir in the role content to test relative symlinks | ||
file: | ||
dest: '{{ remote_tmp_dir }}/dir-traversal/source/role_subdir' | ||
state: directory | ||
|
||
- copy: | ||
dest: '{{ remote_tmp_dir }}/dir-traversal/source/role_subdir/.keep' | ||
content: '' | ||
|
||
- set_fact: | ||
installed_roles: "{{ remote_tmp_dir | realpath }}/dir-traversal/roles" | ||
|
||
- name: build role with symlink to a directory in the role | ||
script: | ||
chdir: '{{ remote_tmp_dir }}/dir-traversal/source' | ||
cmd: create-role-archive.py safe-link-dir.tar ./ role_subdir/.. | ||
executable: '{{ ansible_playbook_python }}' | ||
|
||
- name: install role successfully | ||
command: | ||
cmd: 'ansible-galaxy role install --roles-path {{ remote_tmp_dir }}/dir-traversal/roles safe-link-dir.tar' | ||
chdir: '{{ remote_tmp_dir }}/dir-traversal/source' | ||
register: galaxy_install_ok | ||
|
||
- name: check for the directory symlink in the role | ||
stat: | ||
path: "{{ installed_roles }}/safe-link-dir.tar/symlink" | ||
register: symlink_in_role | ||
|
||
- assert: | ||
that: | ||
- symlink_in_role.stat.exists | ||
- symlink_in_role.stat.lnk_source == installed_roles + '/safe-link-dir.tar' | ||
|
||
- name: remove tarfile for next test | ||
file: | ||
path: '{{ remote_tmp_dir }}/dir-traversal/source/safe-link-dir.tar' | ||
state: absent | ||
|
||
- name: build role with safe relative symlink | ||
script: | ||
chdir: '{{ remote_tmp_dir }}/dir-traversal/source' | ||
cmd: create-role-archive.py safe.tar ./ role_subdir/../context.txt | ||
executable: '{{ ansible_playbook_python }}' | ||
|
||
- name: install role successfully | ||
command: | ||
cmd: 'ansible-galaxy role install --roles-path {{ remote_tmp_dir }}/dir-traversal/roles safe.tar' | ||
chdir: '{{ remote_tmp_dir }}/dir-traversal/source' | ||
register: galaxy_install_ok | ||
|
||
- name: check for symlink in role | ||
stat: | ||
path: "{{ installed_roles }}/safe.tar/symlink" | ||
register: symlink_in_role | ||
|
||
- assert: | ||
that: | ||
- symlink_in_role.stat.exists | ||
- symlink_in_role.stat.lnk_source == installed_roles + '/safe.tar/context.txt' | ||
|
||
- name: remove test directories | ||
file: | ||
path: '{{ remote_tmp_dir }}/dir-traversal/{{ item }}' | ||
state: absent | ||
loop: | ||
- source | ||
- target | ||
- roles |