cmd/root: Don't validate subordinate IDs when generating the completions

Ever since commit bafbbe81c9, the shell completions are generated
while building Toolbx using the 'completion' command.  This involves
running toolbox(1) itself, and hence validating the subordinate user and
group ID ranges.

Unfortunately, some build environments, like openSUSE's, don't have
subordinate ID ranges set up.  Therefore, it's better to not validate
the subordinate ID ranges when generating the shell completions, since
they are generated by Cobra itself and subordinate ID ranges are not
involved at all.

Note that subordinate ID ranges may be needed when the generated shell
completions are actually used in interactive command line environments.
The shell completions invoke the hidden '__complete' command to get the
results that are presented to the user, and, if needed, the subordinate
ID ranges will continue to be used by podman(1) as part of that.

Some changes by Debarshi Ray.

https://github.com/containers/toolbox/issues/1246
https://github.com/containers/toolbox/pull/1249
This commit is contained in:
Jan Zerebecki 2023-03-01 19:52:28 +01:00 committed by Debarshi Ray
parent 816a7cab9e
commit f555029304

View file

@ -401,6 +401,11 @@ func validateSubIDRanges(cmd *cobra.Command, args []string, user *user.User) (bo
return true, nil
}
if cmdName, completionCmdName := cmd.Name(), completionCmd.Name(); cmdName == completionCmdName {
logrus.Debugf("Look-up not needed: command %s doesn't need them", cmdName)
return true, nil
}
if _, err := utils.ValidateSubIDRanges(user); err != nil {
logrus.Debugf("Looking for sub-GID and sub-UID ranges: %s", err)
return false, newSubIDError()