Skip to content

Commit 6b4d175

Browse files
authored
NM-103: add dst rule to acls (#1095)
* add dst rule to acls * update go mod
1 parent 19ca6c6 commit 6b4d175

File tree

3 files changed

+185
-1
lines changed

3 files changed

+185
-1
lines changed

firewall/iptables_linux.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,16 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
733733
}
734734
if len(aclRule.IPList) > 0 {
735735
allowedIps := []string{}
736+
dstAllowedIps := []string{}
736737
for _, ip := range aclRule.IPList {
737738
allowedIps = append(allowedIps, ip.String())
738739
}
740+
if len(aclRule.Dst) > 0 {
741+
for _, ip := range aclRule.Dst {
742+
dstAllowedIps = append(dstAllowedIps, ip.String())
743+
}
744+
}
745+
739746
rulesSpec := [][]string{}
740747
if len(aclRule.AllowedPorts) > 0 {
741748

@@ -744,6 +751,9 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
744751
continue
745752
}
746753
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
754+
if len(dstAllowedIps) > 0 {
755+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
756+
}
747757
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
748758
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
749759
}
@@ -759,6 +769,9 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
759769

760770
} else {
761771
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
772+
if len(dstAllowedIps) > 0 {
773+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
774+
}
762775
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
763776
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
764777
}
@@ -786,9 +799,15 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
786799

787800
if len(aclRule.IP6List) > 0 {
788801
allowedIps := []string{}
802+
dstAllowedIps := []string{}
789803
for _, ip := range aclRule.IP6List {
790804
allowedIps = append(allowedIps, ip.String())
791805
}
806+
if len(aclRule.Dst6) > 0 {
807+
for _, ip := range aclRule.Dst6 {
808+
dstAllowedIps = append(dstAllowedIps, ip.String())
809+
}
810+
}
792811
rulesSpec := [][]string{}
793812
if len(aclRule.AllowedPorts) > 0 {
794813

@@ -797,6 +816,9 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
797816
continue
798817
}
799818
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
819+
if len(dstAllowedIps) > 0 {
820+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
821+
}
800822
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
801823
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
802824
}
@@ -812,6 +834,9 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
812834

813835
} else {
814836
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
837+
if len(dstAllowedIps) > 0 {
838+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
839+
}
815840
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
816841
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
817842
}
@@ -864,16 +889,25 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
864889
}
865890
if len(aclRule.IPList) > 0 {
866891
allowedIps := []string{}
892+
dstAllowedIps := []string{}
867893
for _, ip := range aclRule.IPList {
868894
allowedIps = append(allowedIps, ip.String())
869895
}
896+
if len(aclRule.Dst) > 0 {
897+
for _, ip := range aclRule.Dst {
898+
dstAllowedIps = append(dstAllowedIps, ip.String())
899+
}
900+
}
870901
rulesSpec := [][]string{}
871902
if len(aclRule.AllowedPorts) > 0 {
872903
for _, port := range aclRule.AllowedPorts {
873904
if port == "" {
874905
continue
875906
}
876907
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
908+
if len(dstAllowedIps) > 0 {
909+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
910+
}
877911
if aclRule.AllowedProtocol.String() != "" {
878912
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
879913
}
@@ -889,6 +923,9 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
889923

890924
} else {
891925
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
926+
if len(dstAllowedIps) > 0 {
927+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
928+
}
892929
if aclRule.AllowedProtocol.String() != "" {
893930
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
894931
}
@@ -915,9 +952,15 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
915952
}
916953
if len(aclRule.IP6List) > 0 {
917954
allowedIps := []string{}
955+
dstAllowedIps := []string{}
918956
for _, ip := range aclRule.IP6List {
919957
allowedIps = append(allowedIps, ip.String())
920958
}
959+
if len(aclRule.Dst6) > 0 {
960+
for _, ip := range aclRule.Dst6 {
961+
dstAllowedIps = append(dstAllowedIps, ip.String())
962+
}
963+
}
921964
rulesSpec := [][]string{}
922965
if len(aclRule.AllowedPorts) > 0 {
923966

@@ -926,6 +969,9 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
926969
continue
927970
}
928971
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
972+
if len(dstAllowedIps) > 0 {
973+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
974+
}
929975
if aclRule.AllowedProtocol.String() != "" {
930976
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
931977
}
@@ -940,6 +986,9 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
940986

941987
} else {
942988
ruleSpec := []string{"-s", strings.Join(allowedIps, ",")}
989+
if len(dstAllowedIps) > 0 {
990+
ruleSpec = append(ruleSpec, "-d", strings.Join(dstAllowedIps, ","))
991+
}
943992
if aclRule.AllowedProtocol.String() != "" {
944993
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
945994
}

go.mod

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/google/nftables v0.3.0
1515
github.com/google/uuid v1.6.0
1616
github.com/gorilla/websocket v1.5.3
17-
github.com/gravitl/netmaker v1.0.1-0.20250829065133-ed913c1fb2b7
17+
github.com/gravitl/netmaker v1.0.1-0.20250908022208-a3232234b3c9
1818
github.com/gravitl/tcping v0.1.2-0.20230801110928-546055ebde06
1919
github.com/guumaster/hostctl v1.1.4
2020
github.com/hashicorp/go-version v1.7.0
@@ -41,28 +41,42 @@ require (
4141

4242
require (
4343
aead.dev/minisign v0.2.0 // indirect
44+
cloud.google.com/go/auth v0.16.5 // indirect
45+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
46+
cloud.google.com/go/compute/metadata v0.8.0 // indirect
4447
filippo.io/edwards25519 v1.1.0 // indirect
4548
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
4649
github.com/Microsoft/go-winio v0.6.1 // indirect
50+
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
51+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
4752
github.com/containerd/log v0.1.0 // indirect
53+
github.com/coreos/go-oidc/v3 v3.15.0 // indirect
4854
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
55+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
4956
github.com/distribution/reference v0.6.0 // indirect
5057
github.com/docker/docker v25.0.6+incompatible // indirect
5158
github.com/docker/go-connections v0.4.0 // indirect
5259
github.com/docker/go-units v0.5.0 // indirect
5360
github.com/felixge/httpsnoop v1.0.4 // indirect
5461
github.com/fsnotify/fsnotify v1.8.0 // indirect
5562
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
63+
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
64+
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
5665
github.com/go-logr/logr v1.4.3 // indirect
5766
github.com/go-logr/stdr v1.2.2 // indirect
5867
github.com/go-playground/locales v0.14.1 // indirect
5968
github.com/go-playground/universal-translator v0.18.1 // indirect
6069
github.com/go-playground/validator/v10 v10.27.0 // indirect
6170
github.com/go-sql-driver/mysql v1.8.1 // indirect
6271
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
72+
github.com/goccy/go-json v0.10.2 // indirect
6373
github.com/gogo/protobuf v1.3.2 // indirect
6474
github.com/google/go-cmp v0.7.0 // indirect
75+
github.com/google/s2a-go v0.1.9 // indirect
76+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
77+
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
6578
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e // indirect
79+
github.com/gorilla/handlers v1.5.2 // indirect
6680
github.com/gorilla/mux v1.8.1 // indirect
6781
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
6882
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -72,26 +86,37 @@ require (
7286
github.com/jackc/puddle/v2 v2.2.2 // indirect
7387
github.com/jinzhu/inflection v1.0.0 // indirect
7488
github.com/jinzhu/now v1.1.5 // indirect
89+
github.com/kelseyhightower/envconfig v1.4.0 // indirect
7590
github.com/kr/text v0.2.0 // indirect
7691
github.com/leodido/go-urn v1.4.0 // indirect
92+
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
93+
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
94+
github.com/lestrrat-go/httpcc v1.0.1 // indirect
95+
github.com/lestrrat-go/iter v1.0.2 // indirect
96+
github.com/lestrrat-go/jwx v1.2.29 // indirect
97+
github.com/lestrrat-go/option v1.0.1 // indirect
7798
github.com/lib/pq v1.10.9 // indirect
7899
github.com/mattn/go-sqlite3 v1.14.32 // indirect
79100
github.com/mdlayher/genetlink v1.2.0 // indirect
80101
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
81102
github.com/mdlayher/socket v0.5.1 // indirect
103+
github.com/okta/okta-sdk-golang/v5 v5.0.6 // indirect
82104
github.com/opencontainers/go-digest v1.0.0 // indirect
83105
github.com/opencontainers/image-spec v1.0.2 // indirect
106+
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 // indirect
84107
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
85108
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
86109
github.com/pkg/errors v0.9.1 // indirect
87110
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
88111
github.com/posthog/posthog-go v1.6.4 // indirect
112+
github.com/pquerna/otp v1.5.0 // indirect
89113
github.com/rivo/uniseg v0.4.6 // indirect
90114
github.com/rogpeppe/go-internal v1.14.1 // indirect
91115
github.com/rqlite/gorqlite v0.0.0-20240122221808-a8a425b1a6aa // indirect
92116
github.com/sagikazarmark/locafero v0.7.0 // indirect
93117
github.com/seancfoley/bintree v1.3.1 // indirect
94118
github.com/seancfoley/ipaddress-go v1.7.1 // indirect
119+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
95120
github.com/sourcegraph/conc v0.3.0 // indirect
96121
github.com/spf13/afero v1.12.0 // indirect
97122
github.com/spf13/cast v1.7.1 // indirect
@@ -107,13 +132,21 @@ require (
107132
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
108133
go.opentelemetry.io/otel/trace v1.37.0 // indirect
109134
go.uber.org/atomic v1.9.0 // indirect
135+
go.uber.org/automaxprocs v1.6.0 // indirect
110136
go.uber.org/multierr v1.9.0 // indirect
111137
golang.org/x/mod v0.26.0 // indirect
138+
golang.org/x/oauth2 v0.30.0 // indirect
112139
golang.org/x/sync v0.16.0 // indirect
113140
golang.org/x/text v0.28.0 // indirect
114141
golang.org/x/time v0.12.0 // indirect
115142
golang.org/x/tools v0.35.0 // indirect
116143
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
144+
google.golang.org/api v0.248.0 // indirect
145+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect
146+
google.golang.org/grpc v1.74.2 // indirect
147+
google.golang.org/protobuf v1.36.7 // indirect
148+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
149+
gopkg.in/mail.v2 v2.3.1 // indirect
117150
gopkg.in/yaml.v2 v2.4.0 // indirect
118151
gorm.io/datatypes v1.2.6 // indirect
119152
gorm.io/driver/mysql v1.5.6 // indirect

0 commit comments

Comments
 (0)