Skip to content

Commit 2fd8735

Browse files
committed
added migration script for auth provider and document it
1 parent 03cc443 commit 2fd8735

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

docs/modules/sonarqube/pages/administration.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ There is an `admin` user which is allowed to change settings, install plugins, e
1010

1111
The SonarQube deployment is using an image built in the central ODS namespace. This image is based on the https://hub.docker.com/_/sonarqube, as can be seen in the https://github.com/opendevstack/ods-core/blob/master/sonarqube/docker/Dockerfile[ODS Dockerfile].
1212
If the previous version was installed using Tailor, follow the process to migrate from tailor to helm in https://www.opendevstack.org/ods-documentation/opendevstack/5.x/administration/helm-migration.html
13+
If the previous version was configured to use Atlassian Crowd as Authentication provider, run the script https://github.com/opendevstack/ods-core/tree/master/scripts/migrate-sonar-users.sh in order to migrate current users to use Saml as Authentication provider.
1314

1415
To update SonarQube, the following steps need to be taken:
1516

scripts/migrate-sonar-users.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
set -ue
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
ODS_CORE_DIR=${SCRIPT_DIR%/*}
6+
ODS_CONFIGURATION_DIR="${ODS_CORE_DIR}/../ods-configuration"
7+
8+
echo_done(){
9+
echo -e "\033[92mDONE\033[39m: $1"
10+
}
11+
12+
echo_warn(){
13+
echo -e "\033[93mWARN\033[39m: $1"
14+
}
15+
16+
echo_error(){
17+
echo -e "\033[31mERROR\033[39m: $1"
18+
}
19+
20+
echo_info(){
21+
echo -e "\033[94mINFO\033[39m: $1"
22+
}
23+
24+
25+
SONARQUBE_URL=""
26+
SONAR_ADMIN_USERNAME=""
27+
SONAR_ADMIN_PASSWORD=""
28+
INSECURE=""
29+
30+
function usage {
31+
printf "Migrate SonarQube users from Atlassian Crowd provider to Saml provider.\n\n"
32+
printf "This script will ask interactively for parameters if not in ods-configuraion.\n"
33+
printf "However, you can also pass them directly. Usage:\n\n"
34+
printf "\t-h|--help\t\tPrint usage\n"
35+
printf "\t-v|--verbose\t\tEnable verbose mode\n"
36+
printf "\t-i|--insecure\t\tAllow insecure server connections when using SSL\n"
37+
printf "\n"
38+
printf "\t-s|--sonarqube\t\tSonarQube URL, e.g. 'https://sonarqube.example.com'\n"
39+
printf "\t-u|--admin-user\tAdmin user\n"
40+
printf "\t-p|--admin-password\tAdmin password\n"
41+
}
42+
43+
while [[ "$#" -gt 0 ]]; do
44+
case $1 in
45+
46+
-v|--verbose) set -x;;
47+
48+
-h|--help) usage; exit 0;;
49+
50+
-i|--insecure) INSECURE="--insecure";;
51+
52+
-p|--admin-password) SONAR_ADMIN_PASSWORD="$2"; shift;;
53+
-p=*|--admin-password=*) SONAR_ADMIN_PASSWORD="${1#*=}";;
54+
55+
-u|--admin-user) SONAR_ADMIN_USERNAME="$2"; shift;;
56+
-u=*|--admin-user=*) SONAR_ADMIN_USERNAME="${1#*=}";;
57+
58+
-s|--sonarqube) SONARQUBE_URL="$2"; shift;;
59+
-s=*|--sonarqube=*) SONARQUBE_URL="${1#*=}";;
60+
61+
*) echo_error "Unknown parameter passed: $1"; exit 1;;
62+
esac; shift; done
63+
64+
if [ -f "${ODS_CONFIGURATION_DIR}/ods-core.env" ]; then
65+
66+
if [ -z "${SONARQUBE_URL}" ]; then
67+
SONARQUBE_URL=$(../scripts/get-config-param.sh SONARQUBE_URL)
68+
fi
69+
70+
if [ -z "${SONAR_ADMIN_USERNAME}" ]; then
71+
SONAR_ADMIN_USERNAME=$(../scripts/get-config-param.sh SONAR_ADMIN_USERNAME)
72+
fi
73+
74+
if [ -z "${SONAR_ADMIN_PASSWORD}" ]; then
75+
SONAR_ADMIN_PASSWORD=$(../scripts/get-config-param.sh SONAR_ADMIN_PASSWORD_B64 | base64 -d)
76+
fi
77+
78+
fi
79+
80+
Email_list=$( curl ${INSECURE} ${SONAR_URL}/api/users/search -u admin:${SONAR_ADMIN_TOKEN} | jq .users | grep login | grep @ | tr -d '"' | tr -d "," | cut -f2 -d ":" )
81+
email_list_array=($Email_list)
82+
83+
for email in "${email_list_array[@]}"
84+
do
85+
curl ${INSECURE} -X POST -sSf -u admin:${SONAR_ADMIN_TOKEN} "${SONAR_URL}/api/users/update_identity_provider?newExternalProvider=saml&login=${email}" > /dev/null
86+
echo "User ${email} migrated to Saml"
87+
done

0 commit comments

Comments
 (0)