mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Merge pull request #1804 from Security-Onion-Solutions/fix/wazuh_api_creds_remove
Remove Wazuh API creds after registering initial agent
This commit is contained in:
@@ -47,6 +47,10 @@ cat <<HELP_USAGE
|
||||
HELP_USAGE
|
||||
}
|
||||
|
||||
cleanup_creds() {
|
||||
/usr/sbin/so-wazuh-user-remove $USER
|
||||
}
|
||||
|
||||
register_agent() {
|
||||
# Adding agent and getting Id from manager
|
||||
echo ""
|
||||
@@ -57,8 +61,7 @@ register_agent() {
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
echo -e $API_RESULT | sed -rn 's/.*"message":"(.+)".*/\1/p'
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
# Get agent id and agent key
|
||||
AGENT_ID=$(echo $API_RESULT | cut -d':' -f 4 | cut -d ',' -f 1)
|
||||
AGENT_KEY=$(echo $API_RESULT | cut -d':' -f 5 | cut -d '}' -f 1)
|
||||
@@ -76,8 +79,7 @@ register_agent() {
|
||||
echo "Restarting:"
|
||||
echo ""
|
||||
/var/ossec/bin/ossec-control restart
|
||||
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
remove_agent() {
|
||||
@@ -135,11 +137,15 @@ shift $(($OPTIND - 1))
|
||||
# fi
|
||||
|
||||
# Default action -> try to register the agent
|
||||
echo "Waiting before registering agent..."
|
||||
sleep 30s
|
||||
STATUS=$(curl -s -k -u $USER:$PASSWORD -L $PROTOCOL://$API_IP:$API_PORT/agents/$AGENT_ID | jq .data.status | sed s'/"//g')
|
||||
if [[ $STATUS == "Active" ]]; then
|
||||
if [ -f /opt/so/conf/wazuh/initial_agent_registration.log ]; then
|
||||
echo "Agent $AGENT_ID already registered!"
|
||||
exit 0
|
||||
else
|
||||
register_agent
|
||||
cleanup_creds
|
||||
echo "Initial agent $AGENT_ID with IP $AGENT_IP registered on $DATE." > /opt/so/conf/wazuh/initial_agent_registration.log
|
||||
exit 0
|
||||
fi
|
||||
#remove_agent
|
||||
|
||||
Reference in New Issue
Block a user