Skip to content

Commit

Permalink
Add possibility to disable TLS verify in Docker processor (#79)
Browse files Browse the repository at this point in the history
* Bump idna from 3.4 to 3.7

Bumps [idna](https://github.com/kjd/idna) from 3.4 to 3.7.
- [Release notes](https://github.com/kjd/idna/releases)
- [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst)
- [Commits](kjd/idna@v3.4...v3.7)

---
updated-dependencies:
- dependency-name: idna
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix (#73)

* --- (#74)

updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add possibility to disable TLS verify in Docker processor.

* Fix Python getaddresses changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Hui Zheng <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent 51422dd commit b37d6ee
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
13 changes: 11 additions & 2 deletions _vendor/python_docker/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@

class Registry:

tls_verify = True

def __init__(
self,
hostname: str = "https://registry-1.docker.io",
username: str = None,
password: str = None,
verify: bool = True,
):
self.hostname = hostname
self.username = username
self.password = password
if not verify:
self.tls_verify = False
self.detect_authentication()
self.session = requests.Session()
if not verify:
self.session.verify = False

def detect_authentication(self):
response = requests.get(f"{self.hostname}/v2/")
response = requests.get(f"{self.hostname}/v2/", verify=self.tls_verify)
if "www-authenticate" in response.headers:
auth_scheme, parameters = response.headers[
"www-authenticate"].split(" ", 1)
Expand Down Expand Up @@ -77,7 +84,9 @@ def token_authenticate(self, image: str = None, action: str = None):
base_url += "?" + "&".join(
f"{key}={value}" for key, value in query.items())

response = requests.get(base_url, headers=headers)
response = requests.get(base_url,
headers=headers,
verify=self.tls_verify)
if response.status_code != 200:
raise ValueError(f"token authentication failed for {base_url}")

Expand Down
6 changes: 6 additions & 0 deletions docs/build/docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,18 @@
* [`DockerProcessor`](processors.md#processors.docker.DockerProcessor)


* [`DockerProcessor.destination_tls_verify`](processors.md#processors.docker.DockerProcessor.destination_tls_verify)


* [`DockerProcessor.get_default_config_key()`](processors.md#processors.docker.DockerProcessor.get_default_config_key)


* [`DockerProcessor.process()`](processors.md#processors.docker.DockerProcessor.process)


* [`DockerProcessor.source_tls_verify`](processors.md#processors.docker.DockerProcessor.source_tls_verify)


* [`DockerProcessor.wait_for_operation_done()`](processors.md#processors.docker.DockerProcessor.wait_for_operation_done)


Expand Down
10 changes: 10 additions & 0 deletions docs/build/docs/processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,21 @@ Perform actions on Docker registries.
* **destination_tag** (*str**, **optional*) – Tag to pull/push, defaults to latest.


* **tls_verify** (*bool**, **optional*) – Set false to disable TLS verify at source registry.


* **destination_tls_verify** (*bool**, **optional*) – Set false to disable TLS verify at destination registry.



#### destination_tls_verify(_ = Tru_ )

#### get_default_config_key()

#### process(output_var='docker')

#### source_tls_verify(_ = Tru_ )

#### wait_for_operation_done(ar_service, operation_name)
## processors.download module

Expand Down
28 changes: 22 additions & 6 deletions output/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ def _fetch_ms_access_token(self, client_id, client_secret, tenant_id):

def expand_recipients(self, mail, config):
"""Expands group recipients using the Directory API"""
to_emails = email.utils.getaddresses([mail['mail_to']])
to_emails = []
try:
to_emails = email.utils.getaddresses([mail['mail_to']],
strict=False)
except TypeError:
to_emails = email.utils.getaddresses([mail['mail_to']])
self.logger.debug('Starting expansion of group recipients...',
extra={'to': to_emails})

Expand Down Expand Up @@ -243,7 +248,12 @@ def send_via_smtp(self, transport, mail, embedded_images, config):
(file_name, len(content)))
message.attach(image)

parsed_recipients = email.utils.getaddresses([mail['mail_to']])
parsed_recipients = []
try:
parsed_recipients = email.utils.getaddresses([mail['mail_to']],
strict=False)
except TypeError:
parsed_recipients = email.utils.getaddresses([mail['mail_to']])
recipients = []
for r in parsed_recipients:
recipients.append(r[1])
Expand Down Expand Up @@ -446,14 +456,20 @@ def output(self):
'No HMTL or text email body configured for email output!')

for tpl in ['from', 'to', 'subject']:
mail_template = self.jinja_environment.from_string(
self.output_config[tpl])
mail['mail_%s' % tpl] = mail_template.render()
result = self._jinja_expand_string(self.output_config[tpl], tpl)
mail['mail_%s' % tpl] = result

self.logger.debug('Canonicalizing email formats...')
# Canonicalize the email formats
for tpl in ['from', 'to']:
parsed_emails = email.utils.getaddresses([mail['mail_%s' % tpl]])
parsed_emails = []
try:
parsed_emails = email.utils.getaddresses(
[mail['mail_%s' % tpl]], strict=False)
except TypeError:
parsed_emails = email.utils.getaddresses(
[mail['mail_%s' % tpl]])

if tpl == 'from' and len(parsed_emails) > 1:
raise MultipleSendersException(
'Multiple senders in from field!')
Expand Down
2 changes: 1 addition & 1 deletion processors/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ def process(self, output_var={'projects': 'projects', 'budget': 'budget'}):
response.amount.specified_amount.currency_code,
}
}
return ret
return ret
19 changes: 17 additions & 2 deletions processors/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ class DockerProcessor(Processor):
destination_password (str, optional): Password for Docker registry. (For copy)
destination_image (str): Image to pull/push
destination_tag (str, optional): Tag to pull/push, defaults to latest.
tls_verify (bool, optional): Set false to disable TLS verify at source registry.
destination_tls_verify (bool, optional): Set false to disable TLS verify at destination registry.
"""

source_tls_verify = True
destination_tls_verify = True

def get_default_config_key():
return 'docker'

Expand Down Expand Up @@ -92,9 +97,18 @@ def process(self, output_var='docker'):
credentials.refresh(auth_req)
password = credentials.token

if 'tls_verify' in self.config:
self.source_tls_verify = self._jinja_expand_bool(
self.config['tls_verify'], 'tls_verify')

if 'destination_tls_verify' in self.config:
self.destination_tls_verify = self._jinja_expand_bool(
self.config['destination_tls_verify'], 'destination_tls_verify')

source_registry = Registry(hostname=hostname,
username=username,
password=password)
password=password,
verify=self.source_tls_verify)
destination_registry = None
destination_hostname = None
if 'destination_hostname' not in self.config:
Expand Down Expand Up @@ -124,7 +138,8 @@ def process(self, output_var='docker'):

destination_registry = Registry(hostname=destination_hostname,
username=destination_username,
password=destination_password)
password=destination_password,
verify=self.destination_tls_verify)

if mode == 'image.copy':
destination_image = self._jinja_expand_string(
Expand Down
2 changes: 0 additions & 2 deletions processors/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ def process(self, output_var='slack'):
if new_message:
processed.append(new_message)

print('PROCESSED', processed)

# Prepend an initial prompt that can be instructions or such
if 'prompt' in self.config:
prompt_added = False
Expand Down
2 changes: 0 additions & 2 deletions test/configs/legacy/budget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ outputs:
port: 587
starttls: true
# ssl: false
- type: sendgrid
apiKey: your-sendgrid-api-key
from: [email protected]
to: |
{% for project in projects %}
Expand Down

0 comments on commit b37d6ee

Please sign in to comment.