3718 Commits

Author SHA1 Message Date
Derek McGowan
315891dd2e Remove import comments
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:45 -08:00
Derek McGowan
e4236c93d9 Remove unused pkg/system functions
These were previously only used for pkg/archive

Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:44 -08:00
Derek McGowan
12b2b56fa6 Update archive to use fs.FileInfo over custom stat
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:44 -08:00
Derek McGowan
bb3e95dfdc Update archive to use unix.Mknod directly
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:44 -08:00
Derek McGowan
35b9525f9a Update archive to use its own xattr funcs
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:44 -08:00
Derek McGowan
1b4cbea3a8 Update archive to use time operations directly
Update archive time logic to mirror containerd's

Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-19 10:13:33 -08:00
Sebastiaan van Stijn
4f5ec9994c pkg/reexec: deprecate and migrate to github.com/moby/sys/reexec
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-19 10:12:58 +01:00
Albin Kerouanton
ca85ba2e82 Merge pull request #49114 from thaJeztah/deprecate_BridgeNfIptables_fields
Deprecate BridgeNfIptables and BridgeNfIp6tables fields
2024-12-18 09:22:36 +01:00
Sebastiaan van Stijn
8fd177d79b pkg/reexec: Command: separate public API from implementation
Move the exported `Command` to a platform-agnostic file, and un-export
the platform-specific implementations. This allows us to maintain the
GoDoc in a single place, describing platform-specific differences where
needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-17 10:51:06 +01:00
Sebastiaan van Stijn
6568c06d12 pkg/reexec: make platform-agnostic (again)
The reexec package originally was platform-agnostic, but gained some
Linux-specific handling in 1cb17f03d0.

When Windows support was implemented in Docker, the pkg/reexec package
was adjusted accordingly in 64715c4f33,
which now made the package with with either Linux or Windows, with various
other platforms (freebsd, solaris, darwin) being added back in separate
changes.

Based on the history above, this package should be platform-agnostic, except
for Linux-specific changes introduced in 1cb17f03d0
and 5aee8807a6.

This patch:

- removes the stub-implementation to make it functional on other platforms.
- renames the files for consistency

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-17 10:51:06 +01:00
Sebastiaan van Stijn
7672d60033 pkg/reexec: use const for name of test binary
Also use a slightly different name, because "reexec" is used so
widely as term in this package, making it somewhat confusing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-17 10:51:06 +01:00
Sebastiaan van Stijn
84dfd48d48 Merge pull request #49073 from dmcgowan/archive-remove-ioutils
Decouple pkg/archive from pkg/ioutils
2024-12-16 23:50:02 +01:00
Sebastiaan van Stijn
8991c4e382 Deprecate BridgeNfIptables and BridgeNfIp6tables fields
The netfilter module is now loaded on-demand, and no longer during daemon
startup, making these fields obsolete. These fields are now always `false`
and will be removed in the next relase.

This patch deprecates:

- the `BridgeNfIptables` field in `api/types/system.Info`
- the `BridgeNfIp6tables` field in `api/types/system.Info`
- the `BridgeNFCallIPTablesDisabled` field in `pkg/sysinfo.SysInfo`
- the `BridgeNFCallIP6TablesDisabled` field in `pkg/sysinfo.SysInfo`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 22:10:05 +01:00
Sebastiaan van Stijn
51abfcbf4f Merge pull request #49098 from thaJeztah/deprecate_pkg_system
pkg/system: deprecate types and functions that are only used internally
2024-12-16 16:04:58 +01:00
Sebastiaan van Stijn
504e1d4686 pkg/archive: replace uses of pkg/errors for stdlib errors
Reducing dependencies in preparation of moving pkg/archive to
a separate module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 12:13:24 +01:00
Sebastiaan van Stijn
f0ce367e1e pkg/system: deprecate types and functions that are only used internally
These types and functions are only used internally (through pkg/archive).
Deprecate them, and mark them for removal.

This deprecates the `Lstat()`, `Mkdev()`, `Mknod()`, `FromStatT()`
and `Stat()` functions, and related `StatT` type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 11:40:52 +01:00
Derek McGowan
ba90fd8da0 Decouple pkg/archive from pkg/ioutils
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-12-12 00:14:29 -08:00
Aleksa Sarai
557e4ed83b tests: migrate simple cases to assert.ErrorIs
There were a handful of direct checks against errors.Is that can be
translated to assert.ErrorIs without too much thought. Unfortunately
there are a load of other examples where ErrorIs probably makes sense
but would require testing whether this subtly breaks the test.

These transformations were done by hand.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:21 +11:00
Aleksa Sarai
caae3c051d tests: migrate to assert.ErrorContains when possible
If we have an error type that we're checking a substring against, we
should really be checking using ErrorContains to indicate the right
semantics to assert.

Mostly done using these transforms:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.ErrorContains(e, s)) -> assert.ErrorContains(t, e, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.Contains(err.Error(), s)) -> assert.ErrorContains(t, err, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Check(t, is.Contains(err.Error(), s)) -> assert.Check(t, is.ErrorContains(err, s))'

As well as some small fixups to helpers that were doing
strings.Contains explicitly.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:21 +11:00
Paweł Gronowski
e1dd1c5d1d Merge pull request #47955 from CharityKathure/windows-containerd-as-managed-process
Windows: Run containerd as managed process
2024-11-15 10:20:18 +00:00
Sebastiaan van Stijn
b034dc41a2 deprecate pkg/platform and move internal
Functions in this package are only used internally in the daemon for
the `/info` endpoint (Architecture), and as part of `stats` (NumProcs).

I was not able to find external consumers, but deprecating the package
first, so that we can remove / dismantle the package in a follow-up.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 15:05:56 +01:00
Sebastiaan van Stijn
d67a21b6fc pkg/idtools: remove redundant capturing of loop vars (copyloopvar)
pkg/idtools/idtools_unix_test.go:188:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:19 +01:00
Sebastiaan van Stijn
1a89c1e4a6 pkg/archive: remove redundant capturing of loop vars (copyloopvar)
pkg/archive/archive_test.go:820:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:19 +01:00
Sebastiaan van Stijn
35aa84fbc2 pkg/plugins: remove redundant capturing of loop vars (copyloopvar)
pkg/plugins/client_test.go:108:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    pkg/plugins/client_test.go:132:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:10 +01:00
Sebastiaan van Stijn
222b3a9e5c Merge pull request #48834 from vvoland/gounits-alias
all: Remove redundant `units` alias for `go-units`
2024-11-07 19:37:19 +01:00
Paweł Gronowski
c0045476b8 all: Remove redundant units alias for go-units
The alias is not needed as the package is already named `units`.
It was also not aliases consistently across the project.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-11-07 15:55:16 +01:00
Charity Kathure
84965c0752 Windows: Run containerd as managed process
Signed-off-by: Charity Kathure <ckathure@microsoft.com>
Co-authored-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2024-11-06 21:04:31 +03:00
Sebastiaan van Stijn
24bd11ce22 pkg/plugins: TestLocalSocket ignore deepequalerrors (govet)
govet produces this linting warning because the Plugin types that are
compared contain a activateErr field. This should be fine to ignore here.

    pkg/plugins/discovery_unix_test.go:48:7: deepequalerrors: avoid using reflect.DeepEqual with errors (govet)
            if !reflect.DeepEqual(p, pp) {
                ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:54:54 +01:00
Sebastiaan van Stijn
38db7265fc pkg/plugins: loadWithRetry: fix shadowed variables (govet)
pkg/plugins/plugins.go:231:6: shadow: declaration of "pl" shadows declaration at line 214 (govet)
            if pl, exists := storage.plugins[name]; exists {
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:54:53 +01:00
Sebastiaan van Stijn
32aa56af00 pkg/idtools: fix shadowed variable (govet)
pkg/idtools/usergroupadd_linux.go:94:2: shadow: declaration of "ranges" shadows declaration at line 25 (govet)
        ranges, err := parseSubuid(name)
        ^
    pkg/idtools/usergroupadd_linux.go:131:2: shadow: declaration of "ranges" shadows declaration at line 25 (govet)
        ranges, err := parseSubuid("ALL")
        ^
    pkg/idtools/usergroupadd_linux.go:140:2: shadow: declaration of "ranges" shadows declaration at line 25 (govet)
        ranges, err := parseSubgid("ALL")
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:54:51 +01:00
Sebastiaan van Stijn
a309e88dff pkg/tarsum: renderSumForHeader: ignore G110 in tests (gosec)
pkg/tarsum/tarsum_test.go:555:15: G110: Potential DoS vulnerability via decompression bomb (gosec)
            if _, err = io.Copy(io.Discard, tr); err != nil {
                        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:50:22 +01:00
Sebastiaan van Stijn
79196deae9 pkg/authorization: fix G112 Potential Slowloris Attack (gosec)
Not a real issue for tests, but easy to fix;

    pkg/authorization/authz_unix_test.go:387:12: G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-06 12:50:21 +01:00
Sebastiaan van Stijn
79e9619412 pkg/archive: ignore G103 (gosec)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-05 21:12:45 +01:00
Sebastiaan van Stijn
ae87c1d84c remove deprecated pkg/directory
This package was deprecated in 3a3bb1cb50,
and moved internally. The deprecation was backported to v27.1.0 through
d1ea2b1fec, so this package can be removed
for v28.0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-28 10:25:51 +01:00
Sebastiaan van Stijn
2054fd99b1 pkg/longpath: remove deprecated Prefix const
This const was deprecated in 424c22390e in
v27.0 and is no longer used, so can be removed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-28 10:20:53 +01:00
Paweł Gronowski
11aa9e1aae Merge pull request #48417 from adams1mon/try-fix-flaky-plugin-client-test
Increase flaky test sleep, replace deprecated assert
2024-10-22 13:06:51 +02:00
Sebastiaan van Stijn
3f9e489ce5 Merge pull request #48706 from thaJeztah/stringid_optimize
pkg/stringid: optimize GenerateRandomID
2024-10-21 16:53:04 +02:00
Sebastiaan van Stijn
71fffa7a03 Merge pull request #48707 from thaJeztah/stringid_tabletest
pkg/stringid: replace TestShortenIdXXX with TestTruncateID table test
2024-10-21 13:20:25 +02:00
Sebastiaan van Stijn
0539b7073e pkg/stringid: optimize GenerateRandomID
GenerateRandomID has a check to verify if the generated ID was numeric. This
check was added because a container's short-ID is used as default hostname for
containers, which isn't allowed to be consisting of only numbers (see [moby#3869]
and https://bugzilla.redhat.com/show_bug.cgi?id=1059122.

Producing an random ID with only numbers is a rare corner-case, but the check
would always be executed and wasn't optimized.

This patch applies some optimizations:

- The code was using `strconv.ParseUInt`, which has additional checks for
  signs ("+" or "-"); `hex.EncodeToString` would never produce these, so
  we can use `strconv.ParseInt` instead (which doesn't have these checks).
- The code was using `TruncateID(id)` to get the short-ID. The `TruncateID`
  function is designed to also handle digests, and for that checks for
  the given ID to contain colons (`:`), which it would split to remove
  the algorithm (`sha256:`) before truncating to the short-ID length.
  That check wasn't needed either, because those would not be produced
  by `hex.EncodeToString`, so instead, we can just truncate the ID.
- Finally, all we _really_ need to check for is if the ID consists of only
  numeric characters (`0-9`) so, let's do just that; if any non-numeric
  value is found, the ID is valid, and we can terminate the loop.

I did some basic benchmark to compare all of the above in isolation;

- BenchmarkParseInt: `strconv.ParseInt(TruncateID(id), 10, 64)`
- BenchmarkParseUInt: `strconv.ParseUint(TruncateID(id), 10, 64)`
- BenchmarkParseUIntNoTrunc: `strconv.ParseUint(id[:shortLen], 10, 64)`
- BenchmarkAllNum: `allNum(id[:shortLen])`

Results of the above:

    BenchmarkParseInt-10                1713937       691.0 ns/op     480 B/op      18 allocs/op
    BenchmarkParseIntNoTrunc-10         3385483       356.1 ns/op     480 B/op      18 allocs/op
    BenchmarkParseUInt-10               2112538       567.7 ns/op     384 B/op      12 allocs/op
    BenchmarkParseUIntNoTrunc-10        4325847       266.7 ns/op     384 B/op      12 allocs/op
    BenchmarkAllNum-10                 77277264        15.29 ns/op      0 B/op       0 allocs/op

Difference for `GenerateRandomID` as a whole is less dramatic, as in most
cases `ParseInt` would bail out early, but still saves some allocations, and
performance is ~14% better:

    BenchmarkGenerateRandomID-10        2807764       424.5 ns/op     240 B/op       6 allocs/op
    BenchmarkGenerateRandomIDNew-10     3288866       366.6 ns/op     160 B/op       3 allocs/op

[moby#3869]: https://github.com/moby/moby/issues/3869

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-21 11:17:05 +02:00
Akihiro Suda
4194bc0c93 Merge pull request #48708 from thaJeztah/pkg_archive_remove_deprecated
pkg/archive: remove deprecated CanonicalTarNameForPath, NewTempArchive, TempArchive
2024-10-21 13:32:51 +09:00
Sebastiaan van Stijn
7ebe625db7 pkg/archive: move deprecated NewTempArchive, TempArchive to test-utils
These were deprecated in 7ce1edd7c6, which
is part of v27.0.0. Move them to a test-file as they were only used for
tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-20 17:36:04 +02:00
Sebastiaan van Stijn
b313fcb8ff pkg/archive: remove deprecated CanonicalTarNameForPath
This was deprecated in 92b8d93f47, which
is part of v27.0.0, so we can remove it from master.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-20 17:24:04 +02:00
Sebastiaan van Stijn
c837027a9c pkg/stringid: replace TestShortenIdXXX with TestTruncateID table test
These tests were named confusingly as they're testing `TruncateID`.
While renaming, let's also combine them into a single test using
a test-table, so that the test-cases can carry some description
what they're testing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-20 16:59:36 +02:00
Sebastiaan van Stijn
83f17b0cbb pkg/stringid: remove deprecated IsShortID, ValidateID
- `IsShortID` was deprecated in 2100a70741
- `ValidateID` was deprecated in e19e6cf7f4

Both are part of 27.0, so we can remove these.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-20 16:15:22 +02:00
Sebastiaan van Stijn
4a2361ea09 pkg/authorization: update link to API documentation
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-12 17:23:29 +02:00
Aarni Koskela
367125e0cc Use pools.Copy for archive file copy operations
Signed-off-by: Aarni Koskela <akx@iki.fi>
2024-10-08 12:47:41 +03:00
Nathan Baulch
59eba0ae13 Fix typos
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
2024-09-06 21:53:09 +10:00
Brian Goff
55752bb1ec Merge pull request #47983 from cpuguy83/skip_corrupted_log_files
Make log reading more robust to errors
2024-09-03 08:58:08 -07:00
Adam Simon
28dc2f6fac Increase test handler sleep, replace deprecated assert
- increase mock handler processing time to 50ms to try to prevent it from finishing before the 10ms client timeout occurs
- replace deprecated error type assertion

Signed-off-by: Adam Simon <adamsimon85100@gmail.com>
2024-09-02 16:40:45 +00:00
Sebastiaan van Stijn
8d06e70f34 Merge pull request #48132 from robmry/bind_socket_for_docker_proxy
Create docker-proxy TCP/UDP listener sockets in the daemon
2024-08-08 20:30:58 +02:00