Skip to content

networkd: NetLabel integration#23269

Merged
topimiettinen merged 1 commit intosystemd:mainfrom
topimiettinen:networkd-netlabel
Jun 6, 2022
Merged

networkd: NetLabel integration#23269
topimiettinen merged 1 commit intosystemd:mainfrom
topimiettinen:networkd-netlabel

Conversation

@topimiettinen
Copy link
Copy Markdown
Contributor

New directives IPv4NetLabelUnlabel= and IPv6NetLabelUnlabel= provide a
method for integrating dynamic network configuration into Linux NetLabel
subsystem rules, used by Linux security modules (LSMs) for network access
control. The options expect a whitespace separated list of NetLabel
labels. The labels must conform to lexical restrictions of LSM labels. When
an interface is configured with IP addresses, the addresses and subnetwork
masks will be appended to the NetLabel Fallback Peer Labeling rules. They will
be removed when the interface is deconfigured. Failures to manage the labels
will be ignored.

Example:

IPv4NetLabelUnlabel=system_u:object_r:localnet_peer_t:s0

With the above rules for interface eth0, when the interface is configured with
an IPv4 address of 10.0.0.0/8, systemd-networkd performs the equivalent of
netlabelctl operation

$ sudo netlabelctl unlbl add interface eth0 address:10.0.0.0/8 label:system_u:object_r:localnet_peer_t:s0

Result:

$ sudo netlabelctl -p unlbl list
...
 interface: eth0
   address: 10.0.0.0/8
    label: "system_u:object_r:localnet_peer_t:s0"
...

@topimiettinen
Copy link
Copy Markdown
Contributor Author

Information for Fallback Peer Labeling for SELinux could be helpful to the reviewers.

@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented May 4, 2022

This pull request introduces 1 alert when merging 133cf88 into b0221bb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@topimiettinen
Copy link
Copy Markdown
Contributor Author

focal-amd failure most likely unrelated.

@yuwata PTAL.

Copy link
Copy Markdown
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of introducing IPv4NetLabelUnlabel=and IPv6NetLabelUnlabel= in [Network] section, please add NetLabel= or so in [Address], [DHCPv4], [DHCPv6], [IPv6AcceptRA], [DHCPPrefixDelegation] sections.
Then, we can assign different labels to each address.

Also, please move the netlabel related functions to networkd-netlabel.[ch] or so, as networkd-address.c and networkd-network.c are already too big.

@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks new-feature and removed please-review labels May 6, 2022
@topimiettinen topimiettinen force-pushed the networkd-netlabel branch 2 times, most recently from f1e10ff to 705af57 Compare May 9, 2022 19:11
@topimiettinen topimiettinen requested a review from yuwata May 9, 2022 20:23
@yuwata yuwata added please-review and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks ci-failure-appears-unrelated labels May 10, 2022
@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review labels May 10, 2022
@topimiettinen topimiettinen added please-review and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 10, 2022
@topimiettinen
Copy link
Copy Markdown
Contributor Author

Hmm, still fails because of memory leaks.

@yuwata yuwata added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label May 15, 2022
@topimiettinen
Copy link
Copy Markdown
Contributor Author

Thanks for the review, updated.

@topimiettinen topimiettinen removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label May 16, 2022
@topimiettinen
Copy link
Copy Markdown
Contributor Author

All green!

New directive `NetLabel=` provides a method for integrating dynamic network
configuration into Linux NetLabel subsystem rules, used by Linux security
modules (LSMs) for network access control. The option expects a whitespace
separated list of NetLabel labels. The labels must conform to lexical
restrictions of LSM labels. When an interface is configured with IP addresses,
the addresses and subnetwork masks will be appended to the NetLabel Fallback
Peer Labeling rules. They will be removed when the interface is
deconfigured. Failures to manage the labels will be ignored.

Example:
```
[DHCP]
NetLabel=system_u:object_r:localnet_peer_t:s0
```

With the above rules for interface `eth0`, when the interface is configured with
an IPv4 address of 10.0.0.0/8, `systemd-networkd` performs the equivalent of
`netlabelctl` operation

```
$ sudo netlabelctl unlbl add interface eth0 address:10.0.0.0/8 label:system_u:object_r:localnet_peer_t:s0
```

Result:
```
$ sudo netlabelctl -p unlbl list
...
 interface: eth0
   address: 10.0.0.0/8
    label: "system_u:object_r:localnet_peer_t:s0"
...
```
@topimiettinen topimiettinen merged commit 3cf6383 into systemd:main Jun 6, 2022
@topimiettinen topimiettinen deleted the networkd-netlabel branch June 7, 2022 17:23
@keszybz
Copy link
Copy Markdown
Member

keszybz commented Jun 8, 2022

Why was this merged without review?

@topimiettinen
Copy link
Copy Markdown
Contributor Author

But it was reviewed by @yuwata.

@evverx
Copy link
Copy Markdown
Contributor

evverx commented Jun 8, 2022

FWIW to avoid scenarios like this it should be possible to somewhat enforce approvals with https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule

Optionally, to require approvals before a pull request can be merged, select Require approvals, click the Required number of approvals before merging drop-down menu, then select the number of approving reviews you would like to require on the branch.

It's probably bureaucracy but on the other hand it appears a lot of PRs have been approved like that anyway so it seems it shouldn't be too annoying.

@yuwata
Copy link
Copy Markdown
Member

yuwata commented Jun 9, 2022

But it was reviewed by @yuwata.

I reviewed several times, but I have neither said 'LGTM' nor set the green label...

Sorry for late final review, but this needs to be re-reviewed. Temporary setting 'merged-but-needs-fixing'.

Comment on lines +1117 to +1121
<para>This setting provides a method for integrating dynamic network configuration into Linux
NetLabel subsystem rules, used by Linux security modules (LSMs) for network access control. The
option expects a whitespace separated list of NetLabel labels. The labels must conform to lexical
restrictions of LSM labels. When an interface is configured with IP addresses, the addresses and
subnetwork masks will be appended to the NetLabel Fallback Peer Labeling rules. They will be
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to add some hyperrefences here, e.g. to kernel docs for LSM and NetLabel.

<varlistentry>
<term><varname>NetLabel=</varname></term>
<listitem>
<para>As in [Address] section.</para>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This setting accepts the same arguments as NetLabel= in the [Address] section."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same short text 'As in ...' like is used elsewhere in this manual page (MUDURL=, UseDNS=, MACAddress= etc). Wouldn't it be more consistent to use similar style also here so that it can be sort of skipped by the reader more easily?

<varlistentry>
<term><varname>NetLabel=</varname></term>
<listitem>
<para>As in [Address] section.</para>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

<varlistentry>
<term><varname>NetLabel=</varname></term>
<listitem>
<para>As in [Address] section.</para>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

return 1;
}

log_link_debug(link, "NetLabel operation successful");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this message is not very informative. If I saw it without context, I would have no idea what was being done and why. Can you rephrase it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be nice to have more verbose message explaining what exactly was successful (or what failed). But there isn't any context related to the operation available in the callback, just Link (which may have several Address) and the raw message.

In the earlier version I used synchronous sending and then the errors messages were able to be more precise.

/* Label semantics depend on LSM but let's do basic checks */
if (!string_is_safe(w)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Bad NetLabel label, ignoring: %s", w);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If w is not safe, it shouldn't be printed. Please cescape it before pritning.

r = netlabel_command(NLBL_UNLABEL_C_STATICADD, label, address);
if (r < 0)
log_link_warning_errno(address->link, r, "Adding NetLabel %s for IP address %s failed, ignoring: %m",
label, strna(addr_str));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%m is missing.

Comment on lines +156 to +157
int r;
Set **set = data;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set **set = ASSERT_PTR(data);
int r;

topimiettinen added a commit to topimiettinen/systemd that referenced this pull request Jun 11, 2022
Add links to documentation to NetLabel, LSM, Netlabel Fallback Peer Labeling
and NFT.

Use a positive boolean function nft_identifier_good() to help grok the checks
more easily than nft_identifier_bad().

Escape logged invalid items.

Add an ASSERT_PTR() for 'data' in config_parse_netlabel().

Use a different debug message when NFT operation fails.

Align nfproto_table strings.

Remove NFT_SET_MSGS, it's only used once.
@topimiettinen
Copy link
Copy Markdown
Contributor Author

Created #23712 for the fixes.

yuwata pushed a commit to yuwata/systemd that referenced this pull request Jun 17, 2022
yuwata pushed a commit to yuwata/systemd that referenced this pull request Jun 18, 2022
yuwata added a commit to yuwata/systemd that referenced this pull request Jun 22, 2022
This reverts PR systemd#23269 and its follow-up commit. Especially,
2299b1c (partially), and
3cf6383.

The PR was merged without final approval, and has several issues:
- The NetLabel for static addresses are not assigned, as labels are
  stored in the Address objects managed by Network, instead of Link.
- If NetLabel is specified for a static address, then the address
  section will be invalid and the address will not be configured,
- It should be implemented with Request object,
- There is no test about the feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants