Skip to content

Commit

Permalink
[CWS] bundled rules per origin
Browse files Browse the repository at this point in the history
  • Loading branch information
safchain committed Dec 18, 2023
1 parent a87ec42 commit 56fd7dd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
21 changes: 17 additions & 4 deletions pkg/security/rules/bundled_policy_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,37 @@
package rules

import (
"github.com/hashicorp/go-multierror"

"github.com/DataDog/datadog-agent/pkg/security/config"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
"github.com/DataDog/datadog-agent/pkg/version"
"github.com/hashicorp/go-multierror"
)

// BundledPolicyProvider specify the policy provider for bundled policies
type BundledPolicyProvider struct{}
type BundledPolicyProvider struct {
cfg *config.RuntimeSecurityConfig
}

// NewBundledPolicyProvider returns a new bundled policy provider
func NewBundledPolicyProvider(cfg *config.RuntimeSecurityConfig) *BundledPolicyProvider {
return &BundledPolicyProvider{
cfg: cfg,
}
}

// LoadPolicies implements the PolicyProvider interface
func (p *BundledPolicyProvider) LoadPolicies([]rules.MacroFilter, []rules.RuleFilter) ([]*rules.Policy, *multierror.Error) {
bundledRules := newBundledPolicyRules(p.cfg)

policy := &rules.Policy{}

policy.Name = "bundled_policy"
policy.Source = "bundled"
policy.Version = version.AgentVersion
policy.Rules = bundledPolicyRules
policy.Rules = bundledRules

for _, rule := range bundledPolicyRules {
for _, rule := range bundledRules {
rule.Policy = policy
}

Expand Down
22 changes: 14 additions & 8 deletions pkg/security/rules/bundled_policy_provider_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
package rules

import (
"github.com/DataDog/datadog-agent/pkg/security/config"
"github.com/DataDog/datadog-agent/pkg/security/events"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
)

var bundledPolicyRules = []*rules.RuleDefinition{{
ID: events.RefreshUserCacheRuleID,
Expression: `rename.file.destination.path in [ "/etc/passwd", "/etc/group" ]`,
Actions: []rules.ActionDefinition{{
InternalCallbackDefinition: &rules.InternalCallbackDefinition{},
}},
Silent: true,
}}
func newBundledPolicyRules(cfg *config.RuntimeSecurityConfig) []*rules.RuleDefinition {
if cfg.EBPFLessEnabled {
return []*rules.RuleDefinition{}
}
return []*rules.RuleDefinition{{
ID: events.RefreshUserCacheRuleID,
Expression: `rename.file.destination.path in [ "/etc/passwd", "/etc/group" ]`,
Actions: []rules.ActionDefinition{{
InternalCallbackDefinition: &rules.InternalCallbackDefinition{},
}},
Silent: true,
}}
}
9 changes: 7 additions & 2 deletions pkg/security/rules/bundled_policy_provider_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
// Package rules holds rules related files
package rules

import "github.com/DataDog/datadog-agent/pkg/security/secl/rules"
import (
"github.com/DataDog/datadog-agent/pkg/security/config"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
)

var bundledPolicyRules = []*rules.RuleDefinition{}
func newBundledPolicyRules(_ *config.RuntimeSecurityConfig) []*rules.RuleDefinition {
return []*rules.RuleDefinition{}
}
2 changes: 1 addition & 1 deletion pkg/security/rules/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (e *RuleEngine) notifyAPIServer(ruleIDs []rules.RuleID, policies []*monitor
func (e *RuleEngine) gatherDefaultPolicyProviders() []rules.PolicyProvider {
var policyProviders []rules.PolicyProvider

policyProviders = append(policyProviders, &BundledPolicyProvider{})
policyProviders = append(policyProviders, NewBundledPolicyProvider(e.config))

// add remote config as config provider if enabled.
if e.config.RemoteConfigurationEnabled {
Expand Down

0 comments on commit 56fd7dd

Please sign in to comment.