From a733a59b8d502bfff6c67d1433c1a980a74a6d4d Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 10 Oct 2019 14:29:08 -0400 Subject: [PATCH 01/57] prevent the creation of Host names that contain Jinja --- awx/main/management/commands/inventory_import.py | 5 +++++ awx/main/models/inventory.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 7a23c1a63f..7bd60e3402 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -28,6 +28,7 @@ from awx.main.models.inventory import ( Host ) from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data +from awx.main.utils.safe_yaml import sanitize_jinja # other AWX imports from awx.main.models.rbac import batch_role_ancestor_rebuilding @@ -795,6 +796,10 @@ class Command(BaseCommand): if self.instance_id_var: instance_id = self._get_instance_id(mem_host.variables) host_attrs['instance_id'] = instance_id + try: + sanitize_jinja(mem_host_name) + except ValueError as e: + raise ValueError(str(e) + ': {}'.format(mem_host_name)) db_host = self.inventory.hosts.update_or_create(name=mem_host_name, defaults=host_attrs)[0] if enabled is False: logger.debug('Host "%s" added (disabled)', mem_host_name) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 7618b36eb3..baf4624726 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -61,6 +61,7 @@ from awx.main.models.notifications import ( ) from awx.main.models.credential.injectors import _openstack_data from awx.main.utils import _inventory_updates, region_sorting, get_licenser +from awx.main.utils.safe_yaml import sanitize_jinja __all__ = ['Inventory', 'Host', 'Group', 'InventorySource', 'InventoryUpdate', @@ -754,6 +755,13 @@ class Host(CommonModelNameNotUnique, RelatedJobsMixin): update_host_smart_inventory_memberships.delay() connection.on_commit(on_commit) + def clean_name(self): + try: + sanitize_jinja(self.name) + except ValueError as e: + raise ValidationError(str(e) + ": {}".format(self.name)) + return self.name + def save(self, *args, **kwargs): self._update_host_smart_inventory_memeberships() super(Host, self).save(*args, **kwargs) From c013d656c8967c4b8444bdb5df0b3114f62c74df Mon Sep 17 00:00:00 2001 From: Graham Mainwaring Date: Mon, 21 Oct 2019 16:10:25 -0400 Subject: [PATCH 02/57] Add UI toggle to disable public Galaxy (#3867) --- awx/main/conf.py | 10 +++++++++ awx/main/redact.py | 8 ++++--- awx/main/tasks.py | 12 +++++++--- awx/settings/defaults.py | 22 ++++++++++--------- .../jobs-form/configuration-jobs.form.js | 3 +++ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/awx/main/conf.py b/awx/main/conf.py index cce5e0a5de..f63fee564f 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -513,6 +513,16 @@ register( category_slug='jobs' ) +register( + 'PUBLIC_GALAXY_ENABLED', + field_class=fields.BooleanField, + default=True, + label=_('Allow Access to Public Galaxy'), + help_text=_('Allow or deny access to the public Ansible Galaxy during project updates.'), + category=_('Jobs'), + category_slug='jobs' +) + register( 'STDOUT_MAX_BYTES_DISPLAY', field_class=fields.IntegerField, diff --git a/awx/main/redact.py b/awx/main/redact.py index ae60684377..77fc062135 100644 --- a/awx/main/redact.py +++ b/awx/main/redact.py @@ -12,10 +12,12 @@ class UriCleaner(object): @staticmethod def remove_sensitive(cleartext): + # exclude_list contains the items that will _not_ be redacted + exclude_list = [settings.PUBLIC_GALAXY_SERVER['url']] if settings.PRIMARY_GALAXY_URL: - exclude_list = [settings.PRIMARY_GALAXY_URL] + [server['url'] for server in settings.FALLBACK_GALAXY_SERVERS] - else: - exclude_list = [server['url'] for server in settings.FALLBACK_GALAXY_SERVERS] + exclude_list += [settings.PRIMARY_GALAXY_URL] + if settings.FALLBACK_GALAXY_SERVERS: + exclude_list += [server['url'] for server in settings.FALLBACK_GALAXY_SERVERS] redactedtext = cleartext text_index = 0 while True: diff --git a/awx/main/tasks.py b/awx/main/tasks.py index ff53cd00ac..a91a4cf4b2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1959,9 +1959,15 @@ class RunProjectUpdate(BaseTask): env['PROJECT_UPDATE_ID'] = str(project_update.pk) env['ANSIBLE_CALLBACK_PLUGINS'] = self.get_path_to('..', 'plugins', 'callback') env['ANSIBLE_GALAXY_IGNORE'] = True - # Set up the fallback server, which is the normal Ansible Galaxy by default - galaxy_servers = list(settings.FALLBACK_GALAXY_SERVERS) - # If private galaxy URL is non-blank, that means this feature is enabled + # Set up the public Galaxy server, if enabled + if settings.PUBLIC_GALAXY_ENABLED: + galaxy_servers = [settings.PUBLIC_GALAXY_SERVER] + else: + galaxy_servers = [] + # Set up fallback Galaxy servers, if configured + if settings.FALLBACK_GALAXY_SERVERS: + galaxy_servers = settings.FALLBACK_GALAXY_SERVERS + galaxy_servers + # Set up the primary Galaxy server, if configured if settings.PRIMARY_GALAXY_URL: galaxy_servers = [{'id': 'primary_galaxy'}] + galaxy_servers for key in GALAXY_SERVER_FIELDS: diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 658d41d6b3..ab8a5492e8 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -635,16 +635,18 @@ PRIMARY_GALAXY_USERNAME = '' PRIMARY_GALAXY_TOKEN = '' PRIMARY_GALAXY_PASSWORD = '' PRIMARY_GALAXY_AUTH_URL = '' -# Settings for the fallback galaxy server(s), normally this is the -# actual Ansible Galaxy site. -# server options: 'id', 'url', 'username', 'password', 'token', 'auth_url' -# To not use any fallback servers set this to [] -FALLBACK_GALAXY_SERVERS = [ - { - 'id': 'galaxy', - 'url': 'https://galaxy.ansible.com' - } -] + +# Settings for the public galaxy server(s). +PUBLIC_GALAXY_ENABLED = True +PUBLIC_GALAXY_SERVER = { + 'id': 'galaxy', + 'url': 'https://galaxy.ansible.com' +} + +# List of dicts of fallback (additional) Galaxy servers. If configured, these +# will be higher precedence than public Galaxy, but lower than primary Galaxy. +# Available options: 'id', 'url', 'username', 'password', 'token', 'auth_url' +FALLBACK_GALAXY_SERVERS = [] # Enable bubblewrap support for running jobs (playbook runs only). # Note: This setting may be overridden by database settings. diff --git a/awx/ui/client/src/configuration/forms/jobs-form/configuration-jobs.form.js b/awx/ui/client/src/configuration/forms/jobs-form/configuration-jobs.form.js index 445b0864a2..ab3aa7404c 100644 --- a/awx/ui/client/src/configuration/forms/jobs-form/configuration-jobs.form.js +++ b/awx/ui/client/src/configuration/forms/jobs-form/configuration-jobs.form.js @@ -89,6 +89,9 @@ export default ['i18n', function(i18n) { type: 'text', reset: 'PRIMARY_GALAXY_AUTH_URL', }, + PUBLIC_GALAXY_ENABLED: { + type: 'toggleSwitch', + }, AWX_TASK_ENV: { type: 'textarea', reset: 'AWX_TASK_ENV', From 9c9bf0ed8479e79ea40ea40d76eb654be11c722b Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Mon, 21 Oct 2019 16:13:52 -0400 Subject: [PATCH 03/57] Handle undefined schedule value in job detail component --- awx/ui/client/features/output/details.component.js | 4 +++- awx/ui/client/features/output/details.partial.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/features/output/details.component.js b/awx/ui/client/features/output/details.component.js index 532b04055a..de76ee669e 100644 --- a/awx/ui/client/features/output/details.component.js +++ b/awx/ui/client/features/output/details.component.js @@ -282,10 +282,12 @@ function getLaunchedByDetails () { tooltip = strings.get('tooltips.SCHEDULE'); link = `/#/templates/job_template/${jobTemplate.id}/schedules/${schedule.id}`; value = $filter('sanitize')(schedule.name); - } else { + } else if (schedule) { tooltip = null; link = null; value = $filter('sanitize')(schedule.name); + } else { + return null; } return { label, link, tooltip, value }; diff --git a/awx/ui/client/features/output/details.partial.html b/awx/ui/client/features/output/details.partial.html index 14bf856269..7264059b49 100644 --- a/awx/ui/client/features/output/details.partial.html +++ b/awx/ui/client/features/output/details.partial.html @@ -5,7 +5,7 @@
- +