mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-07 17:52:46 +01:00
Merge pull request #5850 from Security-Onion-Solutions/kilo
Upgrade to Kratos 0.7.6-alpha.1
This commit is contained in:
@@ -101,6 +101,9 @@ function validatePassword() {
|
||||
if [[ $len -lt 6 ]]; then
|
||||
fail "Password does not meet the minimum requirements"
|
||||
fi
|
||||
if [[ $len -gt 72 ]]; then
|
||||
fail "Password is too long (max: 72)"
|
||||
fi
|
||||
check_password_and_exit "$password"
|
||||
}
|
||||
|
||||
@@ -237,8 +240,12 @@ function syncElastic() {
|
||||
if [[ -f "$databasePath" && -f "$socRolesFile" ]]; then
|
||||
# Append the SOC users
|
||||
echo "select '{\"user\":\"' || ici.identifier || '\", \"data\":' || ic.config || '}'" \
|
||||
"from identity_credential_identifiers ici, identity_credentials ic " \
|
||||
"where ici.identity_credential_id=ic.id and instr(ic.config, 'hashed_password') " \
|
||||
"from identity_credential_identifiers ici, identity_credentials ic, identities i " \
|
||||
"where " \
|
||||
" ici.identity_credential_id=ic.id " \
|
||||
" and ic.identity_id=i.id " \
|
||||
" and instr(ic.config, 'hashed_password') " \
|
||||
" and i.state == 'active' " \
|
||||
"order by ici.identifier;" | \
|
||||
sqlite3 "$databasePath" | \
|
||||
jq -r '.user + ":" + .data.hashed_password' \
|
||||
@@ -381,6 +388,19 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
function migrateLockedUsers() {
|
||||
# This is a migration function to convert locked users from prior to 2.3.90
|
||||
# to inactive users using the newer Kratos functionality. This should only
|
||||
# find locked users once.
|
||||
lockedEmails=$(curl -s http://localhost:4434/identities | jq -r '.[] | select(.traits.status == "locked") | .traits.email')
|
||||
if [[ -n "$lockedEmails" ]]; then
|
||||
echo "Disabling locked users..."
|
||||
for email in $lockedEmails; do
|
||||
updateStatus "$email" locked
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function updateStatus() {
|
||||
email=$1
|
||||
status=$2
|
||||
@@ -391,24 +411,18 @@ function updateStatus() {
|
||||
response=$(curl -Ss -L "${kratosUrl}/identities/$identityId")
|
||||
[[ $? != 0 ]] && fail "Unable to communicate with Kratos"
|
||||
|
||||
oldConfig=$(echo "select config from identity_credentials where identity_id='${identityId}';" | sqlite3 "$databasePath")
|
||||
schemaId=$(echo "$response" | jq -r .schema_id)
|
||||
|
||||
# Capture traits and remove obsolete 'status' trait if exists
|
||||
traitBlock=$(echo "$response" | jq -c .traits | sed -re 's/,?"status":".*?"//')
|
||||
|
||||
state="active"
|
||||
if [[ "$status" == "locked" ]]; then
|
||||
config=$(echo $oldConfig | sed -e 's/hashed/locked/')
|
||||
echo "update identity_credentials set config=CAST('${config}' as BLOB) where identity_id='${identityId}';" | sqlite3 "$databasePath"
|
||||
[[ $? != 0 ]] && fail "Unable to lock credential record"
|
||||
|
||||
echo "delete from sessions where identity_id='${identityId}';" | sqlite3 "$databasePath"
|
||||
[[ $? != 0 ]] && fail "Unable to invalidate sessions"
|
||||
else
|
||||
config=$(echo $oldConfig | sed -e 's/locked/hashed/')
|
||||
echo "update identity_credentials set config=CAST('${config}' as BLOB) where identity_id='${identityId}';" | sqlite3 "$databasePath"
|
||||
[[ $? != 0 ]] && fail "Unable to unlock credential record"
|
||||
fi
|
||||
|
||||
updatedJson=$(echo "$response" | jq ".traits.status = \"$status\" | del(.verifiable_addresses) | del(.id) | del(.schema_url) | del(.created_at) | del(.updated_at)")
|
||||
response=$(curl -Ss -XPUT -L ${kratosUrl}/identities/$identityId -d "$updatedJson")
|
||||
[[ $? != 0 ]] && fail "Unable to mark user as locked"
|
||||
|
||||
state="inactive"
|
||||
fi
|
||||
body="{ \"schema_id\": \"$schemaId\", \"state\": \"$state\", \"traits\": $traitBlock }"
|
||||
response=$(curl -fSsL -XPUT "${kratosUrl}/identities/$identityId" -d "$body")
|
||||
[[ $? != 0 ]] && fail "Unable to update user"
|
||||
}
|
||||
|
||||
function updateUser() {
|
||||
@@ -547,6 +561,11 @@ case "${operation}" in
|
||||
echo "Password is acceptable"
|
||||
;;
|
||||
|
||||
"migrate")
|
||||
migrateLockedUsers
|
||||
echo "User migration complete"
|
||||
;;
|
||||
|
||||
*)
|
||||
fail "Unsupported operation: $operation"
|
||||
;;
|
||||
|
||||
@@ -1037,6 +1037,9 @@ main() {
|
||||
echo "Checking sudoers file."
|
||||
check_sudoers
|
||||
|
||||
echo "Checking for necessary user migrations."
|
||||
so-user migrate
|
||||
|
||||
if [[ -n $lsl_msg ]]; then
|
||||
case $lsl_msg in
|
||||
'distributed')
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"format": "email",
|
||||
"title": "E-Mail",
|
||||
"minLength": 6,
|
||||
"maxLength": 100,
|
||||
"ory.sh/kratos": {
|
||||
"credentials": {
|
||||
"password": {
|
||||
@@ -25,16 +26,19 @@
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string",
|
||||
"title": "First Name"
|
||||
"title": "First Name",
|
||||
"maxLength": 100
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string",
|
||||
"title": "Last Name"
|
||||
"title": "Last Name",
|
||||
"maxLength": 100
|
||||
},
|
||||
"status": {
|
||||
"note": {
|
||||
"type": "string",
|
||||
"title": "Status"
|
||||
}
|
||||
"title": "Note",
|
||||
"maxLength": 100
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"email"
|
||||
|
||||
Reference in New Issue
Block a user