2023-09-25 01:06:07 +02:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-09-25 01:06:07 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package aa
|
|
|
|
|
2024-05-25 23:36:39 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2024-05-05 15:19:25 +02:00
|
|
|
|
2024-05-28 19:15:22 +02:00
|
|
|
const UNIX Kind = "unix"
|
2024-04-23 22:26:09 +02:00
|
|
|
|
2024-05-25 23:01:29 +02:00
|
|
|
func init() {
|
2024-05-28 19:15:22 +02:00
|
|
|
requirements[UNIX] = requirement{
|
2024-05-25 23:01:29 +02:00
|
|
|
"access": []string{
|
|
|
|
"create", "bind", "listen", "accept", "connect", "shutdown",
|
|
|
|
"getattr", "setattr", "getopt", "setopt", "send", "receive",
|
|
|
|
"r", "w", "rw",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-25 01:06:07 +02:00
|
|
|
type Unix struct {
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
2023-09-25 01:06:07 +02:00
|
|
|
Qualifier
|
2024-04-23 22:17:25 +02:00
|
|
|
Access []string
|
2024-04-15 00:58:34 +02:00
|
|
|
Type string
|
|
|
|
Protocol string
|
|
|
|
Address string
|
|
|
|
Label string
|
|
|
|
Attr string
|
|
|
|
Opt string
|
|
|
|
PeerLabel string
|
|
|
|
PeerAddr string
|
2023-09-25 01:06:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-19 23:43:02 +02:00
|
|
|
func newUnixFromLog(log map[string]string) Rule {
|
2023-09-25 01:06:07 +02:00
|
|
|
return &Unix{
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase: newRuleFromLog(log),
|
2024-04-15 00:58:34 +02:00
|
|
|
Qualifier: newQualifierFromLog(log),
|
2024-05-28 19:15:22 +02:00
|
|
|
Access: Must(toAccess(UNIX, log["requested_mask"])),
|
2023-09-25 01:06:07 +02:00
|
|
|
Type: log["sock_type"],
|
|
|
|
Protocol: log["protocol"],
|
|
|
|
Address: log["addr"],
|
2024-04-15 00:58:34 +02:00
|
|
|
Label: log["label"],
|
2023-09-25 01:06:07 +02:00
|
|
|
Attr: log["attr"],
|
|
|
|
Opt: log["opt"],
|
2024-04-15 00:58:34 +02:00
|
|
|
PeerLabel: log["peer"],
|
2023-09-25 01:06:07 +02:00
|
|
|
PeerAddr: log["peer_addr"],
|
|
|
|
}
|
|
|
|
}
|
2023-09-25 01:09:11 +02:00
|
|
|
|
2024-05-25 23:36:39 +02:00
|
|
|
func (r *Unix) Validate() error {
|
|
|
|
if err := validateValues(r.Kind(), "access", r.Access); err != nil {
|
|
|
|
return fmt.Errorf("%s: %w", r, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-19 19:34:58 +02:00
|
|
|
func (r *Unix) Compare(other Rule) int {
|
2023-09-25 01:09:11 +02:00
|
|
|
o, _ := other.(*Unix)
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Access, o.Access); res != 0 {
|
|
|
|
return res
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Type, o.Type); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Protocol, o.Protocol); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Address, o.Address); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Label, o.Label); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Attr, o.Attr); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Opt, o.Opt); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.PeerLabel, o.PeerLabel); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.PeerAddr, o.PeerAddr); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
return r.Qualifier.Compare(o.Qualifier)
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-04-23 22:26:09 +02:00
|
|
|
|
|
|
|
func (r *Unix) String() string {
|
2024-05-05 00:41:47 +02:00
|
|
|
return renderTemplate(r.Kind(), r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Unix) Constraint() constraint {
|
|
|
|
return blockKind
|
|
|
|
}
|
|
|
|
|
2024-05-28 19:15:22 +02:00
|
|
|
func (r *Unix) Kind() Kind {
|
|
|
|
return UNIX
|
2024-04-23 22:26:09 +02:00
|
|
|
}
|