← All articles

Labeled IPsec

How labeled IPsec carries SELinux security context across hosts, how peer controls enforce policy, and how to verify a Libreswan deployment.

Encryption protects network traffic against disclosure and modification in transit. It does not, on its own, determine whether a particular workload should be allowed to communicate with a particular service. Even an authenticated tunnel can carry traffic from several processes with different responsibilities.

Labeled IPsec connects IPsec with SELinux mandatory access control. It associates security context information with IPsec security associations, allowing participating systems to consider the security attributes of communication peers in addition to network addresses, ports and protocols. The result depends on the SELinux policy, the IPsec configuration and the trustworthiness of both endpoints.

A Powerful Security Model

Consider two confined services on one host. A public-facing web process and an internal processing service can both route packets to a remote host. The remote address alone does not distinguish their purposes. An IPsec tunnel between the machines can protect both flows, but the existence of that tunnel does not itself express whether both services should be allowed to reach the remote application.

A labeled design can add that distinction. A policy might permit a connection from an internal processing domain to a database service while denying an otherwise network-reachable public-facing domain. This is an intended policy outcome, not an automatic consequence of enabling IPsec: labels must be assigned, propagated and checked by the relevant policy on the participating systems.

An authenticated IPsec association carries label context between workloads; both hosts still enforce their policy.
The remote peer and its label assignment remain part of the trust model.

The distinction becomes especially valuable in an MLS or MCS environment, where the sensitivity levels or categories associated with workloads and information matter across machine boundaries. Type enforcement, MLS and MCS are related parts of SELinux, but their constraints and intended guarantees differ. A label alone does not establish a complete MLS design: the policy and the other systems handling the data must enforce the intended information-flow rules.

Applying SELinux Security Contexts to IPsec

An SELinux security context is commonly written as:

user:role:type[:range]

The type is important to type-enforcement decisions. When MLS or MCS is in use, the level or range adds sensitivity and/or category information. The exact meaning and effect of each component depend on the loaded policy; identical-looking strings are useful across hosts only when the participating policies interpret them compatibly.

In Linux, a local kernel security identifier represents a context. For outgoing traffic, the socket is a source of security information used in the networking path. Labeled IPsec associates security contexts with XFRM policy and security-association state; the receiving system can use the association’s peer-label information in SELinux checks. See the kernel documentation on security identifiers and network traffic.

In a negotiated Linux labeled-IPsec setup, the full SELinux context is exchanged as part of establishing the security association and associated with the IPsec state. It does not need to appear as a complete context string inside each data packet. The receiving kernel can look up the relevant label using the association that processed the packet. The SO_PEERSEC documentation describes how an application can obtain a peer security context in supported situations. Availability and behavior depend on protocol and labeling configuration; applications should handle errors and the absence of a usable context.

IPsec policies and security associations

Two IPsec concepts are useful when diagnosing this path:

  • The Security Policy Database (SPD) describes how traffic matching selectors should be treated: for example, whether it requires IPsec and which policy applies. In a labeled setup, the policy can include a security context.
  • The Security Association Database (SAD) contains the security associations (SAs) used to process protected traffic, including cryptographic state and, for labeled IPsec, associated security context information.

An IPsec SA is directional. A bidirectional conversation therefore involves inbound and outbound protection state rather than one symmetric, all-purpose SA. IKE authenticates peers and negotiates keying and IPsec state; the Linux XFRM subsystem applies policy and processes the packets. A successful IKE exchange is necessary in a negotiated deployment, but it does not prove that SELinux is enforcing the intended workload restrictions.

IKEv2 label negotiation and SELinux policy matching

RFC 9478 specifies the IKEv2 TS_SECLABEL traffic selector. It is used alongside an IP-address selector; the label is not a replacement for network selectors. The RFC treats the label as an opaque value for IKE negotiation and requires an exact match for this selector. Both implementations must support compatible labeled-IPsec negotiation for interoperability.

That exact IKEv2 selector match is a different operation from SELinux’s association:polmatch decision between a flow context and an IPsec policy context. The latter is evaluated according to the loaded SELinux policy and can support the policy’s intended relationship between the two contexts. Do not assume that an IKE selector match alone proves that the local SELinux policy permits the intended communication, or that every implementation and version uses the RFC in the same way without verification.

What the peer label means

A peer label represents security attributes assigned within the sender’s environment and carried through the labeled networking mechanism. It is not an independently verified claim that a particular business transaction or human user is authorized.

The receiving system must trust the authenticated peer to maintain its own confinement and label assignment. If that host is compromised, misconfigured or permitted to assign inappropriate labels, the receiver cannot repair the trust problem merely by reading the label. Certificate and peer identity validation, policy compatibility, protection of the keying daemon and the integrity of both hosts are part of the security boundary.

Benefits of Labeled IPsec

Labeled IPsec can extend mandatory access decisions beyond the boundaries of one machine:

  • Workload separation: network-reachable services can be distinguished by their security domains rather than by host address alone.
  • Information-flow controls: MLS or MCS attributes can participate in the policy where the deployed policy supports the intended use.
  • Protected transport: ESP can provide confidentiality, integrity and peer-associated protection when configured appropriately.
  • Reviewable relationships: the permitted source domain, receiving domain and label range can be documented and tested together.

These benefits are conditional. A label does not replace application authentication or object-level authorization, and ESP encryption does not itself determine which SELinux permissions are granted. Protecting a service also requires considering alternative routes, local bypasses and peers outside the labeled trust domain.

SELinux network controls work at different layers

SELinux does not make all network decisions in one place. As the SELinux Notebook networking chapter explains, there are socket-level checks as well as checks applied to packets in the networking stack. Depending on configuration and policy, relevant controls can include socket and port permissions, peer-label checks, network-interface and node checks, and packet labels.

Peer labels describe security attributes associated with the communication peer. Labeled IPsec and NetLabel can supply information used for peer labeling. With the network_peer_controls policy capability, the receiving socket’s label and the derived peer label are evaluated through the peer class. Conceptually, a type-enforcement rule can look like this:

allow receiving_socket_t remote_peer_t:peer recv;

The names are illustrative, not a policy module to install. A real flow may also require socket, port, association, interface, node and MLS/MCS checks. The exact checks depend on the active policy and networking configuration. Do not resolve a denial by adding this rule without first understanding the labels, the intended flow and the policy interfaces available for the distribution.

Paul Moore’s Network Peer Controls explains the consolidation of earlier NetLabel and IPsec receive checks into a common peer check. It is a valuable description of the model, but it was written in 2008: its paths and statements about what was enabled by default at that time should not be copied as current distribution instructions.

A host can expose the active capability through selinuxfs. For a read-only check, where that filesystem is mounted at the usual path:

cat /sys/fs/selinux/policy_capabilities/network_peer_controls

A value of 1 indicates that the policy capability is active; it does not by itself prove that a particular connection is labeled or that the desired peer permissions exist.

NetLabel, fallback labels and SECMARK

These mechanisms are related, but they do not carry the same information in the same way:

MechanismRoleSecurity consideration
Labeled IPsecAssociates peer context with protected IPsec state.Depends on trusted peers, IPsec configuration and SELinux policy.
NetLabel with CIPSO/CALIPSOTransports supported security-label information using IP labeling protocols.Interoperability, label mapping and network handling must be designed; it is not by itself encryption.
NetLabel fallback labelingAssigns a local peer label to otherwise unlabeled traffic based on configured network characteristics.The label is a local classification, not a cryptographically authenticated statement from the remote workload.
SECMARKApplies local SELinux security marks to packets using network filtering rules.A packet mark is distinct from the remote peer’s security context.

CIPSO and CALIPSO are often used to convey MLS attributes; do not assume that a full SELinux context is transported between hosts in the same way as labeled IPsec. Paul Moore describes a special full-label CIPSO loopback mechanism; that local-only case should not be generalized to ordinary remote CIPSO traffic. His articles on fallback labels and SECMARK explain the different sources and uses of these labels.

Implementing Labeled IPsec

Start with a communication matrix, not a copied tunnel configuration. Record the initiating domain and context, the receiving domain and context, the intended operation, the address and port selectors, the applicable sensitivity or categories, and the flows that must be denied. Identify who controls each endpoint and which paths would bypass the required IPsec policy.

Libreswan on RHEL and compatible systems

Libreswan is the IPsec implementation provided by RHEL and is a natural starting point for RHEL and compatible distributions. Its IKE daemon is pluto; on Linux, the kernel’s XFRM subsystem handles IPsec policy and packet processing. The distribution’s actual package version, build options, SELinux policy and backported fixes must be checked on both peers.

Libreswan’s upstream development documentation calls the connection option sec-label=. It describes an LSM security label used for labeled IPsec and notes that the option was called policy-label= before Libreswan 4.2. It also records the removal of IKEv1 labeled-IPsec support in Libreswan 5.0. The web development manual still contains an example using the older option name, so its example and its option heading should not be assumed to describe identical versions. Older package documentation may instead describe policy-label=; the manual installed with the actual package is the starting point for its supported syntax. Current Libreswan ipsec.conf documentation and the separately published Libreswan manual illustrate why version matters.

The label supplied for an IPsec policy is not necessarily the same thing as the specific workload context associated with an established flow. For example, a policy context can identify a policy type and range against which flow contexts are evaluated. Its permitted relationship to a flow context depends on the installed SELinux policy; copying a context string from another system does not create that relationship.

The Notebook’s historical Libreswan example uses an IKEv1-era configuration and policy-label=. It remains useful for understanding the relationship between security contexts and IPsec policy, but it should not be treated as a current copy-and-paste configuration. Validate IKE version, labeled-IPsec support and interoperability against the installed versions on both hosts. An older release or distribution backport may differ from upstream behavior.

The association class includes permissions such as setcontext and polmatch relevant to labeled IPsec state and policy matching. The historical association receive/send checks and the peer receive check should not be conflated: which checks apply depends on the policy capability and the networking path. Inspect the actual policy and AVC records rather than assuming a single allow rule enables the complete flow. See the Notebook’s networking chapter and object-class reference.

Other implementations

strongSwan also supports labeled IPsec in supported configurations. Its label_mode settings have different meanings: selinux integrates with SELinux-aware kernel labeling, while simple does not install labels in the kernel. If a design depends on kernel-enforced labels, verify the installed strongSwan build, plugins and effective mode; do not infer support merely from the presence of an IKE connection. See the strongSwan connection reference and SELinux plugin documentation.

Observing the system

The following read-only checks can help establish what is actually present. Commands prefixed with sudo require administrative privileges; omit sudo in a root shell. Output and available options vary by distribution and version. IPsec state output can contain sensitive operational details and must be handled appropriately.

getenforce
ipsec --version
sudo ip xfrm policy list
sudo ip xfrm state list nokeys
sudo ausearch -m AVC,USER_AVC -ts recent -i

nokeys suppresses key material where supported by the installed ip command. Do not publish raw state, credentials or keys in troubleshooting reports. XFRM state and policy entries help show configured selectors and security contexts; they do not alone establish which workload generated a particular flow or prove that an unauthorized flow cannot use another path. Correlate them with process and socket contexts, daemon logs, traffic observations and SELinux audit events. Audit coverage is not necessarily complete: dontaudit rules and audit configuration can suppress events.

Verification: test the allowed and denied paths

A useful verification plan tests enforcement rather than only checking that a tunnel is up:

  1. Allowed flow: establish a connection from the intended domain and record the source and receiving contexts, matching XFRM policy and association, and application outcome.
  2. Denied domain: from a different confined domain, attempt the same reachable destination and verify denial under the intended SELinux policy. Keep addresses and ports comparable so the test isolates the domain distinction.
  3. Wrong range or categories: where MLS/MCS policy is part of the design, exercise an incompatible context and verify that the intended constraint rejects the flow.
  4. Peer and label failure: test an unauthorized peer and an unacceptable or missing label; verify the actual failure behavior.
  5. No cleartext or unlabeled bypass: in a controlled environment, make the labeled association unavailable and verify through network and application observations that traffic cannot use an unintended alternative route.
  6. Lifecycle: repeat relevant checks after rekeying, daemon or host restart, and policy updates.

For every test, record package and kernel versions, active policy, network namespace and routing context, observed XFRM state and the evidence for the result. An absent AVC or missing backend event is not sufficient proof of a denial unless the audit and observation paths are known to be complete.

Conclusion

Labeled IPsec brings authenticated, protected IPsec communication together with SELinux security-context information. Its practical value is the ability to express and test workload and information-flow distinctions across hosts, provided that the policies, peer trust and network configuration support those distinctions.

That question fits the wider Sovereign Fortress approach: define authority and permitted information flows first, then gather evidence that the chosen implementation enforces them. Labeled IPsec is one possible building block; it is not a prerequisite for every WAF deployment.

References

← Back to all articles

Contact Info

Send us a message

Tell us about your application, infrastructure or security requirements. All fields below are required.

Protected by our own security check.