-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle sctp and add option all to handle all network ops
Signed-off-by: rksharma95 <[email protected]>
- Loading branch information
1 parent
4887324
commit 22b8338
Showing
24 changed files
with
523 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2022 Authors of KubeArmor | ||
|
||
package bpflsm | ||
|
||
import ( | ||
"strings" | ||
|
||
tp "github.com/kubearmor/KubeArmor/KubeArmor/types" | ||
) | ||
|
||
func handleAllNetworkRule(protocols *[]tp.NetworkProtocolType) { | ||
allProtocols := []tp.NetworkProtocolType{} | ||
|
||
allWithNoFromSourceAllow := false | ||
allWithNoFromSourceBlock := false | ||
|
||
sourcesBlock := map[string]string{} | ||
sourcesAllow := map[string]string{} | ||
|
||
for _, net := range *protocols { | ||
if strings.ToUpper(net.Protocol) == "ALL" { | ||
if len(net.FromSource) == 0 { | ||
if net.Action == "Allow" && !allWithNoFromSourceAllow { | ||
for r := range netType { | ||
allProtocols = append(allProtocols, tp.NetworkProtocolType{ | ||
Protocol: r, | ||
Action: net.Action, | ||
}) | ||
} | ||
allWithNoFromSourceAllow = true | ||
} else if net.Action == "Block" && !allWithNoFromSourceBlock { | ||
for r := range netType { | ||
allProtocols = append(allProtocols, tp.NetworkProtocolType{ | ||
Protocol: r, | ||
Action: net.Action, | ||
}) | ||
} | ||
allWithNoFromSourceBlock = true | ||
} | ||
} else { | ||
for _, src := range net.FromSource { | ||
if _, ok := sourcesAllow[src.Path]; !ok && net.Action == "Allow" { | ||
sourcesAllow[src.Path] = net.Action | ||
} | ||
if _, ok := sourcesBlock[src.Path]; !ok && net.Action == "Block" { | ||
sourcesBlock[src.Path] = net.Action | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// add all with fromsource rules | ||
|
||
if len(sourcesAllow) > 0 { | ||
sources := []tp.MatchSourceType{} | ||
for src := range sourcesAllow { | ||
sources = append(sources, tp.MatchSourceType{ | ||
Path: src, | ||
}) | ||
} | ||
for r := range netType { | ||
allProtocols = append(allProtocols, tp.NetworkProtocolType{ | ||
Protocol: r, | ||
Action: "Allow", | ||
FromSource: sources, | ||
}) | ||
} | ||
} | ||
|
||
if len(sourcesBlock) > 0 { | ||
sources := []tp.MatchSourceType{} | ||
for src := range sourcesBlock { | ||
sources = append(sources, tp.MatchSourceType{ | ||
Path: src, | ||
}) | ||
} | ||
for r := range netType { | ||
allProtocols = append(allProtocols, tp.NetworkProtocolType{ | ||
Protocol: r, | ||
Action: "Block", | ||
FromSource: sources, | ||
}) | ||
} | ||
} | ||
|
||
*protocols = append(*protocols, allProtocols...) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.