Deploy Apache Guacamole on GKE and Cloud SQL Stay organized with collections Save and categorize content based on your preferences.
This document describes how you deployApache Guacamole on GKE and Cloud SQL.
These instructions are intended for server administrators and engineers who wantto host Guacamole on GKE and Cloud SQL. The documentassumes you are familiar with deploying workloads to Kubernetesand Cloud SQL for MySQL. We recommend that you be familiar with Identity and Access Management andGoogle Compute Engine as well.
Architecture
The following diagram shows how a Google Cloud load balancer isconfigured with IAP, to protect an instance of the Guacamoleclient running in GKE:
The Guacamole client connects to the guacd backend service, which brokers remotedesktop connections to one or more Compute Engine VMs. The scripts alsodeploy a Cloud SQL instance to manage configuration data for Guacamole.
For details, seeApache Guacamole on GKE and Cloud SQL.
Objectives
- Deploy the infrastructure by using Terraform.
- Create a Guacamole database in Cloud SQL.
- Deploy Guacamole to a GKE Cluster by using Skaffold.
- Test a connection to a VM through Guacamole.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage, use thepricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, seeClean up.
Before you begin
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Enable the Resource Manager, Service Usage, Artifact Registry, and Compute Engine APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.In the Google Cloud console, activate Cloud Shell.
Deploy the infrastructure
In this section, you use Terraform to deploy the following resources:
- Virtual Private Cloud
- A firewall rule
- A GKE cluster
- An Artifact Registry repository
- Cloud SQL for MySQL
- A VM for managing the MySQL database
- Service accounts
The Terraform configuration also enablesthe use of IAP in your project.
In Cloud Shell, clone the GitHub repository:
gitclonehttps://github.com/GoogleCloudPlatform/guacamole-on-gcp.gitDeploy the required infrastructure by using Terraform:
cdguacamole-on-gcp/tf-infraunsetGOOGLE_CLOUD_QUOTA_PROJECTterraforminit-upgradeterraformapplyFollow the instructions to enter your Google Cloud project ID.
To approve Terraform's request to deploy resources to your project,enter
yes.Deploying all resources takes several minutes to complete.
Deploy the Guacamole database
In this section, you create the Guacamole database and tables inCloud SQL for MySQL, and populate the database with the administrator userinformation.
In Cloud Shell, set environment variables and find thedatabase root password:
cd..sourcebin/read-tf-output.shMake a note of the database root password; you need it in the followingsteps.
The script reads output variables from the Terraform run and sets thefollowing environment variables, which are used throughout this procedure:
CLOUD_SQL_INSTANCEZONEREGIONDB_MGMT_VMPROJECT_IDGKE_CLUSTERGUACAMOLE_URLSUBNETCopy the
create-schema.sqlandinsert-admin-user.sqlscript filesto the database management VM, and then connect to the VM:gcloudcomputescp\--tunnel-through-iap\--zone=$ZONE\create-schema.sql\insert-admin-user.sql\$DB_MGMT_VM:gcloudcomputessh$DB_MGMT_VM\--zone=$ZONE\--tunnel-through-iapA console session to the Database Management VM through Cloud Shellis now established.
Install MySQL client tools:
sudoapt-getupdatesudoapt-getinstall-ymariadb-clientConnect to Cloud SQL and create the database. When promptedfor a password, use the root password you noted earlier in this section.
exportCLOUD_SQL_PRIVATE_IP=$(curlhttp://metadata.google.internal/computeMetadata/v1/instance/attributes/cloud_sql_ip-H"Metadata-Flavor: Google")mysql-h$CLOUD_SQL_PRIVATE_IP-uroot-pGrant the database user permissions over the newly created database:
CREATEDATABASEguacamole;USEguacamole;GRANTSELECT,INSERT,UPDATE,DELETEONguacamole.*TO'guac-db-user';FLUSHPRIVILEGES;SOURCEcreate-schema.sql;SOURCEinsert-admin-user.sql;quitAfter the MySQL commands finish running, exit the VM SSH session:
exit
Deploy Guacamole to GKE by using Skaffold
In this section, you deploy the Guacamole application tothe GKE cluster, by usingSkaffold.Skaffold handles the workflow for building, pushing, and deploying the Guacamoleimages to the GKE clusters.
In Cloud Shell, deploy the GKE configurationby using terraform:
cdtf-k8sterraforminit-upgradeterraformapply-parallelism=1Get credentials for the GKE cluster:
gcloudcontainerclustersget-credentials\--region$REGION$GKE_CLUSTERRun Skaffold from the root of the cloned git repository:
cd..skaffold--default-repo$REGION-docker.pkg.dev/$PROJECT_ID/guac-reporunThe Skaffold tool builds container images for Guacamole throughGoogle Cloud Build (the command line includes a flag that specifies which repository to push theimages to). The tool also runs akustomize step to generate Kubernetes ConfigMaps and Secrets based on the output ofthe Terraform run.
Verify that the certificate was provisioned:
kubectlget-wmanagedcertificates/guacamole-client-cert\-nguacamole\-ojsonpath="{.spec.domains[0]} is {.status.domainStatus[0].status}"Provisioning the certificate can take up to 60 minutes to complete.
Once the certificate is provisioned, you can visit your URL in a browser.
View the URL from the terraform output:
echo$GUACAMOLE_URLIn a browser window, enter the URL that you got in the previous step.
When IAP prompts you, sign in with your Googlecredentials.
After you sign in, you are logged into Guacamole with administrativeprivileges, based on the
Note: The OAuth configuration created by this procedure is set tointernal.This means you must use a Google Account in the same organization as theone you used to deploy Guacamole in this procedure; otherwise, you receiveaninsert-admin-user.sqlscript you ran previouslyin this procedure.HTTP/403 org_internalerror. If your browser session is already signedinto a different Google Account, try connecting to the URL in an incognitomode tab.
You can now add additional users based on their email address through theGuacamole user interface. For details, seeAdministration in the Guacamole documentation.These additional users also require permissions through GoogleIAM, with theIAP-secured Web App User role.
Test a connection to a VM
After you deploy, configure, and successfully sign in to Guacamole, you cancreate a Windows VM and connect to the newly created VM through Guacamole.
Create a VM
In Cloud Shell, create a Windows VM to test connections to:
exportTEST_VM=windows-vmgcloudcomputeinstancescreate$TEST_VM\--project=$PROJECT_ID\--zone=$ZONE\--machine-type=n1-standard-1\--subnet=$SUBNET\--no-address\--image-family=windows-2019\--image-project=windows-cloud\--boot-disk-size=50GB\--boot-disk-type=pd-standard\—-shielded-secure-bootAfter running the command, you may need to wait a few minutes for Windows tofinish initializing, before you proceed to the next step.
Reset the Windows password for the VM you just created:
gcloudcomputereset-windows-password$TEST_VM\--user=admin\--zone=$ZONE
Add a new connection to the VM
- In a browser window, enter the Guacamole instance URL fromDeploy Guacamole to GKE using Skaffold, and then sign in through IAP.
- In the Guacamole UI, click your username, and then clickSettings.
- Under theConnections tab, clickNew Connection.
- In theName field, enter a name for the connection.
- In theLocation field, enter the location for the connection.
- From theProtocol drop-down list, selectRDP.
UnderNetwork, in theHostname field, enter the name of the VMyou created,
windows-vm.Your project DNS resolves this hostname to the instance's internal IP address.
Note: If you choose to create your VM in a different zone than yourGuacamole GKE cluster, you need to fully qualify theVM name. For details, seeInternal DNS.In theAuthentication section, set the following fields:
- Username:
admin - Password: the password you got when you reset the password for the VM
- Security mode:
NLA(Network Level Authentication) Ignore server certificate: select the checkbox
Compute Engine Windows VMs are provisioned with a self-signedcertificate for Remote Desktop Services, so you need to instructGuacamole to ignore certificate validation issues.
- Username:
ClickSave.
Click your username, and selectHome.
Click the connection you just created to test connectivity.After a few seconds, you should see the desktop of the VM instance.
For more details on configuring Guacamole, see theApache Guacamole Manual.
Clean up
To avoid incurring charges to your Google Cloud account for the resources usedin this procedure, either delete the project that contains the resources, or keepthe project and delete the individual resources.
Delete the project
Delete the new resources
As an alternative to deleting the entire project, you can delete the individualresources created during this procedure. Note that the OAuth Consent Screenconfiguration cannot be removed from a project, only modified.
In Cloud Shell, use terraform to delete the resources:
cd~/guacamole-on-gcp/tf-k8sterraformdestroycd~/guacamole-on-gcp/tf-infraterraformdestroygcloudcomputeinstancesdelete$TEST_VM–-zone=$ZONE
What's next
- Review the GKE guidance onHardening your cluster's security.
- ReviewEncrypt secrets at the application layer to learn how to boost security for secrets, such as database credentials andOAuth credentials.
- ReviewIAM Conditions to learn how to provide more granular control over user access to Guacamole.
- Understand more about how IAP integration works byreviewing the custom authentication provider in theGitHub repository.
- For more reference architectures, diagrams, and best practices, explore theCloud Architecture Center.
Contributors
Author:Richard Grime | Principal Architect, UK Public Sector
Other contributors:
- Aaron Lind | Solution Engineer, Application Innovation
- Eyal Ben Ivri | Cloud Solutions Architect
- Ido Flatow | Cloud Solutions Architect
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-01-09 UTC.