Skip to content

Instantly share code, notes, and snippets.

@eumel8
Last active May 23, 2023 13:20
Show Gist options
  • Save eumel8/0d50ceaca7c71fe4f55d440886734291 to your computer and use it in GitHub Desktop.
Save eumel8/0d50ceaca7c71fe4f55d440886734291 to your computer and use it in GitHub Desktop.
migrate Rancher Keycloak saml to oidc user
#!/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