To Upstart an Alloydb auth proxy service in production

I have provisioned a compute VM instance for alloydb service.

I would like to know, if is there a way to package the alloydb auth proxy as a service, so that it can automatically start up without a manual intervention to start it up, in case the VM reboots?

Currently, In my VM instance using a windows image. However, I found an automation script approach to upstart an alloydb VM instance with a Linux image, through a terraform and Powershell. But I'm not sure if it's supports a compute VM instance with a windows image in gcp, to upstart the alloydb service automatically. Is there a helpful documentation with examples to support this usecase?

1 1 220
1 REPLY 1

To set up the AlloyDB Auth Proxy as a service on a Windows VM in Google Cloud Platform (GCP), you can use a combination of PowerShell scripting and Windows Task Scheduler or Services to ensure that the proxy starts automatically upon system startup. While there might not be direct documentation from Google Cloud specific to packaging the AlloyDB Auth Proxy as a Windows service, you can follow a general approach to achieve this.

Approach 1: Using Windows Task Scheduler

  1. Create a PowerShell Script: Write a PowerShell script to start the AlloyDB Auth Proxy. Save this script on your VM. For example, save it as StartAlloyDBProxy.ps1.

     
    # StartAlloyDBProxy.ps1 
    Start-Process "path\to\alloydb-auth-proxy.exe" -ArgumentList "your_proxy_arguments" 
    

    Replace placeholders with actual values for your setup.

  2. Create a Scheduled Task: Use Task Scheduler to run the PowerShell script at system startup.

    • Open Task Scheduler and create a new task.
    • In the "General" tab, give your task a name and choose "Run whether user is logged on or not".
    • In the "Triggers" tab, add a new trigger for "At startup".
    • In the "Actions" tab, add a new action to start a program, set the program/script to powershell.exe, and add arguments -ExecutionPolicy Bypass -File "path\to\StartAlloyDBProxy.ps1".
    • Adjust other settings as needed and save the task.

Approach 2: Using NSSM 

  1. Download NSSM: Get NSSM from https://nssm.cc/ and extract it on your VM.

  2. Install Your Service: Open a command prompt as an administrator and use NSSM to install your AlloyDB Auth Proxy as a service.

     
    nssm install AlloyDBAuthProxy "path\to\alloydb-auth-proxy.exe" your_proxy_arguments 
    

    Replace placeholders with your specific details.

  3. Set the Service to Start Automatically: Configure the service to start automatically:

     
    nssm set AlloyDBAuthProxy Start SERVICE_AUTO_START 
    
  4. Start the Service: Start the service:

     
    nssm start AlloyDBAuthProxy 
    

Important Considerations

  • Service Account: Create an IAM service account with the necessary AlloyDB roles. Download its key file and place it in a secure location on your VM. Ensure the Auth Proxy uses this key for authentication.
  • Firewall: Verify that your VM's firewall allows traffic to the AlloyDB instance's port on the local IP address where the Auth Proxy will listen.

Documentation and Resources