Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[batch] Restrict mount propagation for job container mounts #12960

Merged
merged 3 commits into from
May 3, 2023
Merged
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
37 changes: 24 additions & 13 deletions batch/batch/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,21 @@ async def _run_container(self) -> bool:

return False

def _validate_container_config(self, config):
for mount in config['mounts']:
# bind mounts are given the dummy type 'none'
if mount['type'] == 'none':
# Mount events should not be propagated from the job container to the host
assert 'shared' not in mount['options']
assert any(option in mount['options'] for option in ('private', 'slave'))

async def _write_container_config(self):
config = await self.container_config()
self._validate_container_config(config)

os.makedirs(self.config_path)
with open(f'{self.config_path}/config.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(await self.container_config()))
f.write(json.dumps(config))

# https://github.com/opencontainers/runtime-spec/blob/master/config.md
async def container_config(self):
Expand Down Expand Up @@ -1179,7 +1190,7 @@ def _mounts(self, uid, gid):
'source': v_host_path,
'destination': v_container_path,
'type': 'none',
'options': ['rbind', 'rw', 'shared'],
'options': ['bind', 'rw', 'private'],
}
)

Expand Down Expand Up @@ -1235,13 +1246,13 @@ def _mounts(self, uid, gid):
'source': f'/etc/netns/{self.netns.network_ns_name}/resolv.conf',
'destination': '/etc/resolv.conf',
'type': 'none',
'options': ['rbind', 'ro'],
'options': ['bind', 'ro', 'private'],
},
{
'source': f'/etc/netns/{self.netns.network_ns_name}/hosts',
'destination': '/etc/hosts',
'type': 'none',
'options': ['rbind', 'ro'],
'options': ['bind', 'ro', 'private'],
},
]
)
Expand Down Expand Up @@ -1484,7 +1495,7 @@ def __init__(
'source': self.io_host_path(),
'destination': '/io',
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
}
self.input_volume_mounts.append(io_volume_mount)
self.main_volume_mounts.append(io_volume_mount)
Expand Down Expand Up @@ -1642,7 +1653,7 @@ def __init__(
'source': f'{self.cloudfuse_data_path(bucket)}',
'destination': config['mount_path'],
'type': 'none',
'options': ['rbind', 'rw', 'shared'],
'options': ['bind', 'rw', 'private'],
}
)

Expand All @@ -1652,7 +1663,7 @@ def __init__(
'source': self.secret_host_path(secret),
'destination': secret["mount_path"],
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
}
self.main_volume_mounts.append(volume_mount)
# this will be the user credentials
Expand Down Expand Up @@ -2348,37 +2359,37 @@ async def create_and_start(
'source': JVM.SPARK_HOME,
'destination': JVM.SPARK_HOME,
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
},
{
'source': '/jvm-entryway',
'destination': '/jvm-entryway',
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
},
{
'source': '/hail-jars',
'destination': '/hail-jars',
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
},
{
'source': root_dir,
'destination': root_dir,
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
},
{
'source': '/batch',
'destination': '/batch',
'type': 'none',
'options': ['rbind', 'rw'],
'options': ['bind', 'rw', 'private'],
},
{
'source': cloudfuse_dir,
'destination': '/cloudfuse',
'type': 'none',
'options': ['rbind', 'ro', 'rslave'],
'options': ['rbind', 'ro', 'slave'],
},
]

Expand Down