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

skip write /proc/self/attr/keycreate when selinux label is null #214

Closed
wants to merge 1 commit into from

Conversation

ningmingxiao
Copy link
Contributor

@ningmingxiao ningmingxiao commented Jul 29, 2024

@ningmingxiao
Copy link
Contributor Author

@kolyshkin

@thaJeztah
Copy link
Member

Looks like your commit is missing a DCO sign-off in the commit message; can you add one? When doing so, please use your real name for the sign-off (not your github handle/username); you can find some instructions in the output from the DCO check here; https://github.com/opencontainers/selinux/pull/214/checks?check_run_id=28026773649

@ningmingxiao
Copy link
Contributor Author

Looks like your commit is missing a DCO sign-off in the commit message; can you add one? When doing so, please use your real name for the sign-off (not your github handle/username); you can find some instructions in the output from the DCO check here; https://github.com/opencontainers/selinux/pull/214/checks?check_run_id=28026773649

done

@thaJeztah
Copy link
Member

Thanks! Oh minor nit; label is a string, but the commit message says when selinux label is null

Perhaps;

SetKeyLabel: ignore empty selinux labels

Looking at the change; it looks like we don't have a test-case for setting an empty label; would probably be good to add one;

func TestKeyLabel(t *testing.T) {
needSELinux(t)
label := "system_u:object_r:container_t:s0:c1,c2"
if err := selinux.SetKeyLabel(label); err != nil {
t.Fatal(err)
}
nlabel, err := selinux.KeyLabel()
if err != nil {
t.Fatal(err)
}
if label != nlabel {
t.Errorf("KeyLabel %s != %s", nlabel, label)
}
}

@thaJeztah
Copy link
Member

In general; I see that previously we would try to set an empty label, but then ignore the error if it was a os.ErrPermission.

Slightly wondering, but maybe out of scope for this PR (and I could use input from @kolyshkin and @rhatdan on this);

  • Should (ideally?) empty labels be handled by the caller (i.e. don't call SetKeyLabel if there's no label)
  • And instead SetKeyLabel returning an error (invalid label)?

Somewhat related to the above; could there be valid use-cases of trying to unset this? (so could an empty label have the intent of "unset" what's there?). I see you linked to a runc PR;

Looking at that PR;

  • I think it might be more correct for the caller (runc) to not call SetKeyLabel if there's no value to set?
  • Also looking at the code, I see various instances of defer selinux.SetKeyLabel("") - do we know what the intent there was? Was the intent to reset values that were previously set?

Because if that's the case, then possibly this PR is actually hiding a bug / incorrect use in runc, and it would be better for SetKeyLabel to return an error on empty values.

Screenshot 2024-07-29 at 11 20 42

@ningmingxiao
Copy link
Contributor Author

we should let runc do it

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.

2 participants