feat(aa): ensure the prebuild jobs are working.

This commit is contained in:
Alexandre Pujol 2024-05-29 21:12:54 +01:00
parent fe4c86a245
commit 23eaa20fb7
Failed to generate hash of commit
5 changed files with 29 additions and 16 deletions

View file

@ -22,12 +22,12 @@ var (
// Resolve resolves variables and includes definied in the profile preamble // Resolve resolves variables and includes definied in the profile preamble
func (f *AppArmorProfileFile) Resolve() error { func (f *AppArmorProfileFile) Resolve() error {
// Resolve preamble includes // Resolve preamble includes
for _, include := range f.Preamble.GetIncludes() { // for _, include := range f.Preamble.GetIncludes() {
err := f.resolveInclude(include) // err := f.resolveInclude(include)
if err != nil { // if err != nil {
return err // return err
} // }
} // }
// Resolve variables // Resolve variables
for _, variable := range f.Preamble.GetVariables() { for _, variable := range f.Preamble.GetVariables() {

View file

@ -58,7 +58,7 @@ func Run(file *paths.Path, profile string) (string, error) {
for _, b := range Builds { for _, b := range Builds {
profile, err = b.Apply(opt, profile) profile, err = b.Apply(opt, profile)
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("%s %s: %w", b.Name(), opt.File, err)
} }
} }
return profile, nil return profile, nil

View file

@ -30,10 +30,21 @@ func init() {
} }
func (b Userspace) Apply(opt *Option, profile string) (string, error) { func (b Userspace) Apply(opt *Option, profile string) (string, error) {
p := aa.DefaultTunables() if ok, _ := opt.File.IsInsideDir(cfg.RootApparmord.Join("abstractions")); ok {
p.ParseVariables(profile) return profile, nil
p.ResolveAttachments() }
att := p.NestAttachments() if ok, _ := opt.File.IsInsideDir(cfg.RootApparmord.Join("tunables")); ok {
return profile, nil
}
f := aa.DefaultTunables()
if err := f.Parse(profile); err != nil {
return "", err
}
if err := f.Resolve(); err != nil {
return "", err
}
att := f.GetDefaultProfile().GetAttachments()
matches := regAttachments.FindAllString(profile, -1) matches := regAttachments.FindAllString(profile, -1)
if len(matches) > 0 { if len(matches) > 0 {
strheader := strings.Replace(matches[0], "@{exec_path}", att, -1) strheader := strings.Replace(matches[0], "@{exec_path}", att, -1)

View file

@ -71,11 +71,11 @@ func Run(file *paths.Path, profile string) (string, error) {
opt := NewOption(file, match) opt := NewOption(file, match)
drtv, ok := Directives[opt.Name] drtv, ok := Directives[opt.Name]
if !ok { if !ok {
return "", fmt.Errorf("Unknown directive: %s", opt.Name) return "", fmt.Errorf("Unknown directive '%s' in %s", opt.Name, opt.File)
} }
profile, err = drtv.Apply(opt, profile) profile, err = drtv.Apply(opt, profile)
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("%s %s: %w", drtv.Name(), opt.File, err)
} }
} }
return profile, nil return profile, nil

View file

@ -2,6 +2,8 @@
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io> // Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
// TODO: Local variables in profile header need to be resolved
package directive package directive
import ( import (
@ -40,8 +42,8 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
for name := range opt.ArgMap { for name := range opt.ArgMap {
profiletoTransition := util.MustReadFile(cfg.RootApparmord.Join(name)) profiletoTransition := util.MustReadFile(cfg.RootApparmord.Join(name))
dstProfile := aa.DefaultTunables() dstProfile := aa.DefaultTunables()
dstProfile.ParseVariables(profiletoTransition) dstProfile.Parse(profiletoTransition)
for _, variable := range dstProfile.Variables { for _, variable := range dstProfile.Preamble.GetVariables() {
if variable.Name == "exec_path" { if variable.Name == "exec_path" {
for _, v := range variable.Values { for _, v := range variable.Values {
rules = append(rules, &aa.File{ rules = append(rules, &aa.File{
@ -57,7 +59,7 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
aa.IndentationLevel = strings.Count( aa.IndentationLevel = strings.Count(
strings.SplitN(opt.Raw, Keyword, 1)[0], aa.Indentation, strings.SplitN(opt.Raw, Keyword, 1)[0], aa.Indentation,
) )
rules.Sort() rules = rules.Sort()
new := rules.String() new := rules.String()
new = new[:len(new)-1] new = new[:len(new)-1]
return strings.Replace(profileRaw, opt.Raw, new, -1), nil return strings.Replace(profileRaw, opt.Raw, new, -1), nil