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

[release-1.x backport] logName(): lazily lookup userName instead of on init() #144

Conversation

thaJeztah
Copy link

backport of #143 for the release-1.x branch

What this PR does / why we need it:

Commit c46b9e1 (#123, and backported to v1 through #124) implemented a workaround for situations on Windows where user.Current() was not available.

On Linux/Unix ennvironments, user.Current() may be calling (among others) getgrnam_r (https://linux.die.net/man/3/getgrgid_r), which:

Returns a pointer to a structure containing the broken-out fields of
the record in the group database (e.g., the local group file /etc/group,
NIS, and LDAP) that matches the group name name.

This means that the init() function might be making network connections,
which is not desirable.

This patch changes the lookup to be performed lazily. A sync.Once was
added so that lookup is only performed once (to keep the behavior that
was previously provided by using init().

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Relates to #123
Relates to docker/cli#2420

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

If accepted, I would like this to see this backported to the v1 branch (and possibly included in a v1.0.1 or v1.0.2 release)

Release note:

Perform userName lookup lazily, instead of on init()

Commit c46b9e1 implemented
a workaround for situations on Windows where `user.Current()`
was not available.

On Linux/Unix ennvironments, `user.Current()` may be calling
(among others) `getgrnam_r` (https://linux.die.net/man/3/getgrgid_r),
which:

> Returns a pointer to a structure containing the broken-out fields of
> the record in the group database (e.g., the local group file /etc/group,
> NIS, and LDAP) that matches the group name name.

This means that the `init()` function might be making network connections,
which is not desirable.

This patch changes the lookup to be performed lazily. A `sync.Once` was
added so that lookup is only performed once (to keep the behavior that
was previously provided by using `init()`.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 134f148)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 11, 2020
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: thaJeztah
To complete the pull request process, please assign lavalamp
You can assign the PR to them by writing /assign @lavalamp in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@thaJeztah
Copy link
Author

/assign @neolit123
/assign @dims

@neolit123
Copy link
Member

ideally backports should include only critical bug fixes. how can we tell if is this one?

@thaJeztah
Copy link
Author

Perhaps it's not critical (let me /cc @tiborvass on this, who I think looked into this at some point w.r.t. what kind of calls user.Current() made)

@dims
Copy link
Member

dims commented Jul 26, 2020

/close

let's close this for now.

@k8s-ci-robot
Copy link

@dims: Closed this PR.

In response to this:

/close

let's close this for now.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants