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

feat: warn for signs of external mender installation #744

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mender-convert-modify
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ mkdir -p work/rootfs
sudo mount ${boot_part} work/boot
sudo mount ${root_part} work/rootfs

probe_untainted_rootfs_input

if [ -z "${MENDER_DEVICE_TYPE}" ]; then
# Observed systems who do not have this file, e.g images generated with mkosi
if [ -f work/rootfs/etc/hostname ]; then
Expand Down
23 changes: 23 additions & 0 deletions modules/probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Checks there is no preexisting mender integration on the golden image
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Checks there is no preexisting mender integration on the golden image
# Checks if there is a preexisting mender integration on the golden image

#
# mender-convert expects a vanilla image wihtout mender installed by other means.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# mender-convert expects a vanilla image wihtout mender installed by other means.
# mender-convert expects a vanilla image without mender installed by other means.

# If you provide as input an image that has mender installed by other means already
# it might fail.
# This function will just print warnings for traces of things that look like a tainted input image
probe_untainted_rootfs_input() {
# None of these should be present in a clean rootfs
directories=(
"work/rootfs/var/lib/mender-monitor"
"work/rootfs/var/lib/mender-configure"
"work/data/mender"
)

for dir in "${directories[@]}"; do
if [ -e "$dir" ]; then
log_warn "$dir exists!"
log_warn "Input image contain traces Mender of previous Mender installation"
log_warn "The conversion might fail. Please provide a clean input image."
fi
done
Comment on lines +24 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest something like this instead to avoid hardcoding the paths:

Suggested change
directories=(
"work/rootfs/var/lib/mender-monitor"
"work/rootfs/var/lib/mender-configure"
"work/data/mender"
)
for dir in "${directories[@]}"; do
if [ -e "$dir" ]; then
log_warn "$dir exists!"
log_warn "Input image contain traces Mender of previous Mender installation"
log_warn "The conversion might fail. Please provide a clean input image."
fi
done
directories="$(sudo find work/ -type d -name "mender*")"
## None of these should be present in a clean rootfs
if [ -n "$directories" ]; then
log_warn "Found following directories:\n$directories"
log_warn "Input image contains traces of Mender"
log_warn "The conversion might fail. Please provide a clean input image."
fi

}

# Prints target architecture
#
# No input parameters and these work on the assumption that boot and root parts
Expand Down