#!/bin/bash # # Copyright 2014-2023 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 . . /usr/sbin/so-common usage() { echo "Usage: $0 " 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 TEMPPW=$FLEET_SA_PW! # Create New User CREATE_OUTPUT=$(docker exec so-fleet fleetctl user create --email $USER_EMAIL --name $USER_EMAIL --password $TEMPPW --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 # Reset New User Password to user supplied password echo "$USER_PASS" | so-fleet-user-update "$USER_EMAIL" # 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)