Skip to content

Commit

Permalink
error when isolation chroot and network is set
Browse files Browse the repository at this point in the history
Folluow up to commit 4c9fc47. This only check for the given flags,
however users may have BUILDAH_ISOLATION set in which case this error
path was not triggered and caused confusion.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Jun 15, 2023
1 parent c089488 commit d6b43c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/buildah/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ func runCmd(c *cobra.Command, args []string, iopts runInputOptions) error {
if err != nil {
return err
}
if c.Flag("network").Changed && c.Flag("isolation").Changed {
if c.Flag("network").Changed {
if isolation == buildah.IsolationChroot {
if ns := namespaceOptions.Find(string(specs.NetworkNamespace)); ns != nil {
if !ns.Host {
return fmt.Errorf("cannot set --network other than host with --isolation %s", c.Flag("isolation").Value.String())
return fmt.Errorf("cannot set --network other than host with isolation %s", isolation)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) (
// Following log line is used in integration test.
logrus.Debugf("Setting MaxPullPushRetries to %d and PullPushRetryDelay to %v", iopts.Retry, pullPushRetryDelay)

if c.Flag("network").Changed && c.Flag("isolation").Changed {
if c.Flag("network").Changed {
if isolation == define.IsolationChroot {
if ns := namespaceOptions.Find(string(specs.NetworkNamespace)); ns != nil {
if !ns.Host {
return options, nil, nil, fmt.Errorf("cannot set --network other than host with --isolation %s", c.Flag("isolation").Value.String())
return options, nil, nil, fmt.Errorf("cannot set --network other than host with isolation %s", isolation)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ RUN ping -c 1 4.2.2.2
_EOF

run_buildah 125 build --network=none --isolation=chroot $WITH_POLICY_JSON ${TEST_SCRATCH_DIR}
expect_output --substring "cannot set --network other than host with --isolation chroot"
expect_output --substring "cannot set --network other than host with isolation chroot"

BUILDAH_ISOLATION=chroot run_buildah 125 build --network=none $WITH_POLICY_JSON ${TEST_SCRATCH_DIR}
expect_output --substring "cannot set --network other than host with isolation chroot"
}

@test "bud with .dockerignore #1" {
Expand Down
4 changes: 2 additions & 2 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ $output"
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
cid=$output
run_buildah 125 run --isolation=chroot --network=none $cid sh -c 'echo "nameserver 110.110.0.110" >> /etc/resolv.conf; cat /etc/resolv.conf'
expect_output --substring "cannot set --network other than host with --isolation chroot"
expect_output --substring "cannot set --network other than host with isolation chroot"
run_buildah rm -a
}

Expand All @@ -769,7 +769,7 @@ $output"
cid=$output
# should fail by default
run_buildah 125 run --isolation=chroot --network=none $cid wget google.com
expect_output --substring "cannot set --network other than host with --isolation chroot"
expect_output --substring "cannot set --network other than host with isolation chroot"
}

@test "run --network=private must mount a fresh /sys" {
Expand Down

0 comments on commit d6b43c3

Please sign in to comment.