1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-10 05:18:17 +03:00
Commit Graph

66561 Commits

Author SHA1 Message Date
Topi Miettinen
fc289dd0ad
network: firewall integration with NFT sets
New directive `NFTSet=` provides a method for integrating network configuration
into firewall rules with NFT sets. The benefit of using this setting is that
static network configuration or dynamically obtained network addresses can be
used in firewall rules with the indirection of NFT set types. For example,
access could be granted for hosts in the local subnetwork only. Firewall rules
using IP address of an interface are also instantly updated when the network
configuration changes, for example via DHCP.

This option expects a whitespace separated list of NFT set definitions. Each
definition consists of a colon-separated tuple of source type (one of
"address", "prefix", or "ifindex"), NFT address family (one of "arp", "bridge",
"inet", "ip", "ip6", or "netdev"), table name and set name. The names of tables
and sets must conform to lexical restrictions of NFT table names. The type of
the element used in the NFT filter must match the type implied by the
directive ("address", "prefix" or "ifindex") and address type (IPv4 or IPv6)
as shown type implied by the directive ("address", "prefix" or "ifindex") and
address type (IPv4 or IPv6) must also match the set definition.

When an interface is configured with IP addresses, the addresses, subnetwork
masks or interface index will be appended to the NFT sets. The information will
be removed when the interface is deconfigured. systemd-networkd only inserts
elements to (or removes from) the sets, so the related NFT rules, tables and
sets must be prepared elsewhere in advance. Failures to manage the sets will be
ignored.

/etc/systemd/network/eth.network
```
[DHCPv4]
...
NFTSet=prefix:netdev:filter:eth_ipv4_prefix
```

Example NFT rules:
```
table netdev filter {
        set eth_ipv4_prefix {
                type ipv4_addr
                flags interval
        }
        chain eth_ingress {
                type filter hook ingress device "eth0" priority filter; policy drop;
                ip saddr != @eth_ipv4_prefix drop
                accept
        }
}
```
```
$ sudo nft list set netdev filter eth_ipv4_prefix
table netdev filter {
        set eth_ipv4_prefix {
                type ipv4_addr
                flags interval
                elements = { 10.0.0.0/24 }
        }
}
```
2023-08-26 21:37:09 +03:00
Topi Miettinen
274ffe1abb
shared/firewall-util: make NFT table init optional 2023-08-23 19:54:08 +03:00
Topi Miettinen
0872f0bbe9
shared/firewall-util: parametrize table name
Parametrize table name for nft_{add,del}_element.
2023-08-23 19:53:50 +03:00
Topi Miettinen
940965803e
shared/firewall-util: parametrize table and set names
Parametrize table and set names for fw_nftables_add_masquerade_internal, rename
to nft_set_element_op_iprange to reflect more general usage. Export and use
nfproto_is_valid().

Remove also unused and obsolete NFPROTO_DECNET.
2023-08-23 19:53:13 +03:00
Mike Yuan
804c6397bc man/systemd: avoid duplicate variable name 2023-08-05 15:05:10 +09:00
Frantisek Sumsal
04bce24d4e test: ignore missing libudev when creating the test image
Same scenario as with libsystemd - ldd might use unprefixed RPATH, and
we install our own stuff into the image unconditionally anyway.

Also, bail out early if we hit a missing DSO with a possibly helpful
message.
2023-08-05 13:32:17 +09:00
Dan Streetman
9afd4dde22 tpm2: use ELEMENTSOF() instead of sizeof() for TPML_PCR_SELECTION pcrSelections field
The count field indicates the number of elements in the pcrSelections field,
and the size of each elements is greater than 1 byte, so using sizeof() is
incorrect when verifying the count field is valid; instead ELEMENTSOF() should
be used.

Caught by coverity check: https://github.com/systemd/systemd/pull/26331#pullrequestreview-1556629586
2023-08-05 13:31:59 +09:00
Yu Watanabe
42f13f10d5
Merge pull request #28681 from yuwata/udev-vs-tmpfiles
Udev vs tmpfiles
2023-08-05 13:30:49 +09:00
Luca Boccassi
06e8f7af7b
Merge pull request #28398 from ddstreet/tpm2_specify_pcr_value
Tpm2 specify pcr value
2023-08-04 21:04:03 +01:00
Yu Watanabe
23acdb8d0b test: shorten timeout for 'udevadm monitor'
The command should never finish, it is not necessary to wait so long.
2023-08-05 05:03:20 +09:00
Yu Watanabe
b768379e8b test: add short test for device node permission 2023-08-05 04:52:16 +09:00
Yu Watanabe
31845ef554 unit: make udev rules take precesence over tmpfiles
Without this change, there are no ordering between udevd and tmpfiles,
and if tmpfiles is invoked later it may discard the permission set by
udevd.

Fixes an issue introduced by b42482af90.

Fixes #28588 and #28653.
2023-08-05 04:38:39 +09:00
Yu Watanabe
33b91308c2 Revert "tmpfiles.d: adjust /dev/vfio/vfio access mode"
The issue needs to be fixed by setting proper ordering between the
tmpfiles and udevd.

See issue #28653, especially
https://github.com/systemd/systemd/issues/28653#issuecomment-1665181625.

This reverts commit a3d610998a.
2023-08-05 04:32:01 +09:00
Zbigniew Jędrzejewski-Szmek
8cb0008977 journalctl: fix loggging invocation
Fixup for f882a986c2.
2023-08-04 20:21:13 +01:00
Luca Boccassi
7f878268ff
Merge pull request #28679 from keszybz/two-new-news-tweaks
Two news tweaks
2023-08-04 19:24:46 +01:00
Daan De Meyer
73e6b6974b
Merge pull request #28669 from DaanDeMeyer/mkosi-fix
mkosi: Make sure our systemd build always overrides the distros
2023-08-04 20:16:55 +02:00
Daan De Meyer
5dd814d7cd tmpfiles: Consider ENOPKG as information not available
We already handle the case where /etc/machine-id is empty. Let's make
sure we also handle the case where /etc/machine-id is "uninitialized".
2023-08-04 20:16:23 +02:00
Luca Boccassi
bdfa3f3a5c portablectl: fix regression when using --force without extension parameters
c18f4eb9e9 made it possible to use --force with various verbs, by
going through the newer D-Bus methods. Except it didn't, as it regressed
during PR review refactorings, and nobody noticed because there were no
tests for it. Fix it, and add tests.

Follow-up for c18f4eb9e9
2023-08-04 18:29:57 +01:00
Luca Boccassi
0e387e1295
Merge pull request #28673 from YHNdnzj/hibernate-resume-escape-node
hibernate-resume-generator: escape device path passed to hibernate-resume
2023-08-04 16:46:56 +01:00
Dan Streetman
e85ddd9644 tpm2: update TEST-70-TPM2 to test passing PCR value to systemd-cryptenroll
Add tests to use expected, not current, PCR values during sealing.
2023-08-04 11:20:33 -04:00
Dan Streetman
1782b0b88c man: update systemd-cryptenroll man page with details on --tpm2-pcrs format change
The previous commit extended the accepted format of --tpm2-pcrs to allow
specifying the hash algorithm (i.e. PCR bank) and hash digest value, this
updates the man page with those changes.
2023-08-04 11:20:31 -04:00
Dan Streetman
9e4379945b tpm2: move policy calculation out of tpm2_seal()
Move the calculation of the sealed object policy hash out of the tpm2_seal()
function. Instead, callers of tpm2_seal() can directly call
tpm2_calculate_sealing_policy() and then provide the policy hash to
tpm2_seal().
2023-08-04 11:20:22 -04:00
Dan Streetman
e3acb4d24c tpm2: add functions to convert TPM2B_PUBLIC to/from openssl pkey or PEM
Add functions to convert a PEM or pkey to TPM2B_PUBLIC, and functions to
convert TPM2B_PUBLIC to pkey or fingerprint.

Supports both RSA and ECC keys.

Add ECC support to some test-tpm2 tests, and tests to cover the newly added functions.
2023-08-04 11:19:54 -04:00
Dan Streetman
cffeee92bb openssl: add test-openssl
Add openssl unit tests.
2023-08-04 11:18:14 -04:00
Dan Streetman
0fdcfa7812 test: add DEFINE_HEX_PTR() helper function
Use function in test-tpm2 to convert hex strings to void* and len vars.
2023-08-04 10:57:08 -04:00
Dan Streetman
900e73f80e openssl: add ecc_pkey_new(), ecc_pkey_from_curve_x_y(), ecc_pkey_to_curve_x_y()
Add function to create openssl pkey from ECC curve and point, and function to
get curve id and x/y point from existing ECC pkey. Also add function to create
new ECC key for specified curve.

Also add DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO() to handle case when func() is
a macro, not a function symbol; specifically in this case it is used for
OPENSSL_free() which is a macro.
2023-08-04 10:57:08 -04:00
Dan Streetman
dcec950ca1 openssl: add rsa_pkey_new(), rsa_pkey_from_n_e(), rsa_pkey_to_n_e()
Add function to generate an EVP_PKEY for a specific 'n' and 'e', and function
to get 'n' and 'e' values from existing RSA public key. Also add a function to
generate a new RSA key with a specified number of bits.
2023-08-04 10:57:07 -04:00
Dan Streetman
4af788c70c openssl: add openssl_pkey_from_pem()
Add function to create EVP_PKEY from PEM buffer.
2023-08-04 10:57:07 -04:00
Dan Streetman
b4a6fcd5c5 tpm2: add tpm2_pcr_read_missing_values()
Add function to read all unset values in an array of Tpm2PCRValue entries.

Also publish tpm2_pcr_read() in header.
2023-08-04 10:57:07 -04:00
Dan Streetman
53b91e1981 tpm2: add TPM2B_*_MAKE(), TPM2B_*_CHECK_SIZE() macros
The tpm2-tss library has many structs with only an array and size; these macros
make it easy to assign to these structs.
2023-08-04 10:57:07 -04:00
Dan Streetman
07c0406117 tpm2: change tpm2_parse_pcr_argument() parameters to parse to Tpm2PCRValue array
In order to allow users to specify expected PCR values, change the
tpm2_parse_pcr_argument() to parse the text argument into an array of
Tpm2PCRValue objects, which provide not only the selected PCR indexes, but also
(optionally) the hash algorithm and hash value for each PCR index.
2023-08-04 10:57:07 -04:00
Dan Streetman
6e8fb3ad5f tpm2: change tpm2_calculate_policy_pcr(), tpm2_calculate_sealing_policy() to use Tpm2PCRValue array
An array of Tpm2PCRValue objects effectively replaces a TPML_PCR_SELECTION
object combined with an array of (properly ordered) TPM2B_DIGEST objects.

Also update tpm2_calculate_sealing_policy() pin parameter to boolean use_pin,
since the function does not need to know the pin value, only if a pin is being
used.
2023-08-04 10:57:07 -04:00
Dan Streetman
75de375aaf tpm2: declare tpm2_log_debug_*() functions in tpm2_util.h
Allow other code to use the log debug functions; e.g. they are useful in test
code.
2023-08-04 10:57:07 -04:00
Dan Streetman
e00f46ac7f tpm2: move declared functions in header lower down
Move some function declarations lower down, below the Tpm2Context and
Tpm2Handle typedefs; later commits will reference the typedefs in some of the
functions, so the typedefs need to come first in the header.

This only moves the declarations, none of the declarations are modified.
2023-08-04 10:57:07 -04:00
Dan Streetman
323eb4803a tpm2: add Tpm2PCRValue struct and associated functions
Add a new struct that can represent a PCR index, hash, and value all
together. This replaces code (e.g. the tpm2_pcr_read() parameters) that
required using both a TPML_PCR_SELECTION as well as array of TPM2B_DIGEST
entries, which was difficult to correlate the selection hash/index to each
digest.
2023-08-04 10:57:05 -04:00
Dan Streetman
13b551744b tpm2: add more helper functions for managing TPML_PCR_SELECTION and TPMS_PCR_SELECTION
Add more functions to help manage these objects.
2023-08-04 10:55:53 -04:00
Dan Streetman
dbaae766c7 tpm2: change tpm2_tpm*_pcr_selection_to_mask() to return mask
This simplifies use of the functions, as well as avoiding the use of -ENOENT
from tpm2_tpml_pcr_selection_to_mask().
2023-08-04 10:55:53 -04:00
Dan Streetman
c9df1fb119 tpm2: add tpm2_hash_alg_to_size()
Add function to get the hash size for a hash algorithm
2023-08-04 10:55:53 -04:00
Dan Streetman
240774f5ce tpm2: add debug logging to functions converting hash or asym algs to/from strings or ids
Add debug log message if the algorithm name or id is not known.
2023-08-04 10:55:53 -04:00
Daan De Meyer
33772b5da6 mkosi: Use SuccessActionExitStatus= in mkosi-check-and-shutdown.service 2023-08-04 16:49:07 +02:00
Daan De Meyer
6ac5aa97ec mkosi: Make sure our systemd build always overrides the distros
Currently, we install the systemd install tree in the base image and
then build the initrd and final images from the base image. This means
if that any systemd package is pulled in during the initrd or final
image builds, it will override our version.

To fix this, we stop installing our build of systemd in the base image,
and store it in the output directory instead. That allows us to refer to
it using ExtraTrees= in the final and initrd image builds to install it
after all the distro packages have been installed, ensuring our version
always takes priority.
2023-08-04 16:49:07 +02:00
Daan De Meyer
f2f8ed193c mkosi: Update to latest 2023-08-04 16:48:58 +02:00
Daan De Meyer
a1fedc613f test-user-util: Drop tty check in gid_to_name() test
The tty user is not guaranteed to exist, so let's remove the dependency
from the test.
2023-08-04 16:48:39 +02:00
Zbigniew Jędrzejewski-Szmek
b77ff21ade NEWS: adjust grammar 2023-08-04 15:45:26 +01:00
Zbigniew Jędrzejewski-Szmek
e9ae4187bb NEWS: expand list of new Startup* settings
This way users can grep/search the NEWS file for when a given setting was
added.
2023-08-04 15:45:26 +01:00
Kingbom Dou
8f1c446979 timesyncd: emit signal when timesyncd NTPServers property changes
Emit signal when timesyncd LinkNTPServers property changes

Tested:
```
 Monitoring bus message stream.
```
```
> Type=signal  Endian=l  Flags=1  Version=1 Cookie=21  Timestamp="Fri 2023-05-19 07:50:47.427051 UT"
  Sender=:1.623  Path=/org/freedesktop/timesync1  Interface=org.freedesktop.DBus.Properties  Memberd
  UniqueName=:1.623
  MESSAGE "sa{sv}as" {
          STRING "org.freedesktop.timesync1.Manager";
          ARRAY "{sv}" {
                  DICT_ENTRY "sv" {
                          STRING "LinkNTPServers";
                          VARIANT "as" {
                                  ARRAY "s" {
                                          STRING "10.8.8.18";
                                          STRING "10.8.8.19";
                                  };
                          };
                  };
          };
          ARRAY "s" {
          };
  };
```
```
> Type=signal  Endian=l  Flags=1  Version=1 Cookie=28  Timestamp="Fri 2023-05-19 07:53:22.609416 UT"
  Sender=:1.623  Path=/org/freedesktop/timesync1  Interface=org.freedesktop.DBus.Properties  Memberd
  UniqueName=:1.623
  MESSAGE "sa{sv}as" {
          STRING "org.freedesktop.timesync1.Manager";
          ARRAY "{sv}" {
                  DICT_ENTRY "sv" {
                          STRING "LinkNTPServers";
                          VARIANT "as" {
                                  ARRAY "s" {
                                          STRING "10.8.8.18";
                                          STRING "10.8.8.20";
                                  };
                          };
                  };
          };
          ARRAY "s" {
          };
  };
```
```
> Type=signal  Endian=l  Flags=1  Version=1 Cookie=6  Timestamp="Fri 2023-05-19 08:12:26.964666 UTC"
  Sender=:1.627  Path=/org/freedesktop/timesync1  Interface=org.freedesktop.DBus.Properties  Memberd
  UniqueName=:1.627
  MESSAGE "sa{sv}as" {
          STRING "org.freedesktop.timesync1.Manager";
          ARRAY "{sv}" {
                  DICT_ENTRY "sv" {
                          STRING "LinkNTPServers";
                          VARIANT "as" {
                                  ARRAY "s" {
                                          STRING "10.8.8.18";
                                  };
                          };
                  };
          };
          ARRAY "s" {
          };
  };
```
```
> Type=signal  Endian=l  Flags=1  Version=1 Cookie=162  Timestamp="Mon 2023-07-10 09:06:18.865654 UTC"
  Sender=:1.1  Path=/org/freedesktop/timesync1  Interface=org.freedesktop.DBus.Properties  Member=PropertiesChanged
  UniqueName=:1.1
  MESSAGE "sa{sv}as" {
          STRING "org.freedesktop.timesync1.Manager";
          ARRAY "{sv}" {
                  DICT_ENTRY "sv" {
                          STRING "RuntimeNTPServers";
                          VARIANT "as" {
                                  ARRAY "s" {
                                          STRING "10.2.16.10";
                                  };
                          };
                  };
          };
          ARRAY "s" {
          };
  };
```

Signed-off-by: Kingbom Dou <doujinbao@bytedance.com>
2023-08-04 14:25:41 +01:00
Mike Yuan
caf8d692ed
hibernate-resume-generator: escape device path passed to hibernate-resume
Follow-up for #27330

Fixes #28668
2023-08-04 21:04:45 +08:00
Mike Yuan
83d373d213
man/systemd.unit: DefaultTimeoutStartSec= -> DefaultDeviceTimeoutSec=
for device unit job timeouts

Follow-up for #24044
2023-08-04 20:53:02 +08:00
Antonio Alvarez Feijoo
000680a68d man/systemd-fsck@.service: clarify passno and noauto combination in /etc/fstab
Fixes #28657
2023-08-04 11:33:18 +01:00
Daan De Meyer
bd6c95c00b debug-generator: Use generator_add_symlink() 2023-08-04 11:32:42 +01:00