Commit Graph

63 Commits

Author SHA1 Message Date
Akihiro Suda
d26587c725
archive: disable looking up usernames and groupnames on the host
These strings were resolved using the user information on the host
filesystem and were decreasing reproducibility.

For moby/buildkit issue 3688

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-03-08 02:04:40 +09:00
Akihiro Suda
9b510e9a8f
lint: silence "SA1019: tar.TypeRegA has been deprecated... (staticheck)"
"SA1019: tar.TypeRegA has been deprecated since Go 1.11 and an alternative has been available since Go 1.1:
Use TypeReg instead. (staticcheck)"

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-02-16 03:50:23 +09:00
Akihiro Suda
dc48349248
epoch: propagate SOURCE_DATE_EPOCH via ctx
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-12-12 09:02:35 +09:00
Akihiro Suda
a22f0a4c3e
archive: set WithModTimeUpperBound when WithSourceDateEpoch is set
WithModTimeUpperBound sets the upper bound value of the ModTime property
of the tar entry structs.

WithSourceDateEpoch now implies WithModTimeUpperBound too,
in addition to WithWhiteoutTime.

For moby/buildkit issue 3296

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-11-22 22:21:44 +09:00
Akihiro Suda
70fbedc217
archive: add WithSourceDateEpoch() for whiteouts
This makes diff archives to be reproducible.

The value is expected to be passed from CLI applications via the $SOUCE_DATE_EPOCH env var.

See https://reproducible-builds.org/docs/source-date-epoch/
for the $SOURCE_DATE_EPOCH specification.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-10-08 08:45:03 +09:00
Samuel Karp
f4095a6876
Merge pull request #7386 from mxpv/no-same-owner 2022-09-09 21:52:41 -07:00
Maksym Pavlenko
0f51aa874d Add NoSameOwner option when unpacking tars
When unpacking a TAR archive, containerd preserves file's owner:
https://github.com/containerd/containerd/blob/main/archive/tar.go#L384

In some cases this behavior is not desired. In current implementation we
avoid `Lchown` on Windows. Another case when this should be skipped is
when using native snapshotter on darwin and running as non-root user.

This PR extracts a generic option - `WithNoSameOwner` (same as
`tar --no-same-owner`) to skip `Lchown` when its not required.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-09-09 17:07:26 -07:00
Sebastiaan van Stijn
19db697a5a
archive: replace tarName() with filepath.ToSlash()
This code was copied from github.com/moby/moby/pkg/archive;
28842d3f09,
which got later simplified in
a5aed699cf

This patch aligns the containerd implementation with those changes, and uses
filepath.ToSlash() unconditionally on all platforms, as it's a no-op on platforms
that use a forward-slash; https://github.com/golang/go/blob/go1.19/src/path/filepath/path.go#L175-L183

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-30 15:19:58 +02:00
Ye Sijun
68a55fe8bd
make xattr EPERM non-fatal in createTarFile
Signed-off-by: Ye Sijun <junnplus@gmail.com>
2022-06-23 15:17:30 +08:00
Samuel Karp
2ab8c12fc8
archive: use Linkat on FreeBSD for hardlinks
Calling link(2) with a symlink as the target will cause FreeBSD to
attempt to create a new hard link pointing to the target of the symlink
rather than a hardlink to the symlink itself. By contrast, Linux creates
a hardlink to the symlink.

Use linkat(2) instead, which accepts a flag controlling this behavior.
If linkat(2) is called with AT_SYMLINK_FOLLOW, it will behave the same
as link(2).  If linkat(2) is called without AT_SYMLINK_FOLLOW, it will
behave the same as Linux's link(2) instead.

See FreeBSD's implementation of ln(1), which uses linkat(2) and controls
this behavior by way of the -P and -L flags:
3003117253/bin/ln/ln.c (L342-L343)

Signed-off-by: Samuel Karp <me@samuelkarp.com>
2022-06-09 18:54:09 -07:00
Akihiro Suda
d2f30150b3
archive: add human-readable hint to Lchown error
Before:
```
$ nerdctl pull gcr.io/kubeflow-images-public/tensorflow-1.14.0-notebook-cpu:v0.7.0
FATA[0026] failed to extract layer sha256:f8a604834d388fd3d04c26e4ed832b36b617ea8a4e0b1665b9199bd10cfcb171: mount callback failed on /var/lib/containerd/tmpmounts/containerd-mount1818823128:
lchown /var/lib/containerd/tmpmounts/containerd-mount1818823128/usr/local/bin/docker-credential-gcr: invalid argument: unknown
```

After:
```
$ nerdctl pull gcr.io/kubeflow-images-public/tensorflow-1.14.0-notebook-cpu:v0.7.0
FATA[0027] failed to extract layer sha256:f8a604834d388fd3d04c26e4ed832b36b617ea8a4e0b1665b9199bd10cfcb171: mount callback failed on /var/lib/containerd/tmpmounts/containerd-mount3521205359:
failed to Lchown "/var/lib/containerd/tmpmounts/containerd-mount3521205359/usr/local/bin/docker-credential-gcr" for UID 205001, GID 5000:
lchown /var/lib/containerd/tmpmounts/containerd-mount3521205359/usr/local/bin/docker-credential-gcr: invalid argument
(Hint: try increasing the number of subordinate IDs in /etc/subuid and /etc/subgid): unknown
```

Related to moby/moby issue 43576 but for containerd

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-05-24 17:57:53 +09:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
Artem Khramov
2bffb5f9b2
FreeBSD: fix tar headers & the nil check on getxattr
On FreeBSD + zfs, stat call seem to return garbage in RDev for regular
files & folders. The value returned is large enough not to fit into
`Devmajor` & `Devminor` fields of the tar header. Fortunately, these
fields are required just for special devices.

This change

* adds a check into `setHeaderForSpecialDevice` that the
  input header represents a special device. If it's not the case, we
  don't set the Devmajor & Devminor fields.

* fixes the nil check on `getxattr`: it never returns nils, but rather
  an empty slice instead

Signed-off-by: Artem Khramov <akhramov@pm.me>
2021-09-21 19:22:41 +03:00
Shiming Zhang
ccc5ee3038 archive: Add WriteDiff error logs
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
2021-09-06 18:04:17 +08:00
Kazuyoshi Kato
bc4cea4e44 docs: rename main to master
containerd and opencontainers/image-spec have renamed its main branch
from "master" to "main"

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-08-10 09:42:16 -07:00
Derek McGowan
53835221f6
Cleanup lchmod logic in archive
Move to single lchmod interface mirroring other implementations.
Separate logic for freebsd which supports symlink no follow flag.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-07-08 13:44:28 -07:00
ktock
4a46ea2f4b archive: Expose ChangeWriter to allow customized diff computing
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2021-06-21 18:48:00 +09:00
Paul "TBBle" Hampson
c7504987e6 Implement windowsDiff.Compare via hcsshim/pkg/ociwclayer
This parallels the implementation of windowsDiff.Apply, including
bouncing very briefly though archive.WriteDiff and then straight back
out into Windows-specific code.

It's mostly pulling existing mechanisms from non-Windows Compare or
Windows Apply, and highlights that there's probably a lot of scope for
refactoring on top of this.

Now the export-related integration tests pass CI on Windows.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-04-10 02:02:33 +10:00
Paul "TBBle" Hampson
3e47cdf70f Use go-winio tar-application code instead of our own
applyFunc now takes an io.Reader instead of a tar.Reader because I'm
trying to mirror the API of the not-yet-exposed implementation of this
same behaviour in github.com/Microsoft/hcsshim/internal/ociwclayer,
with an eye to later moving to that implementation it is ever exposed.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2020-12-03 02:42:54 +11:00
Sebastiaan van Stijn
dc92ad6520
Replace errors.Cause() with errors.Is()
Dependencies may be switching to use the new `%w` formatting
option to wrap errors; switching to use `errors.Is()` makes
sure that we are still able to unwrap the error and detect the
underlying cause.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-08 14:36:45 +02:00
Tonis Tiigi
372472b5f6 archive: truncate modification time
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-08-27 17:42:32 -07:00
Derek McGowan
bcc4a146e4
Support applying with parent directories
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-08-16 15:49:47 -07:00
Lantao Liu
81386df917
Add direct unpack support for overlay and aufs
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-08-15 12:09:32 -07:00
Lantao Liu
14f7e52725 Unpack should set 0755 when the parent directory doesn't exist.
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-02-14 13:38:12 -08:00
Ace-Tang
6f944e4190 fix: SCHILY.xattrs should be SCHILY.xattr
from golang code
bad6b6fa91/src/archive/tar/common.go (L110)

add unit test for tar xattr

Fixes: #2863

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-12-13 09:56:26 +08:00
zhangyue
996c60616a fix: fix error info start capitalized
Signed-off-by: zhangyue <zy675793960@yeah.net>
2018-11-28 15:26:16 +08:00
Michael Crosby
5a47c5ec1d Add lib support as an option
Some images like `criu` will have extra libs that it requires.  This
adds lib support via LD_LIBRARY_PATH and InstallOpts

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-02 17:11:29 -04:00
Evan Hazlett
1537f31381 Add install support for binary images
This adds a way for users to programatically install containerd binary
dependencies.

With runtime v2 and new shim's being built, it will be a challenge to
get those onto machines.  Users would have to find the link, download,
place it in their path, yada yada yada.

With this functionality of a managed `/opt` directory, containerd can
use existing image and distribution infra. to get binarys, shims, etc
onto the system.

Configuration:

*default:* `/opt/containerd`

*containerd config:*
```toml
[plugins.opt]
	path = "/opt/mypath"

```

Usage:

*code:*

```go
image, err := client.Pull(ctx, "docker.io/crosbymichael/runc:latest")
client.Install(ctx, image)
```

*ctr:*

```bash
ctr content fetch docker.io/crosbymichael/runc:latest
ctr install docker.io/crosbymichael/runc:latest
```

You can manage versions and see what is running via standard image
commands.

Images:

These images MUST be small and only contain binaries.

```Dockerfile
FROM scratch
Add runc /bin/runc
```

Containerd will only extract files in `/bin` of the image.

Later on, we can add support for `/lib`.

The code adds a service to manage an `/opt/containerd` directory and
provide that path to callers via the introspection service.

How to Test:

Delete runc from your system.

```bash
> sudo ctr run --rm  docker.io/library/redis:alpine redis
ctr: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v1.linux/default/redis/log.json: no such file or directory): exec: "runc": executable file not found in $PATH: unknown

> sudo ctr content fetch docker.io/crosbymichael/runc:latest
> sudo ctr  install docker.io/crosbymichael/runc:latest

> sudo ctr run --rm  docker.io/library/redis:alpine redis
1:C 01 Aug 15:59:52.864 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 01 Aug 15:59:52.864 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 01 Aug 15:59:52.864 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 01 Aug 15:59:52.866 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 01 Aug 15:59:52.866 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 01 Aug 15:59:52.866 # Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 01 Aug 15:59:52.870 * Running mode=standalone, port=6379.
1:M 01 Aug 15:59:52.870 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 01 Aug 15:59:52.870 # Server initialized
1:M 01 Aug 15:59:52.870 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 01 Aug 15:59:52.870 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 01 Aug 15:59:52.870 * Ready to accept connections
^C1:signal-handler (1533139193) Received SIGINT scheduling shutdown...
1:M 01 Aug 15:59:53.472 # User requested shutdown...
1:M 01 Aug 15:59:53.472 * Saving the final RDB snapshot before exiting.
1:M 01 Aug 15:59:53.484 * DB saved on disk
1:M 01 Aug 15:59:53.484 # Redis is now ready to exit, bye bye...
```

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-02 17:11:29 -04:00
Wei Fu
3b1534c47a bugfix: allow hardlink to softlink file
With `fs.RootPath`, the target file will be the file which the softlink
points to, like:

  touch /tmp/zzz
  ln -s /tmp/zzz /tmp/xxx
  ln /tmp/xxx /tmp/yyy

The `/tmp/yyy` should be same with the `/tmp/xxx`, not `/tmp/zzz`. We
should allow hardlink to softlink file.

Signed-off-by: Wei Fu <fhfuwei@163.com>
2018-07-19 15:13:50 +08:00
Tom Godkin
fc8bce59b9 Use user-specific temp directory if set
This allows non-privileged users to use containerd. This is part of a
larger track of work integrating containerd into Cloudfoundry's garden
with support for rootless.

[#156343575]

Signed-off-by: Claudia Beresford <cberesford@pivotal.io>
2018-05-04 10:27:58 +01:00
Ian Campbell
2ec3382d2d Ignore sockets when creating a tar stream of a layer
The go-tar implementation which is used cannot handle sockets.

There's no good reason to preserve a socket, they are basically useless without
the process which made them.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
2018-03-22 15:19:35 +00:00
Stephen J Day
9cdd036393
build: bump to Go 1.10
Bumps the build to use Go 1.10, which allows us to drop the forked tar
package.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2018-02-26 16:47:24 -08:00
Kunal Kushwaha
b12c3215a0 Licence header added
Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2018-02-19 10:32:26 +09:00
Brian Goff
c776b6d8d9 Use continuity fs package
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-02-07 12:40:52 -05:00
Derek McGowan
d778dd15d8
Fixes missing whiteout parent directories
Ensures include parents is called for whiteouts

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-02-02 17:02:14 -08:00
Derek McGowan
dfadd8ce75
Fix duplicate directories entries on metadata change
Currently directory changes are not added to the list of
included directories, allowing those directories to receive
duplicate entries where there is both a metadata change to the
directory and a change to a file under that directory.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-01-24 14:28:51 -08:00
Stephen J Day
cd72819b53
archive, cio, cmd, linux: use buffer pools
To avoid buffer bloat in long running processes, we try to use buffer
pools where possible. This is meant to address shim memory usage issues,
but may not be the root cause.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2018-01-22 13:52:06 -08:00
Derek McGowan
384d46d8bd
archive: check whiteout path before removal
Ensure whiteout is not pointing to the current directory
or parent directory before removing. Protects against invalid
removal of the parent or current directory.

Add whiteout related tar tests using manufactured tar conditions.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-01-12 11:43:39 -08:00
Derek McGowan
c9dd974c27
Add parent directories to tar
Alternate solution which better accounts for hard links.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-01-02 16:01:31 -08:00
Michael Crosby
e479165a38
Merge pull request #1903 from darrenstahlmsft/ArchiveOpts
Implement Archive.apply on Windows
2018-01-02 16:08:36 -05:00
Derek McGowan
d4317a1b0d
Fix parent directories not included in tar
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-12-15 12:04:47 -08:00
Darren Stahl
c195ebb3e2 Implement archive.Apply on Windows
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-12-15 11:33:03 -08:00
Michael Crosby
a56e7420a7
Merge pull request #1812 from darrenstahlmsft/revendor
Revendor hcsshim and go-tar
2017-11-29 15:52:07 -05:00
Derek McGowan
bc9cb25012
Update tar to use PAXRecords instead of Xattrs
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-11-28 17:03:14 -08:00
Daniel Nephin
ee04cfa3f9 Add staticcheck linter
Fix issues with sync.Pool being passed an array and not a pointer.
See https://github.com/dominikh/go-tools/blob/master/cmd/staticcheck/docs/checks/SA6002

Add missing tests for content.Copy

Fix T.Fatal being called in a goroutine

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-11-28 13:05:30 -05:00
Stephen Day
70b5668351 Merge pull request #1631 from dmcgowan/cancel-unpack
archive: update apply diff to support context cancellation
2017-10-17 05:33:25 -07:00
Derek McGowan
dcf7ff5db5
Update apply diff to support context cancellation
Allows cancellation of apply when the grpc service issues a cancel.
Adds a timing log for apply.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 16:48:55 -07:00
Derek McGowan
e20b371807
Remove umask, replace with explicit chmod after create
Call chmod on all open files and created directories to
ensure permission is set as expected without changing umask.

Fixes #1608

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 15:13:18 -07:00
Michael Crosby
f43b7acfd2 Update files based on go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-02 10:15:28 -04:00
Kenfe-Mickael Laventure
308ebe7e43
Add missing return when failing to write tar header
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
2017-08-04 10:41:38 -07:00