Skip to content

Conversation

@rhatdan
Copy link
Collaborator

@rhatdan rhatdan commented Nov 16, 2021

SELinux C library has two functions for dealing with file labels, one
which follows symlinks and one that does not.

Golang bindings should work the same way. The lack of this function is
resulting in containers/buildah#3630 which has
to hack around the problem.

Signed-off-by: Daniel J Walsh [email protected]

@rhatdan
Copy link
Collaborator Author

rhatdan commented Nov 16, 2021

This is a breaking change, but I think it is worth it, and probably affects almost nobody.

@rhatdan
Copy link
Collaborator Author

rhatdan commented Nov 16, 2021

@nalind PTAL

@rhatdan
Copy link
Collaborator Author

rhatdan commented Nov 16, 2021

@thaJeztah @kolyshkin @mrunalp PTAL

Comment on lines 64 to 65
// SetFileLabel sets the SELinux label for this path or returns an error.
// follow symlinks
Copy link
Collaborator

Choose a reason for hiding this comment

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

This have to be a complete sentence.

return setFileLabel(fpath, label)
}

// SetFileLabel sets the SELinux label for this path or returns an error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/SetFileLabel/LSetFileLabel/g

}

// SetFileLabel sets the SELinux label for this path or returns an error.
// does not follow symlinks
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the argument is a symbolic link, the label is set on the link itself. This function makes no attempt to follow the symlink.

Or somesuch.

Comment on lines 81 to 83
// LFileLabel returns the SELinux label for this path does not follow symlinks
// or returns an error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does not look like a valid English sentence.

return index, nil
}

// setFileLabel sets the SELinux label for this path or returns an error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/setFileLabel/lsetFileLabel/


// SetFileLabel sets the SELinux label for this path or returns an error.
// does not follow symlinks
func LSetFileLabel(fpath string, label string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it should be named LsetFileLabel as other similar functions have lowercase letter after L (os.Lstat, unix.Lsetxattr).

return string(label), nil
}

// fileLabel returns the SELinux label for this path or returns an error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

function name is wrong

func lfileLabel(fpath string) (string, error) {
if fpath == "" {
return "", ErrEmptyPath
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use lFileLabel.


label, err := getxattr(fpath, xattrNameSelinux)
if err != nil {
return "", &os.PathError{Op: "lgetxattr", Path: fpath, Err: err}
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: /slgetxattr/getxattr/

}

dest = make([]byte, sz)
sz, errno = doLgetxattr(path, attr, dest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo? s/doLgetxattr/dogetxattr/

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rhatdan ^^^

@rhatdan rhatdan force-pushed the lgetfile branch 4 times, most recently from 7902b0b to 71d5187 Compare November 18, 2021 12:42
@rhatdan
Copy link
Collaborator Author

rhatdan commented Nov 18, 2021

@kolyshkin @thaJeztah I think i have fixed all my cut and paste errors. PTAL

thaJeztah
thaJeztah previously approved these changes Nov 18, 2021
Copy link
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.

code LGTM

the remaining nits are for non-exported functions, not a show-stopper per-se


// setFileLabel sets the SELinux label for this path or returns an error.
func setFileLabel(fpath string, label string) error {
// lSetFileLabel sets the SELinux label for this path or returns an error.
Copy link
Member

Choose a reason for hiding this comment

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

nit: I guess this one also could use the "not following symlinks"

return nil
}

// setFileLabel sets the SELinux label for this path or returns an error.
Copy link
Member

Choose a reason for hiding this comment

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

nit: same

return string(label), nil
}

// lFileLabel returns the SELinux label for this path or returns an error.
Copy link
Member

Choose a reason for hiding this comment

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

nit: same

@thaJeztah
Copy link
Member

The only thing I'm wondering (w.r.t. breaking change); could there be cases where labels are set on /var/run/.... (which usually is a symlink to /run/... ?

@rhatdan
Copy link
Collaborator Author

rhatdan commented Nov 18, 2021

I think this change would not effect a path with a symlink in it, it only effects if the basename is a symlink.
So if you were trying to label /var/run, you would now label /run, and leave the /var/run symlink alone.

But if you were labeling /var/run/foobar, and foobar was a file, it would label the file correctly.

SELinux C library has two functions for dealing with file labels, one
which follows symlinks and one that does not.

Golang bindings should work the same way.  The lack of this function is
resulting in containers/buildah#3630 which has
to hack around the problem.

Signed-off-by: Daniel J Walsh <[email protected]>
Copy link
Collaborator

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM

@kolyshkin kolyshkin requested a review from thaJeztah November 19, 2021 03:22
@rhatdan rhatdan merged commit 66c8503 into opencontainers:main Nov 19, 2021
@thaJeztah
Copy link
Member

I think this change would not effect a path with a symlink in it, it only effects if the basename is a symlink. So if you were trying to label /var/run, you would now label /run, and leave the /var/run symlink alone.

But if you were labeling /var/run/foobar, and foobar was a file, it would label the file correctly.

Thanks! Makes sense (should probably have looked closer); agreed I don't expect that to be too problematic.

(post-merge LGTM - saw you addressed those last nits; thanks!)

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.

3 participants