/
List Workspaces and their Assigned Groups

List Workspaces and their Assigned Groups

This article describes how to use the Kasm API to list all workspaces and their assigned groups.

Sometimes it is necessary to know which workspaces do not have a group assignment or to know which groups a workspace is being explicitly granted access.

This knowledge helps when needing to cleanup unused workspaces or manage workspace access to users.

 Instructions

  1. Create a Linux bash called “list-workspaces-and-group-assignments” with the following contents:

DOMAIN=vdi.contoso.com API_KEY='g1po3hMxxxxx' API_SECRET='xxxxxxtHg5KUDlgKYwXlvXwyeHhRxxxx' ## Get all worspaces IDs workspaces=$( curl -sk 'https://'$DOMAIN'/api/public/get_images' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ --data-raw '{"api_key":"'$API_KEY'","api_key_secret":"'$API_SECRET'"}' \ | jq -rc '[ .[][] | {"image_id":.image_id, "image_friendly_name":.friendly_name}]' ) # echo "$workspaces" # echo "" ## Get all group IDs groups=$( curl -sk 'https://'$DOMAIN'/api/public/get_groups' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ --data-raw '{"api_key":"'$API_KEY'","api_key_secret":"'$API_SECRET'"}' \ | jq -rc '[ .[][] | {"group_id":.group_id, "name":.name}]' ) # echo "$groups" # echo "" ## Get all workspaces assigned to groups shopt -s lastpipe workspaces_assigned_to_a_group='' echo "$groups" | jq -c '.[]' | while read i; do group_id=$(echo "$i" | jq -rc '.group_id') group_name=$(echo "$i" | jq -rc '.name') # echo "group_id: $group_id group_name: $group_name" sleep 0.25 workspaces_assigned_to_a_group+=$(echo " " curl -sk 'https://'$DOMAIN'/api/public/get_images_group' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ --data-raw '{"api_key":"'$API_KEY'","api_key_secret":"'$API_SECRET'","target_group":{"group_id":"'$group_id'"}}' \ | jq -rc '.[][] | {"group_id":.group_id, "group_name":.group_name, "image_id":.image_id, "image_friendly_name":.image_friendly_name}' ) done workspaces_assigned_to_a_group=$(echo "$workspaces_assigned_to_a_group" | sort -u) # echo "workspaces_assigned_to_a_group: $workspaces_assigned_to_a_group" ## Generate final report. ## List all workspaces followed by the groups they are assigned to. shopt -s lastpipe echo "$workspaces" | jq -c '.[]' | while read i; do image_id=$(echo "$i" | jq -rc '.image_id') image_friendly_name=$(echo "$i" | jq -rc '.image_friendly_name') # echo "image_id: $image_id image_friendly_name: $image_friendly_name" first=0 groups_with_selected_image='[' echo "$workspaces_assigned_to_a_group" | jq -c '.' | while read i; do group_id=$(echo "$i" | jq -rc '.group_id') group_name=$(echo "$i" | jq -rc '.group_name') group_image_id=$(echo "$i" | jq -rc '.image_id') group_image_friendly_name=$(echo "$i" | jq -rc '.image_friendly_name') if [ "$image_id" == "$group_image_id" ]; then if [ $first -eq 0 ]; then first=1; else groups_with_selected_image+="," fi groups_with_selected_image+="{\"group_id\":\"$group_id\", \"group_name\":\"$group_name\"}" # echo "group_id: $group_id group_name: $group_name group_image_id: $group_image_id group_image_friendly_name: $group_image_friendly_name" fi done groups_with_selected_image+="]" echo "image_id: $image_id image_friendly_name: $image_friendly_name num_of_groups: $(echo "$groups_with_selected_image" | jq -rc '. | length')" echo "$groups_with_selected_image" | jq -rc '.[]' echo '' done

 

  1. On line 1 replace the variable value for “DOMAIN" with the hostname, IP, or FQDN to your Kasm environment.

  2. One lines 2 and 3 replace the variable values for “API_KEY“ and “API_SECRET“ with a read-only API token for with view permissions to images and groups. (Reference Developer API — Kasm 1.10.0 documentation )

  3. Run the bash script.

  4. The output will display to the standard output.

 

Sample output:

num_of_groups: 1 image_id: 61ed49348a554fe3bc3c1d3550000000 image_friendly_name: Chrome {"group_id":"78e521a4638e4e259ea47a3cc4000000","group_name":"Super User Group 1"} num_of_groups: 0 image_id: 74825f0c4a224e63bbcf0fef00000000 image_friendly_name: Sublime Text num_of_groups: 0 image_id: c19f7351da4a408d9566fe6500000000 image_friendly_name: Signal num_of_groups: 2 image_id: 8af68383f3c14c1d82fc9f8f00000000 image_friendly_name: Edge {"group_id":"78e521a4638e4e259ea47a3cc420000","group_name":"Super User Group 1"} {"group_id":"59ea47a3cc000000078e521a4638e4e2","group_name":"OSINT users"} num_of_groups: 0 image_id: 1f05afff68824787a60d92f500000000 image_friendly_name: Discord num_of_groups: 1 image_id: 49e18ce87b3d4edfac1980200000000 image_friendly_name: Brave {"group_id":"78e521a4638e4e259ea47a3cc0000000","group_name":"Super User Group 2"}

 


Related Docs:

 Related articles

  • Links to related kb articles in the Confluence project

 

Related content