Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bridge: Add macspoofchk support #639

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

EdDev
Copy link
Contributor

@EdDev EdDev commented Jun 24, 2021

The new macspoofchk field is added to the bridge plugin to support
anti-mac-spoofing.
When the parameter is enabled, traffic is limited to the mac addresses
of the container interface (the veth peer that is placed in the
container ns).

The implementation is using nftables and should only be used on nodes
that support it.

Notes:

  • This change is under e2e and functional testing, confirming it works as expected beyond the existing integration tests.
  • The go-nft used in this PR is not a tagged version. Post testing and documentation a tag will be added and the dependency updated.

@EdDev EdDev force-pushed the bridge-macspoofchk branch 5 times, most recently from b9a0c7e to 000a8b4 Compare June 28, 2021 12:11
@EdDev EdDev changed the title [Under Testing] bridge: Add macspoofchk support bridge: Add macspoofchk support Jun 28, 2021
@EdDev
Copy link
Contributor Author

EdDev commented Jun 28, 2021

Verification: The change has been tested on kubevirt and confirmed to function properly (nftables config added, mac correctly filtered and configuration removed from node after pod termination).

@EdDev EdDev force-pushed the bridge-macspoofchk branch 2 times, most recently from 684e240 to fbb5622 Compare June 29, 2021 19:06
@dcbw
Copy link
Member

dcbw commented Jun 30, 2021

@EdDev can you rebase on top of your container-veth static MAC now that it's merged?

@EdDev EdDev force-pushed the bridge-macspoofchk branch from fbb5622 to 0cd73fe Compare June 30, 2021 16:23
@EdDev
Copy link
Contributor Author

EdDev commented Jun 30, 2021

@EdDev can you rebase on top of your container-veth static MAC now that it's merged?

Done

Copy link

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

First pass very basic questions more or less

pkg/link/spoofcheck.go Show resolved Hide resolved
pkg/link/spoofcheck.go Show resolved Hide resolved
pkg/link/spoofcheck.go Outdated Show resolved Hide resolved
pkg/link/spoofcheck.go Show resolved Hide resolved
@EdDev EdDev force-pushed the bridge-macspoofchk branch from 0cd73fe to f6bfdc0 Compare July 20, 2021 14:10
@EdDev
Copy link
Contributor Author

EdDev commented Jul 20, 2021

change: Answered review comment about using the go-nft library rule lookup.

@qinqon
Copy link

qinqon commented Jul 21, 2021

@EdDev can you split the PR into two commits one with deps bump and the other with the changes ?

@EdDev
Copy link
Contributor Author

EdDev commented Jul 21, 2021

@EdDev can you split the PR into two commits one with deps bump and the other with the changes ?

I am unsure if it is acceptable by the maintainers here, so I prefer to wait with that for their input.
The added value in splitting like that is ease of review, but it comes with the cost that the commit is not self contained.

Copy link

@AlonaKaplan AlonaKaplan left a comment

Choose a reason for hiding this comment

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

Partial review, I didn't review the tests yet.

pkg/link/spoofcheck.go Show resolved Hide resolved
pkg/link/spoofcheck.go Show resolved Hide resolved
pkg/link/spoofcheck.go Show resolved Hide resolved
pkg/link/spoofcheck.go Show resolved Hide resolved
plugins/main/bridge/bridge.go Show resolved Hide resolved
Copy link

@AlonaKaplan AlonaKaplan left a comment

Choose a reason for hiding this comment

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

Couldn't find any e2e tests for the change. Did I miss something?

plugins/main/bridge/bridge_test.go Show resolved Hide resolved
Copy link
Contributor Author

@EdDev EdDev left a comment

Choose a reason for hiding this comment

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

Couldn't find any e2e tests for the change. Did I miss something?

AFAIK there are no functional tests which check that the configuration on the system is actually affecting the traffic. The tests here are just checking that the configuration is reaching the system/kernel.

Nevertheless, I have checked this as stated here.
Adding e2e tests to kubevirt should cover this.

plugins/main/bridge/bridge_test.go Show resolved Hide resolved
@EdDev EdDev force-pushed the bridge-macspoofchk branch from f6bfdc0 to bf36e4c Compare July 26, 2021 20:32
@EdDev
Copy link
Contributor Author

EdDev commented Jul 26, 2021

Change: answered a review comment.

@qinqon
Copy link

qinqon commented Jul 27, 2021

/lgtm

1 similar comment
@AlonaKaplan
Copy link

/lgtm

EdDev added a commit to EdDev/cluster-network-addons-operator that referenced this pull request Jul 27, 2021
As an intermediate and temporary step, consume the changes posted to the
CNI bridge [1].

Once the PR is merged into the original repo, this change will be
reverted.

In case the PR will not be merged into the original repo, we will
proceed with a more formal resolution.

[1] containernetworking/plugins#639

Signed-off-by: Edward Haas <edwardh@redhat.com>
kubevirt-bot pushed a commit to kubevirt/cluster-network-addons-operator that referenced this pull request Aug 5, 2021
* components: Consume CNI Bridge with macspoofchk support

As an intermediate and temporary step, consume the changes posted to the
CNI bridge [1].

Once the PR is merged into the original repo, this change will be
reverted.

In case the PR will not be merged into the original repo, we will
proceed with a more formal resolution.

[1] containernetworking/plugins#639

Signed-off-by: Edward Haas <edwardh@redhat.com>

* components: Build linux-bridge CNI from new sources

This patch builds a new image from the newly updated components.yaml.

Signed-off-by: Petr Horáček <phoracek@redhat.com>

Co-authored-by: Petr Horáček <phoracek@redhat.com>
@EdDev EdDev force-pushed the bridge-macspoofchk branch from bf36e4c to cbec9bf Compare August 25, 2021 06:14
@EdDev
Copy link
Contributor Author

EdDev commented Aug 25, 2021

change: Rebase

pkg/link/spoofcheck.go Outdated Show resolved Hide resolved
@squeed
Copy link
Member

squeed commented Sep 1, 2021

This looks good to me. I have a minor bit of bikeshedding that, honestly, can be ignored.

Can you also file a PR updating the bridge documentation: https://github.com/containernetworking/cni.dev/blob/main/content/plugins/current/main/bridge.md

Thanks!

@mccv1r0
Copy link
Member

mccv1r0 commented Sep 8, 2021

This should also support MAC to IPv6 addresses as well

@squeed
Copy link
Member

squeed commented Sep 8, 2021

hey @EdDev, just to make explicit, what security is this providing? In other words, what is enforced?

  • Port A can only source traffic from mac A
  • Port A can only receive traffic to mac A
  • Mac A can only source traffic from IPs A...
  • Mac A can only receive traffic to IPs A...

Separately, should we add an explicit rule for the gateway?

@EdDev EdDev force-pushed the bridge-macspoofchk branch 2 times, most recently from f2ada05 to aadcf9a Compare September 13, 2021 10:50
@EdDev
Copy link
Contributor Author

EdDev commented Sep 13, 2021

Change: Bumped go-nft to v0.2.0 to overcome the SELinux issue detected on some platforms.

The new macspoofchk field is added to the bridge plugin to support
anti-mac-spoofing.
When the parameter is enabled, traffic is limited to the mac addresses
of the container interface (the veth peer that is placed in the
container ns).
Any traffic that exits the pod is checked against the source mac address
that is expected. If the mac address is different, the frames are
dropped.

The implementation is using nftables and should only be used on nodes
that support it.

Signed-off-by: Edward Haas <edwardh@redhat.com>
@EdDev EdDev force-pushed the bridge-macspoofchk branch from aadcf9a to 081ed44 Compare September 14, 2021 09:50
@EdDev
Copy link
Contributor Author

EdDev commented Sep 14, 2021

hey @EdDev, just to make explicit, what security is this providing? In other words, what is enforced?

* Port A can only source traffic from mac A

* Port A can only receive traffic to mac A

* Mac A can only source traffic from IPs A...

* Mac A can only receive traffic to IPs A...

I tried to add this to the commit message and the PR description.
mac-spoof is bout L2 only, it filters traffic based on the "approved" source mac address on pod egress traffic.

Therefore, any traffic that exists the pod (on the specific interface), is checked against the source mac address.
It is not looking at higher layers (e.g. IP & TCP protocols).
Furthermore, ingress traffic is not examined, so multicast, broadcast and potential DoS attacks are not checked or handled.

Separately, should we add an explicit rule for the gateway?

The rule is on the veth peer at the host side. It is supposed to handle any L2 traffic from that veth interface, so I do not think we need a special handling if the destination mac address is the gateway.
Do you see a special issue here?

@EdDev
Copy link
Contributor Author

EdDev commented Sep 14, 2021

This should also support MAC to IPv6 addresses as well

mac-spook-check is not handing L3 spoofing (e.g. IP), so I think we are good.

EdDev added a commit to EdDev/cni.dev that referenced this pull request Sep 14, 2021
@EdDev
Copy link
Contributor Author

EdDev commented Sep 14, 2021

This looks good to me. I have a minor bit of bikeshedding that, honestly, can be ignored.

Can you also file a PR updating the bridge documentation: https://github.com/containernetworking/cni.dev/blob/main/content/plugins/current/main/bridge.md

Thanks!

Done

Copy link
Member

@matthewdupre matthewdupre left a comment

Choose a reason for hiding this comment

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

Code looks sensible but I haven't gone through the tests

@dcbw
Copy link
Member

dcbw commented Sep 29, 2021

@EdDev looks good in general, could you resolve the PR comments that you feel have been addressed?

@EdDev
Copy link
Contributor Author

EdDev commented Sep 30, 2021

@EdDev looks good in general, could you resolve the PR comments that you feel have been addressed?

@dcbw I think I covered all comments. Went over the "opened" ones and marked them as resolved.

@mccv1r0
Copy link
Member

mccv1r0 commented Oct 6, 2021

I think this is ready to go
/lgtm

@matthewdupre matthewdupre merged commit f1f128e into containernetworking:master Oct 6, 2021
@EdDev EdDev deleted the bridge-macspoofchk branch October 10, 2021 06:48
EdDev added a commit to EdDev/cluster-network-addons-operator that referenced this pull request Oct 12, 2021
As containernetworking/plugins#639 has been
merged to the plugins repo, revert back to track it instead of the
temporary repo which included the macspoofchk feature.

Signed-off-by: Edward Haas <edwardh@redhat.com>
kubevirt-bot pushed a commit to kubevirt/cluster-network-addons-operator that referenced this pull request Oct 14, 2021
* components: Track the formal CNI plugins repo

As containernetworking/plugins#639 has been
merged to the plugins repo, revert back to track it instead of the
temporary repo which included the macspoofchk feature.

Signed-off-by: Edward Haas <edwardh@redhat.com>

* components: Rebuild linux bridge image

Signed-off-by: Petr Horáček <phoracek@redhat.com>

Co-authored-by: Petr Horáček <phoracek@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants