Commit Graph

3465 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
2ce811e632 migrate to github.com/moby/sys/user/userns
The userns package in libcontainer was integrated into the moby/sys/user
module at commit [3778ae603c706494fd1e2c2faf83b406e38d687d][1].

The userns package is used in many places, and currently either depends
on runc/libcontainer, or on containerd, both of which have a complex
dependency tree. This patch is part of a series of patches to unify the
implementations, and to migrate toward that implementation to simplify
the dependency tree.

[1]: 3778ae603c

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-25 12:47:34 +02:00
Jameson Hyde
5282cb25d0 If url includes scheme, urlPath will drop hostname, which would not match the auth check
Signed-off-by: Jameson Hyde <jameson.hyde@docker.com>
(cherry picked from commit 754fb8d9d03895ae3ab60d2ad778152b0d835206)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-07-15 18:43:48 +02:00
Jameson Hyde
2ac8a479c5 Authz plugin security fixes for 0-length content and path validation
Signed-off-by: Jameson Hyde <jameson.hyde@docker.com>

fix comments

(cherry picked from commit 9659c3a52bac57e615b5fb49b0652baca448643e)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-07-15 18:43:43 +02:00
Akihiro Suda
7083f1fb55 Merge pull request #48108 from thaJeztah/internalize_pkg_directory
pkg/directory: deprecate, and move to internal
2024-07-02 15:52:56 +09:00
Akihiro Suda
9db812f691 Merge pull request #48109 from thaJeztah/remove_pkg_dmesg
pkg/dmesg: remove deprecated package
2024-07-02 15:52:29 +09:00
Sebastiaan van Stijn
efdaca2792 pkg/rootless/specconv: move to internal
This package is only used by the daemon, so move it to the internal
rootless package instead.

Note that technically this could be in daemon/internal, but as there's
already an existing internal/rootless package (which needs to be in the
top-level internal package because it's also used by /plugin), I'm moving
it there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-01 21:05:19 +02:00
Sebastiaan van Stijn
b7d26f2f8f pkg/dmesg: remove deprecated package
This package was deprecated in 805ccd2365
and is no longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-01 20:55:06 +02:00
Sebastiaan van Stijn
3a3bb1cb50 pkg/directory: deprecate, and move to internal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-01 20:44:31 +02:00
Sebastiaan van Stijn
80900bdbcd pkg/directory: fix comment, and remove import comments
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-01 20:43:27 +02:00
Brian Goff
f3d377e422 Merge pull request #48097 from thaJeztah/internalize_containerfs
pkg/containerfs: move to internal
2024-07-01 16:09:48 +00:00
Paweł Gronowski
2427c4bf92 Merge pull request #48101 from thaJeztah/capabilities_internal
pkg/capabilities move to daemon/internal
2024-07-01 17:40:09 +02:00
Sebastiaan van Stijn
c0dd5c18f6 Merge pull request #48081 from thaJeztah/gofumpt
do another run of gofumpt
2024-07-01 16:17:54 +02:00
Sebastiaan van Stijn
d80a3f2e48 pkg/capabilities move to daemon/internal
This package was added in 8f936ae8cf, and
never had external consumers. Let's move it internal.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-01 00:49:15 +02:00
Sebastiaan van Stijn
f2970e5358 pkg/containerfs: move to internal
The only external consumer are the `graphdriver` and `graphdriver/shim`
packages in github.com/docker/go-plugins-helpers, which depended on
[ContainerFS][1], which was removed in 9ce2b30b81.

graphdriver-plugins were deprecated in 6da604aa6a,
and support for them removed in 555dac5e14,
so removing this should not be an issue.

Ideally this package would've been moved inside `daemon/internal`, but it's used
by the `daemon` (cleanupContainer), `plugin` package, and by `graphdrivers`,
so needs to be in the top-level `internal/` package.

[1]: 6eecb7beb6/graphdriver/api.go (L218)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-30 19:13:23 +02:00
Sebastiaan van Stijn
a3e6ce95c4 pkg/containerfs: cleanup GoDoc, and make Windows a proper wrapper
- Improve some GoDoc to use docs links
- Change the Windows stub to an actual wrapper function, as we don't
  want it to be updateable, and it currently shows as "variable" on
  pkg.go.dev, which is confusing.
- Remove "import" comments in preparation of moving this package

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-30 19:13:16 +02:00
Sebastiaan van Stijn
e2ae6907c6 pkg/containerfs: remove CleanScopedPath and make it internal
The container package is the only consumer of this function in our code
and there's no known external users;
https://grep.app/search?q=.CleanScopedPath%28&filter[lang][0]=Go

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-30 18:18:02 +02:00
Sebastiaan van Stijn
969993a729 pkg/archive: createTarFile: consistently use the same value for userns
createTarFile accepts a opts (TarOptions) argument to specify whether
userns is enabled; whe should consider always detecting locally, but
at least make sure we're consistently working with the same value within
this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-28 12:21:03 +02:00
Sebastiaan van Stijn
379ce56cd8 pkg/archive: handleTarTypeBlockCharFifo: don't discard EPERM errors
This function was discarding EPERM errors if it detected that userns was
enabled; move such checks to the caller-site, so that they can decide
how to handle the error (which, in case of userns may be to log and ignore).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-28 12:11:52 +02:00
Sebastiaan van Stijn
af85e47343 pkg/archive: getWhiteoutConverter: don't error with userns enabled
Since 838047a1f5, the overlayWhiteoutConverter
is supported with userns enabled, so we no longer need this check.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-28 12:05:13 +02:00
Sebastiaan van Stijn
56fa45773f pkg/plugins: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 23:18:49 +02:00
Sebastiaan van Stijn
0e2d40c24a pkg/archive: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 23:18:49 +02:00
Sebastiaan van Stijn
d4160d5aa7 pkg/archive: reformat code to make #nosec comment work again
Looks like the way it picks up #nosec comments changed, causing the
linter error to re-appear;

    pkg/archive/archive_linux.go:57:17: G305: File traversal when extracting zip/tar archive (gosec)
                    Name:       filepath.Join(hdr.Name, WhiteoutOpaqueDir),
                                ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-26 02:08:00 +02:00
Sebastiaan van Stijn
48ff86ec64 pkg/longpath: AddPrefix: use early returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 12:04:26 +02:00
Sebastiaan van Stijn
424c22390e pkg/longpath: deprecate Prefix const
This const was exported because it was in use by pkg/symlink. This
dependency was removed in a48c6e3005,
after which this const was only used internally.

This patch deprecates the const and introduces a non-exported const
to use.

There are no known external consumers of this const, so we may skip
deprecating it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 12:03:27 +02:00
Sebastiaan van Stijn
680e6d6e1c Merge pull request #48000 from thaJeztah/nosec_comments
pkg/archive. pkg/tarsum: format #nosec comments to standard format
2024-06-17 11:46:25 +02:00
Sebastiaan van Stijn
c114b5e6f0 Merge pull request #47997 from thaJeztah/pkg_archive_no_longpath
pkg/archive, pkg/chrootarchive: remove dependency on pkg/longpath
2024-06-17 11:43:59 +02:00
Sebastiaan van Stijn
9c7f20e255 Merge pull request #48003 from thaJeztah/pkg_archive_cleanup
pkg/archive: assorted minor refactors and cleanups
2024-06-17 11:11:42 +02:00
Sebastiaan van Stijn
21a7686862 Merge pull request #47995 from thaJeztah/stringid_cleanups
pkg/stringid: deprecate ValidateID, IsShortID
2024-06-17 10:55:06 +02:00
Sebastiaan van Stijn
e788628e2e Merge pull request #48005 from thaJeztah/pkg_archive_rm_kernelversion_check
pkg/archive: TestChangesDirsEmpty, TestChangesDirsMutated: no kernel-version check
2024-06-17 10:34:36 +02:00
Akihiro Suda
ec4bac431c Merge pull request #47999 from thaJeztah/deprecate_pkg_dmesg
pkg/dmesg: deprecate, and use internal utility instead
2024-06-17 01:50:53 +09:00
Akihiro Suda
ff652c82e9 Merge pull request #48001 from thaJeztah/pkg_archive_deprecate_CanonicalTarNameForPath
pkg/archive: deprecate CanonicalTarNameForPath
2024-06-17 01:50:21 +09:00
Sebastiaan van Stijn
3108165c94 pkg/archive: TestChangesDirsEmpty, TestChangesDirsMutated: no kernel-version check
TestChangesDirsEmpty and TestChangesDirsMutated fail on Windows V19H1 (1903)
and up, possibly due to changes in the kernel:

    === FAIL: github.com/docker/docker/pkg/archive TestChangesDirsEmpty (0.21s)
    changes_test.go:261: Reported changes for identical dirs: [{\dirSymlink C}]

    === FAIL: github.com/docker/docker/pkg/archive TestChangesDirsMutated (0.14s)
    changes_test.go:391: unexpected change "C \\dirSymlink" "\\dirnew"

commit 8f4b3b0ad4 added a version-dependent
skip for those tests, but as we no longer run CI on versions before V19H1,
we can remove the kernel-version check, and skip it on Windows unconditionally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 18:40:50 +02:00
Sebastiaan van Stijn
17ca8b62bd pkg/archive: remove uses of iota
While using iota can be convenient, it can also make it harder to grasp
what value is assigned. Use of iota also makes changing values implicit;
changing the order of these consts implicitly means their value changes.

This can be problematic, as some of these consts are a plain `int` and
while golang is strong-typed, it does allow plain `int` values to be
used for such values.

For example, `archive.Tar` accepts a `Compression` as second argument,
but allows a plain int to be passed, so both of these are equivalent;

    archive.Tar(contextDir, archive.Uncompressed)
    archive.Tar(contextDir, 0)

This patch removes the use of `iota`, and instead explicitly setting a
value for each to prevent accidental changes in their value, which can
be hard to discover.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
94caeeb401 pkg/archive: don't call system.Lgetxattr on unsupported platforms
[pkg/system.Lgetxattr] is only implemented on Linux, and always produces
an ErrNotSupportedPlatform on other platforms.

This patch removes the call to this function, but intentionally leaves
it commented-out as a reminder to include this code if this would ever
be refactored and implemented on other platforms.

[pkg/system.Lgetxattr]: d1273b2b4a/pkg/system/xattrs_unsupported.go (L1-L8)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
c565a3a1fe pkg/archive: collectFileInfo: don't create FileInfo if unused
The system.Lstat may fail, in which case it would be discarded,
so let's move it later.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
7ce1edd7c6 pkg/archive: deprecate NewTempArchive, TempArchive
These were added in baacae8345, but are
currently only used in tests inside pkg/archive. There are no external
users of this function, so we should deprecated them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:07:47 +02:00
Sebastiaan van Stijn
92b8d93f47 pkg/archive: deprecate CanonicalTarNameForPath
Commit d59758450b changed this function to
be a wrapper for `filepath.ToSlash`. It was used in the CLI for the classic
builder, but is no longer used in our codebase.

However, there may still be some consumers that copied the CLI code for the
classic builder that didn't synchronise their implementation yet, so let's
deprecate this function to give them a warning that they should no longer
use this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 16:56:25 +02:00
Sebastiaan van Stijn
0ffc0c95e6 pkg/tarsum: format #nosec comments to standard format
gosec uses a non-standard format for "automated" comments to suppress
false positives (such comments should not have a leading space, but
are not allowed to start with a non-alphabetical character). However,
current versions of gosec do allow a leading space.

This patch reformats the comments to prevent them from being changed
by IDEs when reformating code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 14:31:27 +02:00
Sebastiaan van Stijn
cb19b59b65 pkg/archive: format #nosec comments to standard format
gosec uses a non-standard format for "automated" comments to suppress
false positives (such comments should not have a leading space, but
are not allowed to start with a non-alphabetical character). However,
current versions of gosec do allow a leading space.

This patch reformats the comments to prevent them from being changed
by IDEs when reformating code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 14:31:18 +02:00
Sebastiaan van Stijn
805ccd2365 pkg/dmesg: deprecate, and use internal utility instead
This package was originally added in 46833ee1c3
for use in the devicemapper graphdriver. The devicemapper graphdriver was
deprecated and has been removed. The only remaining consumer is an integration
test.

Deprecate the package and mark it for removal in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 12:41:39 +02:00
Sebastiaan van Stijn
c7f4abc14a pkg/dmesg: use unix.SYSLOG_ACTION_READ_ALL instead of local variable
This value was originally added in 46833ee1c3,
at which time golang.org/x/sys/unix didn't have utilities for this syscall.
A later patch switched the implementation to use the golang/x/sys/unix
implementation in 2841b05b71, but kept the
local variable.

golang.org/x/sys now has a const for this, so let's use it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 12:41:39 +02:00
Sebastiaan van Stijn
9389f76f6d pkg/chrootarchive: remove dependency on pkg/longpath
Copy the function to the package, so that we don't have a dependency
on pkg/longpath.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 17:32:08 +02:00
Sebastiaan van Stijn
f657a75bf6 pkg/archive: remove dependency on pkg/longpath
Copy the function to the package, so that we don't have a dependency
on pkg/longpath.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 17:30:13 +02:00
Sebastiaan van Stijn
2100a70741 pkg/stringid: deprecate IsShortID
This function is no longer used, and has no external users. Deprecated
the function and mark if for removal for the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 15:35:07 +02:00
Sebastiaan van Stijn
e19e6cf7f4 pkg/stringid: deprecate ValidateID
This function is only used for the legacy v1 image format.

Deprecate the function, and make image/v1 self-contained.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 15:34:38 +02:00
Sebastiaan van Stijn
0566e38cbf Merge pull request #47605 from jonasgeiler/43626-rootless-native-overlay-diff
rootless: overlay2: support native overlay diff when using rootless-mode in kernel 5.11 and above
2024-06-10 18:57:19 +02:00
Sebastiaan van Stijn
cf796aa56a pkg/reexec: touch-up GoDoc, and remove "import" comments
Touch-up some GoDoc in the package, and remove "import" comments.

This package is used in BuildKit, and could be a potential candidate
for moving to a separate module. The "import" comments are ignored when
used in go module mode so have little benefit. Let's remove them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:13 +02:00
Sebastiaan van Stijn
d20a074f33 pkg/reexec: remove gotest.tools from tests
This package is used in BuildKit, and could be a potential candidate
for moving to a separate module. While it's not too problematic to have
this dependency, the tests only used basic assertions from gotest.tools,
which could be easily re-implemented without the dependency.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:12 +02:00
Sebastiaan van Stijn
defd5a08f4 pkg/reexec: unify non-Linux implementation of Command
The Windows, Darwin, and FreeBSD implementations were identical, other
than their GoDoc to be different. Unify them so that we don't have to
maintain separate GoDoc for each.

It's worth noting that FreeBSD also supports Pdeathsig, so could be
using the same implementation as Linux. However, we don't test/maintain
the FreeBSD implementation, and it would require updating to GoDoc to
be more specific about the use of `/proc/self/exe`, so keeping the
status quo for now.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:12 +02:00
Sebastiaan van Stijn
004451c812 pkg/reexec: unify implementation of Self() and remove stub
This combines the implementations of the Self function, to allow having
a single GoDoc to document the behavior. The naiveSelf function is kept,
because it's used in unit-tests.

There is a minor change in behavior, as this patch removes the stub for
unsupported platforms (non-linux, windows, freebsd or darwin), which will
now use `os.Args[0]`. The stub was added in 21537b818d
to fix compilation of https://github.com/ethereum/go-ethereum on OpenBSD,
which had docker/docker as dependency. It looks like that repository no
longer has this dependency, and as this was only to make the code
compilable, is unlikely to be a problem.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:11 +02:00