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

reduce the chance of parsing /etc/passwd & /etc/group #4042

Closed
wants to merge 1 commit into from

Conversation

lifubang
Copy link
Member

@lifubang lifubang commented Sep 28, 2023

According to #3998 (comment), we can do the third step to reduce the chance of parsing /etc/passwd & /etc/group when start or exec to a container.

Because in runtime-spec(https://github.com/opencontainers/runtime-spec/blob/v1.0.2/config.md#posix-platform-user), uid, gid, and additionalGids are all defined as a numeric field/array. It is no need to parse a numeric id from /etc/passwd or /etc/group, except $HOME is empty or gid is not provided(But runtime-spec said gid is required).

@lifubang lifubang marked this pull request as draft September 28, 2023 16:31
libcontainer/init_linux.go Outdated Show resolved Hide resolved
libcontainer/init_linux.go Outdated Show resolved Hide resolved
@lifubang lifubang force-pushed the feat-RemovePasswd branch 3 times, most recently from 42d0004 to 3cd5c86 Compare September 28, 2023 16:51
Signed-off-by: lifubang <lifubang@acmcoder.com>
@lifubang lifubang marked this pull request as ready for review September 28, 2023 17:10
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

The number to string to number conversion is ugly.

I think we should do a change like this:

@@ -68,8 +68,9 @@ type initConfig struct {
        ProcessLabel     string                `json:"process_label"`
        AppArmorProfile  string                `json:"apparmor_profile"`
        NoNewPrivileges  bool                  `json:"no_new_privileges"`
-       User             string                `json:"user"`
-       AdditionalGroups []string              `json:"additional_groups"`
+       UID              int                   `json:"uid"`
+       GID              int                   `json:"gid"`
+       AdditionalGroups []int                 `json:"additional_groups"`
        Config           *configs.Config       `json:"config"`
        Networks         []*network            `json:"network"`
        PassedFilesCount int                   `json:"passed_files_count"`

and the rest will be greatly simplified.

@kolyshkin
Copy link
Contributor

I think we should do a change like this:

and the same for Process struct:

        // Env specifies the environment variables for the process.
        Env []string
 
-       // User will set the uid and gid of the executing process running inside the container
+       // UID and GID of the executing process running inside the container
        // local to the container's user and group configuration.
-       User string
+       UID, GID int
 
        // AdditionalGroups specifies the gids that should be added to supplementary groups
        // in addition to those that the user belongs to.
-       AdditionalGroups []string
+       AdditionalGroups []int
 
        // Cwd will change the processes current working directory inside the container's rootfs.
        Cwd string

@kolyshkin
Copy link
Contributor

In fact, I forgot I had the code doing all that already. Rebased it, PTAL: #3999

@lifubang
Copy link
Member Author

OK, thanks, leave one to save our reviewing time.

@lifubang lifubang closed this Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants