Commit graph

648 commits

Author SHA1 Message Date
Michael Hofmann
840df1dc92 Restore LOOP_CONFIGURE fallback for kernel < 5.8
The fallback that was initially present in #1253 is needed for the
current GitLab runners which have a Container-Optimized OS [1] with
kernel 5.4 [2] without support for LOOP_CONFIGURE [3].

[1] https://docs.gitlab.com/ee/ci/runners/saas/linux_saas_runner.html
[2] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L31
[3] https://gitlab.com/cki-project/containers/-/jobs/4381560305#L1166

Signed-off-by: Michael Hofmann <mhofmann@redhat.com>
2023-06-20 12:18:15 +02:00
schutzbot
a8bba69935 Post release version bump
[skip ci]
2023-06-07 08:14:17 +00:00
schutzbot
a7b3ef3936 Post release version bump
[skip ci]
2023-05-24 08:13:14 +00:00
schutzbot
4add41d50f Post release version bump
[skip ci]
2023-05-10 08:13:14 +00:00
Thomas Lavocat
dfcd847c8e osbuild/loop: fix typo 2023-05-05 15:42:47 +02:00
Thomas Lavocat
da11ef4eb0 loop: use LOOP_CONFIGURE instead of LOOP_SET_FD
LOOP_CONFIGURE allows to atomically configure the decive when opening
it. This avoid the possibility of a race condition where between set_fd
and set_status some operations are already accepted by the loopback
device. See https://lwn.net/Articles/820408/

This feature was included in the linux kernel 5.8 however it is safe to
not include any kind of fallback to the previous method as @obudai
points out that:

LOOP_CONFIGURE was backported into RHEL 8 kernel in RHEL 8.4 as a part
of https://bugzilla.redhat.com/show_bug.cgi?id=1881760 (block layer:
update to upstream v5.8).

Since RHEL 8.4 is currently the oldest supported release that we support
running osbuild on, it might be just fine implementing this without the
fallback.

From a centos stream 8 container:
kernel-4.18.0-448.el8.x86_64
- loop: Fix missing discard support when using LOOP_CONFIGURE (Ming Lei) [1997338]
- [block] loop: Set correct device size when using LOOP_CONFIGURE (Ming Lei) [1881760]
- [block] loop: unset GENHD_FL_NO_PART_SCAN on LOOP_CONFIGURE (Ming Lei) [1881760]
- [block] loop: Add LOOP_CONFIGURE ioctl (Ming Lei) [1881760]
2023-05-05 15:42:47 +02:00
schutzbot
1eb71723a0 Post release version bump
[skip ci]
2023-04-26 08:15:08 +00:00
Tomáš Hozza
bf3e096735 Fix errors reported by new version of mypy
Fix the following errors:

```
osbuild/util/lvm2.py:117: error: Only instance methods can be decorated with @property
osbuild/api.py:50: error: Only instance methods can be decorated with @property
osbuild/sources.py:85: error: Only instance methods can be decorated with @property
```

Chaining of `@classmethod` and `@property` has been deprecated since
Python 3.11 with a note that chaining didn't work correctly in some
cases.

Relevant links:
https://github.com/python/mypy/issues/13746
https://docs.python.org/3.11/whatsnew/3.11.html#language-builtins

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-04-12 11:57:18 +02:00
schutzbot
1df905222e Post release version bump
[skip ci]
2023-04-12 08:13:49 +00:00
Achilleas Koutsou
b83fd8650c osbuild-mpp: extract is_manifest_list() function
Extract the is_manifest_list() function from the ImageManifest object in
osbuild-mpp into a util function to be reused by the skopeo source.
2023-03-31 14:57:26 +02:00
schutzbot
7f68136324 Post release version bump
[skip ci]
2023-03-29 08:14:39 +00:00
schutzbot
36341203a1 Post release version bump
[skip ci]
2023-02-27 16:41:44 +00:00
schutzbot
b5b3a5ba8c Post release version bump
[skip ci]
2023-02-20 14:37:54 +00:00
schutzbot
291726a83b Post release version bump
[skip ci]
2023-02-15 08:15:11 +00:00
Thomas Lavocat
5eefdc1e9a mounts: add possiblity to use norecovery with ro
To avoid kernel panics if the kernel attempts to recover the filesystem
when it's mounted as readonly. Offer the possiblity to use the
norecovery option for journaling file systems (Xfs, Ext4, Btrfs).
2023-02-10 14:09:03 +01:00
schutzbot
ab2d48350a Post release version bump
[skip ci]
2023-02-07 15:51:39 +00:00
Thomas Lavocat
8f08433804 mounts: accept more mount options
Before we could only ask OSBuild to mount a device as readonly. But
devices can have more mount options than this. Supporting more options
is necessary for the new version of image-info that is using OSBuild's
internals in order to mount the image it wants to work on. Otherwise,
for instance, some umasks aren't applied properly and we can get
differences in rpm-verify results, thus corrupting the DB.

Mount is now accepting:
* readonly
* uid
* gid
* umask
* shortname
2023-02-01 12:29:58 +01:00
schutzbot
c0fb5cf90c Post release version bump
[skip ci]
2023-01-20 16:04:06 +00:00
schutzbot
c3eef90fed Post release version bump
[skip ci]
2023-01-18 08:14:30 +00:00
schutzbot
423f0a77c8 Post release version bump
[skip ci]
2023-01-04 08:14:40 +00:00
schutzbot
1133f4d24f Post release version bump
[skip ci]
2022-12-21 08:15:55 +00:00
David Rheinsberg
18c69d2620 util/fscache: add cachedir-tag support
The cachedir-tag specification defines how to mark directories as
cache-directories. This allows tools like `tar` to ignore those
directories if desired (e.g., see `tar --ignore-caches`). This is very
useful to avoid huge cache-directories in backups and remote
synchronizations.

The spec simply defines a file called `CACHEDIR.TAG` with the first 43
bytes to be: "Signature: 8a477f597d28d172789f06886806bc55" (which
happens to be the MD5-checksum of ".IsCacheDirectory". Further content
is to be ignored. Any such files marks the directory in question as a
cache-directory.

The cachedir-tag has been successfully deployed in tools like `cargo`
and `VLC`, and is currently discussed to be implemented in Firefox. More
information is available here: https://bford.info/cachedir/

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:43 +01:00
David Rheinsberg
51d0f60843 util/fscache: add trace hooks
Add trace-hooks to the FsCache._atomic_open() helper, including a
primitive trace-infrastructure. They allow interrupting cache operation
and running arbitrary code.

The trace-hooks will be used by the test-suite to trigger the races we
want to protect against. During runtime, the traces should not be used
and thus will always be `None`.

This is a very primitive way to hook into the runtime execution and test
the atomicity of the operations. However, it is simple enough for our
tests and avoids pulling in huge tracing suites.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
290efe50fe util/fscache: make _atomic_open() NFS compatible
On NFS, we need to be careful with cached metadata. To make sure our
_atomic_open() can correctly catch races during open+lock, we must be
careful to catch `ESTALE` and `ENOENT` from `stat()` calls. Otherwise,
the lock-acquisition guarantees that data is coherent, even on NFS.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
144e0126a3 util/fscache: drop unused _libc
We no longer use the direct libc accessor, so drop it.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
2c18a54e4d util/fscache: avoid RENAME_NOREPLACE on commit
We used to commit cache-entries with a rename+RENAME_NOREPLACE. This,
however, is not available on NFS. Change the code to use `os.rename()`
and rely on the _documented_ kernel behavior that non-empty target
directories cannot be replaced.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
e6b77ac7df util/fscache: avoid RENAME_NOREPLACE in _atomic_file()
The `RENAME_NOREPLACE` option is not available on NFS. Avoid using it
in _atomic_file() to allow NFS backed storage.

If the caller allows replacing the destination entry, we simply use the
original `os.rename()` system call. This will unconditionally replace
the destination on all file-systems.

If the caller requests `no-replace`, we cannot use `os.rename()`.
Instead, we use `os.link()` to create a new hard-link on the
destination. This will always fail if the destination already exists.
We then rely on the cleanup-path to unlink the original temporary
entry.

This will require adjustments in future maintenance tasks on the cache,
since they need to be aware that entries can be hardlinked temporarily.
However, we already consider `uuid-*` entries in the object-store to be
temporary and unaccounted for similar reasons, so this doesn't even
break our cache-maintenance ideas.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
8a9efa89fc util/fscache: provide store_tree() helper
Add a helper that copies an entire directory tree including all metadata
into the cache. Use it in the ObjectStore to commit entries.

Unlike FsCache.store() this does not require entering the context from
the call-site. Instead, all data is directly passed to the cache and the
operation is under full control of the cache.

The ObjectStore is adjusted to make use of this. This requires exposing
the root-path (rather than the tree-path) to be accessible for
individual objects, hence a `path`-@property is added alongside the
`tree`-@property. Note that `__fspath__` still refers to the tree-path,
since this is the only path really required for outside access other
than from the object-manager itself.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
David Rheinsberg
50f8f6ac47 util/fscache: simplify get(*, None)
The default value for `get()` is `None`, so no reason to specify it
explicitly. Simplify the respective calls in FsCache.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-20 16:56:32 +01:00
Christian Kellner
3cc26444c9 monitor: show pipeline's source epoch
If set, print the source epoch of the pipeline.
2022-12-15 13:10:35 +00:00
Christian Kellner
6c0183da21 pipeline: set source_epoch for tree
This will lead to all mtimes that are newer than the creation time
of `tree` being clamped to `source_epoch`, if that was specified
for the pipeline. Specifically it means that all files that were
created during the build will be clamped to it. This should make
builds more reproducible.
2022-12-15 13:10:35 +00:00
Christian Kellner
15dc8b7a00 objectstore: clamp mtime on commit
When we commit objects to the store and there is a `source_epoch`
set on the `Object`, clamp the mtime. This is needed because it
is possible that the object corresponds to the last stage of a
pipeline[1] and it could later directly be exported without going
through `finalize` again. Also we are doing in on object itself
and not the cloned path so that resuming and checkpointing will
behave identical.

[1] not even necessarily the pipeline we are currently building.
2022-12-15 13:10:35 +00:00
Christian Kellner
76197c70c4 objectstore: support source_epoch for Object
Add a new `source_epoch` attribute that if set, will lead to all
mtimes that are newer or equal to the creation date being clamped
to the specified `source_epoch` time when the object is finalized.
2022-12-15 13:10:35 +00:00
Christian Kellner
b3c53e7275 objectstore: record creation time in Object
When an new Object is created, save the creation time in a new
metadata entry called `info`. A new property called `created`
is added to inspect the creation date.
2022-12-15 13:10:35 +00:00
Christian Kellner
39d38d33fd util/path: new clamp mtime function
New utility function to clamp all mtimes of a given path to a
certain timestamp. Clamp here means that any timestamp later
than the specified upper bound will be set to the upper bound.
2022-12-15 13:10:35 +00:00
David Rheinsberg
ef20b40faa util/fscache: introduce versioning
Add a new field to the cache-information called `version`, which is a
simple integer that is incremented on any backward-incompatible change.

The cache-implementation is modified to avoid any access to the cache
except for `<cache>/staging/`. This means, changes to the staging area
must be backwards compatible at all cost. Furthermore, it means we can
always successfully run osbuild even on possibly incompatible caches,
because we can always just ignore the cache and fully rely on the
staging area being accessible.

The `load()` method will always return cache-misses. The `store()`
method simply discards the entry instead of storing it. Note that
`store()` needs to provide a context to the caller, hence this
implementation simply creates another staging-context to provide to the
caller and then discard. This is non-optimal, but keeps the API simple
and avoids raising an exception to the caller (but this can be changed
if it turns out to be problematic or unwanted).

Lastly, the `cache.info` field behaves as usual, since this is also the
field used to read the cache-version. However, this file is never
written to improve resiliency and allow blacklisting buggy versions from
the past.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2022-12-15 08:55:39 +01:00
Sanne Raymaekers
cb989f79b1 util: fix typo in get_consumer_secrets
Consumer key and cert paths were swapped.
2022-12-09 21:46:43 +01:00
Christian Kellner
ae0680da11 osbuid: integrate FsCache into ObjectStore
Integrate the recently added file system cache `FsCache` into our
object store `ObjectStore`. NB: This changes the semantics of it:
previously a call to `ObjectStore.commit` resulted in the object
being in the cache (i/o errors aside). But `FsCache.store`, which
is now the backing store for objects, will only commit objects if
there is enough space left. Thus we cannot rely that objects are
present for reading after a call to `FsCache.store`. To cope with
this we now always copy the object into the cache, even for cases
where we previously moved it: for the case where commit is called
with `object_id` matching `Object.id`, which is the case for when
`commit` is called for last stage in the pipeline. We could keep
this optimization but then we would have to special case it and
not call `commit` for these cases but only after we exported all
objects; or in other words, after we are sure we will never read
from any committed object again. The extra complexity seems not
worth it for the little gain of the optimization.
Convert all the tests for the new semantic and also remove a lot
of them that make no sense under this new paradigm.

Add a new command line option `--cache-max-size` which will set
the maximum size of the cache, if specified.
2022-12-09 12:03:40 +01:00
Christian Kellner
1e0e1fa2c2 util: add helper to parse size strings
Code is based on `common.DataSizeToUint64` in Composer, with a
modification to allow `unlimited` so that the result is compatible
with `fscache.MaximumSizeType`.

[1] f4aed3e6e2/internal/common/helpers.go (L46)
2022-12-09 12:03:40 +01:00
Christian Kellner
809c9e7828 pipeline,api: write metadata directly
Instead of transmitting stage metadata over a socket and then
writing it via `Object.meta.write`, use the latter and bind
mount the corresponding file into the stage so it can directly
be written to from the stage. Change `api.metadata` to do so,
which means that this change is transparent for the stages.
2022-12-09 12:03:40 +01:00
Christian Kellner
8b638562d1 pipeline: remove metadata from BuildResult
The metadata field became unused with the previous commit, which
uses `Object.meta` to read the metadata.
2022-12-09 12:03:40 +01:00
Christian Kellner
4b94769f6b format: read metadata from object not result
Now that metadata is stored and can be accessed via `Object.meta`,
read it from the built or stored objects when serializing the
result in the `format.output` functions.
2022-12-09 12:03:40 +01:00
Christian Kellner
1205de0abb objectstore: integrate metadata object
Integrate the new `Metadata` object as `meta` property on `Object`.
Use it to actually store metadata after a successful stage run.
A new class `PathAdapter` is introduce which is in turned used to
expose the base path of `Object` as `os.PathLike` so it can be
passed as path to `Metadata`. The advantage is that any changes
to the base path in `Object` will automatically be picked up by
`Metadata`; the prominent, and currently only, case where this is
happening in `Object` is `store_tree`.
2022-12-09 12:03:40 +01:00
Christian Kellner
fec9dcea97 objectstore: implement a new metadata class
Implement a new class, nested inside `Object`, to read and write
metadata. It is indexed by a key and individual pieces of meta-
data are stored in separate files. Empty files are not created.
2022-12-09 12:03:40 +01:00
Christian Kellner
baa547b5e9 fmt/v2: extract metadata gathering into function
Extract the piece of code that gathers the metadata from the
result struct into its own (nested) method. It is easier to
read but also prepares for a future change where we read the
metadata from the store instead of the result dict.
2022-12-09 12:03:40 +01:00
Christian Kellner
8f40faf3d5 cli: move result reporting into store context
Move the reporting of results into the try-cache and ObjectStore
context. This prepares to use the store during the `fmt.output`
call and possible reporting of store cache usages.
2022-12-09 12:03:40 +01:00
Christian Kellner
917c5bb2f5 objectstore: store object data within subfolder
Instead of storing the (tree) data directly at the root of the
object specific directory, move it into a `data/tree` subfolder.
This prepares for two things:
1) the `tree` folder will allow us to add another folder next to
   it to store metadata.
2) storing both, `tree` and the future metadata folder in a
   common subfolder, prepares for the future integration
   with the new caching layer (`FsCache`).
2022-12-09 12:03:40 +01:00
schutzbot
cf4608fe43 Post release version bump
[skip ci]
2022-12-07 08:15:17 +00:00
David Rheinsberg
4df05b8509 util: add file system cache
This commit introduces a new utility module called `fscache`. It
implements a cache module that stores data on the file system. It
supports parallel access and protects data with file-system locks. It
provides three basic functions:

    FsCache.load("<name>"):
        Loads the cache entry with the specified name, acquires a
        read-lock and yields control to the caller to use the entry.
        Once control returns, the entry is unlocked again.

        If the entry cannot be found, a cache miss is signalled via
        FsCache.MissError.

    FsCache.store("<name>"):
        Creates a new anonymous cache entry and yields control to the
        caller to fill in. Once control returns, the entry is renamed
        to the specified name, thus committing it to the object store.

    FsCache.stage():
        Create a new anonymous staging entry and yield control to the
        caller. Once control returns, the entry is completely
        discarded.

        This is primarily used to create a working directory for osbuild
        pipeline operations. The entries are volatile and automatic
        cleanup is provided.

        To commit a staging entry, you would eventually use
        FsCache.store() and rename the entire data directory into the
        non-volatile entry. If the staging area and store are on
        different file-systems, or if the data is to be retained for
        further operations, then the data directory needs to be copied.

Additionally, the cache maintains a size limit and discards any entries
if the limit is exceeded. Future extensions will implement cache pruning
if a configured watermark is reached, based on last-recently-used
logics.

Many more cache extensions are possible. This module introduces a first
draft of the most basic cache and hopefully lays ground for a new cache
infrastructure.

Lastly, note that this only introduces the utility helper. Further work
is required to hook it up with osbuild/objectstore.py.
2022-12-06 09:48:38 +01:00
David Rheinsberg
efe4ad4b92 linux: add Libc accessor with renameat2(2)
Add a new utility that wraps ctypes.CDLL() for the self-embedded
libc.so. Initially, it only exposes renameat2(2), but more can be added
when needed in the future.

The Libc class is very similar to the existing LibCap class, with a
similar instantiation logic with singleton access.

In the future, the Libc class will allow access to other system calls
and libc.so functionality, when needed.
2022-12-06 09:48:38 +01:00