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

api/pre-1.44: Default ReadOnlyNonRecursive to true #47391

Merged
merged 2 commits into from Feb 27, 2024

Conversation

vvoland
Copy link
Contributor

@vvoland vvoland commented Feb 15, 2024

Don't change the behavior for older clients and keep the same behavior.

- How to verify it
TestContainerBindMountReadOnlyDefault

- Description for the changelog

- To preserve backwards compatibility, read-only mounts are not recursive by default when using older clients (API version < v1.44).

- A picture of a cute animal (not mandatory but encouraged)

return errdefs.InvalidParameter(errors.New("BindOptions.ReadOnlyForceRecursive needs API v1.44 or newer"))
} else {
bo = &mount.BindOptions{}
hostConfig.Mounts[idx].BindOptions = bo
Copy link
Contributor Author

@vvoland vvoland Feb 15, 2024

Choose a reason for hiding this comment

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

Note: This is needed, because m.BindOptions = ... would only overwrite the BindOptions in the m variable which is a local copy of the original mount and not a reference to the Mount in hostConfig.Mounts.

@vvoland
Copy link
Contributor Author

vvoland commented Feb 15, 2024

Failure related, test needs adjustment:

=== Failed
=== FAIL: amd64.integration-cli TestDockerCLIRunSuite/TestRunMount (0.08s)
    docker_cli_run_test.go:4396: assertion failed: err is not nil: got error while creating a container with [--mount type=bind,src=/tmp/mount1181042325/mnt1,dst=/foo --mount type=bind,src=/tmp/mount1181042325/mnt2,dst=/bar] (mount-0-0)
    --- FAIL: TestDockerCLIRunSuite/TestRunMount (0.08s)

EDIT: Oh, actually it's not the test, ReadOnlyNonRecursive was set true also for non-readonly mounts which made it error out. Changed the default to only apply for m.ReadOnly mounts.

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@vvoland
Copy link
Contributor Author

vvoland commented Feb 16, 2024

Looks like some failures are related:

      Command:  /usr/local/cli-integration/docker run -d -v /vol1 -v /tmp/test-put-container-archive-err-symlink-in-volume-to-read-only-rootfs-1579682919:/vol2 -v /tmp/test-put-container-archive-err-symlink-in-volume-to-read-only-rootfs-1579682919/vol3:/vol3 -v /tmp/test-put-container-archive-err-symlink-in-volume-to-read-only-rootfs-1579682919/vol_ro:/vol_ro:ro --read-only busybox /bin/sh -c #(nop)
        ExitCode: 125
        Error:    exit status 125
        Stdout:   
        Stderr:   /usr/local/cli-integration/docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/test-put-container-archive-err-symlink-in-volume-to-read-only-rootfs-1579682919/vol_ro.
        See '/usr/local/cli-integration/docker run --help'.

Parsing added by this PR doesn't return-early in case of error, so not sure yet why that happens..

@vvoland vvoland force-pushed the rro-backwards-compatible branch 2 times, most recently from 6694464 to 8057434 Compare February 19, 2024 13:04
api/server/router/container/container_routes.go Outdated Show resolved Hide resolved
api/server/router/container/container_routes.go Outdated Show resolved Hide resolved
}
}
newBinds = append(newBinds, b)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this clear the Binds field after they've been migrated?

Also wondering if this migration should always happen, so also on current API versions 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't migrate all Binds (yet), only the read-only ones to reduce potential blast area.

Was planning to make a separate PR that would also deprecate the Binds field and transform all of them to Mounts.

@vvoland vvoland force-pushed the rro-backwards-compatible branch 3 times, most recently from f4db0f9 to 1f7ccf9 Compare February 20, 2024 10:47
@vvoland
Copy link
Contributor Author

vvoland commented Feb 20, 2024

This looks green now, failures are unrelated and are caused by Docker Hub search API being down.

api/types/backend/backend.go Outdated Show resolved Hide resolved
daemon/create.go Outdated Show resolved Hide resolved
@vvoland vvoland force-pushed the rro-backwards-compatible branch 2 times, most recently from 8539542 to 6e21f36 Compare February 22, 2024 10:23
@@ -426,6 +426,69 @@ func TestContainerCopyLeaksMounts(t *testing.T) {
assert.Equal(t, mountsBefore, mountsAfter)
}

func TestContainerBindMountReadOnlyDefault(t *testing.T) {
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 we need a to check if rro is supported on the kernel for the test to function properly.

Alternatively, we could just check the registered mountpoints in the API to see if the option is set as expected.

Copy link
Member

Choose a reason for hiding this comment

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

Also sorry, one more check, test should be skipped if api version is < 1.44.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? It also tests that the behavior doesn't change when <1.44 API is requested.

Copy link
Member

Choose a reason for hiding this comment

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

So yes technically the 1.43 test should pass on an older daemon.
But the 1.44 test would fail since it is not a supported version.

Copy link
Contributor Author

@vvoland vvoland Feb 26, 2024

Choose a reason for hiding this comment

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

1.44 test will be skipped: 0f8270b#diff-0ac47068153ec59b77b2044bd459fb6395f028e6e112dc03645f7ba72f324bf2R456

But yeah the version: "" would fail, updated it to also be skipped.

Also, added the test for api.MinSupportedAPIVersion client version.

Don't error out when mount source doesn't exist and mounts has
`CreateMountpoint` option enabled.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Don't change the behavior for older clients and keep the same behavior.
Otherwise client can't opt-out (because `ReadOnlyNonRecursive` is
unsupported before 1.44).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable upgrading RO mounts to RRO when a client speaks API older than v1.44 (Docker v25)
4 participants