Skip to content

Commit b55a754

Browse files
add nft rules template (#47)
1 parent 4f7a858 commit b55a754

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

cmds/modules/netlightd/main.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const (
3434
//go:embed nft/rules.nft
3535
var nftRules embed.FS
3636

37+
//go:embed nft/lansecurity.tmpl
38+
var securityRules string
39+
3740
// Module is entry point for module
3841
var Module cli.Command = cli.Command{
3942
Name: "netlightd",
@@ -111,6 +114,11 @@ func action(cli *cli.Context) error {
111114
return fmt.Errorf("failed to apply host nft rules: %w", err)
112115
}
113116
rules.Close()
117+
118+
if err := nft.DropTrafficToLAN(securityRules); err != nil {
119+
return fmt.Errorf("failed to drop traffic to lan: %w", err)
120+
}
121+
114122
_, err = netlight.CreateNDMZBridge()
115123
if err != nil {
116124
return fmt.Errorf("failed to create ndmz bridge: %w", err)
@@ -134,10 +142,6 @@ func action(cli *cli.Context) error {
134142
return fmt.Errorf("failed to setup mycelium on host: %w", err)
135143
}
136144

137-
// if err := nft.DropTrafficToLAN(); err != nil {
138-
// return fmt.Errorf("failed to drop traffic to lan: %w", err)
139-
// }
140-
141145
mod, err := netlight.NewNetworker()
142146
if err != nil {
143147
return fmt.Errorf("failed to create Networker: %w", err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
flush chain inet filter forward;
2+
3+
table inet filter {
4+
chain forward {
5+
type filter hook forward priority filter; policy accept;
6+
7+
# @th,16,16 is raw expression for sport/dport in transport header
8+
# used due to limitation on the installed nft v0.9.1
9+
meta l4proto { tcp, udp } @th,16,16 { 9650, 9651 } accept;
10+
11+
# accept traffic to only default gateway
12+
ip daddr {{.GatewayIP}} accept;
13+
14+
# drop traffic to all other ips on the subnet
15+
ip daddr {{.SubnetIP}} drop;
16+
}
17+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ require (
4040
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20241127100051-77e684bcb1b2
4141
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.16.1-0.20241229121208-76ac3fea5e67
4242
github.com/threefoldtech/zbus v1.0.1
43-
github.com/threefoldtech/zosbase v0.1.3-0.20250226154121-1ad00c2e23c7
43+
github.com/threefoldtech/zosbase v0.1.3-0.20250304112457-4fe70d8d47ff
4444
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
4545
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
4646
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.16.1-0.20241229121208-76ac3
542542
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.16.1-0.20241229121208-76ac3fea5e67/go.mod h1:93SROfr+QjgaJ5/jIWtIpLkhaD8Pv8WbdfwvwMNG2p4=
543543
github.com/threefoldtech/zbus v1.0.1 h1:3KaEpyOiDYAw+lrAyoQUGIvY9BcjVRXlQ1beBRqhRNk=
544544
github.com/threefoldtech/zbus v1.0.1/go.mod h1:E/v/xEvG/l6z/Oj0aDkuSUXFm/1RVJkhKBwDTAIdsHo=
545-
github.com/threefoldtech/zosbase v0.1.3-0.20250226154121-1ad00c2e23c7 h1:PzwfyBeCFIwLXSpDD3M+U7XQmQ3G0SGWd1kcbM05oyI=
546-
github.com/threefoldtech/zosbase v0.1.3-0.20250226154121-1ad00c2e23c7/go.mod h1:rxc49wA04S4IsBOYe0omVO7nu7GXridueh2PJh34gSo=
545+
github.com/threefoldtech/zosbase v0.1.3-0.20250304112457-4fe70d8d47ff h1:jKXimkoOIOpv+3/VHp5cag7WYAduFcBw6IlX4nMlsqk=
546+
github.com/threefoldtech/zosbase v0.1.3-0.20250304112457-4fe70d8d47ff/go.mod h1:rxc49wA04S4IsBOYe0omVO7nu7GXridueh2PJh34gSo=
547547
github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0=
548548
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
549549
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=

0 commit comments

Comments
 (0)