<div dir="auto">Thanks Seth</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 22, 2022, 8:21 PM Seth Arnold <<a href="mailto:seth.arnold@canonical.com">seth.arnold@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Sep 22, 2022 at 07:16:32PM -0400, Murali Selvaraj wrote:<br>
> -> How do we approach preparing an Apparmor profile for a shell script as<br>
> the first time I am doing this.<br>
> -> As our embedded device like legacy and many scripts internally invokes<br>
> few other scripts based on the different scenarios.<br>
> -> In such cases, do we have any suggestion to generate an Apparmor profile<br>
> for shell script or any example in our earlier forum queries (If possible,<br>
> please share here as I could not find it).<br>
<br>
What will execute your shell script? is it already confined? How you start<br>
to write the profile depends upon how the script is executed.<br>
<br>
The easiest is to use complain mode and the interactive tools to get most<br>
of the way there. This can work great if the script is launched via a<br>
systemd service, or by a daemon that accepts on-demand commands to run<br>
it, etc. If it's run via sysv-init or other unusual process supervisor<br>
system it might be a challenge to get the execution environment close<br>
to production use.<br>
<br>
If it's run by a systemd service, something like the following might work:<br>
<br>
in one terminal:<br>
sudo aa-genprof /path/to/shell/script.sh<br>
<br>
in another terminal:<br>
sudo systemctl start servicename<br>
sudo systemctl stop servicename<br>
<br>
return to the first terminal and answer the questions.<br>
<br>
Then repeat the start process, interact with whatever service it provides<br>
a little bit, then stop it again, and then answer more genprof questions.<br>
<br>
Hopefully you can iterate to something that's pretty close to final<br>
quality this way.<br>
<br>
If your script isn't started via a 'clean' process supervisor like<br>
systemd, you may need to write a complain mode profile by hand, reboot,<br>
use aa-logprof to get questions / answers; and repeat via repeated<br>
reboots.<br>
<br>
I hope this helps.<br>
<br>
Thanks<br>
</blockquote></div>