Skip to content

Commit

Permalink
Tweak message when cgroups are not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
EtiennePerot committed Oct 3, 2024
1 parent eaa142a commit ab75cde
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions open-webui/functions/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,18 +2210,18 @@ def check_platform(cls):
@classmethod
def check_cgroups(cls):
"""
Verifies that cgroupfs is mounted and usable for resource limit enforcement.
Verifies that cgroupfs is mounted and usable for resource limiting.
:return: Nothing.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limit enforcement.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limiting.
"""
if not os.path.exists("/sys/fs/cgroup"):
raise cls.EnvironmentNeedsSetupException(
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
if not os.path.exists("/sys/fs/cgroup/cgroup.subtree_control"):
raise cls.EnvironmentNeedsSetupException(
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2"
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2, or disable resource limiting if appropriate"
)
# Try to open the file for writing to see if we can actually control cgroups.
# They may be mounted read-only, as is default with Docker.
Expand All @@ -2233,16 +2233,16 @@ def check_cgroups(cls):
except OSError:
if os.geteuid() != 0:
raise cls.EnvironmentNeedsSetupException(
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root"
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root, or disable resource limiting if appropriate"
)
raise cls.EnvironmentNeedsSetupException(
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
with open("/sys/fs/cgroup/cgroup.controllers", "rb") as subtree_control_f:
controllers = subtree_control_f.read().decode("ascii").split(" ")
if "memory" not in controllers:
raise cls.EnvironmentNeedsSetupException(
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it"
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it, or disable resource limiting if appropriate"
)

@classmethod
Expand Down
14 changes: 7 additions & 7 deletions open-webui/tools/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,18 +1658,18 @@ def check_platform(cls):
@classmethod
def check_cgroups(cls):
"""
Verifies that cgroupfs is mounted and usable for resource limit enforcement.
Verifies that cgroupfs is mounted and usable for resource limiting.
:return: Nothing.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limit enforcement.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limiting.
"""
if not os.path.exists("/sys/fs/cgroup"):
raise cls.EnvironmentNeedsSetupException(
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
if not os.path.exists("/sys/fs/cgroup/cgroup.subtree_control"):
raise cls.EnvironmentNeedsSetupException(
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2"
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2, or disable resource limiting if appropriate"
)
# Try to open the file for writing to see if we can actually control cgroups.
# They may be mounted read-only, as is default with Docker.
Expand All @@ -1681,16 +1681,16 @@ def check_cgroups(cls):
except OSError:
if os.geteuid() != 0:
raise cls.EnvironmentNeedsSetupException(
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root"
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root, or disable resource limiting if appropriate"
)
raise cls.EnvironmentNeedsSetupException(
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
with open("/sys/fs/cgroup/cgroup.controllers", "rb") as subtree_control_f:
controllers = subtree_control_f.read().decode("ascii").split(" ")
if "memory" not in controllers:
raise cls.EnvironmentNeedsSetupException(
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it"
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it, or disable resource limiting if appropriate"
)

@classmethod
Expand Down
14 changes: 7 additions & 7 deletions src/safecode/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,18 +1217,18 @@ def check_platform(cls):
@classmethod
def check_cgroups(cls):
"""
Verifies that cgroupfs is mounted and usable for resource limit enforcement.
Verifies that cgroupfs is mounted and usable for resource limiting.
:return: Nothing.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limit enforcement.
:raises EnvironmentNeedsSetupException: If cgroupfs is not mounted or unusable for resource limiting.
"""
if not os.path.exists("/sys/fs/cgroup"):
raise cls.EnvironmentNeedsSetupException(
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs not mounted as /sys/fs/cgroup but necessary for the sandbox to enforce memory limits; please mount it (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
if not os.path.exists("/sys/fs/cgroup/cgroup.subtree_control"):
raise cls.EnvironmentNeedsSetupException(
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2"
"/sys/fs/cgroup/cgroup.subtree_control not found; make sure you are using cgroups v2, or disable resource limiting if appropriate"
)
# Try to open the file for writing to see if we can actually control cgroups.
# They may be mounted read-only, as is default with Docker.
Expand All @@ -1240,16 +1240,16 @@ def check_cgroups(cls):
except OSError:
if os.geteuid() != 0:
raise cls.EnvironmentNeedsSetupException(
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root"
"This script is not running as root, but it needs to do so in order to enforce resource limits; please run as root, or disable resource limiting if appropriate"
)
raise cls.EnvironmentNeedsSetupException(
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`)"
"cgroupfs is not mounted writable but necessary for the sandbox to enforce memory limits; please remount it as writable (`--mount=type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly=false`), or disable resource limiting if appropriate"
)
with open("/sys/fs/cgroup/cgroup.controllers", "rb") as subtree_control_f:
controllers = subtree_control_f.read().decode("ascii").split(" ")
if "memory" not in controllers:
raise cls.EnvironmentNeedsSetupException(
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it"
"cgroupfs does not have the 'memory' controller enabled, necessary to enforce memory limits; please enable it, or disable resource limiting if appropriate"
)

@classmethod
Expand Down

0 comments on commit ab75cde

Please sign in to comment.