Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

[WIP] Add SSL Certificate Support to Fast Pull and Push #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tools/fast_puller_.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
parser.add_argument('--directory', action='store',
help='Where to save the image\'s files.')

parser.add_argument('--certificates', nargs='*', help='A comma separated ' +
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this parser argument can get pulled into a common helper since it's duplicated at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'tuple of key file, cert, and domain. (From httplib2 ' +
'docs) Add a key and cert that will be used for an SSL ' +
'connection to the specified domain. keyfile is the name ' +
'of a PEM formatted file that contains your private key. ' +
'certfile is a PEM formatted certificate chain file.')

_THREADS = 8


Expand All @@ -58,6 +65,12 @@ def main():

transport = transport_pool.Http(httplib2.Http, size=_THREADS)

if args.certificates:
for item in args.certificates:
logging.info('Adding certificate %s', item)
key, cert, domain = item.split(',')
transport.add_certificate(key, cert, domain)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test to ensure, this actually works. Looking at the code I have some doubts.


if '@' in args.name:
name = docker_name.Digest(args.name)
else:
Expand Down
13 changes: 13 additions & 0 deletions tools/fast_pusher_.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
parser.add_argument('--oci', action='store_true',
help='Push the image with an OCI Manifest.')

parser.add_argument('--certificates', nargs='*', help='A comma separated ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to disallow paths, which contain a comma, right? Any plans for an encoding?

'tuple of key file, cert, and domain. (From httplib2 ' +
'docs) Add a key and cert that will be used for an SSL ' +
'connection to the specified domain. keyfile is the name ' +
'of a PEM formatted file that contains your private key. ' +
'certfile is a PEM formatted certificate chain file.')

_THREADS = 8


Expand Down Expand Up @@ -123,6 +130,12 @@ def main():

transport = transport_pool.Http(httplib2.Http, size=_THREADS)

if args.certificates:
for item in args.certificates:
logging.info('Adding certificate %s', item)
key, cert, domain = item.split(',')
transport.add_certificate(key, cert, domain)

# Resolve the appropriate credential to use based on the standard Docker
# client logic.
creds = docker_creds.DefaultKeychain.Resolve(name)
Expand Down
12 changes: 12 additions & 0 deletions transport/transport_pool_.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def _return_transport(self, transport):
# We returned an item, notify a waiting thread.
self._condition.notify(n=1)

def add_certificate(self, key, cert, domain):
"""Adds a certificate to all of the underlying transports.

From httplib2 docs:

Add a key and cert that will be used for an SSL connection to the
specified domain. keyfile is the name of a PEM formatted file that contains
your private key. certfile is a PEM formatted certificate chain file.
"""
for transport in self._transports:
transport.add_certificate(key, cert, domain)

def request(self, *args, **kwargs):
"""This awaits a transport and delegates the request call.

Expand Down