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

linux: reject sysctl kernel.domainname when OCI knob domainname is set #1017

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Oct 1, 2022

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

@flouthoc
Copy link
Collaborator Author

flouthoc commented Oct 1, 2022

Previous discussion here: opencontainers/runtime-spec#1156 (comment)

@flouthoc
Copy link
Collaborator Author

flouthoc commented Oct 1, 2022

@giuseppe @AkihiroSuda PTAL, I think we should block kernel.domainname but I think then runc would also need this change so that there is parity.

@flouthoc flouthoc marked this pull request as draft October 1, 2022 11:47
@flouthoc flouthoc marked this pull request as ready for review October 1, 2022 12:18
@rhatdan
Copy link
Member

rhatdan commented Oct 1, 2022

@kolyshkin WDYT?

@AkihiroSuda
Copy link

AkihiroSuda commented Oct 1, 2022

It is still a valid sysctl value and not rejected in the Runtime spec, so no need to reject it in crun/runc IMHO

@flouthoc
Copy link
Collaborator Author

flouthoc commented Oct 1, 2022

@AkihiroSuda Ah while writing/running tests it looked like, kernel.domainname has a conflicting nature with the new field domainname. I did a quick check in runc code I think other sysctls are blocked because of same reason ( See: https://github.com/opencontainers/runc/blob/main/libcontainer/configs/validate/validator.go#L207 )

But if we decide to allow this, should we specify which one will take priority is it sysctl or the field domainname ?

Edit: there is also this line in validator https://github.com/opencontainers/runc/blob/main/libcontainer/configs/validate/validator.go#L203

@giuseppe
Copy link
Member

giuseppe commented Oct 2, 2022

I think we should reject the sysctl only when the domainname value is also set.

Otherwise, we risk breaking older users that were using the sysctl directly.

@flouthoc flouthoc changed the title linux: reject sysctl kernel.domainname in favor of OCI knob domainname linux: reject sysctl kernel.domainname when OCI knob domainname is set Oct 3, 2022
// conflict with already set field `domainname` in
// OCI spec, in such scenario crun will fail to prevent
// unexpected behaviour for end user.
return crun_make_error (err, 0, "the sysctl `%s` conflicts with OCI field `domainname`", original_value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably no need to raise an error if strcmp(name, def->domainname) == 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda I think you meant strcmp(original_value, def->domainname) , since name is the key of sysctl which is kernel.domainname.

I have added this condition and also a test for this.

@flouthoc flouthoc force-pushed the reject-sysctl-domainname branch 2 times, most recently from ee34c11 to 2c73b88 Compare October 3, 2022 03:17
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

Following commit ensures that crun rejects sysctl `kernel.domainname`
when OCI field `domainname` is already set.

Signed-off-by: Aditya R <arajan@redhat.com>
@flouthoc flouthoc requested review from AkihiroSuda and giuseppe and removed request for AkihiroSuda October 3, 2022 03:30
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@flouthoc
Copy link
Collaborator Author

Runc issue for similar PR: opencontainers/runc#3629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants