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

Move the HostConfig portion of Inspect inside libpod #3522

Merged
merged 3 commits into from
Jul 18, 2019

Conversation

mheon
Copy link
Member

@mheon mheon commented Jul 8, 2019

When we first began writing Podman, we ran into a major issue when implementing Inspect. Libpod deliberately does not tie its internal data structures to Docker, and stores most information about containers encoded within the OCI spec. However, Podman must present a CLI compatible with Docker, which means it must expose all the information in 'docker inspect' - most of which is not contained in the OCI spec or libpod's Config struct.

Our solution at the time was the create artifact. We JSON'd the complete CreateConfig (a parsed form of the CLI arguments to 'podman run') and stored it with the container, restoring it when we needed to run commands that required the extra info.

Over the past month, I've been looking more at Inspect, and refactored large portions of it into Libpod - generating them from what we know about the OCI config and libpod's (now much expanded, versus previously) container configuration. This path comes close to completing the process, moving the last part of inspect into libpod and removing the need for the create artifact.

This improves libpod's compatability with non-Podman containers. We no longer require an arbitrarily-formatted JSON blob to be present to run inspect.

Fixes: #3500

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2019
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon

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-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 8, 2019
@mheon
Copy link
Member Author

mheon commented Jul 8, 2019

Still to do: There are a few things that I need to add as spec annotations so we can still retrieve them. I also need to remove the calls to create the artifact.

@mheon mheon force-pushed the nix_the_artifact branch from de59c44 to 7f62732 Compare July 8, 2019 23:29
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2019
@mheon
Copy link
Member Author

mheon commented Jul 9, 2019

Alright, this one's shaping up nicely. I need to hit a few TODOs tomorrow, but it's basically ready for review.

@mheon
Copy link
Member Author

mheon commented Jul 9, 2019

Downsides of this:

  • We lose a few (small) things in inspect for old containers that weren't created by Podman with this patch. --security-opt and --privileged being the biggest.
  • If you downgrade, new containers will cause inspect to segfault (no create artifact)

@mheon
Copy link
Member Author

mheon commented Jul 9, 2019

Build fails on windows... I'll fix it tomorrow.

if err != nil {
return nil, err
}
for _, cap := range g.Config.Process.Capabilities.Bounding {
Copy link
Member Author

Choose a reason for hiding this comment

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

@rhatdan PTAL at this section. I'm thinking Bounding is the safest set of capabilities to compute against, but I could be wrong.

Copy link
Member

Choose a reason for hiding this comment

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

Best we got.

// We are a device node. Get major/minor.
sysstat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return errors.Errorf("Could not convert stat output for use")
Copy link
Member

Choose a reason for hiding this comment

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

Need a better error message, this means nothing to me.

if err != nil {
return nil, err
}
for _, cap := range g.Config.Process.Capabilities.Bounding {
Copy link
Member

Choose a reason for hiding this comment

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

Best we got.

@rhatdan
Copy link
Member

rhatdan commented Jul 9, 2019

Overall LGTM

@mheon mheon force-pushed the nix_the_artifact branch from 5766612 to ce98117 Compare July 10, 2019 13:07
@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

Everything except --security-opt should be done now.

@mheon mheon changed the title [WIP] Move the HostConfig portion of Inspect inside libpod Move the HostConfig portion of Inspect inside libpod Jul 10, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2019
@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

The last thing I wanted to check was blkio-weight-device, but it seems like Fedora kernels don't even support that... I think we're good here.

@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

Oh, wait, one more thing to do - need to retrieve the side of the TTY, if one is created.

@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

Note to self: Conmon PID inside of inspect is wrong. Conmon double-forks to daemonize, so we can't use the PID of our direct child.

@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

Conclusion on TTY size: I don't think it's possible without Conmon changes. Should be good to merge without it - the old version of Inspect didn't include it either.

@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

@@ -188,21 +176,11 @@ func iterateInput(ctx context.Context, size bool, args []string, runtime *adapte
break
}
} else {
libpodInspectData, err := ctr.Inspect(size)
data, err = ctr.Inspect(size)
if err != nil {
inspectError = errors.Wrapf(err, "error getting libpod container inspect data %s", ctr.ID())
Copy link
Member

Choose a reason for hiding this comment

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

we prob should drop the libpod bits here ... container should suffice?

@baude
Copy link
Member

baude commented Jul 10, 2019

have you compared before and after performance to make sure we didnt regress?

LGTM

@mheon
Copy link
Member Author

mheon commented Jul 10, 2019

It seemed identical, but my system is fast enough that both finish in well under a second.

We could get better numbers on something slower, I think.

@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #3521) made this pull request unmergeable. Please resolve the merge conflicts.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2019
@mheon mheon force-pushed the nix_the_artifact branch from 2d5d6a7 to e60a27f Compare July 11, 2019 14:50
@mheon
Copy link
Member Author

mheon commented Jul 11, 2019

Rebased

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2019
@mheon mheon force-pushed the nix_the_artifact branch 3 times, most recently from 2e180e2 to 922c747 Compare July 15, 2019 19:34
@mheon
Copy link
Member Author

mheon commented Jul 15, 2019

@vrothberg @giuseppe @rhatdan @baude Any chance I can get a held LGTM here? Need this landed to do some further work on inspect

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

just an inline question, otherwise LGTM

@@ -461,8 +462,21 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
return errors.Wrapf(define.ErrInternal, "container create failed")
}
ctr.state.PID = ss.si.Pid
if cmd.Process != nil {
ctr.state.ConmonPID = cmd.Process.Pid
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 still need cmd.Process.Pid when ctr.config.ConmonPidFile == ""?

Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't get a correct PID in this case (it was always off because of the double-fork). We won't be able to get a PID for old containers without ConmonPidFile set, but no PID is better than reporting an incorrect PID.

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.

Just a nit. But LGTM.

// This is very expensive to initialize.
// So we don't want to initialize it unless we absolutely have to - IE,
// there are things that require a major:minor to path translation.
var deviceNodes map[string]string
Copy link
Member

Choose a reason for hiding this comment

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

Nit of a nit: sync.Once can help hiding such details in the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

That actually breaks error propagation - Do can't return errors that occur during the function. We can wire up manual error handling with closures, but at that point we're at roughly the same line count.

@mheon
Copy link
Member Author

mheon commented Jul 17, 2019

Pushed a fresh version adding --security-opt in. We're now basically completely compatible except for terminal size, which is... difficult, and requires conmon changes. And probably isn't particularly important.

mheon and others added 3 commits July 17, 2019 16:48
When we first began writing Podman, we ran into a major issue
when implementing Inspect. Libpod deliberately does not tie its
internal data structures to Docker, and stores most information
about containers encoded within the OCI spec. However, Podman
must present a CLI compatible with Docker, which means it must
expose all the information in 'docker inspect' - most of which is
not contained in the OCI spec or libpod's Config struct.

Our solution at the time was the create artifact. We JSON'd the
complete CreateConfig (a parsed form of the CLI arguments to
'podman run') and stored it with the container, restoring it when
we needed to run commands that required the extra info.

Over the past month, I've been looking more at Inspect, and
refactored large portions of it into Libpod - generating them
from what we know about the OCI config and libpod's (now much
expanded, versus previously) container configuration. This path
comes close to completing the process, moving the last part of
inspect into libpod and removing the need for the create
artifact.

This improves libpod's compatability with non-Podman containers.
We no longer require an arbitrarily-formatted JSON blob to be
present to run inspect.

Fixes: containers#3500

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Our previous method (just read the PID that we spawned) doesn't
work - Conmon double-forks to daemonize, so we end up with a PID
pointing to the first process, which dies almost immediately.

Reading from the PID file gets us the real PID.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
We can infer no-new-privileges. For now, manually populate
seccomp (can't infer what file we sourced from) and
SELinux/Apparmor (hard to tell if they're enabled or not).

Signed-off-by: Matthew Heon <mheon@redhat.com>
@mheon mheon force-pushed the nix_the_artifact branch from 922c747 to c91bc31 Compare July 17, 2019 20:48
@mheon
Copy link
Member Author

mheon commented Jul 17, 2019

If anyone wants to merge once it's green, would be appreciated.

@mheon
Copy link
Member Author

mheon commented Jul 17, 2019

/retest

@rhatdan
Copy link
Member

rhatdan commented Jul 18, 2019

/test images

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, pulling the trigger...

@vrothberg
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 18, 2019
@openshift-merge-robot openshift-merge-robot merged commit 7488ed6 into containers:master Jul 18, 2019
@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 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman-inspect segfault on infra-container
8 participants