Skip to content

Commit 6242c2a

Browse files
committed
mock: re-allow running mock as root
Turns out many users are running mock directly under root. So don't limit them. Moving the non-root check into simple_load_config() where it is still desired (third-party use of simple_load_config() was the original reason for adding the check). And changing the Exception into a warning. Complements: 1f2a06e Fixes: https://bugzilla.redhat.com/2135203 Fixes: #990 Fixes: #991
1 parent 01bb5b7 commit 6242c2a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mock/py/mockbuild/config.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import socket
1717
import sys
18+
import warnings
1819

1920
from templated_dictionary import TemplatedDictionary
2021
from . import exception
@@ -613,11 +614,6 @@ def update_config_from_file(config_opts, config_file):
613614
# better form of configuration (like YAML, json, or so?). But historically
614615
# the configuration is just a python-syntax file, so as a poor safety
615616
# measure we disallow this for root (saved set-*IDs checked, too!)
616-
for the_id in getresuid() + getresgid():
617-
if the_id != 0:
618-
continue
619-
raise exception.ConfigError("Can't parse Mock configuration under root")
620-
621617
try:
622618
exec(content) # pylint: disable=exec-used
623619
except Exception as exc:
@@ -764,6 +760,16 @@ def list_configs(config_opts):
764760
@traceLog()
765761
def simple_load_config(name, config_path=None):
766762
""" wrapper around load_config() intended by use 3rd party SW """
763+
764+
for the_id in getresuid() + getresgid():
765+
if the_id != 0:
766+
continue
767+
warnings.warn(
768+
"Parsing Mock configuration as root is highly discouraged, "
769+
"see https://rpm-software-management.github.io/mock/#setup"
770+
)
771+
break
772+
767773
if config_path is None:
768774
config_path = MOCKCONFDIR
769775
return load_config(config_path, name)

0 commit comments

Comments
 (0)