Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile linter #607

Merged
merged 6 commits into from
Dec 13, 2024
Merged

Add profile linter #607

merged 6 commits into from
Dec 13, 2024

Conversation

nobody43
Copy link
Contributor

Abstractions/tunables checks weren't done, they will take a while.
I don't know how you want to integrate it, so leaving it up to you. As well as applying the suggestions (or tell me how you see it being handled).
I will work in the same direction, after 3 weeks.

Related #570

def readApparmorFile(fullpath):
'''AA file could contain multiple AA profiles'''
headers = (
'# AppArmor.d - Full set of apparmor profiles',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modernize the name? (apparmor.d -> AppArmor.d)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not. apparmor.d refers to /etc/apparmor.d not to AppArmor. Plus I don't want to have to update all headers (again).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, reverted.

@roddhjav
Copy link
Owner

roddhjav commented Nov 19, 2024

Nice work thanks a lot. It is really useful to have you working on this.

I think that for now, your current structure will do it. Ideally (later), it would be nice to provide a proper aa-lint tool. I think we should try to make a linter that is not specific for this project (and that can ignore some check).

I think the implementation of aa-lint should looks like existing linter in python such as yamllint. Thus, you will have to create a new directory in the apparmor.d project, e.g.: aa-lint with the python code.

I am going to create a new issue where we can discuss both the structure of the linter and the list of checks it should implement.

@roddhjav roddhjav mentioned this pull request Nov 19, 2024
@roddhjav
Copy link
Owner

roddhjav commented Nov 21, 2024

When I run the script over the profiles with python tests/profile_check.py -d apparmor.d, I get the following error for
all profiles:

{
  "filename": "apparmor.d/groups/apt/apt-config",
  "profile": null,
  "severity": "WARNING",
  "line": null,
  "reason": "No trailing syntax hint",
  "suggestion": "# vim:syntax=apparmor"
}

That does not sound normal...

Suggesting owner for some file pattern is a good thing, however, it can raise some issues. E.g: a program running as root can have some legitimate access inside @{HOME}/ or temporary files owner by another user.

Comment on lines 451 to 463
try:
from apparmor.regex import *
from apparmor.aa import is_skippable_file
from apparmor.rule.file import FileRule, FileRuleset
from apparmor.common import convert_regexp
try:
from apparmor.rule.variable import separate_vars
except ModuleNotFoundError:
from apparmor.aa import separate_vars

except ModuleNotFoundError:
raise ModuleNotFoundError(f"""Can't find 'python3-apparmor' package! Install with:
$ sudo apt install python3-apparmor""")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nobody43
Copy link
Contributor Author

nobody43 commented Nov 22, 2024

That does not sound normal...

That was because of trailing '\n'. What would be the policy - add to suggestion or remove from the line?

Suggesting owner for some file pattern is a good thing, however, it can raise some issues.

Should I remove it?

Also I don't understand why your filename isn't an absolute path.

@roddhjav
Copy link
Owner

roddhjav commented Nov 23, 2024

We don't care if the vim syntax has a trailing line, so remove it. To be more precise, this is:

  1. Not a bit issue, so let's not annoy profile developer with that
  2. Not what has been done in the profile and thus, it would require to update all of them.

Also I don't understand why your filename isn't an absolute path.

It is a full path, I manually anonymized the data.

@nobody43
Copy link
Contributor Author

nobody43 commented Nov 23, 2024

We don't care if the vim syntax has a trailing line, so remove it.

I don't think that's possible while preserving the check. Each line in file have trailing \n at the end. While making a comparison I have to preserve it. Similar issue when taking original line as suggestion - see with output of handleFileMessages().

It is a full path, I manually anonymized the data.

Then you should delete the comment entirely because of edit history.

UPD: on the other hand, it would be better to obscure it:

    for m in messages:
        if m.get('suggestion'):
            if m['suggestion'].endswith('\n'):
                m['suggestion'] = m.get('suggestion').removesuffix('\n')

Comment on lines +321 to +328
# Ensure singular '@{exec_path}'
if not gotAttach:
messages.append({'filename': fullpath,
'profile': None,
'severity': 'WARNING',
'line': None,
'reason': "'@{exec_path}' must be defined as main path attachment",
'suggestion': None})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ignore orphan profiles like apparmor.d/groups/children/? (in future PRs)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they will have to be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profiles-m-r/pam_roles move to profiles-m-r/pam/ and also exclude?

@roddhjav roddhjav merged commit edaa450 into roddhjav:main Dec 13, 2024
7 checks passed
@roddhjav
Copy link
Owner

Thanks, merged!

For future PR, try to follow the same architecture as yamllint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants