mirror of
https://github.com/konstruktoid/hardening.git
synced 2026-04-25 16:55:53 +03:00
[GH-ISSUE #123] Disabling Snap removal #56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rams3sh on GitHub (May 14, 2022).
Original GitHub issue: https://github.com/konstruktoid/hardening/issues/123
Originally assigned to: @konstruktoid on GitHub.
Describe the bug
This is not actually a bug.
I am trying to use hardening as part of EC2 Image Builder in AWS which is actually dependent on a service named AWS SSM agent running within the host instance. This is installed via snap and uninstalling snap apparently removes this agent. Logs snippet below from the output for reference.
Additional context
I would want to know which file / line would be responsible for removal of snap as I was unable to determine that. I am planning to comment out those lines in my local version and use them as part of the pipeline.
@konstruktoid commented on GitHub (May 14, 2022):
Hi @rams3sh and thanks for creating the issue.
To be honest, I don't exactly know what removes snap but there's a workaround described in the readme.
I'll have a look at creating a working AWS SSM version.
@rams3sh commented on GitHub (May 14, 2022):
@konstruktoid
Actually the provided solution would not work in this case, since it would lead to snap uninstallation first and then later reinstallation of snap. The SSM agent will be removed during this process which is a blocker for image building via EC2 Image Builder.
Throughout the process of hardening via the Image Builder, AWS SSM agent should be alive and talking to the service for feedbacks of completion of each stage.
@konstruktoid commented on GitHub (May 14, 2022):
Yeah, but if you're using an AMI and running the script after the installation I believe the workaround does work.
Are you using Packer or something similar?
My plan is to sit down later today and write a Packer template
@rams3sh commented on GitHub (May 14, 2022):
So I use the EC2 image builder (in another words which acts as a packer / ansible in my case) orchestrating the entire hardening process. This hardening script is one part of the complete workflow.
During the complete execution of the workflow, an agent (AWS SSM Agent) sits inside the AMI orchestrating and monitoring the status of each workflow step and reports back to the service. If AWS SSM gets uninstalled, its like packer / ansible binary getting removed from the system while the ansible role / packer template is being run currently, leading to hardening process getting stopped abruptly.
Hence the need for the agent to be kept untouched during the hardening process.
@rams3sh commented on GitHub (May 14, 2022):
TL;DR
Removal of
apport,rsyncandpopularity-contestleads to uninstallation of snapd resulting in removal of ssm agent.Long Version
I debugged the execution of the script and narrowed down the problem.
Used the below dirty script to identify the issue. It recursively simulates the package removal and displays the package that would be removed.
Placed the above script as
apt-get-purge-simulatein /usr/bin and replaced$APT purgeacross all scripts withapt-get-purge-simulateto identify the root package because of whom snapd gets removed.Log snippet below :-
Re-ran the hardening again after removal of
popularity-contestandrsyncfrom f_apport (scripts/apport) and f_package_remove (scripts/packages).The snapd got removed again. Finally after trial and error with multiple runs of commenting out certain functions found out that apport also removed snapd.
Repeated the run again with removal of apport from the
scripts/packages. Finally the script finished sucessfully with snap being intact.Below script achieves the above
Holding these three packages back for the SSM may not be right from security standpoint. However, with my limited understanding and knowledge as on date, this is the only way we can use hardening with EC2 Image Builder. Removal of these three packages has to be probably handled outside the context of the EC2 Image builder.
@konstruktoid commented on GitHub (May 14, 2022):
Great work! Makes no sense to me why
apportorpopularity-contestis a dependency forsnapdbut here we are, will add a variable to fix this.@konstruktoid commented on GitHub (May 14, 2022):
According to https://packages.ubuntu.com/focal/snapd there is no dependency.
@rams3sh commented on GitHub (May 14, 2022):
Thanks !!
I did check that site and I myself actually couldnt figure out why it's behaving the way it is .
I was using Ubuntu 20 LTS version for this.
@konstruktoid commented on GitHub (May 14, 2022):
Hmm, purging those doesn't remove snapd from me.
@konstruktoid commented on GitHub (May 14, 2022):
But you are correct, your code works ¯_(ツ)_/¯
@konstruktoid commented on GitHub (May 14, 2022):
I've added a Packer configuration with an installation script, see #124
I'll add a
snapdvariable soon.@rams3sh commented on GitHub (May 15, 2022):
@konstruktoid . You are rite. But this happens only during the execution of the complete script. It's weird , but thats how it functions.
Removing the package individually does not result in snap being removed.
@konstruktoid commented on GitHub (May 16, 2022):
KEEP_SNAPDvariable added