Skip to content

Commit 4bcd920

Browse files
committed
feat: 🚸 Add SAGEMAKER_LOCAL_SELINUX_ENABLED environment variable
This flag can be used to turn on/off the SELinux labels for docker volumes
1 parent e3d5422 commit 4bcd920

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/sagemaker/local/image.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
TRAINING_JOB_NAME_ENV_NAME = "TRAINING_JOB_NAME"
5050
S3_ENDPOINT_URL_ENV_NAME = "S3_ENDPOINT_URL"
5151

52+
# SELinux Enabled
53+
SELINUX_ENABLED = os.environ.get("SAGEMAKER_LOCAL_SELINUX_ENABLED", "False").lower() in ["1", "true", "yes"]
54+
5255
logger = logging.getLogger(__name__)
5356

5457

@@ -887,13 +890,14 @@ def __init__(self, host_dir, container_dir=None, channel=None):
887890

888891
self.container_dir = container_dir if container_dir else "/opt/ml/input/data/" + channel
889892
self.host_dir = host_dir
890-
if platform.system() == "Linux":
893+
map_format = "{}:{}"
894+
if platform.system() == "Linux" and SELINUX_ENABLED:
891895
# Support mounting shared volumes in SELinux enabled hosts
892-
self.container_dir += ":z"
896+
map_format += ":z"
893897
if platform.system() == "Darwin" and host_dir.startswith("/var"):
894898
self.host_dir = os.path.join("/private", host_dir)
895899

896-
self.map = "{}:{}".format(self.host_dir, self.container_dir)
900+
self.map = map_format.format(self.host_dir, self.container_dir)
897901

898902

899903
def _stream_output(process):

0 commit comments

Comments
 (0)