Last active
May 23, 2023 13:20
-
-
Save eumel8/0d50ceaca7c71fe4f55d440886734291 to your computer and use it in GitHub Desktop.
migrate Rancher Keycloak saml to oidc user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# keycloak saml user object: | |
# principalIds: | |
# - keycloak_user://[email protected] | |
# - local://u-pxxxxxxx | |
# | |
# keycloak oidc user object: | |
# principalIds: | |
# - keycloakoidc_user://[email protected] | |
# - local://u-pxxxxxxx | |
for i in `kubectl get users.management.cattle.io -o custom-columns="USER:".metadata.name --no-headers` | |
do | |
pri=$(kubectl get users.management.cattle.io $i -o json | jq -r '.principalIds[]?') | |
for p in $pri | |
do | |
if [[ $p =~ "keycloak_user" ]]; then | |
e=$(echo $p |sed 's/^.*\/\///') | |
echo "migrate $i - $e" | |
kubectl get users.management.cattle.io $i -o json \ | |
| jq '.principalIds = ["keycloakoidc_user://'$e'","local://'$i'"]' \ | |
| kubectl replace -f - --validate=false | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment