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

podman pod create --pid flag #10894

Merged
merged 1 commit into from
Jul 15, 2021
Merged

Conversation

cdoern
Copy link
Contributor

@cdoern cdoern commented Jul 9, 2021

added support for --pid flag. User can specify ns:file, pod, private, or host pid namespace values. container returns an error since you cannot point the ns of the pods infra container
to a container outside of the pod.

Signed-off-by: cdoern [email protected]

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 9, 2021
@cdoern cdoern force-pushed the pidPod branch 2 times, most recently from bcc4d84 to 9474e69 Compare July 9, 2021 16:35
@rhatdan
Copy link
Member

rhatdan commented Jul 9, 2021

What does "pod" mean? Are you allowing pod's to join other pods pid namespace?

libpod/define/pod_inspect.go Outdated Show resolved Hide resolved
libpod/define/pod_inspect.go Outdated Show resolved Hide resolved
libpod/options.go Outdated Show resolved Hide resolved
if pod.valid {
return define.ErrPodFinalized
}
pod.config.Pid = inp
Copy link
Member

Choose a reason for hiding this comment

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

We need to require that UsePodPID is set in the pod configuration - we have to be sharing the pod PID namespace for this to be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to require that UsePodPID is set in the pod configuration - we have to be sharing the pod PID namespace for this to be set.

Should I require it by checking and erroring out if not set, or warn the user and set it for them?

Copy link
Member

Choose a reason for hiding this comment

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

Good question. I was leaning towards just erroring out unless the user passes --share as well to specify that the PID namespace is shared, but that seems like a bad user experience. @rhatdan Should setting --pid automatically cause the pod to share the PID namespace?

libpod/pod.go Outdated Show resolved Hide resolved
libpod/pod.go Outdated
@@ -170,6 +174,16 @@ func (p *Pod) CPUQuota() int64 {
return 0
}

// Pid returns the pod process id namespace value
Copy link
Member

Choose a reason for hiding this comment

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

This isn't getting the PID, but rather the path of the infra container's PID file?

It's also not really related to the PID namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was unsure here of what would be helpful here @mheon, because the namespace just contains pod or host or whatever the user passed or a ns file if specified. What would this be expected to return?

Copy link
Member

Choose a reason for hiding this comment

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

Returning the mode of the namespace is what I would expect - we want to tell the user how the pod was configured. The PID of the pod's init container isn't that valuable.

Copy link
Member

Choose a reason for hiding this comment

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

Similar comment here for me, I'd change the variable to indicate it's pidmode and not the pid to help make the support of this more clear months down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea @TomSweeneyRedHat. I will change to make it more explicit that it returns the mode passed by the user.

libpod/pod_api.go Outdated Show resolved Hide resolved
ns := spec.LinuxNamespace{}
pidVal := p.config.Pid.NSMode
if pidVal != "" {
if pidVal == "container" {
Copy link
Member

Choose a reason for hiding this comment

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

This validation should be done in the option (WithPid() so we only have to do it once and we can reject invalid configurations at creation time, not runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay @mheon , to streamline this and preserve the originally passed values I might make another InfraContainerConfig value that is an actual specs.LinuxNameSpace{}. This will allow me to be able to print the proper mode in podInspect but also not have to parse anything again in runtime_pod_infra_linux.go

libpod/runtime_pod_linux.go Outdated Show resolved Hide resolved
@@ -146,6 +147,17 @@ func (p *PodCreateOptions) CPULimits() *specs.LinuxCPU {
return cpu
}

func setNamespaces(p *PodCreateOptions) (specgen.Namespace, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggest renaming to "getPIDNamespace" or, alternatively, making this return a struct which identifies which namespace is which - right now this is only useful for setting the PID namespace, but eventually we'll end up with four-ish settable namespaces.

@@ -102,6 +102,13 @@ func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod
options = append(options, libpod.WithInfraCommand(p.InfraCommand))
}

if !p.Pid.IsDefault() {
options = append(options, libpod.WithPid(p.Pid))
if p.Pid.NSMode == "pod" {
Copy link
Member

Choose a reason for hiding this comment

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

This bit doesn't seem necessary?

pkg/domain/entities/pods.go Outdated Show resolved Hide resolved
libpod/options.go Outdated Show resolved Hide resolved
}
if p.config.UsePodPID {
ns := specs.LinuxNamespace{}
ns.Type = "pid"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we need to recreate the namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think specs.LinuxNameSpace{} is the type that the infra generator takes versus specgen.NameSpace, we need to switch over at some point and this is behind the scenes enough.

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh, I missed the type change. Hm. My concern would be forwards-compat - we need to make sure that pods from before this change, without a valid namespace in the DB, continue to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, the specgen.ParseNamespace() function I use in pkg/domain/entities/pods.go takes the type specgen.NameSpace so the actual validation and parsing relies more on the specgen version this is just a conversion. This switch will only execute when someone explicitly says --pid=... so would forwards-compat be a problem?

libpod/options.go Outdated Show resolved Hide resolved
@cdoern cdoern force-pushed the pidPod branch 2 times, most recently from 6740c45 to 66359de Compare July 9, 2021 20:03
@cdoern
Copy link
Contributor Author

cdoern commented Jul 9, 2021

What does "pod" mean? Are you allowing pod's to join other pods pid namespace?

pod means that the containers will default to using the pod's pid ns which is similar to private (the default). I added this because the specgen.parsenamespace() function utilizes this value so we are going to accept.

@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2021
libpod/pod.go Outdated
@@ -97,6 +98,8 @@ type InfraContainerConfig struct {
HasInfraContainer bool `json:"makeInfraContainer"`
NoNetwork bool `json:"noNetwork,omitempty"`
HostNetwork bool `json:"infraHostNetwork,omitempty"`
Pid specgen.Namespace `json:"infraPid,omitempty"`
LinuxPidNS specs.LinuxNamespace `json:"LinuxPIDNS,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Do we need both of these? I would imagine we can get the mode just by looking at the specs.LinuxNamespace - or, alternatively, generate the specs.LinuxNamespace from the specgen.Namespace when creating the infra container?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mheon I kept both of them in order to parse the Pid NS before runtime. The types are different as specgen.Namespace contains info like host or pod which I do use again at runtime but specs.LinuxNamespace is the actual NS struct containing pid and the proper path. Not sure if I can parse before runtime and not have both of these but I will look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@cdoern cdoern force-pushed the pidPod branch 4 times, most recently from 7d32fe8 to d044791 Compare July 13, 2021 22:03
@@ -120,6 +120,14 @@ Add a DNS alias for the container. When the container is joined to a CNI network

Disable creation of /etc/hosts for the pod.

#### **--pid**=*pid*

Set the PID mode for the pod Default is to create a private PID namespace for the pod. Requires PID NS to be shared.
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 having a hard time parsing this. Maybe?

Suggested change
Set the PID mode for the pod Default is to create a private PID namespace for the pod. Requires PID NS to be shared.
Set the PID mode for the pod. The default is to create a private PID namespace for the pod. Requires the PID namespace to be shared.

@@ -120,6 +120,14 @@ Add a DNS alias for the container. When the container is joined to a CNI network

Disable creation of /etc/hosts for the pod.

#### **--pid**=*pid*
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking "process ID (pid) when reading this. I'll let others over-rule me, but I'd rather the option be named something else, in case we ever manipulate the pid later down the road. Perhaps --pid-mode, regardless, at least change the variable:

Suggested change
#### **--pid**=*pid*
#### **--pid**=*pid-mode*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like --pid-ns might be more accurate if anything @TomSweeneyRedHat. Only thing is, container create calls it --pid

Copy link
Member

Choose a reason for hiding this comment

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

Ugh. They should be the same in both places, and it looks like Docker has gone with --pid too, so we probably ought to stay with --pid. Rather than *pid-mode* at line 123, I'd be fine with *pid-ns* if you prefer for the variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay @TomSweeneyRedHat I am good with keeping it as --pid, probably best so people don't get confused as to what this flag is compared to container create and docker

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM in general. Just two comments.

libpod/pod.go Outdated
@@ -97,6 +98,7 @@ type InfraContainerConfig struct {
HasInfraContainer bool `json:"makeInfraContainer"`
NoNetwork bool `json:"noNetwork,omitempty"`
HostNetwork bool `json:"infraHostNetwork,omitempty"`
Pid specgen.Namespace `json:"infraPid,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be called PidNS to prevent mistaking it for a process ID. Same at other places in the code.

But I do agree that --pid makes sense on the CLI to remain consistent with container create.

podCreate = podmanTest.Podman([]string{"pod", "create", "--pid", ns, "--share", "pid"})
podCreate.WaitWithDefaultTimeout()
Expect(podCreate).Should(ExitWithError())

Copy link
Member

Choose a reason for hiding this comment

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

Will the pid ns now be displayed in podman inspect? If so, it would be nice to exercise that here in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vrothberg we decided to output the NSMode the user gave us as it is more helpful, aka: path, pod, private... I will check for that here, thanks for calling that out!

@baude
Copy link
Member

baude commented Jul 15, 2021

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2021
@baude
Copy link
Member

baude commented Jul 15, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2021
added support for --pid flag. User can specify ns:file, pod, private, or host.
container returns an error since you cannot point the ns of the pods infra container
to a container outside of the pod.

Signed-off-by: cdoern <[email protected]>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2021
@cdoern
Copy link
Contributor Author

cdoern commented Jul 15, 2021

sorry had to re-push to fix a test, ran locally and all green. should be good now @baude

@rhatdan
Copy link
Member

rhatdan commented Jul 15, 2021

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 15, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cdoern, rhatdan

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

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 15, 2021
@ashley-cui
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2021
@openshift-merge-robot openshift-merge-robot merged commit 12b67aa into containers:main Jul 15, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants