Move from package-based to path-based secret-store filters #181
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20261118-move-from-package-based-to-path-based-secret-store-filters"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR moves the secret-store filter from a package-based to a more general
path-based concept. PackageFilter is moved to lib.pf.Pkg, and becomes an
implementation of the new PathFilter base class.
lib.Distro.pkg_files() -> .pkg_paths()
filesis a term that can be used for many aspects of a file, its path, its content, a handle, so better usepkg_pathsinstead ofpkg_filesfor Distro's method to inform about which files a package holds. That also aligns better with the recent move from PackageFilter toward PathFilter.lib.util: Add kebab_to_pascal() and pascal_to_kebab()
PathFilter.create()currently instantiates individual filters in a match - case over the filter URI's protocol. The plan is to instantiate filters without match / case based on a protocol naming scheme only, so we better introduce one at this point. Adoptjw-python'skebab_to_pascal()andpascal_to_kebab()functions as a foundation for a future naming convention.lib.FileContext: Add _set / _create_path_filter()
Make the
__create_path_filter()closure an overwritable, protected method_create_path_filter(), and add_set_path_filter()to allow subclasses to hook into external path filter manipulations, too.lib.Distro.paths(): Add method
After the introduction of path-based filters, accompany the existing
pkg_paths()method by a more fine-grainedpaths()method, taking a PathFilter instead of a PackageFilter. It additionally takes apkg_namesargument, which is then dispatched to the filter if it's a package filter. The API isn't glorious, but works for now and is easily changeable in the future: **kwargs comes to mind, or a PackageFilter which brings its own package names.pf.Pkg._access(): Use Distro.paths()
Distro.paths()now allows to spare a detour inPkg._access()- we can directly get to the list of paths instead of viaDistro.select()->pkg_paths().lib.ec.secret_store: "content|config" -> "target"
Rename
lib.ec.secret_store.layout.content_name()totarget_name()and KvFile'sconfig_pathtotarget_path().Targetis a better name to settle on instead ofconfigorcontent. It's used in other contexts, too, referring to secret compilation output.lib.pf.PkgSecrets: Add
The on-host store scopes its address space to the config paths backed by installed packages, but the scope lives inside KvFile: it derives the set from the distro itself and consults it in the individual operations. A context that carries a filter must behave as the filter mandates, so the wanted set belongs in a filter of its own.
Add the pkg-secrets path filter, a Pkg whose space is the config paths of the matching packages' template files - the path with the
.jw-tmplsuffix stripped - plus the directories leading to them. A compound or blob address maps to its config path, a key address to the config path of the compound it lives under; any other address is judged on its own. The spec form follows pkg: a bare spec matches every installed package, and pkg-secrets:url=~REGEXnarrows the backing set to packages whose url matches. Pkg parses its criterion through an overridable_parse_spec(), and its_match_pkg()matches every package on a None criterion, so both filters share the parsing and matching code.lib.ec.secret_store.KvFile: Use PkgSecrets.target_paths()
.jw-secretand.jw-secret-filedetection on a distro's packages should happend in a central place.PkgSecrets.distro_target_paths()is that place, use it, instead of rolling our own detection loop.target_paths()is a welcome performance-enhancement, reusing PkgSecrets' cache.lib.ec.secret_store.KvFile: Use lib.pf.PkgSecrets
Do the filtering outside of KvFile, in a standard way.
KvFile currently instantiates its backend distro with a self-instantiated backend filter, and doesn't propagate the filter passed to its ctor up to its base class. This arrangement makes it hard to ensure the class behaves in a standardish way. Allowing the base class filter to do its work, and not pass any filter to the backend context, is the more straightforward architecture, this is what this commit does.
The base class still has some freedom to create a filter. Override the base class's
_create_path_filter()to make sure that filter is a PkgSecrets / pkg-secrets: filter, anything else is not thought through at this point.