feat(aa): improve apparmor struct.
This commit is contained in:
parent
ea1736083a
commit
ab4feda5ba
28 changed files with 638 additions and 496 deletions
108
pkg/aa/rules.go
108
pkg/aa/rules.go
|
|
@ -5,6 +5,7 @@
|
|||
package aa
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -12,43 +13,12 @@ type Rule struct {
|
|||
Comment string
|
||||
NoNewPrivs bool
|
||||
FileInherit bool
|
||||
}
|
||||
|
||||
func (r *Rule) Less(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Rule) Equals(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Qualifier to apply extra settings to a rule
|
||||
type Qualifier struct {
|
||||
Audit bool
|
||||
AccessType string
|
||||
Owner bool
|
||||
NoNewPrivs bool
|
||||
FileInherit bool
|
||||
Optional bool
|
||||
Comment string
|
||||
Prefix string
|
||||
Padding string
|
||||
Optional bool
|
||||
}
|
||||
|
||||
func NewQualifierFromLog(log map[string]string) Qualifier {
|
||||
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
|
||||
}
|
||||
|
||||
audit := false
|
||||
if log["apparmor"] == "AUDIT" {
|
||||
audit = true
|
||||
}
|
||||
|
||||
func newRuleFromLog(log map[string]string) Rule {
|
||||
fileInherit := false
|
||||
if log["operation"] == "file_inherit" {
|
||||
fileInherit = true
|
||||
|
|
@ -76,62 +46,54 @@ func NewQualifierFromLog(log map[string]string) Qualifier {
|
|||
default:
|
||||
}
|
||||
|
||||
return Qualifier{
|
||||
Audit: audit,
|
||||
Owner: owner,
|
||||
return Rule{
|
||||
Comment: msg,
|
||||
NoNewPrivs: noNewPrivs,
|
||||
FileInherit: fileInherit,
|
||||
Optional: optional,
|
||||
Comment: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Rule) Less(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r Rule) Equals(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type Qualifier struct {
|
||||
Audit bool
|
||||
AccessType string
|
||||
}
|
||||
|
||||
func newQualifierFromLog(log map[string]string) Qualifier {
|
||||
audit := false
|
||||
if log["apparmor"] == "AUDIT" {
|
||||
audit = true
|
||||
}
|
||||
return Qualifier{Audit: audit}
|
||||
}
|
||||
|
||||
func (r Qualifier) Less(other Qualifier) bool {
|
||||
if r.Owner == other.Owner {
|
||||
if r.Audit == other.Audit {
|
||||
return r.AccessType < other.AccessType
|
||||
}
|
||||
if r.Audit != other.Audit {
|
||||
return r.Audit
|
||||
}
|
||||
return other.Owner
|
||||
return r.AccessType < other.AccessType
|
||||
}
|
||||
|
||||
func (r Qualifier) Equals(other Qualifier) bool {
|
||||
return r.Audit == other.Audit && r.AccessType == other.AccessType &&
|
||||
r.Owner == other.Owner && r.NoNewPrivs == other.NoNewPrivs &&
|
||||
r.FileInherit == other.FileInherit
|
||||
return r.Audit == other.Audit && r.AccessType == other.AccessType
|
||||
}
|
||||
|
||||
// Preamble specific rules
|
||||
|
||||
type Abi struct {
|
||||
Path string
|
||||
IsMagic bool
|
||||
type All struct {
|
||||
Rule
|
||||
}
|
||||
|
||||
func (r Abi) Less(other Abi) bool {
|
||||
if r.Path == other.Path {
|
||||
return r.IsMagic == other.IsMagic
|
||||
}
|
||||
return r.Path < other.Path
|
||||
func (r *All) Less(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r Abi) Equals(other Abi) bool {
|
||||
return r.Path == other.Path && r.IsMagic == other.IsMagic
|
||||
}
|
||||
|
||||
type Alias struct {
|
||||
Path string
|
||||
RewrittenPath string
|
||||
}
|
||||
|
||||
func (r Alias) Less(other Alias) bool {
|
||||
if r.Path == other.Path {
|
||||
return r.RewrittenPath < other.RewrittenPath
|
||||
}
|
||||
return r.Path < other.Path
|
||||
}
|
||||
|
||||
func (r Alias) Equals(other Alias) bool {
|
||||
return r.Path == other.Path && r.RewrittenPath == other.RewrittenPath
|
||||
func (r *All) Equals(other any) bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue