Migrate users from locked to inactive during soup

This commit is contained in:
Jason Ertel
2021-10-06 15:45:35 -04:00
parent 7d8c8144b0
commit 62c3afc81d
2 changed files with 22 additions and 1 deletions

View File

@@ -385,6 +385,19 @@ EOF
fi 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() { function updateStatus() {
email=$1 email=$1
status=$2 status=$2
@@ -398,7 +411,7 @@ function updateStatus() {
schemaId=$(echo "$response" | jq -r .schema_id) schemaId=$(echo "$response" | jq -r .schema_id)
# Capture traits and remove obsolete 'status' trait if exists # Capture traits and remove obsolete 'status' trait if exists
traitBlock=$(echo "$response" | jq -r .traits | grep -v "\"status\":") traitBlock=$(echo "$response" | jq -c .traits | sed -re 's/,?"status":".*?"//')
state="active" state="active"
if [[ "$status" == "locked" ]]; then if [[ "$status" == "locked" ]]; then
@@ -545,6 +558,11 @@ case "${operation}" in
echo "Password is acceptable" echo "Password is acceptable"
;; ;;
"migrate")
migrateLockedUsers
echo "User migration complete"
;;
*) *)
fail "Unsupported operation: $operation" fail "Unsupported operation: $operation"
;; ;;

View File

@@ -1037,6 +1037,9 @@ main() {
echo "Checking sudoers file." echo "Checking sudoers file."
check_sudoers check_sudoers
echo "Checking for necessary user migrations."
so-user migrate
if [[ -n $lsl_msg ]]; then if [[ -n $lsl_msg ]]; then
case $lsl_msg in case $lsl_msg in
'distributed') 'distributed')