From 51dac059eb51ea62807a68ad59e4256e0a2ff76b Mon Sep 17 00:00:00 2001 From: tonic Date: Wed, 6 May 2015 17:12:05 +0800 Subject: [PATCH 1/2] add privilege for exec_create --- docker/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/client.py b/docker/client.py index 2d1349c0..d5681ed2 100644 --- a/docker/client.py +++ b/docker/client.py @@ -531,7 +531,8 @@ class Client(requests.Session): return self.exec_start(create_res, detach, tty, stream) - def exec_create(self, container, cmd, stdout=True, stderr=True, tty=False): + def exec_create(self, container, cmd, stdout=True, + stderr=True, tty=False, privileged=False): if utils.compare_version('1.15', self._version) < 0: raise errors.InvalidVersion('Exec is not supported in API < 1.15') if isinstance(container, dict): @@ -542,7 +543,7 @@ class Client(requests.Session): data = { 'Container': container, 'User': '', - 'Privileged': False, + 'Privileged': privileged, 'Tty': tty, 'AttachStdin': False, 'AttachStdout': stdout, From abbbbfb2d6a1294238919aa115631416175f1dde Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 20 May 2015 14:58:47 -0700 Subject: [PATCH 2/2] Only allow privileged exec_create for API version >= 1.19 --- docker/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/client.py b/docker/client.py index 022a327a..b6648067 100644 --- a/docker/client.py +++ b/docker/client.py @@ -531,10 +531,14 @@ class Client(requests.Session): return self.exec_start(create_res, detach, tty, stream) - def exec_create(self, container, cmd, stdout=True, - stderr=True, tty=False, privileged=False): + def exec_create(self, container, cmd, stdout=True, stderr=True, tty=False, + privileged=False): if utils.compare_version('1.15', self._version) < 0: raise errors.InvalidVersion('Exec is not supported in API < 1.15') + if privileged and utils.compare_version('1.19', self._version) < 0: + raise errors.InvalidVersion( + 'Privileged exec is not supported in API < 1.19' + ) if isinstance(container, dict): container = container.get('Id') if isinstance(cmd, six.string_types):