Google Cloud Configuration Guide
Table of Contents
- Google Cloud Overview
- Project Creation and Configuration
- Google OAuth 2.0 Configuration
- Cloud Run Configuration
- Cloud Build Configuration
- Artifact Registry Configuration
- Service Account Configuration
- API Enablement
Google Cloud Overview
What is Google Cloud?
Google Cloud Platform (GCP) is a cloud computing service platform provided by Google, offering various cloud services including computing, storage, networking, big data, and machine learning. In this project, we use the following Google Cloud services:
- Cloud Run: Run containerized applications (serverless container runtime environment)
- Cloud Build: Automatically build and deploy applications (CI/CD service)
- Artifact Registry: Store Docker images (container image repository)
- IAM (Identity and Access Management): Manage permissions for users and service accounts
Why Choose Google Cloud?
- Google Ecosystem Integration: Seamless integration with Google Workspace (Sheets, Slides)
- Enterprise Intranet Support: Supports Google internal network deployment (Corp Run)
- Cost Control: Pay-as-you-go pricing, suitable for internal projects
- Unified Tech Stack: Consistent with other Google services used in the project (Gemini, OAuth)
Project Creation and Configuration
Create Google Cloud Project
-
Access Google Cloud Console
- Open Google Cloud Console
- Log in with your Google enterprise account
-
Create New Project
- Click the project selector, select "New Project"
- Enter project name (e.g.,
insighthub-production) - Select organization (if applicable)
- Click "Create"
-
Record Project ID
- After project creation, record the project ID (format:
grcn-sca-bigquery) - Project ID will be used for subsequent configuration
- After project creation, record the project ID (format:
Enable Billing
Note: Even when using enterprise intranet, some services (such as Cloud Run, Cloud Build) may still require billing to be enabled.
-
Link Billing Account
- In project settings, link the organization's billing account
- Or create a new billing account
-
Set Budget Alerts (Optional)
- In "Budgets and Alerts," set budget limits
- Configure alerts to avoid unexpected charges
Google OAuth 2.0 Configuration
What is OAuth 2.0?
OAuth 2.0 is an authorization protocol that allows users to authorize third-party applications to access their Google account information without providing passwords. In this project, OAuth 2.0 is used for:
- User Login: Verify user identity
- Access Google Sheets: Read Google Sheet data that users have permission to access
Create OAuth 2.0 Credentials
1. Enable Google+ API
- Open API Library
- In Google Cloud Console, navigate to "APIs & Services" > "Library"
- Search for "Google+ API" (or "Google Identity Services API")
- Click "Enable"
Note: Google+ API is deprecated, but some OAuth flows still require it. If you can't find it, you can skip this step.
2. Configure OAuth Consent Screen
-
Open OAuth Consent Screen
- Navigate to "APIs & Services" > "OAuth consent screen"
- Select user type (Internal or External)
- Click "Create"
-
Fill in Application Information
- Application Name:
CSA 3A (InsightHub) - User Support Email: Your email address
- Application Logo: (Optional) Upload application icon
- Application Homepage Link: Cloud Run service URL
- Application Privacy Policy Link: (Optional)
- Application Terms of Service Link: (Optional)
- Application Name:
-
Configure Scopes
- Click "Add or Remove Scopes"
- Add the following scopes:
https://www.googleapis.com/auth/userinfo.email(User email)https://www.googleapis.com/auth/userinfo.profile(User basic information)https://www.googleapis.com/auth/spreadsheets.readonly(Read-only access to Google Sheets)
-
Add Test Users (If "External" user type is selected)
- In the "Test Users" section, add email addresses of users allowed to access
- After production environment is published, all users can access
-
Save and Continue
- After completing all steps, click "Save and Continue"
- Confirm configuration information
3. Create OAuth 2.0 Client ID
-
Open Credentials Page
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
-
Select Application Type
- Select "Web application"
-
Configure Client
- Name:
InsightHub Web Client - Authorized JavaScript Origins:
- Development environment:
http://localhost:5173(Vite default port) - Production environment:
https://your-cloud-run-url.run.app
- Development environment:
- Authorized Redirect URIs:
- Development environment:
http://localhost:5173/auth/callback - Production environment:
https://your-cloud-run-url.run.app/auth/callback
- Development environment:
- Name:
-
Create and Record Credentials
- Click "Create"
- Important: Record the following information:
- Client ID: Format like
123456789-abcdefghijklmnop.apps.googleusercontent.com - Client Secret: Format like
GOCSPX-abcdefghijklmnopqrstuvwxyz
- Client ID: Format like
- Client secret is only shown once, please save it securely
Configure Environment Variables
Configure OAuth credentials to environment variables:
Development Environment (.env file):
VITE_GOOGLE_OAUTH_CLIENT_ID=123456789-abcdefghijklmnop.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-abcdefghijklmnopqrstuvwxyz
Production Environment (Cloud Build trigger):
- Add substitution variable
_VITE_GOOGLE_OAUTH_CLIENT_ID - Add substitution variable
_GOOGLE_CLIENT_SECRET
Cloud Run Configuration
Create Cloud Run Service
1. First Deployment
Cloud Run service will be automatically created during the first deployment; no manual creation is needed.
2. Service Configuration
Configure service parameters in cloudbuild.yaml:
- '--region'
- '${_DEPLOY_REGION}' # e.g., asia-northeast1
- '--platform'
- 'managed'
- '--allow-unauthenticated' # Allow unauthenticated access
Configuration Notes:
- region: Select the region closest to users (e.g.,
asia-northeast1for Asia-Pacific) - platform:
managedmeans fully managed, no need to manage infrastructure - allow-unauthenticated: Allow public access (if internal access is needed, this option can be removed)
3. Resource Configuration (Optional)
Resource configuration can be added in Cloud Build:
- '--memory'
- '512Mi'
- '--cpu'
- '1'
- '--timeout'
- '300'
- '--max-instances'
- '10'
- '--min-instances'
- '0'
Configuration Notes:
- memory: Memory per container instance (default 512 MiB)
- cpu: Number of CPUs per container instance (default 1)
- timeout: Request timeout (seconds, default 300)
- max-instances: Maximum number of instances (default 100)
- min-instances: Minimum number of instances (default 0, no instances running when idle)
Cloud Build Configuration
Create Cloud Build Trigger
1. Connect to Source Code Repository
-
Open Cloud Build Triggers
- In Google Cloud Console, navigate to "Cloud Build" > "Triggers"
- Click "Create Trigger"
-
Select Source Code
- Select source code repository (GitHub, GitLab, or Cloud Source Repositories)
- Authorize Cloud Build to access the repository
- Select repository and branch
2. Configure Trigger
-
Trigger Settings
- Name:
insighthub-deploy - Event: Push to a branch
- Branch:
^main$(or your main branch name) - Configuration Type: Cloud Build configuration file (yaml or json)
- Location:
cloudbuild.yaml
- Name:
-
Substitution Variables
- Add the following substitution variables:
| Variable Name | Description | Example Value |
|---|---|---|
_AR_HOSTNAME | Artifact Registry hostname | asia-northeast1-docker.pkg.dev |
_AR_PROJECT_ID | Google Cloud project ID | grcn-sca-bigquery |
_AR_REPOSITORY | Artifact Registry repository name | cloudrun-source-deploy |
_SERVICE_NAME | Cloud Run service name | helen-new-insighthub |
_DEPLOY_REGION | Deployment region | asia-northeast1 |
_VITE_GEMINI_API_KEY | Gemini API Key | AIzaSy... |
_VITE_GOOGLE_OAUTH_CLIENT_ID | OAuth Client ID | 123456789-... |
_VITE_GOOGLE_SLIDES_TEMPLATE_ID | Google Slides template ID | 1a2b3c4d... |
_VITE_HELP_DOCUMENT_URL | Help document URL | https://... |
_AUDIT_LOG_SPREADSHEET_ID | Audit log Google Sheet ID | 1a2b3c4d... |
_APPS_SCRIPT_SLIDES_ID | Image insertion Apps Script ID | 5e6f7g8h... |
_GOOGLE_CLIENT_SECRET | OAuth Client Secret | GOCSPX-... |
Security Recommendations:
- Sensitive information (such as API Key, Client Secret) should be stored using Google Secret Manager
- Read from Secret Manager in triggers instead of direct configuration
- Service Account
- Select the service account used by Cloud Build
- Ensure the service account has the following permissions:
- Cloud Build Service Account
- Artifact Registry Writer
- Cloud Run Admin
3. Save Trigger
- Click "Create" to save the trigger
- Trigger will automatically execute when code is pushed to the specified branch
Artifact Registry Configuration
What is Artifact Registry?
Artifact Registry is Google Cloud's container image repository service, used to store and manage Docker images. Images built by Cloud Build are pushed to Artifact Registry, and then Cloud Run pulls images from Artifact Registry to run.
Create Artifact Registry Repository
1. Open Artifact Registry
- In Google Cloud Console, navigate to "Artifact Registry"
- Click "Create Repository"
2. Configure Repository
- Name:
cloudrun-source-deploy(or your chosen name) - Format: Docker
- Mode: Standard
- Location: Select the same region as Cloud Run (e.g.,
asia-northeast1)
3. Permission Configuration
- Access Control: Use IAM permissions to control access
- Ensure Cloud Build service account has "Artifact Registry Writer" role
- Ensure Cloud Run service account has "Artifact Registry Reader" role
Service Account Configuration
What is a Service Account?
A service account is a special type of account in Google Cloud used to represent applications accessing Google Cloud services, rather than representing users. In this project, service accounts are used for:
- Cloud Build: Execute build and deployment operations
- Apps Script Calls: Call Apps Script through Execution API
- Google Workspace Access: Access Google Sheets and Google Slides
Create Service Account
1. Open IAM & Admin
- In Google Cloud Console, navigate to "IAM & Admin" > "Service Accounts"
- Click "Create Service Account"
2. Configure Service Account
- Service Account Name:
insighthub-service-account - Service Account ID: Auto-generated (can be modified)
- Description:
InsightHub application service account
3. Grant Roles
Add the following roles:
| Role | Description |
|---|---|
| Cloud Run Invoker | Allow invoking Cloud Run services |
| Artifact Registry Reader | Allow reading images from Artifact Registry |
| Service Account User | Allow using service account |
4. Create Key
-
Open Service Account Details
- Click the created service account
- Switch to "Keys" tab
-
Add Key
- Click "Add Key" > "Create New Key"
- Select "JSON" format
- Click "Create"
- Important: JSON key file will be downloaded to local, please save it securely
-
Configure Environment Variables
- Development Environment: Save JSON file to project directory, configure
GOOGLE_SERVICE_ACCOUNT_KEY_PATH - Production Environment: Configure JSON content to
GOOGLE_SERVICE_ACCOUNT_JSONenvironment variable
- Development Environment: Save JSON file to project directory, configure
Service Account Permission Configuration
Apps Script Call Permissions
Service account needs to be able to call Apps Script Execution API:
-
Enable Apps Script API
- In Google Cloud Console, navigate to "APIs & Services" > "Library"
- Search for "Apps Script API"
- Click "Enable"
-
Grant Execution Permission
- In Apps Script project, add service account email as "Viewer" or "Editor"
- Service account email format:
service-account-name@project-id.iam.gserviceaccount.com
Google Workspace Access Permissions
If service account needs to access Google Sheets or Google Slides:
-
Share Resources
- In Google Sheets/Slides, add service account email as "Editor"
- Service account email format:
service-account-name@project-id.iam.gserviceaccount.com
-
Domain-Wide Delegation (Optional)
- If access to all resources within the organization is needed, domain-wide delegation can be configured
- This requires Google Workspace administrator permissions
API Enablement
Required APIs
The following APIs need to be enabled in the Google Cloud project:
| API Name | Purpose | Required |
|---|---|---|
| Cloud Run API | Run containerized applications | ✅ Required |
| Cloud Build API | Build and deploy applications | ✅ Required |
| Artifact Registry API | Store Docker images | ✅ Required |
| Apps Script API | Call Apps Script | ⚠️ Optional |
| Google Sheets API | Access Google Sheets | ⚠️ Optional (if using Google Sheet features) |
| Google Slides API | Access Google Slides | ⚠️ Optional (if using Google Slides features) |
| Google Identity Services API | OAuth 2.0 authentication | ✅ Required |
Enable APIs
-
Open API Library
- In Google Cloud Console, navigate to "APIs & Services" > "Library"
-
Search and Enable
- Search for API name
- Click API card
- Click "Enable" button
-
Verify Enablement Status
- View in "APIs & Services" > "Enabled APIs"
- Ensure all required APIs are enabled
Configuration Checklist
Project Configuration
- Google Cloud project created
- Project ID recorded
- Billing enabled (if needed)
OAuth 2.0 Configuration
- OAuth consent screen configured
- OAuth client ID created
- Client ID and secret recorded
- Redirect URIs configured (development and production environments)
- Environment variables configured
Cloud Run Configuration
- Service region selected
- Resource configuration set (if needed)
- Environment variables configured
Cloud Build Configuration
- Trigger created
- Source code repository connected
- Substitution variables configured
- Service account permissions granted
Artifact Registry Configuration
- Repository created
- Repository region selected
- Permissions configured
Service Account Configuration
- Service account created
- Key downloaded
- Roles granted
- Apps Script permissions configured
- Google Workspace resources shared
API Enablement
- Cloud Run API enabled
- Cloud Build API enabled
- Artifact Registry API enabled
- Apps Script API enabled (if needed)
- Google Identity Services API enabled
Frequently Asked Questions
Q1: OAuth redirect URI mismatch error?
Error Message: redirect_uri_mismatch
Cause: Redirect URI doesn't match OAuth client configuration
Solution:
- Check "Authorized Redirect URIs" in OAuth client configuration
- Ensure it includes the actual redirect URI used (including protocol, domain, path)
- Development and production environments need to be configured separately
Q2: Service account cannot call Apps Script?
Error Message: PERMISSION_DENIED or Script function not found
Cause:
- Apps Script API not enabled
- Service account doesn't have access permission to Apps Script project
- Script ID configuration error
Solution:
- Enable Apps Script API
- In Apps Script project, add service account email as "Viewer"
- Verify Script ID is correct (obtain from Apps Script editor URL)
Q3: Cloud Build build fails with insufficient permissions?
Error Message: PERMISSION_DENIED
Cause: Cloud Build service account lacks necessary permissions
Solution:
- Check the service account used by Cloud Build
- Ensure service account has the following roles:
- Cloud Build Service Account
- Artifact Registry Writer
- Cloud Run Admin
- Service Account User
Q4: How to view service account email address?
Method 1: Through Cloud Console
- Open "IAM & Admin" > "Service Accounts"
- Click service account name
- View "Email" field in details page
Method 2: Through Format Inference
Service account email format: service-account-name@project-id.iam.gserviceaccount.com
Summary
This section detailed Google Cloud configuration steps, including:
- Project Creation: How to create and configure Google Cloud project
- OAuth 2.0 Configuration: How to configure user login and Google Workspace access
- Cloud Run Configuration: How to configure serverless container runtime environment
- Cloud Build Configuration: How to configure automated build and deployment
- Artifact Registry Configuration: How to configure container image repository
- Service Account Configuration: How to create and configure service accounts
- API Enablement: Google Cloud APIs that need to be enabled
Correctly configuring Google Cloud is the foundation for system deployment and operation. Please complete the configuration step by step according to the checklist.
Related Documentation: