Commit f48662eb authored by Nikos Skalkotos's avatar Nikos Skalkotos

Add ChangeMachineId configuration task

This task is used when deploying Linux instances to alter the
content of `/etc/machine-id`. This file contains an ID that is supposed
to be globally unique. When deploying an image it is better to
regenerate a random new one to assure the uniqueness. For more info
check:

https://www.freedesktop.org/software/systemd/man/machine-id.html
parent d302f4ff
......@@ -173,6 +173,11 @@ SUSE and Gentoo derived distributions. The hostname is read from
*SNF_IMAGE_HOSTNAME* variable. In addition to the latter, *SNF_IMAGE_TARGET* is
also required.
**ChangeMachineId**: On Linux instances, this script will generate a new random
machine ID and will place it in ``/etc/machine-id``. For more info check
`here <https://www.freedesktop.org/software/systemd/man/machine-id.html>`_. The
task will fail if *SNF_IMAGE_TARGET* is missing.
**ChangePassword**: Changes the password for a list of existing users. On Linux
systems this is accomplished by directly altering the instance's
``/etc/shadow`` file. On Windows systems a script is injected into the VM's
......@@ -257,6 +262,8 @@ property must be defined.
|AssignHostname |50 |InstallUnattend |EnforcePersonality |TARGET | |
| | | | |HOSTNAME |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+---------------------------+
|ChangeMachineId |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+---------------------------+
|ChangePassword |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_USERS |
| | | | | |PROPERTY_OSFAMILY |
| | | | | |PASSWD |
......
#! /bin/bash
# Copyright (C) 2016 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
### BEGIN TASK INFO
# Provides: ClearMachineId
# RunBefore: EnforcePersonality
# RunAfter: FilesystemResizeMounted
# Short-Description: Regenerate /etc/machine-id file in Linux Systems
### END TASK INFO
set -e
. "@commondir@/common.sh"
trap task_cleanup EXIT
report_task_start
# Check if the task should be prevented from running.
check_if_excluded
check_if_mounted_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing."
fi
# Check if the image overwrites the task
check_if_overwritten
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
exit 0
fi
# Generate a new random UUID
uuid=$(sed 's/-//g' /proc/sys/kernel/random/uuid)
if [ -f "$SNF_IMAGE_TARGET/etc/machine-id" ]; then
echo "$uuid" > "$SNF_IMAGE_TARGET/etc/machine-id"
else
warn "\`/etc/machine-id' file is not present"
fi
# The machine-id may be also cached by dbus
if [ -f "$SNF_IMAGE_TARGET/var/lib/dbus/machine-id" ]; then
echo "$uuid" > "$SNF_IMAGE_TARGET/var/lib/dbus/machine-id"
else
warn "\`/var/lib/dbus/machine-id' file is not present"
fi
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -8,6 +8,7 @@ dist_tasks_SCRIPTS = \
40FilesystemResizeMounted \
50AddSwap \
50AssignHostname \
50ChangeMachineId \
50ChangePassword \
50ConfigureNetwork \
50DeleteSSHKeys \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment