feat(aa): add the link rule.

This commit is contained in:
Alexandre Pujol 2024-05-25 21:56:28 +01:00
parent 81f0163086
commit e38f5b4637
Failed to generate hash of commit
3 changed files with 92 additions and 13 deletions

View file

@ -11,10 +11,11 @@ import (
const (
tokLINK = "link"
tokFILE = "file"
tokOWNER = "owner"
tokSUBSET = "subset"
)
type File struct {
RuleBase
Qualifier
@ -25,17 +26,10 @@ type File struct {
}
func newFileFromLog(log map[string]string) Rule {
owner := false
fsuid, hasFsUID := log["fsuid"]
ouid, hasOuUID := log["ouid"]
isDbus := strings.Contains(log["operation"], "dbus")
if hasFsUID && hasOuUID && fsuid == ouid && ouid != "0" && !isDbus {
owner = true
}
return &File{
RuleBase: newRuleFromLog(log),
Qualifier: newQualifierFromLog(log),
Owner: owner,
Owner: isOwner(log),
Path: log["name"],
Access: toAccess("file-log", log["requested_mask"]),
Target: log["target"],
@ -79,5 +73,68 @@ func (r *File) Constraint() constraint {
}
func (r *File) Kind() string {
return "file"
return tokFILE
}
type Link struct {
RuleBase
Qualifier
Owner bool
Subset bool
Path string
Target string
}
func newLinkFromLog(log map[string]string) Rule {
return &Link{
RuleBase: newRuleFromLog(log),
Qualifier: newQualifierFromLog(log),
Owner: isOwner(log),
Path: log["name"],
Target: log["target"],
}
}
func (r *Link) Less(other any) bool {
o, _ := other.(*Link)
if r.Path != o.Path {
return r.Path < o.Path
}
if r.Target != o.Target {
return r.Target < o.Target
}
if o.Owner != r.Owner {
return r.Owner
}
if r.Subset != o.Subset {
return r.Subset
}
return r.Qualifier.Less(o.Qualifier)
}
func (r *Link) Equals(other any) bool {
o, _ := other.(*Link)
return r.Subset == o.Subset && r.Owner == o.Owner && r.Path == o.Path &&
r.Target == o.Target && r.Qualifier.Equals(o.Qualifier)
}
func (r *Link) String() string {
return renderTemplate(r.Kind(), r)
}
func (r *Link) Constraint() constraint {
return blockKind
}
func (r *Link) Kind() string {
return tokLINK
}
func isOwner(log map[string]string) bool {
fsuid, hasFsUID := log["fsuid"]
ouid, hasOuUID := log["ouid"]
isDbus := strings.Contains(log["operation"], "dbus")
if hasFsUID && hasOuUID && fsuid == ouid && ouid != "0" && !isDbus {
return true
}
return false
}

View file

@ -21,3 +21,21 @@
{{- "," -}}
{{- template "comment" . -}}
{{- end -}}
{{- define "link" -}}
{{- template "qualifier" . -}}
{{- if .Owner -}}
{{- "owner " -}}
{{- end -}}
{{- "link " -}}
{{- if .Subset -}}
{{- "subset " -}}
{{- end -}}
{{- .Path -}}
{{- " " -}}
{{- with .Target -}}
{{ " -> " }}{{ . }}
{{- end -}}
{{- "," -}}
{{- template "comment" . -}}
{{- end -}}

View file

@ -106,6 +106,10 @@
{{- template "file" . -}}
{{- end -}}
{{- if eq $type "Link" -}}
{{- template "link" . -}}
{{- end -}}
{{- if eq $type "Profile" -}}
{{- template "profile" . -}}
{{- end -}}