-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
libct: wrap more unix errors #3270
Conversation
Rebased on git tip to fix 🔴 CI |
When I tried to start a rootless container under a different/wrong user, I got: $ ../runc/runc --systemd-cgroup --root /tmp/runc.$$ run 445 ERRO[0000] runc run failed: operation not permitted This is obviously not good enough. With this commit, the error is: ERRO[0000] runc run failed: fchown fd 9: operation not permitted Alas, there are still some code that returns unwrapped errnos from various unix calls. This is a followup to commit d8ba412 which wrapped many, but not all, bare unix errors. Do wrap some more, using either os.PathError or os.SyscallError. While at it, - use os.SyscallError instead of os.NewSyscallError; - use errors.Is(err, os.ErrXxx) instead of os.IsXxx(err). Signed-off-by: Kir Kolyshkin <[email protected]>
|
Probably unrelated
|
I tried restarting, but for some reason that doesn't appear to work (clicked "re-run job" as well as "re-run failed jobs" from the dropdown 🤔 |
Cirrus CI is actually working (https://cirrus-ci.com/task/4825507825975296), but the result won't be synced back to GitHub web UI until it completes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"LGTM" (❤️ the improved errors); but left a suggestion / comment
@@ -412,7 +413,7 @@ func fixStdioPermissions(config *initConfig, u *user.ExecUser) error { | |||
} { | |||
var s unix.Stat_t | |||
if err := unix.Fstat(int(fd), &s); err != nil { | |||
return err | |||
return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(int(fd)), Err: err} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably mostly a nit, but wondering, given that fd
is a uintptr
, if FormatUint()
would be a closer fit?
return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(int(fd)), Err: err} | |
return &os.PathError{Op: "fstat", Path: "fd " + strconv.FormatUint(uint64(fd), 10), Err: err} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I should propose a strconv.UItoa()
function in Golang 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably mostly a nit, but wondering, given that
fd
is auintptr
, ifFormatUint()
would be a closer fit?
It still needs a typecast, and adds additional argument (10
). I like Atoi because it's a tad shorter.
The difference between FormatInt and FormatUint is latter do not check if the argument is negative.
All in all, it's all the same here, I don't see how one way is better than the other.
I'm even fine with fmt.Sprintf("fd %d", fs)
-- it is slower but we don't care since it's an error path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like Atoi because it's a tad shorter.
Yes, I wish there was a strconv.UItoa()
All in all, it's all the same here, I don't see how one way is better than the other.
It was mostly a nit; wondering if gosec
will complain about it once we enabled it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
When I tried to start a rootless container under a different/wrong user,
I got:
This is obviously not good enough. With this commit, the error is:
ERRO[0000] runc run failed: fchown fd 9: operation not permitted
Alas, there are still some code that returns unwrapped errnos from
various unix calls.
This is a followup to commit d8ba412 (part of PR #3011) which wrapped
many, but not all, bare unix errors. Do wrap some more, using either os.PathError
or os.SyscallError.
While at it,
Signed-off-by: Kir Kolyshkin [email protected]