Beispiel #1
0
    def run(self, tmp=None, task_vars=None):
        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        try:
            delegate_to = self._task.delegate_to
        except (AttributeError, KeyError):
            delegate_to = None

        if delegate_to and not paths._is_localhost_task(self):
            return super(ActionModule, self).run(tmp, task_vars)

        source = self._task.args.get('src', None)
        dest = self._task.args.get('dest', None)
        mode = self._task.args.get('mode', 'push')

        if 'rsync_opts' not in self._task.args:
            self._task.args['rsync_opts'] = []
        if '--safe-links' not in self._task.args['rsync_opts']:
            self._task.args['rsync_opts'].append('--safe-links')

        if mode == 'push' and not paths._is_safe_path(
                source, allow_trusted=True):
            return paths._fail_dict(source, prefix='Syncing files from')
        if mode == 'pull' and not paths._is_safe_path(dest):
            return paths._fail_dict(dest, prefix='Syncing files to')
        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #2
0
    def run(self, tmp=None, task_vars=None):
        '''Overridden primary method from the base class.'''

        if paths._is_localhost_task(self):
            if not self.dispatch_handler():
                raise AnsibleError("Executing local code is prohibited")
        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #3
0
    def run(self, tmp=None, task_vars=None):
        '''Overridden primary method from the base class.'''

        if paths._is_localhost_task(self):
            if not self.dispatch_handler():
                raise AnsibleError("Executing local code is prohibited")
        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #4
0
    def run(self, tmp=None, task_vars=None):
        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        try:
            delegate_to = self._task.delegate_to
        except (AttributeError, KeyError):
            delegate_to = None

        if delegate_to and not paths._is_localhost_task(self):
            return super(ActionModule, self).run(tmp, task_vars)

        source = self._task.args.get('src', None)
        dest = self._task.args.get('dest', None)
        mode = self._task.args.get('mode', 'push')

        if 'rsync_opts' not in self._task.args:
            self._task.args['rsync_opts'] = []
        if '--safe-links' not in self._task.args['rsync_opts']:
            self._task.args['rsync_opts'].append('--safe-links')

        if mode == 'push' and not paths._is_safe_path(source,
                                                      allow_trusted=True):
            return paths._fail_dict(source, prefix='Syncing files from')
        if mode == 'pull' and not paths._is_safe_path(dest):
            return paths._fail_dict(dest, prefix='Syncing files to')
        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #5
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            raise AnsibleError("Executing local code is prohibited")

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #6
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            paths._fail_if_unsafe(self._task.args['dest'])

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #7
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            paths._fail_if_unsafe(self._task.args['dest'])

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #8
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            raise AnsibleError("Executing local code is prohibited")

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #9
0
    def run(self, tmp=None, task_vars=None):
        if paths._is_localhost_task(self):
            raise AnsibleError("Executing local code is prohibited")

        # we need the zuul_log_id on shell and command tasks
        host = paths._sanitize_filename(task_vars.get('inventory_hostname'))
        if self._task.action in ('command', 'shell'):
            self._task.args['zuul_log_id'] = "%s-%s" % (self._task._uuid, host)

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #10
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            for arg in ('src', 'dest'):
                dest = self._task.args.get(arg)
                if dest:
                    paths._fail_if_unsafe(dest)

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #11
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            for arg in ('src', 'dest'):
                dest = self._task.args.get(arg)
                if dest:
                    paths._fail_if_unsafe(dest)

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #12
0
    def handle_known_hosts(self):
        '''Allow known_hosts on localhost

        The :ansible:module:`known_hosts` can be used to add SSH host keys of
        a remote system. When run from a executor it can be used with the
        add_host task to access remote servers. This is needed because ansible
        on the executor is configured to check host keys by default.

        Block any access of files outside the zuul work dir.
        '''
        if paths._is_localhost_task(self):
            path = self._task.args.get('path')
            if path:
                paths._fail_if_unsafe(path)
Beispiel #13
0
    def handle_known_hosts(self):
        '''Allow known_hosts on localhost

        The :ansible:module:`known_hosts` can be used to add SSH host keys of
        a remote system. When run from a executor it can be used with the
        add_host task to access remote servers. This is needed because ansible
        on the executor is configured to check host keys by default.

        Block any access of files outside the zuul work dir.
        '''
        if paths._is_localhost_task(self):
            path = self._task.args.get('path')
            if path:
                paths._fail_if_unsafe(path)
Beispiel #14
0
    def run(self, tmp=None, task_vars=None):
        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            # The patch module has two possibilities of describing where to
            # operate, basedir and dest. We need to perform the safe path check
            # for both.
            dirs_to_check = [
                self._task.args.get('basedir'),
                self._task.args.get('dest'),
            ]

            for directory in dirs_to_check:
                if directory is not None:
                    paths._fail_if_unsafe(directory)

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #15
0
    def run(self, tmp=None, task_vars=None):
        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            # The patch module has two possibilities of describing where to
            # operate, basedir and dest. We need to perform the safe path check
            # for both.
            dirs_to_check = [
                self._task.args.get('basedir'),
                self._task.args.get('dest'),
            ]

            for directory in dirs_to_check:
                if directory is not None:
                    paths._fail_if_unsafe(directory)

        return super(ActionModule, self).run(tmp, task_vars)
Beispiel #16
0
    def run(self, tmp=None, task_vars=None):

        if not paths._is_official_module(self):
            return paths._fail_module_dict(self._task.action)

        if paths._is_localhost_task(self):
            for arg in ('src', 'dest'):
                dest = self._task.args.get(arg)
                if dest:
                    paths._fail_if_unsafe(dest)
            scheme = urlparse(self._task.args['url']).scheme
            if scheme not in ALLOWED_URL_SCHEMES:
                raise AnsibleError(
                    "{scheme} urls are not allowed from localhost."
                    " Only {allowed_schemes} are allowed".format(
                        scheme=scheme,
                        allowed_schemes=ALLOWED_URL_SCHEMES))

        return super(ActionModule, self).run(tmp, task_vars)