sanitize path symbols in inventory_hostname on file cache plugins - #41420
Conversation
4073785 to
bce91aa
Compare
This comment was marked as outdated.
This comment was marked as outdated.
bc02487 to
b349c29
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
File based cache plugins will now correctly handle inventory_hostnames with 'path symbols' in their names. This should allow those using chroot and jail connection plugins to use file based caches now.
60e1f64 to
577b8a1
Compare
…sible#41420) * File based cache plugins filenames fix File based cache plugins will now correctly handle inventory_hostnames with 'path symbols' in their names. This should allow those using chroot and jail connection plugins to use file based caches now. (cherry picked from commit d9d11d6)
…sible#41420) * File based cache plugins filenames fix File based cache plugins will now correctly handle inventory_hostnames with 'path symbols' in their names. This should allow those using chroot and jail connection plugins to use file based caches now. (cherry picked from commit d9d11d6)
| """ | ||
| Ensures key name is safe to use on the filesystem | ||
| """ | ||
| if key not in self._sanitized: |
There was a problem hiding this comment.
@bcoca could you add test coverage for the else-branch here?
| if not self._cache_dir: | ||
| raise AnsibleError("error, '%s' cache plugin requires the 'fact_caching_connection' config option " | ||
| "to be set (to a writeable directory path)" % self.plugin_name) | ||
| raise AnsibleError(f"'{self.plugin_name!r}' cache plugin requires the 'fact_caching_connection' configuration option " |
| if not os.access(self._cache_dir, x): | ||
| raise AnsibleError("error in '%s' cache, configured path (%s) does not have necessary permissions (rwx), disabling plugin" % ( | ||
| self.plugin_name, self._cache_dir)) | ||
| raise AnsibleError(f"'{self.plugin_name!r}' cache, configured path ({self._cache_dir}) does not have necessary permissions (rwx)," |
There was a problem hiding this comment.
@bcoca this line never had tests and you changed it. Could you add coverage?
There was a problem hiding this comment.
@mattclay do we have an extablished convention for excluding such dummy files from coverage? This one shows up in Codecov with 0% so we should either measure it or omit. Can we omit it in coveragerc or is there any other preference?
There was a problem hiding this comment.
The lack of code coverage collection for this plugin is due to an issue with ansible-test. I'm looking to see how difficult it will be to fix.
There was a problem hiding this comment.
This file now shows up with 90.91% coverage.
SUMMARY
Ensure that we don't error out or allow traversal when the inventory_hostname is or has path symbols.
This is common in environments using the
chrootconnection plugin and similar.ISSUE TYPE
COMPONENT NAME
cache plugins
ANSIBLE VERSION
ADDITIONAL INFO
Avoids this error when the inventory_hostname='..' or similar 'path related'
and
When inventory hostname is
/my/chroot/hostname