fix: go linter issue & not defined variables.

This commit is contained in:
Alexandre Pujol 2024-05-30 12:28:12 +01:00
parent 0f382a4d5d
commit bc216176a3
Failed to generate hash of commit
7 changed files with 14 additions and 19 deletions

View file

@ -6,7 +6,7 @@ abi <abi/3.0>,
include <tunables/global>
profile default-sudo @{exec_path} {
profile default-sudo {
include <abstractions/base>
include <abstractions/app/sudo>

View file

@ -12,7 +12,7 @@ abi <abi/3.0>,
include <tunables/global>
profile systemd-service @{exec_path} flags=(attach_disconnected) {
profile systemd-service flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/consoles>
include <abstractions/nameservice-strict>

View file

@ -14,7 +14,7 @@ profile aa-status @{exec_path} {
capability dac_read_search,
capability sys_ptrace,
ptrace (read),
ptrace read,
@{exec_path} mr,

View file

@ -20,7 +20,6 @@ var (
// Include
include1 = &Include{IsMagic: true, Path: "abstraction/base"}
include2 = &Include{IsMagic: false, Path: "abstraction/base"}
include3 = &Include{IfExists: true, IsMagic: true, Path: "abstraction/base"}
includeLocal1 = &Include{IfExists: true, IsMagic: true, Path: "local/foo"}
// Variable
@ -326,8 +325,7 @@ var (
}
// Link
link3LogStr = `apparmor="ALLOWED" operation="link" class="file" profile="dolphin" name="@{user_config_dirs}/kiorc" comm="dolphin" requested_mask="l" denied_mask="l" fsuid=1000 ouid=1000 target="@{user_config_dirs}/#3954"`
link1Log = map[string]string{
link1Log = map[string]string{
"apparmor": "ALLOWED",
"operation": "link",
"class": "file",

View file

@ -10,12 +10,6 @@ import (
"strings"
)
const (
tokALLOW = "allow"
tokAUDIT = "audit"
tokDENY = "deny"
)
type requirement map[string][]string
type constraint uint
@ -126,9 +120,9 @@ func (r Rules) Filter(filter Kind) Rules {
func (r Rules) GetVariables() []*Variable {
res := make([]*Variable, 0)
for _, rule := range r {
switch rule.(type) {
switch rule := rule.(type) {
case *Variable:
res = append(res, rule.(*Variable))
res = append(res, rule)
}
}
return res
@ -137,9 +131,9 @@ func (r Rules) GetVariables() []*Variable {
func (r Rules) GetIncludes() []*Include {
res := make([]*Include, 0)
for _, rule := range r {
switch rule.(type) {
switch rule := rule.(type) {
case *Include:
res = append(res, rule.(*Include))
res = append(res, rule)
}
}
return res

View file

@ -303,13 +303,13 @@ func TestAppArmorLogs_ParseToProfiles(t *testing.T) {
Rules: aa.Rules{
&aa.Unix{
RuleBase: aa.RuleBase{FileInherit: true},
Access: []string{"receive", "send"},
Access: []string{"send", "receive"},
Type: "stream",
Protocol: "0",
},
&aa.Unix{
RuleBase: aa.RuleBase{FileInherit: true},
Access: []string{"receive", "send"},
Access: []string{"send", "receive"},
Type: "stream",
Protocol: "0",
},

View file

@ -42,7 +42,10 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
for name := range opt.ArgMap {
profiletoTransition := util.MustReadFile(cfg.RootApparmord.Join(name))
dstProfile := aa.DefaultTunables()
dstProfile.Parse(profiletoTransition)
err := dstProfile.Parse(profiletoTransition)
if err != nil {
return "", err
}
for _, variable := range dstProfile.Preamble.GetVariables() {
if variable.Name == "exec_path" {
for _, v := range variable.Values {