Skip to content

Commit ec85f12

Browse files
committed
Merge branch 'ewindisch-secopt'
2 parents cf0199b + b097d19 commit ec85f12

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

docker/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
869869
publish_all_ports=False, links=None, privileged=False,
870870
dns=None, dns_search=None, volumes_from=None, network_mode=None,
871871
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
872-
extra_hosts=None, read_only=None, pid_mode=None):
872+
extra_hosts=None, read_only=None, pid_mode=None,
873+
security_opt=None):
873874

874875
if utils.compare_version('1.10', self._version) < 0:
875876
if dns is not None:
@@ -881,6 +882,12 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
881882
'volumes_from is only supported for API version >= 1.10'
882883
)
883884

885+
if utils.compare_version('1.15', self._version) < 0:
886+
if security_opt is not None:
887+
raise errors.InvalidVersion(
888+
'security_opt is only supported for API version >= 1.15'
889+
)
890+
884891
if utils.compare_version('1.17', self._version) < 0:
885892
if read_only is not None:
886893
raise errors.InvalidVersion(
@@ -897,7 +904,8 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
897904
privileged=privileged, dns_search=dns_search, cap_add=cap_add,
898905
cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
899906
network_mode=network_mode, restart_policy=restart_policy,
900-
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode
907+
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
908+
security_opt=security_opt
901909
)
902910

903911
if isinstance(container, dict):

docker/utils/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def create_host_config(
353353
publish_all_ports=False, links=None, privileged=False,
354354
dns=None, dns_search=None, volumes_from=None, network_mode=None,
355355
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
356-
extra_hosts=None, read_only=None, pid_mode=None
356+
extra_hosts=None, read_only=None, pid_mode=None, security_opt=None
357357
):
358358
host_config = {}
359359

@@ -394,6 +394,14 @@ def create_host_config(
394394
if dns is not None:
395395
host_config['Dns'] = dns
396396

397+
if security_opt is not None:
398+
if not isinstance(security_opt, list):
399+
raise errors.DockerException(
400+
'Invalid type for security_opt param: expected list but found'
401+
' {0}'.format(type(security_opt))
402+
)
403+
host_config['SecurityOpt'] = security_opt
404+
397405
if volumes_from is not None:
398406
if isinstance(volumes_from, six.string_types):
399407
volumes_from = volumes_from.split(',')
@@ -542,5 +550,5 @@ def create_container_config(
542550
'MemorySwap': memswap_limit,
543551
'HostConfig': host_config,
544552
'MacAddress': mac_address,
545-
'Labels': labels
553+
'Labels': labels,
546554
}

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ from. Optionally a single string joining container id's with commas
700700
* extra_hosts (dict): custom host-to-IP mappings (host:ip)
701701
* pid_mode (str): if set to "host", use the host PID namespace inside the
702702
container
703+
* security_opt (list): A list of string values to customize labels for MLS systems, such as SELinux.
703704

704705
```python
705706
>>> from docker import Client

tests/test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,19 @@ def test_tar_with_directory_symlinks(self):
22702270
tar = tarfile.open(fileobj=archive)
22712271
self.assertEqual(sorted(tar.getnames()), ['bar', 'bar/foo', 'foo'])
22722272

2273+
#######################
2274+
# HOST CONFIG TESTS #
2275+
#######################
2276+
2277+
def test_create_host_config_secopt(self):
2278+
security_opt = ['apparmor:test_profile']
2279+
result = create_host_config(security_opt=security_opt)
2280+
self.assertIn('SecurityOpt', result)
2281+
self.assertEqual(result['SecurityOpt'], security_opt)
2282+
2283+
with self.assertRaises(docker.errors.DockerException):
2284+
create_host_config(security_opt='wrong')
2285+
22732286

22742287
class StreamTest(Cleanup, unittest.TestCase):
22752288

0 commit comments

Comments
 (0)