Commit Graph

43 Commits

Author SHA1 Message Date
Daniel J Walsh 8d5d763213
Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-19 07:11:44 -04:00
Nalin Dahyabhai bb149ea686 Use errors.Is() instead of os.Is{Not,}Exist
If errors for which os.IsExist() or os.IsNotExist() would have returned
true have been wrapped using fmt.Errorf()'s "%w" verb, os.IsExist() and
os.IsNotExist(), not having been retrofitted to use errors.Is(), will
return false.

Use errors.Is() to check if an error is an os.ErrExist or os.ErrNotExist
error instead of calling os.IsExist() or os.IsNotExist().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 15:36:58 -04:00
Sascha Grunert ce384684c0
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 11:41:47 +02:00
Kir Kolyshkin b34e4d5789 util.go: fix gosimple warning
Fix this warning from gosimple linter:

>	util.go:127:19: S1040: type assertion to the same type: ref.DockerReference() already has type reference.Named (gosimple)
>			if named, ok := ref.DockerReference().(reference.Named); ok {
>					^

Since containers/image commit dfe2fafaa2d702e5a932721aed55b996024051b1
(made in 2017), DockerReference() always return reference.Named type.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-01-18 12:56:34 -08:00
Daniel J Walsh 39f4cfb79d
Stop excessive wrapping
Golang built in functions like os.Create and others print the name of
the file system object when they fail.  Wrapping them a second time
with the file system object, makes the error message look like crap
when reported to the user.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-15 14:03:13 -04:00
Nalin Dahyabhai 3835460c3b Use pipes for copying
Use the copier package to rework how we handle ADD and COPY.

When evaluating cache for content that's being copied/added in, switch
from (digest the data, check for a cache entry, then maybe copy the data
and create the new layer) to (copy the data and create the new layer,
digesting as we go, check for a cache entry, either commit or discard
the new layer).

Use the copier package for ADD, COPY, and for ensuring that a specified
directory exists in the working container's rootfs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-21 12:34:00 -04:00
Daniel J Walsh d125f8f9cc
Add buildah.IsContainer interface
This interface will allow callers to specify a storage container id
and the store and return whether or not the container is a buildah
container.

We want to add the ability to for Podman to identify containers in storage
that it did not create or were created via podman build command.

Podman will use this information to help user identify where the container
came from.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-12 06:21:37 -04:00
Nalin Dahyabhai 55fa8f5a46 copyFileWithTar: close source files at the right time
Close source files after we've finished reading from them, rather than
leaving it for later.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #2072
Approved by: giuseppe
2020-01-09 11:10:24 +00:00
Nalin Dahyabhai 6047edc1d6 Builder.untarPath(): always evaluate b.ContentDigester.Hash()
Make sure we evaluate b.ContentDigester.Hash() every time the callback
returned by Builder.untarPath() is called, since it may be for a
different digest object than the previous time it was called, or
different even from when the callback was first retrieved.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1955
Approved by: rhatdan
2019-10-31 00:37:18 +00:00
Nalin Dahyabhai f0cf07bb60 Move to containers/image v5.0.0
Bump to containers/image's 5.0 release.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1902
Approved by: rhatdan
2019-10-28 15:15:34 +00:00
Miloslav Trmač 797e618cbe Update c/image to v4.0.1
This requires updating all import paths throughout.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1891
Approved by: vrothberg
2019-10-04 07:34:03 +00:00
Nalin Dahyabhai ebf6f518d0 Use content digests in ADD/COPY history entries
Use digests of the added content in history entries that we create for
ADD and COPY instructions, tightening up cache checking just a little
bit more.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1792
Approved by: TomSweeneyRedHat
2019-08-16 20:16:40 +00:00
Nalin Dahyabhai db2b3e48ac add: add a DryRun flag to AddAndCopyOptions
Add a DryRun flag to AddAndCopyOptions, so that we can "copy" content to
digest it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1792
Approved by: TomSweeneyRedHat
2019-08-16 20:16:40 +00:00
Nalin Dahyabhai 5c98d3c220 add: handle hard links when copying with .dockerignore
Detect files that are hard linked together, and use that information to
avoid copying their contents more often than we have to.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1789
Approved by: rhatdan
2019-08-14 15:20:52 +00:00
Nalin Dahyabhai 3f5436f727 add: teach copyFileWithTar() about symlinks and directories
Teach copyFileWithTar() about symbolic links and directories, and use it
to produce tar data to feed to untar() instead of special-casing them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1785
Approved by: vrothberg
2019-08-13 12:41:12 +00:00
Valentin Rothberg 3117f5e7e8 vendor github.com/containers/image@v3.0.0
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1756
Approved by: rhatdan
2019-08-02 14:59:22 +00:00
Sascha Grunert 7eb4e5972d
Add goimports linter and apply fixes
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-07-18 10:42:46 +02:00
Valentin Rothberg ee1b6e25c8 util: remove redundant `return` statement
Reported by golangci-lint.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1678
Approved by: rhatdan
2019-06-19 11:33:36 +00:00
Nalin Dahyabhai 3bdc9edd67 imagebuildah: handle ID mappings for COPY --from
Fix handling of ID mapping for COPY: when copying from other containers,
use their mappings, and when copying from the host, use host mappings.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1630
Approved by: TomSweeneyRedHat
2019-06-06 13:11:25 +00:00
Daniel J Walsh 973bb88ef1 Move tar commands into containers/storage
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1298
Approved by: TomSweeneyRedHat
2019-02-01 18:31:35 +00:00
Nalin Dahyabhai 23ed59594b Add options for empty-layer history entries
Add configuration methods for adding entries which will show up in a
committed image's history, both before and after the new layer that we
add while committing the image.  Expose them from the CLI in the form of
a new --add-history option for the "add", "config", "copy", and "run"
commands.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1300
Approved by: rhatdan
2019-01-21 19:11:21 +00:00
Miloslav Trmač a4200ae6b5 Remove no longer used isReferenceInsecure / isRegistryInsecure
These functions are no longer used. Also, code should typically rely
on the automatic use of the sysregistriesv2 configuration inside
c/image/docker instead of managing that manually, so they are
unlikely to have any users in the future.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1255
Approved by: rhatdan
2019-01-06 14:53:06 +00:00
Miloslav Trmač 9c65e5699c Update for sysregistriesv2 API changes
Mostly this is a straightforward elimination of manual GetRegistries calls.

In getCopyOptions, we just remove setting the DockerInsecureSkipTLSVerify
values because the docker:// tranport now does that automatically.  (This
actually changes behavior, because docker:// supports namespace prefixes
in addition to matching only by hostnames, but that's a superset of the
previous behavior.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1214
Approved by: rhatdan
2018-12-03 20:07:00 +00:00
Nalin Dahyabhai 46c577c87d ReserveSELinuxLabels(): handle wrapped errors from OpenBuilder
ReserveSELinuxLabels() checks if an error returned by OpenBuilder() is a
does-not-exist error, but OpenBuilder() returns wrapped errors now, and
it wasn't checking the root cause error.

When newBuilder() fails, check the right error value when deciding
whether or not deleting the partially-constructed container failed.

OpenBuildersByPath() shouldn't choke on non-buildah containers, so have
it handle does-not-exist errors the same way OpenAllBuilders() does.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1109
Approved by: rhatdan
2018-10-17 21:20:29 +00:00
Miloslav Trmač 6e0074eeed Move the "short name but no search registries" error handling to resolveImage
Use the value now returned by util.ResolveImage instead of trying to
recompute it.

Then drop the no longer used getRegistries.  (It might be reasonable
to split that part of util.ResolveImage to make it shorter; but it should
not ideally have any independent second-guessing callers.  So, just
keep the inlined one instead; that way we certainly don't break it.)

Also drop the no longer used hasRegistry.

CHANGES BEHAVIOR:
- Most notably, the "short name but no search registries" code
  has been broken for some time; pullImage was called with
  localhost/$shortname, which was a qualified name, so the
  specialized error handling was never attempted.
- Temporarily, the error handling in the "short name but no
  search registries" code trigers even if there were actually
  valid values to try (in practice there is always localhost/$shortname,
  and possibly also options.Registry/$shortname).  The next commit
  will improve it again.
- We now have more legitimate access to the original short name,
  so include it in the error message (it was technically available
  before, but using it was awkward).

NOTE: registriesConfPath is computed using the sysregistries
package, but actual access happens using the sysregistriesv2 package.
That should be cleaned up eventually.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #909
Approved by: rhatdan
2018-10-13 11:56:07 +00:00
Nalin Dahyabhai bc2ea08003 Make sure we log or return every error
Make sure that when attempting to diagnose an error, if we encounter an
error during the diagnostic attempt, we return the original error rather
than the error encountered in trying to diagnose it.  Log that one.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1072
Approved by: rhatdan
2018-10-07 12:07:09 +00:00
Nalin Dahyabhai 318fc8940f Enforce "blocked" for registries for the "docker" transport
Check if reading and writing from the registry named by an image is
allowed when the transport is "docker".

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1056
Approved by: rhatdan
2018-10-05 15:30:11 +00:00
Nalin Dahyabhai 62c01da3e4 Correctly set DockerInsecureSkipTLSVerify when pulling images
The image library's copy routine doesn't itself consult the registries
configuration in order to decide whether or not to disable TLS
verification when communicating with a registry, so it's on us to use
the name of a source or destination image to decide whether to set the
flag for that behavior.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1056
Approved by: rhatdan
2018-10-05 15:30:11 +00:00
Daniel J Walsh d0846b1914 Export buildah ReserveSELinuxLables so podman can use it
We want to make sure that buildah and podman don't use the
same SELinux MCS Labels.  So we need to export this function
so libpod can use it.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1041
Approved by: rhatdan
2018-09-30 05:51:28 +00:00
Nalin Dahyabhai 36e174e779 Switch to github.com/containers/image/pkg/sysregistriesv2
Switch from using github.com/containers/image/pkg/sysregistries to using
github.com/containers/image/pkg/sysregistriesv2 to complete unqualified
image names.  Keep v1 around because it'll tell us which configuration
file to name in an error message if things don't work right.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #904
Approved by: rhatdan
2018-08-03 17:26:09 +00:00
Nalin Dahyabhai 8be2b62372 Fix handling of --registries-conf
Instead of ignoring the global --registries-conf option and using only
$REGISTRIES_CONFIG_PATH, use it for the option default.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #854
Approved by: rhatdan
2018-07-07 10:48:44 +00:00
Nalin Dahyabhai edce842f54 Break out getProcIDMappings()
Break getProcIDMappings() out of run.go and turn it into
util.GetHostIDMappings(), and add util.GetSubIDMappings() and
util.ParseIDMappings().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #796
Approved by: rhatdan
2018-06-18 18:38:54 +00:00
Nalin Dahyabhai 002c18a3bb Break out SetupIntermediateMountNamespace()
Break runSetupIntermediateMountNamespace() into its own package.
Move stringInSlice(), getHostIDs(), and getHostRootIDs() into the util
subdirectory and export them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #796
Approved by: rhatdan
2018-06-18 18:38:54 +00:00
Nalin Dahyabhai ae27963cb0 Add(): learn to record hashes of what we add
Add a field to AddOrCopyOptions that can take an io.Writer, more often a
hash.Hash returned by digest.Digester's Hash() method, to calculate a
sum over what we add or copy.

Make the help output summarizing the arguments that "buildah add" and
"buildah copy" accept more closely match their man pages.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #766
Approved by: rhatdan
2018-06-11 12:39:05 +00:00
TomSweeneyRedHat 043fd2e300 Add registry errors for pull
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2018-06-06 13:05:56 -04:00
Nalin Dahyabhai 00fafcf9cb Use CNI to configure container networks
Use CNI to configure networks for containers for which we create new
network namespaces.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai aa5cf3115e add/secrets/commit: Use mappings when setting permissions on added content
Use ID mapping information when setting permissions on content that we
add to the container, and on secrets that we copy in, on pipes that we
use for stdio, and when extracting the whole filesystem as a "layer".

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai 0afa60eb05 Add CLI options for specifying namespace and cgroup setup
Add options to the CLI that specify which cgroups we execute "run"
commands under, and controlling how we set up namespaces for them.
Pass them down to Builders that we create, and allow them to be
overridden by options passed to Builder.Run().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai dfc4c676d0 Always set mappings when using user namespaces
If we're creating a user namespace, we always need to supply at least
one mapping for the UID and GID maps.  If we're not given any mappings,
map the ranges that are available to us, instead of assuming we can map
all possible values, in case we're already in a user namespace.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:00 +00:00
Nalin Dahyabhai 1395e1805a Read UID/GID mapping information from containers and images
Read UID/GID mapping information when creating or importing containers,
and if there is mapping information, use it when building runtime
configurations.

Mounting sysfs in a user namespace requires that we also have our own
network namespace, so default to creating one for that case.

Switch permissions on files that we bind in so that they're writable
from inside of the container.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:00 +00:00
Daniel J Walsh 8ecefa978c Vendor in changes to support sirupsen/logrus
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-10-10 17:30:11 +00:00
Nalin Dahyabhai fc880bcc86 Maintain multiple working container configs
Maintain the container configuration in multiple formats in the Buildah
object, initializing one based on the other, depending on which format
the source image used for its configuration.

Replace directly manipulated fields in the Buildah object (Annotations,
CreatedBy, OS, Architecture, Maintainer, User, Workdir, Env, Cmd,
Entrypoint, Expose, Labels, and Volumes) with accessor functions which
update both configurations and which read from whichever one we consider
to be authoritative.  Drop Args because we weren't using them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #102
Approved by: rhatdan
2017-05-18 18:28:44 +00:00
Nalin Dahyabhai 04ce6f39c4 imagebuildah: Reexport some things
Have imagebuildah reexport some constants and its own Mount type, to
reduce the number of our dependencies that a prospective consumer of
this package would also need to import directly.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #84
Approved by: rhatdan
2017-04-24 14:33:43 +00:00