Skip to content

Commit

Permalink
Merge pull request #22 from 5GSEC/shivkb/add-field-intent-crd
Browse files Browse the repository at this point in the history
fix(nimbus): add fromSource field  to network policy in SecurityIntent CRD
  • Loading branch information
shivaccuknox authored Dec 20, 2023
2 parents 2f042c0 + 0eb4a69 commit 62ff799
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
kind: SecurityIntentBinding
listKind: SecurityIntentBindingList
plural: securityintentbindings
shortNames:
- sib
singular: securityintentbinding
scope: Namespaced
versions:
Expand Down
11 changes: 11 additions & 0 deletions config/crd/bases/intent.security.nimbus.com_securityintents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
kind: SecurityIntent
listKind: SecurityIntentList
plural: securityintents
shortNames:
- sit
singular: securityintent
scope: Namespaced
versions:
Expand Down Expand Up @@ -114,6 +116,15 @@ spec:
description: MatchProtocol defines a protocol for
network policies
properties:
fromSource:
items:
description: FromSource defines a source path
for directory-based policies
properties:
path:
type: string
type: object
type: array
protocol:
type: string
type: object
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/securityintent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ type Port struct {

// MatchProtocol defines a protocol for network policies
type MatchProtocol struct {
Protocol string `json:"protocol,omitempty"`
Protocol string `json:"protocol,omitempty"`
FromSource []FromSource `json:"fromSource,omitempty"`
}

// MatchPath defines a path for process or file policies
Expand Down Expand Up @@ -127,6 +128,7 @@ type SecurityIntentStatus struct {

// SecurityIntent is the Schema for the securityintents API
// +kubebuilder:object:root=true
// +kubebuilder:resource: shortName="sit"
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/securityintentbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type SecurityIntentBindingStatus struct {
}

//+kubebuilder:object:root=true
// +kubebuilder:resource: shortName="sib"
//+kubebuilder:subresource:status

// SecurityIntentBinding is the Schema for the securityintentbindings API
Expand Down
9 changes: 8 additions & 1 deletion pkg/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pkg/controllers/utils/utils_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ func extractToKubeArmorPolicyNetworkType(bindingInfo *general.BindingInfo) kubea
if len(intent.Spec.Intent.Resource) > 0 && len(intent.Spec.Intent.Resource[0].Network) > 0 {
for _, network := range intent.Spec.Intent.Resource[0].Network {
for _, matchProtocol := range network.MatchProtocols {
var fromSources []kubearmorv1.MatchSourceType
for _, source := range matchProtocol.FromSource {
fromSources = append(fromSources, kubearmorv1.MatchSourceType{
Path: kubearmorv1.MatchPathType(source.Path),
})
}
if matchProtocol.Protocol != "" {
networkType.MatchProtocols = append(networkType.MatchProtocols, kubearmorv1.MatchNetworkProtocolType{
Protocol: kubearmorv1.MatchNetworkProtocolStringType(matchProtocol.Protocol),
Protocol: kubearmorv1.MatchNetworkProtocolStringType(matchProtocol.Protocol),
FromSource: fromSources,
})
}
}
Expand Down

0 comments on commit 62ff799

Please sign in to comment.