Skip to content
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

WithAppendAdditionalGroups: better /etc/group handling #9494

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

rumpl
Copy link
Member

@rumpl rumpl commented Dec 8, 2023

Scratch images don't necessarily have the /etc/group file, so we shouldn't fail if opening/parsing it is not needed: if all the group to add are numeric.

@thaJeztah thaJeztah added cherry-pick/1.6.x Change to be cherry picked to release/1.6 branch cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch labels Dec 8, 2023
oci/spec_opts.go Outdated
Comment on lines 898 to 903
if err != nil {
return err
if !os.IsNotExist(err) {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make it a real one-line change;

if err != nil && !os.IsNotExist(err) {

(could also use errors.Is(err, fs.ErrNotExist) / errors.Is(err, os.ErrNotExist))

Copy link
Member Author

Choose a reason for hiding this comment

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

In other parts of the code os.IsNotExist(err) is used, I can switch though if you really want

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with either os.IsNotExist(err) or errors.Is(); ISTR os.IsNotExist also had some code to handle some corner-cases for cgroups (which isn't handled by errors.Is), so changing it in other places would depend on what it's used for.

Was mostly looking at the "make it a one-line", as it slightly reduces cognitive overload (in already complex code). Not an absolute dealbreaker, but as we're changing it 🤷‍♂️

@rumpl rumpl force-pushed the fix-append-additonal-groups branch from 5745d20 to ee4b602 Compare December 11, 2023 11:05
@rumpl rumpl changed the title Don't fail appending additional groups if /etc/group not found WithAppendAddiotionalGroups: better /etc/group handling Dec 11, 2023
@rumpl rumpl force-pushed the fix-append-additonal-groups branch from ee4b602 to b876a37 Compare December 11, 2023 11:25
@thaJeztah
Copy link
Member

In a follow-up we should probably also look at other parts of the code that read /etc/groups and /etc/password, and check if all of those should produce an error, or if it would be an "expected" case, and we could fallback (more specifically; if no explicit user-id or group is looked for)

@rumpl rumpl force-pushed the fix-append-additonal-groups branch from b876a37 to 1cf3094 Compare December 11, 2023 13:40
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.

LGTM, but left one more comment 🙈 (sorry, didn't notice that earlier)

oci/spec_opts.go Outdated
Comment on lines 897 to 898
var ugroups []user.Group
var groupErr error
ugroups, groupErr = user.ParseGroupFile(gpath)
if groupErr != nil && !os.IsNotExist(groupErr) {
Copy link
Member

Choose a reason for hiding this comment

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

Not a show-stopper, but just realised we don't really need the var declarations here, and could keep the original;

Suggested change
var ugroups []user.Group
var groupErr error
ugroups, groupErr = user.ParseGroupFile(gpath)
if groupErr != nil && !os.IsNotExist(groupErr) {
ugroups, groupErr := user.ParseGroupFile(gpath)
if groupErr != nil && !os.IsNotExist(groupErr) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@rumpl rumpl force-pushed the fix-append-additonal-groups branch from 1cf3094 to 5a3ab59 Compare December 12, 2023 09:07
Scratch images don't necessarily have the /etc/group file, so we shouldn't
fail if opening/parsing it is not needed: if all the group to add are numeric.

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
@rumpl rumpl force-pushed the fix-append-additonal-groups branch from 5a3ab59 to 1398186 Compare December 12, 2023 14:25
@rumpl rumpl changed the title WithAppendAddiotionalGroups: better /etc/group handling WithAppendAdditionalGroups: better /etc/group handling Dec 12, 2023
return err
ugroups, groupErr := user.ParseGroupFile(gpath)
if groupErr != nil && !os.IsNotExist(groupErr) {
return groupErr
Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking a bit more about this, I think we want to ignore this error completely, no matter what the error is unless the file is needed. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

imho it would be good to keep this error check and return early in case of parsing error. looking into user.ParseGroupFile impl it does not seem to guarantee nil result on error. so the remaining logic would potentially be processing partially parsed results.

@estesp estesp added this pull request to the merge queue Dec 13, 2023
Merged via the queue into containerd:main with commit 565cc91 Dec 13, 2023
45 checks passed
@fuweid fuweid added cherry-picked/1.7.x PR commits are cherry-picked into release/1.7 branch and removed cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch labels Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick/1.6.x Change to be cherry picked to release/1.6 branch cherry-picked/1.7.x PR commits are cherry-picked into release/1.7 branch size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants