|
|
@ -3,23 +3,25 @@ die() { echo >&2 "$@" ; exit 1 ; } |
|
|
|
|
|
|
|
|
|
|
|
DIRNAME="$(dirname $0)" |
|
|
|
DIRNAME="$(dirname $0)" |
|
|
|
cd "$DIRNAME" |
|
|
|
cd "$DIRNAME" |
|
|
|
[ -r env.production ] && source env.production |
|
|
|
source ../env.production || die "no top level env?" |
|
|
|
[ -r ../env.production ] && source ../env.production |
|
|
|
source env.production || die "no local env?" |
|
|
|
|
|
|
|
|
|
|
|
sudo docker-compose exec -u www-data -T nextcloud \ |
|
|
|
if [ ! -r "env.secrets" ]; then |
|
|
|
./occ app:install sociallogin \ |
|
|
|
NEXTCLOUD_CLIENT_SECRET="$(openssl rand -hex 32)" |
|
|
|
|| die "unable to install sociallogin app" |
|
|
|
NEXTCLOUD_ADMIN_PASSWORD="$(openssl rand -hex 4)" |
|
|
|
|
|
|
|
|
|
|
|
sudo docker-compose exec -u www-data -T nextcloud \ |
|
|
|
echo "Generating secrets: admin password $NEXTCLOUD_ADMIN_PASSWORD" |
|
|
|
./occ config:app:set sociallogin prevent_create_email_exists --value=1 \ |
|
|
|
cat <<EOF > env.secrets |
|
|
|
|| die "unable to config sociallogin" |
|
|
|
# Do not check in! |
|
|
|
|
|
|
|
NEXTCLOUD_ADMIN_PASSWORD=$NEXTCLOUD_ADMIN_PASSWORD |
|
|
|
sudo docker-compose exec -u www-data -T nextcloud \ |
|
|
|
NEXTCLOUD_TRUSTED_DOMAINS=$NEXTCLOUD_HOSTNAME |
|
|
|
./occ config:app:set sociallogin update_profile_on_login --value=1 \ |
|
|
|
NEXTCLOUD_CLIENT_SECRET=$NEXTCLOUD_CLIENT_SECRET |
|
|
|
|| die "unable to config sociallogin" |
|
|
|
EOF |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
source env.secrets || die "no secret env?" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
BASE="https://$KEYCLOAK_HOSTNAME/realms/$REALM/protocol/openid-connect" |
|
|
|
BASE="https://$KEYCLOAK_HOSTNAME/realms/$REALM/protocol/openid-connect" |
|
|
|
SECRET="$(openssl rand -hex 20)" |
|
|
|
|
|
|
|
PROVIDER="$(jq -c . <<EOF |
|
|
|
PROVIDER="$(jq -c . <<EOF |
|
|
|
{ |
|
|
|
{ |
|
|
|
"custom_oidc": [ |
|
|
|
"custom_oidc": [ |
|
|
@ -27,15 +29,15 @@ PROVIDER="$(jq -c . <<EOF |
|
|
|
"name": "keycloak", |
|
|
|
"name": "keycloak", |
|
|
|
"title": "Keycloak", |
|
|
|
"title": "Keycloak", |
|
|
|
"clientId": "nextcloud", |
|
|
|
"clientId": "nextcloud", |
|
|
|
"clientSecret": "$SECRET", |
|
|
|
"clientSecret": "$NEXTCLOUD_CLIENT_SECRET", |
|
|
|
"authorizeUrl": "$BASE/auth", |
|
|
|
"authorizeUrl": "$BASE/auth", |
|
|
|
"tokenUrl": "$BASE/token", |
|
|
|
"tokenUrl": "$BASE/token", |
|
|
|
"userInfoUrl": "$BASE/userinfo", |
|
|
|
"userInfoUrl": "$BASE/userinfo", |
|
|
|
"logoutUrl": "", |
|
|
|
"logoutUrl": "$BASE/logout", |
|
|
|
"displayNameClaim": "", |
|
|
|
|
|
|
|
"scope": "openid", |
|
|
|
"scope": "openid", |
|
|
|
"groupsClaim": "roles", |
|
|
|
"groupsClaim": "roles", |
|
|
|
"style": "keycloak", |
|
|
|
"style": "keycloak", |
|
|
|
|
|
|
|
"displayNameClaim": "", |
|
|
|
"defaultGroup": "" |
|
|
|
"defaultGroup": "" |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
@ -43,26 +45,27 @@ PROVIDER="$(jq -c . <<EOF |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
)" |
|
|
|
)" |
|
|
|
|
|
|
|
|
|
|
|
sudo docker-compose exec -u www-data -T nextcloud \ |
|
|
|
|
|
|
|
./occ config:app:set \ |
|
|
|
|
|
|
|
sociallogin custom_providers \ |
|
|
|
|
|
|
|
--value="$PROVIDER" \ |
|
|
|
|
|
|
|
|| die "unable to set keycloak parameters" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docker-compose up -d || die "unable to bring up docker" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# wait for the nextcloud instance to be responsive |
|
|
|
|
|
|
|
# TODO: how to find out if it is ready? |
|
|
|
|
|
|
|
echo "SLEEPING..." |
|
|
|
|
|
|
|
sleep 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docker-compose exec -u www-data -T nextcloud bash -x <<EOF || die "unable to configure sociallogin" |
|
|
|
|
|
|
|
./occ app:remove sociallogin || echo "not yet installed" |
|
|
|
|
|
|
|
./occ app:install sociallogin || exit 1 |
|
|
|
|
|
|
|
./occ config:app:set sociallogin prevent_create_email_exists --value=1 || exit 1 |
|
|
|
|
|
|
|
./occ config:app:set sociallogin update_profile_on_login --value=1 || exit 1 |
|
|
|
|
|
|
|
./occ config:app:set sociallogin custom_providers --value='$PROVIDER' || exit 1 |
|
|
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
|
|
# create the keycloak side of the secret |
|
|
|
../keycloak/client-delete 'nextcloud' || echo "client did not exist?" |
|
|
|
cd ../keycloak |
|
|
|
|
|
|
|
source env.production |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sudo docker-compose exec -T keycloak \ |
|
|
|
../keycloak/client-create << EOF || die "unable to create client id" |
|
|
|
/opt/keycloak/bin/kcadm.sh \ |
|
|
|
|
|
|
|
create clients \ |
|
|
|
|
|
|
|
--server http://localhost:8080/ \ |
|
|
|
|
|
|
|
--user admin \ |
|
|
|
|
|
|
|
--password "$KEYCLOAK_ADMIN_PASSWORD" \ |
|
|
|
|
|
|
|
--realm master \ |
|
|
|
|
|
|
|
-r "$REALM" \ |
|
|
|
|
|
|
|
-f - <<EOF || die "unable to create client id" |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
"clientId": "nextcloud", |
|
|
|
"clientId": "nextcloud", |
|
|
|
"rootUrl": "https://$NEXTCLOUD_HOSTNAME/", |
|
|
|
"rootUrl": "https://$NEXTCLOUD_HOSTNAME/", |
|
|
@ -70,6 +73,6 @@ sudo docker-compose exec -T keycloak \ |
|
|
|
"redirectUris": [ "https://$NEXTCLOUD_HOSTNAME/*" ], |
|
|
|
"redirectUris": [ "https://$NEXTCLOUD_HOSTNAME/*" ], |
|
|
|
"webOrigins": [ "https://$NEXTCLOUD_HOSTNAME" ], |
|
|
|
"webOrigins": [ "https://$NEXTCLOUD_HOSTNAME" ], |
|
|
|
"clientAuthenticatorType": "client-secret", |
|
|
|
"clientAuthenticatorType": "client-secret", |
|
|
|
"secret": "$SECRET" |
|
|
|
"secret": "$NEXTCLOUD_CLIENT_SECRET" |
|
|
|
} |
|
|
|
} |
|
|
|
EOF |
|
|
|
EOF |
|
|
|