From a6d46ed1a750e95abc042879aed06ab72cadf5a8 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 28 Aug 2023 19:15:22 -0700 Subject: [PATCH 1/3] runc exec: improve options parsing 1. Do not ask for the same option value twice. 2. For tty, we always want false, unless specified, and this is what GetBool gets us. Signed-off-by: Kir Kolyshkin --- exec.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/exec.go b/exec.go index 675f12fb9..0d1250b69 100644 --- a/exec.go +++ b/exec.go @@ -219,9 +219,9 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) { } p := spec.Process p.Args = context.Args()[1:] - // override the cwd, if passed - if context.String("cwd") != "" { - p.Cwd = context.String("cwd") + // Override the cwd, if passed. + if cwd := context.String("cwd"); cwd != "" { + p.Cwd = cwd } if ap := context.String("apparmor"); ap != "" { p.ApparmorProfile = ap @@ -240,17 +240,14 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) { // append the passed env variables p.Env = append(p.Env, context.StringSlice("env")...) - // set the tty - p.Terminal = false - if context.IsSet("tty") { - p.Terminal = context.Bool("tty") - } + // Always set tty to false, unless explicitly enabled from CLI. + p.Terminal = context.Bool("tty") if context.IsSet("no-new-privs") { p.NoNewPrivileges = context.Bool("no-new-privs") } - // override the user, if passed - if context.String("user") != "" { - u := strings.SplitN(context.String("user"), ":", 2) + // Override the user, if passed. + if user := context.String("user"); user != "" { + u := strings.SplitN(user, ":", 2) if len(u) > 1 { gid, err := strconv.Atoi(u[1]) if err != nil { From d6e427e1ea95f9012bb811ab84ece6d3bb59747a Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 28 Aug 2023 19:28:52 -0700 Subject: [PATCH 2/3] runc exec: avoid stuttering in error messages An error from strconv.Atoi already contains the text it fails to parse. Because of that, errors look way too verbose, e.g.: [root@kir-rhat runc-tst]# ./runc exec --user 1:1:1 2345 true ERRO[0000] exec failed: parsing 1:1 as int for gid failed: strconv.Atoi: parsing "1:1": invalid syntax With this patch, the error looks like this now: [root@kir-rhat runc]# ./runc exec --user 1:1:1 2345 true ERRO[0000] exec failed: bad gid: strconv.Atoi: parsing "1:1": invalid syntax Still not awesome, but better. Signed-off-by: Kir Kolyshkin --- exec.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exec.go b/exec.go index 0d1250b69..ad8a369a5 100644 --- a/exec.go +++ b/exec.go @@ -251,13 +251,13 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) { if len(u) > 1 { gid, err := strconv.Atoi(u[1]) if err != nil { - return nil, fmt.Errorf("parsing %s as int for gid failed: %w", u[1], err) + return nil, fmt.Errorf("bad gid: %w", err) } p.User.GID = uint32(gid) } uid, err := strconv.Atoi(u[0]) if err != nil { - return nil, fmt.Errorf("parsing %s as int for uid failed: %w", u[0], err) + return nil, fmt.Errorf("bad uid: %w", err) } p.User.UID = uint32(uid) } From 2cb46c6e0df4cd0d62bebdc8242afb3330810814 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 13 Jun 2024 08:03:08 -0700 Subject: [PATCH 3/3] script/keyring_validate.sh: fix a typo Signed-off-by: Kir Kolyshkin --- script/keyring_validate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/keyring_validate.sh b/script/keyring_validate.sh index 20a0b8561..cb331f62e 100755 --- a/script/keyring_validate.sh +++ b/script/keyring_validate.sh @@ -73,7 +73,7 @@ echo "------------------------------------------------------------" gpg --show-keys <"$root/$project.keyring" echo "------------------------------------------------------------" -# Check that each entry in the kering is actually a maintainer's key. +# Check that each entry in the keyring is actually a maintainer's key. while IFS="" read -d $'\0' -r block || [ -n "$block" ]; do username="$(sed -En "s|^Comment:.* github=(\w+).*|\1|p" <<<"$block")"