Skip to content

Adds MLSEnabled function.#192

Merged
thaJeztah merged 1 commit intoopencontainers:mainfrom
badochov:is_selinux_mls_enabled
Oct 21, 2022
Merged

Adds MLSEnabled function.#192
thaJeztah merged 1 commit intoopencontainers:mainfrom
badochov:is_selinux_mls_enabled

Conversation

@badochov
Copy link
Copy Markdown
Contributor

@rhatdan
Copy link
Copy Markdown
Collaborator

rhatdan commented Oct 19, 2022

LGTM
@thaJeztah @kolyshkin @vrothberg @giuseppe PTAL

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Thanks! left comments inline


// isMLSEnabled checks if MLS is enabled.
func isMLSEnabled() bool {
enabledB, err := os.ReadFile(selinuxMLSEnabledPath())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see it's done in other places as well, but I think the selinuxMLSEnabledPath() may be a bit "too much abstraction", especially as we only use it in a single place; perhaps just inline it;

	enabledB, err := os.ReadFile(filepath.Join(getSelinuxMountPoint(), "mls"))

return false
}

return !bytes.Equal(enabledB, []byte{'1'})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be the reverse? (i.e., it return true if the file contains 1 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ooooh!

/*
 * Function: is_selinux_mls_enabled()
 * Return:   1 on success
 *	     0 on failure
 */

Hm.. right; perhaps would be good to add a comment there to describe it (perhaps also with that link) to explain this is really correct 😅.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need the reverse it, in the linked code I see:

	if (!strcmp(buf, "1"))
		enabled = 1;

Doesn't that mean the function returns 1 when buf is "1"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@giuseppe yes you're right

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i was going through this line and documentation of strcmo multiple times I have no idea how I convoced myself to be wrong so many times

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OH MY! 🤦 for some reason I completely didn't spot that as well. Thanks @giuseppe !!! (it adds to my dislike of "too many booleans")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +216 to +217
// IsMLSEnabled checks if MLS is enabled.
func IsMLSEnabled() bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's more conventional in Go to omit Is prefixes (as the bool return already describes it's a boolean result). (Same for Get (and Set), but that's already in the code, so we can't reverse that 😂).

Perhaps (same for the non-exported variants);

// MLSEnabled checks if MLS is enabled.
func MLSEnabled() bool {

Which will be called as selinux.MLSEnabled(), e.g.

if selinux.MLSEnabled() {
    // do magic stuff!
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank for information :D. I didn't change name of the helper as i could figure out any other name that would be sane and unexported.

Comment on lines +98 to +100
func isMLSEnabled() bool {
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs a return;

func isMLSEnabled() bool {
	return false
}

@thaJeztah
Copy link
Copy Markdown
Member

@badochov you may have missed my last comment;

This needs a return;

func isMLSEnabled() bool {
	return false
}

While updating, could you also update the commit message (change IsMLSEnabled to MLSEnabled )?

@thaJeztah
Copy link
Copy Markdown
Member

Oh, never mind, I see you also didn't address the other comment yet 😅 (let me know when it's updated 👍 )

@badochov
Copy link
Copy Markdown
Contributor Author

@thaJeztah I've updated the PR.

@thaJeztah thaJeztah changed the title Adds IsMLSEnabled function. Adds MLSEnabled function. Oct 19, 2022
thaJeztah
thaJeztah previously approved these changes Oct 19, 2022
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Closes #176.

Signed-off-by: Hubert Badocha <[email protected]>
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing!

@giuseppe PTAL

Copy link
Copy Markdown
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.

Thanks

LGTM

@thaJeztah
Copy link
Copy Markdown
Member

Let me bring this one in; I see @rhatdan already gave a "conceptual" approval, so looks like it should be good to go.

Thanks @badochov !

@thaJeztah thaJeztah merged commit 41ff4c2 into opencontainers:main Oct 21, 2022
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.

Checking if MLS is enabled

4 participants