mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Ensure role file exists before ES state is run
This commit is contained in:
@@ -150,6 +150,23 @@ function createElasticFile() {
|
|||||||
chown "${esUID}:${esGID}" "$filename"
|
chown "${esUID}:${esGID}" "$filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureRoleFileExists() {
|
||||||
|
if [ ! -f "$elasticRolesFile" ]; then
|
||||||
|
echo "Creating new roles file: $elasticRolesFile"
|
||||||
|
rolesTmpFile="${elasticRolesFile}.tmp"
|
||||||
|
createElasticFile "${rolesTmpFile}"
|
||||||
|
authPillarJson=$(lookup_salt_value "auth" "elasticsearch" "pillar" "json")
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_elastic_user" "superuser" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_kibana_user" "superuser" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_logstash_user" "superuser" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_beats_user" "superuser" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "remote_monitoring_collector" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "remote_monitoring_agent" "$rolesTmpFile"
|
||||||
|
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "monitoring_user" "$rolesTmpFile"
|
||||||
|
mv "${rolesTmpFile}" "${elasticRolesFile}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function syncElasticSystemUser() {
|
function syncElasticSystemUser() {
|
||||||
json=$1
|
json=$1
|
||||||
userid=$2
|
userid=$2
|
||||||
@@ -179,6 +196,8 @@ function syncElasticSystemRole() {
|
|||||||
|
|
||||||
function syncElastic() {
|
function syncElastic() {
|
||||||
echo "Syncing users between SOC and Elastic..."
|
echo "Syncing users between SOC and Elastic..."
|
||||||
|
ensureRoleFileExists
|
||||||
|
|
||||||
usersTmpFile="${elasticUsersFile}.tmp"
|
usersTmpFile="${elasticUsersFile}.tmp"
|
||||||
createElasticFile "${usersTmpFile}"
|
createElasticFile "${usersTmpFile}"
|
||||||
|
|
||||||
@@ -263,19 +282,7 @@ function adjustUserRole() {
|
|||||||
identityId=$(findIdByEmail "$email")
|
identityId=$(findIdByEmail "$email")
|
||||||
[[ ${identityId} == "" ]] && fail "User not found"
|
[[ ${identityId} == "" ]] && fail "User not found"
|
||||||
|
|
||||||
if [ ! -f "$filename" ]; then
|
ensureRoleFileExists
|
||||||
rolesTmpFile="${elasticRolesFile}.tmp"
|
|
||||||
createElasticFile "${rolesTmpFile}"
|
|
||||||
authPillarJson=$(lookup_salt_value "auth" "elasticsearch" "pillar" "json")
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_elastic_user" "superuser" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_kibana_user" "superuser" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_logstash_user" "superuser" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_beats_user" "superuser" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "remote_monitoring_collector" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "remote_monitoring_agent" "$rolesTmpFile"
|
|
||||||
syncElasticSystemRole "$authPillarJson" "so_monitor_user" "monitoring_user" "$rolesTmpFile"
|
|
||||||
mv "${rolesTmpFile}" "${elasticRolesFile}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
filename="$elasticRolesFile"
|
filename="$elasticRolesFile"
|
||||||
grep "$role:" "$elasticRolesFile" | grep "$email" && hasRole=1
|
grep "$role:" "$elasticRolesFile" | grep "$email" && hasRole=1
|
||||||
|
|||||||
Reference in New Issue
Block a user