Skip to content

Commit cf7f6c3

Browse files
authored
[misc] Remove default zitadel admin user in deployment script (#4482)
* Delete default zitadel-admin user during initialization Signed-off-by: bcmmbaga <[email protected]> * Refactor Signed-off-by: bcmmbaga <[email protected]> --------- Signed-off-by: bcmmbaga <[email protected]>
1 parent 47e64d7 commit cf7f6c3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

infrastructure_files/getting-started-with-zitadel.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,45 @@ delete_auto_service_user() {
328328
echo "$PARSED_RESPONSE"
329329
}
330330

331+
delete_default_zitadel_admin() {
332+
INSTANCE_URL=$1
333+
PAT=$2
334+
335+
# Search for the default zitadel-admin user
336+
RESPONSE=$(
337+
curl -sS -X POST "$INSTANCE_URL/management/v1/users/_search" \
338+
-H "Authorization: Bearer $PAT" \
339+
-H "Content-Type: application/json" \
340+
-d '{
341+
"queries": [
342+
{
343+
"userNameQuery": {
344+
"userName": "zitadel-admin@",
345+
"method": "TEXT_QUERY_METHOD_STARTS_WITH"
346+
}
347+
}
348+
]
349+
}'
350+
)
351+
352+
DEFAULT_ADMIN_ID=$(echo "$RESPONSE" | jq -r '.result[0].id // empty')
353+
354+
if [ -n "$DEFAULT_ADMIN_ID" ] && [ "$DEFAULT_ADMIN_ID" != "null" ]; then
355+
echo "Found default zitadel-admin user with ID: $DEFAULT_ADMIN_ID"
356+
357+
RESPONSE=$(
358+
curl -sS -X DELETE "$INSTANCE_URL/management/v1/users/$DEFAULT_ADMIN_ID" \
359+
-H "Authorization: Bearer $PAT" \
360+
-H "Content-Type: application/json" \
361+
)
362+
PARSED_RESPONSE=$(echo "$RESPONSE" | jq -r '.details.changeDate // "deleted"')
363+
handle_zitadel_request_response "$PARSED_RESPONSE" "delete_default_zitadel_admin" "$RESPONSE"
364+
365+
else
366+
echo "Default zitadel-admin user not found: $RESPONSE"
367+
fi
368+
}
369+
331370
init_zitadel() {
332371
echo -e "\nInitializing Zitadel with NetBird's applications\n"
333372
INSTANCE_URL="$NETBIRD_HTTP_PROTOCOL://$NETBIRD_DOMAIN"
@@ -346,6 +385,9 @@ init_zitadel() {
346385
echo -n "Waiting for Zitadel to become ready "
347386
wait_api "$INSTANCE_URL" "$PAT"
348387

388+
echo "Deleting default zitadel-admin user..."
389+
delete_default_zitadel_admin "$INSTANCE_URL" "$PAT"
390+
349391
# create the zitadel project
350392
echo "Creating new zitadel project"
351393
PROJECT_ID=$(create_new_project "$INSTANCE_URL" "$PAT")

0 commit comments

Comments
 (0)