-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1892 from rksharma95/feat-network-all
feat(core): handle sctp protocol and all protocols with raw socket and add protocol:all network rule
- Loading branch information
Showing
36 changed files
with
487 additions
and
52 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.