Move from package-based to path-based secret-store filters #181

Merged
Jan Lindemann merged 9 commits from jan/feature/20261118-move-from-package-based-to-path-based-secret-store-filters into master 2026-11-18 19:24:59 +01:00 AGit
Owner

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()

files is a term that can be used for many aspects of a file, its path, its content, a handle, so better use pkg_paths instead of pkg_files for 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. Adopt jw-python's kebab_to_pascal() and pascal_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-grained paths() method, taking a PathFilter instead of a PackageFilter. It additionally takes a pkg_names argument, 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 in Pkg._access() - we can directly get to the list of paths instead of via Distro.select() -> pkg_paths().

lib.ec.secret_store: "content|config" -> "target"

Rename lib.ec.secret_store.layout.content_name() to target_name() and KvFile's config_path to target_path(). Target is a better name to settle on instead of config or content. 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-tmpl suffix 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=~REGEX narrows 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-secret and .jw-secret-file detection 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.

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() `files` is a term that can be used for many aspects of a file, its path, its content, a handle, so better use `pkg_paths` instead of `pkg_files` for 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. Adopt `jw-python`'s `kebab_to_pascal()` and `pascal_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-grained `paths()` method, taking a PathFilter instead of a PackageFilter. It additionally takes a `pkg_names` argument, 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 in `Pkg._access()` - we can directly get to the list of paths instead of via `Distro.select()` -> `pkg_paths()`. #### lib.ec.secret_store: "content|config" -> "target" Rename `lib.ec.secret_store.layout.content_name()` to `target_name()` and KvFile's `config_path` to `target_path()`. `Target` is a better name to settle on instead of `config` or `content`. 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-tmpl` suffix 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=~`REGEX` narrows 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-secret` and `.jw-secret-file` detection 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.
"files" is a term that can be used for many aspects of a file, its path,
its content, a handle, so better use "pkg_paths" instead of "pkg_files" for
Distro's method to inform about which files a package holds. That also
aligns better with the recent move from PackageFilter toward PathFilter.

Signed-off-by: Jan Lindemann <jan@janware.com>
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. Adopt jw-python's kebab_to_pascal() and
pascal_to_kebab() functions as a foundation for a future naming convention.

Signed-off-by: Jan Lindemann <jan@janware.com>
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.

Signed-off-by: Jan Lindemann <jan@janware.com>
After the introduction of path-based filters, accompany the existing
pkg_paths() method by a more fine-grained paths() method, taking a
PathFilter instead of a PackageFilter. It additionally takes a "pkg_names"
argument, 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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Distro.paths() now allows to spare a detour in Pkg._access() - we can
directly get to the list of paths instead of via Distro.select() ->
pkg_paths().

Signed-off-by: Jan Lindemann <jan@janware.com>
Rename lib.ec.secret_store.layout.content_name() to target_name() and
KvFile's config_path to target_path(). "Target" is a better name to settle
on instead of "config" or "content". It's used in other contexts, too,
referring to secret compilation output.

Signed-off-by: Jan Lindemann <jan@janware.com>
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-tmpl
suffix 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=~REGEX narrows 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.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
.jw-secret and .jw-secret-file detection 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 PkgSecret's cache.

Signed-off-by: Jan Lindemann <jan@janware.com>
lib.ec.secret_store.KvFile: Use lib.pf.PkgSecrets
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 5m12s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 6m36s
CI / Packaging test (pull_request) Successful in 0s
f717fe2174
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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-11-18 19:13:06 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!181
No description provided.