A serverless execution framework for Google Cloud operational runbooks. Features a user-friendly Web UI ("Ops Portal") for safe, self-service remediation. Uses Bash + gcloud via Cloud Run and Cloud Tasks to separate intent from execution.
- Trigger: Cloud Tasks (asynchronous queue).
- Execution: Cloud Run (Dispatcher) running a
google/cloud-sdk:slimcontainer. - Runbook Logic: Bash scripts located in
/runbooks.
runbooks/: Contains the automation scripts (e.g.,hello_world.sh,create_test_vm.sh).src/: Contains the dispatcher logic (server.py,runner.sh) andDockerfile.deploy/: Contains infrastructure setup scripts.trigger_fix.sh: CLI helper to trigger a runbook.
-
Prerequisites:
- Google Cloud SDK (
gcloud) installed and authenticated. - Appropriate permissions to create projects, service accounts, and Cloud Run services.
- Google Cloud SDK (
-
Google Sign-In Setup: The Ops Portal uses Google Sign-In to authenticate users. You must create OAuth credentials in the Google Cloud Console:
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Application Type: Web application.
- Name:
Ops Portal. - Authorized Redirect URIs: You will need to add the Cloud Run Service URL +
/authafter deployment (e.g.,https://ops-runner-xyz.a.run.app/auth). For now, you can leave it blank or put a placeholder. - User Type: Choose Internal if you want to restrict access to users within your Google Workspace organization. Choose External (and set to 'Testing') if you need to allow specific external users (requires adding them as Test Users).
- Copy the Client ID and Client Secret.
-
Deploy Infrastructure: Export your credentials and region, then run the setup script.
export REGION=us-central1 export GOOGLE_CLIENT_ID="your-client-id" export GOOGLE_CLIENT_SECRET="your-client-secret" export DOMAIN="example.com" # Your Identity Domain for group sync ./deploy/setup_infra.sh
Note: After deployment, copy the Service URL printed at the end and add it to the "Authorized Redirect URIs" in the GCP Console (append
/authto the URL).This script will:
- Enable required APIs.
- Create a Service Account (
ops-runner-sa). - Grant Project IAM Admin, Cloud Run Invoker, and Cloud Tasks Enqueuer roles.
- Create a Cloud Tasks queue (
ops-queue). - Deploy the Cloud Run service (
ops-runner) with public access enabled (authentication is enforced by the application). - Create an EventArc Trigger to listen for Project Creation events and automatically sync groups if applicable.
⚠️ Security Warning: Thesetup_infra.shscript grantsroles/resourcemanager.projectIamAdminto the Runner Service Account. This is a high-privilege role designed to allow the runner to fix IAM permissions. For a production environment, you should restrict this Service Account's permissions to the minimum required for your specific runbooks.
Navigate to the Cloud Run Service URL.
- You will be redirected to Google Sign-In. Log in with your Google account.
- Select a runbook from the list.
- Fill in the required parameters (parsed from the runbook header).
- Click Execute Runbook to queue the task.
Use the trigger_fix.sh script to enqueue a task. This allows Ops users to trigger fixes without needing direct IAM permissions on the target project.
./trigger_fix.sh <action_name> <target_project_id>Example 1: Hello World
To test the system with a safe, read-only runbook:
./trigger_fix.sh hello_world my-target-projectExample 2: Create Test VM
To create a cheap f1-micro VM for testing (requires Compute Engine API enabled on target project):
./trigger_fix.sh create_test_vm my-target-projectSee the Runbook Development Guide for detailed instructions on creating, testing, and deploying new runbooks.
-
Create a new
.shscript in therunbooks/directory. -
Add metadata headers for the UI:
# DESC: Description of what the script does. # REQ: variable_name (Label for UI)
-
Ensure the script uses the variable names (passed as environment variables) to target the correct resources.
-
Re-deploy the Cloud Run service (or use a build pipeline) to include the new script.
gcloud run deploy ops-runner --source . --platform managed --region ${REGION:-us-central1} --quiet
The framework supports reacting to GCP events via EventArc.
The framework includes a Rules Engine (backed by Firestore) that allows you to define dynamic automation rules via the Web UI.
- Trigger:
google.cloud.resourcemanager.project.v1.create(via Cloud Audit Logs). - Evaluation: The system checks the new project's labels against the rules defined in Firestore.
- Action: If a rule matches (e.g., Label Key
type==gcp-adv), the system iterates through the configured Target Group Templates.- Example Template:
{project_id}-admins@{domain} - Available Variables:
{project_id},{domain} - The system resolves the template variables and triggers the
add_group_to_projectrunbook for each group.
- Example Template:
- Retry: If the group does not exist yet (e.g., syncing from Azure AD), the runbook exits with error, causing Cloud Tasks to retry until success.
Managing Rules: Access the "Rules Engine" from the Ops Portal navigation bar to Add/Delete rules dynamically without changing code.
Event Setup (Org/Folder Level): If you want to trigger automation for projects created anywhere in your Organization or Folder (not just the runner project), use the Setup Helper in the Ops Portal to generate the necessary Log Sink and Pub/Sub commands.
The runner is configured to stream logs to Cloud Logging.
- Standard output (stdout) from runbooks is logged at
INFOlevel. - Standard error (stderr) from runbooks is logged at
ERRORlevel.
- Isolation: Runbooks execute in a serverless container.
- Authentication:
- User Access: Protected by Google Sign-In (OAuth 2.0).
- Authorization: The application enforces authorization by checking if the signed-in user has the
roles/iap.httpsResourceAccessorrole on the project. This mimics IAP behavior at the application level. - Task Execution: Protected by OIDC Token Verification. The worker endpoint
/executevalidates that the request comes from a trusted Service Account via Cloud Tasks.
- Least Privilege: The Runner Service Account should only have the permissions necessary for the runbooks. The default setup grants
Project IAM Adminfor demonstration purposes; audit and scope this down for your needs.
If you see an error saying "Access blocked: [App Name] can only be used within its organization":
- This means your OAuth Consent Screen is set to Internal, but you are trying to sign in with an account outside the Google Workspace organization that owns the project.
- Solution: Sign in with an account from the same organization, or change the User Type to External (and add your email as a Test User) in the Google Cloud Console.
