mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 09:12:45 +01:00
69 lines
2.2 KiB
Bash
Executable File
69 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Copyright 2014,2015,2016,2017,2018,2019,2020,2021 Security Onion Solutions, LLC
|
|
#
|
|
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
. /usr/sbin/so-common
|
|
|
|
usage() {
|
|
echo "Usage: $0 <new-user-email>"
|
|
echo ""
|
|
echo "Adds a new user to Fleet. The new password will be read from STDIN."
|
|
exit 1
|
|
}
|
|
|
|
if [ $# -ne 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
|
|
USER_EMAIL=$1
|
|
FLEET_SA_EMAIL=$(lookup_pillar_secret fleet_sa_email)
|
|
FLEET_SA_PW=$(lookup_pillar_secret fleet_sa_password)
|
|
MYSQL_PW=$(lookup_pillar_secret mysql)
|
|
|
|
# Read password for new user from stdin
|
|
test -t 0
|
|
if [[ $? == 0 ]]; then
|
|
echo "Enter new password:"
|
|
fi
|
|
read -rs USER_PASS
|
|
|
|
check_password_and_exit "$USER_PASS"
|
|
|
|
# Config fleetctl & login with the SO Service Account
|
|
CONFIG_OUTPUT=$(docker exec so-fleet fleetctl config set --address https://127.0.0.1:8080 --tls-skip-verify --url-prefix /fleet 2>&1 )
|
|
SALOGIN_OUTPUT=$(docker exec so-fleet fleetctl login --email $FLEET_SA_EMAIL --password $FLEET_SA_PW 2>&1)
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "Unable to add user to Fleet; Fleet Service account login failed"
|
|
echo "$SALOGIN_OUTPUT"
|
|
exit 2
|
|
fi
|
|
|
|
# Create New User
|
|
CREATE_OUTPUT=$(docker exec so-fleet fleetctl user create --email $USER_EMAIL --name $USER_EMAIL --password $USER_PASS --global-role admin 2>&1)
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
echo "Successfully added user to Fleet"
|
|
else
|
|
echo "Unable to add user to Fleet; user might already exist"
|
|
echo "$CREATE_OUTPUT"
|
|
exit 2
|
|
fi
|
|
|
|
# Disable forced password reset
|
|
MYSQL_OUTPUT=$(docker exec so-mysql mysql -u root --password=$MYSQL_PW fleet -e \
|
|
"UPDATE users SET admin_forced_password_reset = 0 WHERE email = '$USER_EMAIL'" 2>&1) |