Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nimbus): add fromSource field to network policy in SecurityIntent CRD #22

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading