Skip to main content

ContainerToContainer

Struct ContainerToContainer 

Source
pub struct ContainerToContainer {
    pub default_policy: ChainPolicy,
    pub same_network_verdict: Option<RuleVerdict>,
    pub rules: Option<Vec<ContainerToContainerRule>>,
}
Expand description

The container-to-container section, defining how containers can communicate amongst each other.

Fields§

§default_policy: ChainPolicy

The default_policy defines the default for when there is not a specific rule.

§Filtering traffic within the same bridge

Depending on how your host is configured, traffic whose origin and destination interface are the same bridge is not filtered by the kernel netfilter module. This means that this default policy is not honored for traffic between containers that are on the same Docker network, but only for traffic that traverses two bridges.

If your kernel has the br_netfilter kernel-module available, you can set the sysctl net.bridge.bridge-nf-call-iptables to 1 to have the netfilter-module act on traffic within the same bridge, too. You can set this value temporarily like this:

sysctl net.bridge.bridge-nf-call-iptables=1

To permanently set this configuration, take a look at man sysctl.d and man sysctl.conf.

§same_network_verdict: Option<RuleVerdict>

Configure whether traffic between containers within the same network should be allowed or not.

This option is more specific than default_policy, applying to traffic between containers on the same network, rather than also applying across networks. This option has precedence over the default_policy for traffic on the same network.

§Example

Setting the same_network_verdict to accept will allow all traffic between containers on the same network to pass, regardless of the default_policy configured:

[container_to_container]
default_policy = "drop"
same_network_verdict = "accept"

If you want to allow traffic between containers on the same networks in general, but want to restrict traffic on some networks, you can additionally add container-to-container rules to disallow traffic between containers for the desired networks:

[container_to_container]
default_policy = "drop"
same_network_verdict = "accept"

[[container_to_container.rules]]
network = "restricted_network"
verdict = "reject"

§Host configuration

Depending on how your host is configured, traffic whose origin and destination interface are the same bridge (network) is not filtered by the kernel netfilter module.

This means that this verdict is only honored if your kernel has the br_netfilter kernel-module available and the sysctl net.bridge.bridge-nf-call-iptables is set to 1. Otherwise traffic between containers on the same network will always be allowed.

You can set the sysctl-value temporarily like this:

sysctl net.bridge.bridge-nf-call-iptables=1

To permanently set this configuration, take a look at man sysctl.d and man sysctl.conf.

§rules: Option<Vec<ContainerToContainerRule>>

An optional list of rules, see ContainerToContainerRule.

§Example

The easiest way to define the rules is using TOMLs arrays of tables:

[container_to_container]
default_policy = "drop"

[[container_to_container.rules]]
# first rule here
[[container_to_container.rules]]
# second rule here

Trait Implementations§

Source§

impl Clone for ContainerToContainer

Source§

fn clone(&self) -> ContainerToContainer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContainerToContainer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ContainerToContainer

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ContainerToContainer

Source§

impl Hash for ContainerToContainer

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ContainerToContainer

Source§

fn eq(&self, other: &ContainerToContainer) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Process<Iptables> for ContainerToContainer

Source§

fn process( &self, ctx: &ProcessContext<'_, Iptables>, ) -> Result<Option<Vec<IptablesRule>>>

Process the current type within the given ProcessContext, returning zero or more rules to apply with nft.
Source§

impl Process<Nftables> for ContainerToContainer

Source§

fn process( &self, ctx: &ProcessContext<'_, Nftables>, ) -> Result<Option<Vec<String>>>

Process the current type within the given ProcessContext, returning zero or more rules to apply with nft.
Source§

impl StructuralPartialEq for ContainerToContainer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more