mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-02-21 06:25:27 +01:00
fix conflict
This commit is contained in:
0
salt/common/tools/sbin/so-elastic-fleet-agent-policy-view
Normal file → Executable file
0
salt/common/tools/sbin/so-elastic-fleet-agent-policy-view
Normal file → Executable file
0
salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete
Normal file → Executable file
0
salt/common/tools/sbin/so-elastic-fleet-integration-policy-bulk-delete
Normal file → Executable file
@@ -24,7 +24,7 @@ mkdir -p /opt/so/conf/elastic-fleet/certs
|
||||
cp /etc/ssl/certs/intca.crt /opt/so/conf/elastic-fleet/certs
|
||||
cp /etc/pki/elasticfleet* /opt/so/conf/elastic-fleet/certs
|
||||
|
||||
{% if grains.role == 'so-import' %}
|
||||
{% if grains.role in ['so-import', 'so-standalone', 'so-eval'] %}
|
||||
# Add SO-Manager Elasticsearch Ouput
|
||||
ESCACRT=$(openssl x509 -in /opt/so/conf/elastic-fleet/certs/intca.crt)
|
||||
JSON_STRING=$( jq -n \
|
||||
|
||||
15
salt/common/tools/sbin/so-elasticsearch-ilm-lifecycle-status
Executable file
15
salt/common/tools/sbin/so-elasticsearch-ilm-lifecycle-status
Executable file
@@ -0,0 +1,15 @@
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L https://{{ NODEIP }}:9200/_all/_ilm/explain | jq .
|
||||
else
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L https://{{ NODEIP }}:9200/$1/_ilm/explain | jq .[]
|
||||
fi
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
/usr/sbin/so-stop grafana $1
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L -X DELETE https://{{ NODEIP }}:9200/_ilm/policy/$1
|
||||
21
salt/common/tools/sbin/so-elasticsearch-ilm-policy-load
Executable file
21
salt/common/tools/sbin/so-elasticsearch-ilm-policy-load
Executable file
@@ -0,0 +1,21 @@
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
{% import_yaml 'elasticsearch/defaults.yaml' as ESCONFIG with context %}
|
||||
{%- set ES_INDEX_SETTINGS = salt['pillar.get']('elasticsearch:index_settings', default=ESCONFIG.elasticsearch.index_settings, merge=True) %}
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
{%- for index, settings in ES_INDEX_SETTINGS.items() %}
|
||||
{%- if settings.policy is defined %}
|
||||
echo
|
||||
echo "Setting up {{ index }}-logs policy..."
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -b "sid=$SESSIONCOOKIE" -s -k -L -X PUT "https://{{ NODEIP }}:9200/_ilm/policy/{{ index }}-logs" -H 'Content-Type: application/json' -d'{ "policy": {{ settings.policy | tojson(true) }} }'
|
||||
echo
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
echo
|
||||
15
salt/common/tools/sbin/so-elasticsearch-ilm-policy-view
Executable file
15
salt/common/tools/sbin/so-elasticsearch-ilm-policy-view
Executable file
@@ -0,0 +1,15 @@
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L https://{{ NODEIP }}:9200/_ilm/policy | jq .
|
||||
else
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L https://{{ NODEIP }}:9200/_ilm/policy/$1 | jq .[]
|
||||
fi
|
||||
@@ -1,12 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
/usr/sbin/so-restart grafana $1
|
||||
so-elasticsearch-ilm-stop
|
||||
so-elasticsearch-ilm-start
|
||||
12
salt/common/tools/sbin/so-elasticsearch-ilm-start
Executable file
12
salt/common/tools/sbin/so-elasticsearch-ilm-start
Executable file
@@ -0,0 +1,12 @@
|
||||
/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
echo "Starting ILM..."
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L -X POST https://{{ NODEIP }}:9200/_ilm/start
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
/usr/sbin/so-start grafana $1
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L https://{{ NODEIP }}:9200/_ilm/status | jq .
|
||||
12
salt/common/tools/sbin/so-elasticsearch-ilm-stop
Executable file
12
salt/common/tools/sbin/so-elasticsearch-ilm-stop
Executable file
@@ -0,0 +1,12 @@
|
||||
#/bin/bash
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
{%- set NODEIP = salt['pillar.get']('host:mainip', '') %}
|
||||
|
||||
echo "Stopping ILM..."
|
||||
curl -K /opt/so/conf/elasticsearch/curl.config -s -k -L -X POST https://{{ NODEIP }}:9200/_ilm/stop
|
||||
@@ -69,7 +69,7 @@ fi
|
||||
so-firewall --apply --role=heavynodes --ip="$IP"
|
||||
;;
|
||||
'IDH')
|
||||
so-firewall --apply --role=beats_endpoint_ssl --ip="$IP"
|
||||
so-firewall --apply --role=sensors --ip="$IP"
|
||||
;;
|
||||
'RECEIVER')
|
||||
so-firewall --apply --role=receivers --ip="$IP"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# this script is used to delete the default Grafana dashboard folders that existed prior to Grafana dashboard and Salt management changes in 2.3.70
|
||||
|
||||
# Exit if an error occurs. The next highstate will retry.
|
||||
set -e
|
||||
|
||||
folders=$(curl -X GET http://admin:{{salt['pillar.get']('secrets:grafana_admin')}}@localhost:3000/api/folders | jq -r '.[] | @base64')
|
||||
delfolder=("Manager" "Manager Search" "Sensor Nodes" "Search Nodes" "Standalone" "Eval Mode")
|
||||
|
||||
for row in $folders; do
|
||||
title=$(echo ${row} | base64 --decode | jq -r '.title')
|
||||
uid=$(echo ${row} | base64 --decode | jq -r '.uid')
|
||||
|
||||
if [[ " ${delfolder[@]} " =~ " ${title} " ]]; then
|
||||
curl -X DELETE http://admin:{{salt['pillar.get']('secrets:grafana_admin')}}@localhost:3000/api/folders/$uid
|
||||
fi
|
||||
done
|
||||
|
||||
echo "so-grafana-dashboard-folder-delete has been run to delete default Grafana dashboard folders that existed prior to 2.3.70" > /opt/so/state/so-grafana-dashboard-folder-delete-complete
|
||||
|
||||
exit 0
|
||||
@@ -25,7 +25,6 @@ container_list() {
|
||||
if [ $MANAGERCHECK == 'so-import' ]; then
|
||||
TRUSTED_CONTAINERS=(
|
||||
"so-elasticsearch"
|
||||
"so-filebeat"
|
||||
"so-idstools"
|
||||
"so-influxdb"
|
||||
"so-kibana"
|
||||
@@ -47,8 +46,6 @@ container_list() {
|
||||
"so-elastic-agent"
|
||||
"so-elastic-agent-builder"
|
||||
"so-elasticsearch"
|
||||
"so-filebeat"
|
||||
"so-grafana"
|
||||
"so-idh"
|
||||
"so-idstools"
|
||||
"so-influxdb"
|
||||
@@ -73,7 +70,6 @@ container_list() {
|
||||
)
|
||||
else
|
||||
TRUSTED_CONTAINERS=(
|
||||
"so-filebeat"
|
||||
"so-idstools"
|
||||
"so-elasticsearch"
|
||||
"so-logstash"
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
wdurregex="^[0-9]+w$"
|
||||
ddurregex="^[0-9]+d$"
|
||||
|
||||
echo -e "\nThis script is used to reduce the size of InfluxDB by removing old data and retaining only the duration specified."
|
||||
echo "The duration will need to be specified as an integer followed by the duration unit without a space."
|
||||
echo -e "\nFor example, to purge all data but retain the past 12 weeks, specify 12w for the duration."
|
||||
echo "The duration units are as follows:"
|
||||
echo " w - week(s)"
|
||||
echo " d - day(s)"
|
||||
|
||||
while true; do
|
||||
echo ""
|
||||
read -p 'Enter the duration of past data that you would like to retain: ' duration
|
||||
duration=$(echo $duration | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
if [[ "$duration" =~ $wdurregex ]] || [[ "$duration" =~ $ddurregex ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
echo -e "\nInvalid duration."
|
||||
done
|
||||
|
||||
echo -e "\nInfluxDB will now be cleaned and leave only the past $duration worth of data."
|
||||
read -r -p "Are you sure you want to continue? [y/N] " yorn
|
||||
if [[ "$yorn" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||
echo -e "\nCleaning InfluxDb and saving only the past $duration. This may could take several minutes depending on how much data needs to be cleaned."
|
||||
if docker exec -t so-influxdb /bin/bash -c "influx -ssl -unsafeSsl -database telegraf -execute \"DELETE FROM /.*/ WHERE \"time\" >= '2020-01-01T00:00:00.0000000Z' AND \"time\" <= now() - $duration\""; then
|
||||
echo -e "\nInfluxDb clean complete."
|
||||
else
|
||||
echo -e "\nSomething went wrong with cleaning InfluxDB. Please verify that the so-influxdb Docker container is running, and check the log at /opt/so/log/influxdb/influxdb.log for any details."
|
||||
fi
|
||||
else
|
||||
echo -e "\nExiting as requested."
|
||||
fi
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
{%- set role = grains.id.split('_') | last %}
|
||||
{%- if role in ['manager', 'managersearch', 'eval', 'standalone'] %}
|
||||
{%- import_yaml 'influxdb/defaults.yaml' as default_settings %}
|
||||
{%- set influxdb = salt['grains.filter_by'](default_settings, default='influxdb', merge=salt['pillar.get']('influxdb', {})) %}
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
echo -e "\nThis script is used to reduce the size of InfluxDB by downsampling old data into the so_long_term retention policy."
|
||||
|
||||
echo -e "\nInfluxDB will now be downsampled. This could take a few hours depending on how large the database is and hardware resources available."
|
||||
read -r -p "Are you sure you want to continue? [y/N] " yorn
|
||||
if [[ "$yorn" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||
echo -e "\nDownsampling InfluxDb started at `date`. This may take several hours depending on how much data needs to be downsampled."
|
||||
|
||||
{% for dest_rp in influxdb.downsample.keys() -%}
|
||||
{% for measurement in influxdb.downsample[dest_rp].get('measurements', []) -%}
|
||||
|
||||
day=0
|
||||
startdate=`date`
|
||||
while docker exec -t so-influxdb /bin/bash -c "influx -ssl -unsafeSsl -database telegraf -execute \"SELECT mean(*) INTO \"so_long_term\".\"{{measurement}}\" FROM \"autogen\".\"{{measurement}}\" WHERE \"time\" >= '2020-07-21T00:00:00.0000000Z' + ${day}d AND \"time\" <= '2020-07-21T00:00:00.0000000Z' + $((day+1))d GROUP BY time(5m),*\""; do
|
||||
# why 2020-07-21?
|
||||
migrationdate=`date -d "2020-07-21 + ${day} days" +"%y-%m-%d"`
|
||||
|
||||
echo "Downsampling of measurement: {{measurement}} from $migrationdate started at $startdate and completed at `date`."
|
||||
|
||||
newdaytomigrate=$(date -d "$migrationdate + 1 days" +"%s")
|
||||
today=$(date +"%s")
|
||||
if [ $newdaytomigrate -ge $today ]; then
|
||||
break
|
||||
else
|
||||
((day=day+1))
|
||||
startdate=`date`
|
||||
echo -e "\nDownsampling the next day's worth of data for measurement: {{measurement}}."
|
||||
fi
|
||||
done
|
||||
|
||||
{% endfor -%}
|
||||
{% endfor -%}
|
||||
|
||||
echo -e "\nInfluxDb data downsampling complete."
|
||||
|
||||
else
|
||||
echo -e "\nExiting as requested."
|
||||
fi
|
||||
{%- else %}
|
||||
echo -e "\nThis script can only be run on a node running InfluxDB."
|
||||
{%- endif %}
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
echo -e "\nThis script is used to reduce the size of InfluxDB by dropping the autogen retention policy."
|
||||
echo "If you want to retain historical data prior to 2.3.60, then this should only be run after you have downsampled your data using so-influxdb-downsample."
|
||||
|
||||
echo -e "\nThe autogen retention policy will now be dropped from InfluxDB."
|
||||
read -r -p "Are you sure you want to continue? [y/N] " yorn
|
||||
if [[ "$yorn" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||
echo -e "\nDropping autogen retention policy."
|
||||
if docker exec -t so-influxdb influx -format json -ssl -unsafeSsl -execute "drop retention policy autogen on telegraf"; then
|
||||
echo -e "\nAutogen retention policy dropped from InfluxDb."
|
||||
else
|
||||
echo -e "\nSomething went wrong dropping then autogen retention policy from InfluxDB. Please verify that the so-influxdb Docker container is running, and check the log at /opt/so/log/influxdb/influxdb.log for any details."
|
||||
fi
|
||||
else
|
||||
echo -e "\nExiting as requested."
|
||||
fi
|
||||
285
salt/common/tools/sbin/so-influxdb-manage
Normal file
285
salt/common/tools/sbin/so-influxdb-manage
Normal file
@@ -0,0 +1,285 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
. /usr/sbin/so-common
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <operation> [args]"
|
||||
echo ""
|
||||
echo "Supported Operations:"
|
||||
echo " dashboardpath Returns the URL path for a dashboard, requires: <name-of-dashboard>"
|
||||
echo " export Exports all templates to stdout"
|
||||
echo " setup Loads all templates and creates all required buckets"
|
||||
echo " userlist Lists users"
|
||||
echo " useradd Adds a new user, requires: <email>"
|
||||
echo " userdel Removes an existing user, requires: <email>"
|
||||
echo " userenable Enables a user, requires: <email>"
|
||||
echo " userdisable Disables a user, requires: <email>"
|
||||
echo " userpass Updates a user's password, requires: <email>"
|
||||
echo " userpromote Promotes a user to admin: <email>"
|
||||
echo " userdemote Demotes a user from admin: <email>"
|
||||
echo ""
|
||||
echo "If required, the password will be read from STDIN."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
COMMAND=$(basename $0)
|
||||
OP=$1
|
||||
shift
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
log() {
|
||||
echo -e "$(date) | $COMMAND | $@" >&2
|
||||
}
|
||||
|
||||
check_response() {
|
||||
response=$1
|
||||
if [[ "$response" =~ "\"code\":" ]]; then
|
||||
log "Failed. Check the response for more details.\n$response"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
request() {
|
||||
curl -skK /opt/so/conf/influxdb/curl.config "https://localhost:8086/api/v2/$@"
|
||||
}
|
||||
|
||||
lookup_user_id() {
|
||||
email=$1
|
||||
|
||||
response=$(request users?limit=100)
|
||||
check_response "$response"
|
||||
uid=$(echo "$response" | jq -r ".users[] | select(.name == \"$email\").id")
|
||||
if [[ -z "$uid" ]]; then
|
||||
log "User not found"
|
||||
exit 1
|
||||
fi
|
||||
echo "$uid"
|
||||
}
|
||||
|
||||
lookup_stack_id() {
|
||||
oid=$1
|
||||
|
||||
response=$(request "stacks?orgID=$oid&name=Security+Onion")
|
||||
check_response "$response"
|
||||
stackid=$(echo "$response" | jq -r ".stacks[0].id")
|
||||
if [[ -z "$stackid" || "$stackid" == null ]]; then
|
||||
response=$(request stacks -X POST -d "{\"name\":\"Security Onion\",\"orgID\":\"$oid\"}")
|
||||
check_response "$response"
|
||||
stackid=$(echo "$response" | jq -r .id)
|
||||
fi
|
||||
echo "$stackid"
|
||||
}
|
||||
|
||||
change_password() {
|
||||
uid=$1
|
||||
|
||||
set +e
|
||||
test -t 0
|
||||
if [[ $? == 0 ]]; then
|
||||
echo "Enter new password:"
|
||||
fi
|
||||
set -e
|
||||
read -rs pass
|
||||
check_password_and_exit "$pass"
|
||||
response=$(request users/$uid/password -X POST -d "{\"password\":\"$pass\"}")
|
||||
check_response "$response"
|
||||
}
|
||||
|
||||
apply_templates() {
|
||||
oid=$1
|
||||
stackid=$2
|
||||
template_objects_array=$3
|
||||
|
||||
body="{\"orgID\":\"$oid\",\"stackID\":\"$stackid\",\"templates\":$template_objects_array}"
|
||||
response=$(request templates/apply -X POST -d "$body")
|
||||
check_response "$response"
|
||||
}
|
||||
|
||||
setup_bucket() {
|
||||
oid=$1
|
||||
name=$2
|
||||
age=$3
|
||||
shardduration=$4
|
||||
|
||||
response=$(request "buckets?orgID=$oid&name=$name")
|
||||
bucketid=$(echo "$response" | jq -r ".buckets[0].id")
|
||||
if [[ -z "$bucketid" || "$bucketid" == null ]]; then
|
||||
response=$(request buckets -X POST -d "{\"name\":\"$name\",\"orgID\":\"$oid\"}")
|
||||
check_response "$response"
|
||||
bucketid=$(echo "$response" | jq -r .id)
|
||||
fi
|
||||
response=$(request buckets/$bucketid -X PATCH -d "{\"name\":\"$name\",\"retentionRules\":[{\"everySeconds\":$age,\"shardGroupDurationSeconds\":$shardduration,\"type\":\"expire\"}]}")
|
||||
check_response "$response"
|
||||
}
|
||||
|
||||
lookup_org_id_with_wait() {
|
||||
max_attempts=30
|
||||
attempts=0
|
||||
wait=10
|
||||
while [[ $attempts -lt $max_attempts ]]; do
|
||||
response=$(request orgs?org=Security+Onion)
|
||||
oid=$(echo "$response" | jq -r ".orgs[] | select(.name == \"Security Onion\").id")
|
||||
if [[ -z $oid ]]; then
|
||||
attempts=$((attempts+1))
|
||||
log "Server does not appear to be running or fully initialized - will try again in $wait seconds ($attempts / $max_attempts)"
|
||||
sleep $wait
|
||||
else
|
||||
echo "$oid"
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
log "Server has not started after $max_attempts attempts - aborting"
|
||||
exit 1
|
||||
}
|
||||
|
||||
oid=$(lookup_org_id_with_wait)
|
||||
|
||||
case "$OP" in
|
||||
|
||||
setup)
|
||||
log "Ensuring organization is setup correctly"
|
||||
|
||||
# Load templates if at least one has been modified since the last setup
|
||||
newest=$(ls -1t /opt/so/conf/influxdb/templates/ | head -1)
|
||||
if [ /opt/so/conf/influxdb/templates/$newest -nt /opt/so/conf/influxdb/last_template_setup ]; then
|
||||
log "Updating templates"
|
||||
stackid=$(lookup_stack_id "$oid")
|
||||
for file in /opt/so/conf/influxdb/templates/*; do
|
||||
if [[ "$templates_array" != "" ]]; then
|
||||
templates_array="$templates_array,"
|
||||
fi
|
||||
template=$(cat "$file")
|
||||
templates_array="$templates_array{\"contents\":$template}"
|
||||
done
|
||||
apply_templates "$oid" "$stackid" "[$templates_array]"
|
||||
echo $(date) > /opt/so/conf/influxdb/last_template_setup
|
||||
else
|
||||
log "Templates have not been modified since last setup"
|
||||
fi
|
||||
|
||||
# Setup buckets and retention periods if at least one has been modified since the last setup
|
||||
if [ /opt/so/conf/influxdb/buckets.json -nt /opt/so/conf/influxdb/last_bucket_setup ]; then
|
||||
log "Updating buckets and retention periods"
|
||||
for rp in so_short_term so_long_term; do
|
||||
bucket=telegraf/$rp
|
||||
log "Ensuring bucket is created and configured; bucket=$bucket"
|
||||
age=$(cat /opt/so/conf/influxdb/buckets.json | jq -r .$rp.duration)
|
||||
shard_duration=$(cat /opt/so/conf/influxdb/buckets.json | jq -r .$rp.shard_duration)
|
||||
setup_bucket "$oid" "$bucket" "$age" "$shard_duration"
|
||||
done
|
||||
echo $(date) > /opt/so/conf/influxdb/last_bucket_setup
|
||||
else
|
||||
log "Buckets have not been modified since last setup"
|
||||
fi
|
||||
;;
|
||||
|
||||
userlist)
|
||||
log "Listing existing users"
|
||||
response=$(request users)
|
||||
check_response "$response"
|
||||
echo "$response" | jq -r '.users[] | "\(.id): \(.name) (\(.status))"'
|
||||
;;
|
||||
|
||||
useradd)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Adding new user; email=$email"
|
||||
response=$(request users -X POST -d "{\"name\":\"$email\"}")
|
||||
check_response "$response"
|
||||
uid=$(echo "$response" | jq -r .id)
|
||||
|
||||
log "Adding new user to organization"
|
||||
response=$(request orgs/$oid/members -X POST -d "{\"id\":\"$uid\"}")
|
||||
check_response "$response"
|
||||
|
||||
change_password "$uid"
|
||||
;;
|
||||
|
||||
userpass)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Updating user password; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
change_password "$uid"
|
||||
;;
|
||||
|
||||
userdel)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Deleting user; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
response=$(request users/$uid -X DELETE)
|
||||
check_response "$response"
|
||||
;;
|
||||
|
||||
userenable)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Enabling user; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
response=$(request users/$uid -X PATCH -d "{\"name\":\"$email\",\"status\":\"active\"}")
|
||||
check_response "$response"
|
||||
;;
|
||||
|
||||
userdisable)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Disabling user; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
response=$(request users/$uid -X PATCH -d "{\"name\":\"$email\",\"status\":\"inactive\"}")
|
||||
check_response "$response"
|
||||
;;
|
||||
|
||||
userpromote)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Promoting user to admin; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
response=$(request orgs/$oid/members/$uid -X DELETE)
|
||||
response=$(request orgs/$oid/owners -X POST -d "{\"id\":\"$uid\"}")
|
||||
check_response "$response"
|
||||
;;
|
||||
|
||||
userdemote)
|
||||
[ $# -ne 1 ] && usage
|
||||
email=$1
|
||||
log "Demoting user from admin; email=$email"
|
||||
uid=$(lookup_user_id "$email")
|
||||
response=$(request orgs/$oid/owners/$uid -X DELETE)
|
||||
response=$(request orgs/$oid/members -X POST -d "{\"id\":\"$uid\"}")
|
||||
check_response "$response"
|
||||
;;
|
||||
|
||||
export)
|
||||
log "Exporting all organization templates"
|
||||
request templates/export -X POST -d "{\"orgIDs\":[{\"orgID\":\"$oid\"}]}" -H "Content-Type: application/json"
|
||||
;;
|
||||
|
||||
dashboardpath)
|
||||
[ $# -ne 1 ] && usage
|
||||
name=$1
|
||||
response=$(request dashboards?limit=100&orgID=$oid)
|
||||
check_response "$response"
|
||||
dbid=$(echo "$response" | jq -r ".dashboards[] | select(.name == \"$name\").id")
|
||||
if [[ -z "$dbid" ]]; then
|
||||
log "Dashboard not found"
|
||||
exit 1
|
||||
fi
|
||||
echo -n "/influxdb/orgs/$oid/dashboards/$dbid"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
@@ -119,6 +119,18 @@ function add_elastic_to_minion() {
|
||||
" " >> $PILLARFILE
|
||||
}
|
||||
|
||||
# Add IDH Services info to the minion file
|
||||
function add_idh_to_minion() {
|
||||
printf '%s\n'\
|
||||
"idh:"\
|
||||
" restrict_management_ip: $IDH_MGTRESTRICT"\
|
||||
" services:" >> "$PILLARFILE"
|
||||
IFS=',' read -ra IDH_SERVICES_ARRAY <<< "$IDH_SERVICES"
|
||||
for service in ${IDH_SERVICES_ARRAY[@]}; do
|
||||
echo " - $service" | tr '[:upper:]' '[:lower:]' | tr -d '"' >> "$PILLARFILE"
|
||||
done
|
||||
}
|
||||
|
||||
function add_logstash_to_minion() {
|
||||
# Create the logstash advanced pillar
|
||||
printf '%s\n'\
|
||||
@@ -183,8 +195,8 @@ function createEVAL() {
|
||||
add_sensor_to_minion
|
||||
}
|
||||
|
||||
function createIDHNODE() {
|
||||
echo "Nothing custom needed for IDH nodes"
|
||||
function createIDH() {
|
||||
add_idh_to_minion
|
||||
}
|
||||
|
||||
function createIMPORT() {
|
||||
|
||||
@@ -587,7 +587,10 @@ case "${operation}" in
|
||||
createUser "$email" "${role:-$DEFAULT_ROLE}" "${firstName}" "${lastName}" "${note}"
|
||||
syncAll
|
||||
echo "Successfully added new user to SOC"
|
||||
check_container fleet && echo "$password" | so-fleet-user-add "$email"
|
||||
echo "$password" | so-influxdb-manage useradd "$email"
|
||||
if [[ "$role" == "superuser" ]]; then
|
||||
echo "$password" | so-influxdb-manage userpromote "$email"
|
||||
fi
|
||||
;;
|
||||
|
||||
"list")
|
||||
@@ -605,6 +608,9 @@ case "${operation}" in
|
||||
if addUserRole "$email" "$role"; then
|
||||
syncElastic
|
||||
echo "Successfully added role to user"
|
||||
if [[ "$role" == "superuser" ]]; then
|
||||
echo "$password" | so-influxdb-manage userpromote "$email"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
@@ -618,6 +624,9 @@ case "${operation}" in
|
||||
deleteUserRole "$email" "$role"
|
||||
syncElastic
|
||||
echo "Successfully removed role from user"
|
||||
if [[ "$role" == "superuser" ]]; then
|
||||
echo "$password" | so-influxdb-manage userdemote "$email"
|
||||
fi
|
||||
;;
|
||||
|
||||
"password")
|
||||
@@ -628,6 +637,7 @@ case "${operation}" in
|
||||
updateUserPassword "$email"
|
||||
syncAll
|
||||
echo "Successfully updated user password"
|
||||
echo "$password" | so-influxdb-manage userpass "$email"
|
||||
;;
|
||||
|
||||
"profile")
|
||||
@@ -647,7 +657,7 @@ case "${operation}" in
|
||||
updateStatus "$email" 'active'
|
||||
syncAll
|
||||
echo "Successfully enabled user"
|
||||
echo "Fleet user will need to be recreated manually with so-fleet-user-add"
|
||||
so-influxdb-manage userenable "$email"
|
||||
;;
|
||||
|
||||
"disable")
|
||||
@@ -658,7 +668,7 @@ case "${operation}" in
|
||||
updateStatus "$email" 'locked'
|
||||
syncAll
|
||||
echo "Successfully disabled user"
|
||||
check_container fleet && so-fleet-user-delete "$email"
|
||||
so-influxdb-manage userdisable "$email"
|
||||
;;
|
||||
|
||||
"delete")
|
||||
@@ -669,7 +679,7 @@ case "${operation}" in
|
||||
deleteUser "$email"
|
||||
syncAll
|
||||
echo "Successfully deleted user"
|
||||
check_container fleet && so-fleet-user-delete "$email"
|
||||
so-influxdb-manage userdel "$email"
|
||||
;;
|
||||
|
||||
"sync")
|
||||
|
||||
Reference in New Issue
Block a user