Skip to content

Commit 6894b64

Browse files
committed
linux: reject sysctl kernel.domainname in favor of OCI knob domainname
Setting sysctl `kernel.domainname` directly by user is not environment agnostic, it shows either incorrect ( on non-working ) behaviour in `rootless` environment. It was decided to make this part of `runtime-spec` so the OCI runtime can itself handle this behaviour correctly. As a result a new field `domainname` was added to `runtime-spec`. Since crun already implementes this field therefore `sysctl` configured by user conflicts with the behaviour expected by the OCI runtime. Runtime-spec PR: opencontainers/runtime-spec#1156 Furthermore a similar `sysctl` `kernal.hostname` is blocked by crun explicitly to prevent this conflicting behaviour. https://github.com/containers/crun/blob/main/src/libcrun/linux.c#L3203 Signed-off-by: Aditya R <[email protected]>
1 parent 4934df9 commit 6894b64

File tree

2 files changed

+17
-35
lines changed

2 files changed

+17
-35
lines changed

src/libcrun/linux.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,13 +3191,7 @@ validate_sysctl (const char *original_value, const char *name, unsigned long nam
31913191
}
31923192

31933193
if (strcmp (name, "kernel/domainname") == 0)
3194-
{
3195-
if (namespaces_created & CLONE_NEWUTS)
3196-
return 0;
3197-
3198-
namespace = "UTS";
3199-
goto fail;
3200-
}
3194+
return crun_make_error (err, 0, "the sysctl `%s` conflicts with OCI field `domainname`", original_value);
32013195

32023196
if (strcmp (name, "kernel/hostname") == 0)
32033197
return crun_make_error (err, 0, "the sysctl `%s` conflicts with OCI field `hostname`", original_value);

tests/test_start.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -199,34 +199,22 @@ def test_uts_sysctl():
199199
if cid is not None:
200200
run_crun_command(["delete", "-f", cid])
201201

202-
conf = base_config()
203-
conf['process']['args'] = ['/init', 'true']
204-
add_all_namespaces(conf, utsns=False)
205-
conf['linux']['sysctl'] = {'kernel.domainname' : 'foo'}
206-
cid = None
207-
try:
208-
_, cid = run_and_get_output(conf)
209-
sys.stderr.write("unexpected success\n")
210-
return -1
211-
except:
212-
return 0
213-
finally:
214-
if cid is not None:
215-
run_crun_command(["delete", "-f", cid])
216-
217-
conf = base_config()
218-
conf['process']['args'] = ['/init', 'true']
219-
add_all_namespaces(conf)
220-
conf['linux']['sysctl'] = {'kernel.domainname' : 'foo'}
221-
cid = None
222-
try:
223-
_, cid = run_and_get_output(conf)
224-
return 0
225-
except:
226-
return -1
227-
finally:
228-
if cid is not None:
229-
run_crun_command(["delete", "-f", cid])
202+
# setting kernel.domainname must always fail.
203+
for utsns in [True, False]:
204+
conf = base_config()
205+
conf['process']['args'] = ['/init', 'true']
206+
add_all_namespaces(conf, utsns=utsns)
207+
conf['linux']['sysctl'] = {'kernel.domainname' : 'foo'}
208+
cid = None
209+
try:
210+
_, cid = run_and_get_output(conf)
211+
sys.stderr.write("unexpected success\n")
212+
return -1
213+
except:
214+
return 0
215+
finally:
216+
if cid is not None:
217+
run_crun_command(["delete", "-f", cid])
230218
return 0
231219

232220
def test_start():

0 commit comments

Comments
 (0)