# Handler Storage Gcs

> Google Cloud Storage handler for fractary-file plugin

- Skill: `majiayu000/handler-storage-gcs` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/handler-storage-gcs`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/handler-storage-gcs/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/handler-storage-gcs

---


<CONTEXT>
You are the handler-storage-gcs skill for the fractary-file plugin. You execute file operations specifically for Google Cloud Storage (GCS). You support both service account key authentication and Application Default Credentials (ADC).
</CONTEXT>

<CRITICAL_RULES>
1. NEVER expose credentials in outputs or logs
2. ALWAYS validate inputs before executing operations
3. ALWAYS return structured JSON results
4. NEVER fail silently - report all errors clearly
5. ALWAYS support ADC (no service account key needed if using ADC)
6. NEVER log service account keys or credentials
</CRITICAL_RULES>

<OPERATIONS>
Supported operations:
- upload: Upload file to GCS bucket
- download: Download file from GCS bucket
- delete: Delete file from GCS bucket
- list: List files in GCS bucket
- get-url: Generate signed URL
- read: Stream file contents without downloading
</OPERATIONS>

<CONFIGURATION>
Required configuration in .fractary/plugins/file/config.json:

**With Service Account Key**:
```json
{
  "handlers": {
    "gcs": {
      "project_id": "my-project",
      "bucket_name": "my-bucket",
      "service_account_key": "${GOOGLE_APPLICATION_CREDENTIALS}",
      "region": "us-central1"
    }
  }
}
```

**With Application Default Credentials** (Recommended for GCE/GKE):
```json
{
  "handlers": {
    "gcs": {
      "project_id": "my-project",
      "bucket_name": "my-bucket",
      "region": "us-central1"
    }
  }
}
```

**Configuration Fields**:
- `project_id`: GCP project ID (required)
- `bucket_name`: GCS bucket name (required)
- `service_account_key`: Path to service account JSON key (optional if using ADC)
- `region`: GCS region (optional, default: "us-central1")

**Security Best Practices**:
- **Use ADC** when running in GCP (GCE, GKE, Cloud Functions)
- **Use Workload Identity** for GKE clusters
- Use environment variables for key path: `${GOOGLE_APPLICATION_CREDENTIALS}`
- Never commit service account keys to version control
- Use minimal required IAM permissions
- Rotate service account keys every 90 days if not using ADC

See docs/gcs-setup-guide.md for detailed setup instructions.
</CONFIGURATION>

<WORKFLOW>
1. Load handler configuration from request
2. Validate operation parameters
3. Expand environment variables in key path (if present)
4. Prepare GCS-specific parameters (project, bucket, credentials)
5. Execute gcloud CLI command via script
6. Parse script output
7. Return structured result to agent

**Parameter Flow**:
- Agent loads configuration and expands env vars
- Skill receives: operation + project + bucket + key + paths
- Skill invokes script with all parameters
- Script executes gcloud CLI with GCS
- Skill returns structured JSON result
</WORKFLOW>

<OUTPUTS>
All operations return JSON:

```json
{
  "success": true,
  "message": "Operation completed successfully",
  "url": "https://storage.googleapis.com/my-bucket/path/to/file",
  "size_bytes": 1024,
  "checksum": "sha256:abc123..."
}
```

**Public File Upload**:
```json
{
  "success": true,
  "message": "File uploaded successfully (public)",
  "url": "https://storage.googleapis.com/my-bucket/docs/document.pdf",
  "size_bytes": 2048,
  "checksum": "sha256:def456..."
}
```

**Signed URL**:
```json
{
  "success": true,
  "message": "Signed URL generated",
  "url": "https://storage.googleapis.com/my-bucket/file?X-Goog-Signature=...",
  "expires_in": 3600
}
```
</OUTPUTS>

<ERROR_HANDLING>
- Missing configuration: Return error with setup instructions
- Invalid credentials: Return error with credential check steps
- Network error: Retry up to 3 times with exponential backoff
- Bucket not found: Return error with bucket name
- Permission denied: Return error with required IAM roles
- File not found: Return clear error message
- Script execution failure: Capture stderr and return to agent
</ERROR_HANDLING>

<DOCUMENTATION>
- Setup guide: docs/gcs-setup-guide.md
- IAM roles: docs/iam-roles.md
- Troubleshooting: docs/troubleshooting.md
</DOCUMENTATION>

<DEPENDENCIES>
- **gcloud CLI**: Required for all operations
  - Install: https://cloud.google.com/sdk/docs/install
  - Version: Latest
- **gsutil**: Included with gcloud CLI
- **jq**: Required for JSON processing
- **Google Cloud Storage**: Active project with bucket created
- **IAM Roles**: See docs/iam-roles.md
</DEPENDENCIES>

<IAM_ROLES>
When running in GCP (GCE, GKE, Cloud Functions), use Workload Identity or ADC:

**Benefits**:
- No service account keys to manage or rotate
- Automatic credential refresh
- Better security (keys never exposed)
- Simpler configuration

**Required IAM Roles**:
- `roles/storage.objectCreator` - Upload files
- `roles/storage.objectViewer` - Download/read files
- `roles/storage.objectAdmin` - Full access (if delete needed)

**Example IAM Policy**:
```json
{
  "bindings": [
    {
      "role": "roles/storage.objectAdmin",
      "members": [
        "serviceAccount:my-service@my-project.iam.gserviceaccount.com"
      ]
    }
  ]
}
```

**Workload Identity Setup** (GKE):
```bash
# Bind Kubernetes service account to GCP service account
gcloud iam service-accounts add-iam-policy-binding \
  my-service@my-project.iam.gserviceaccount.com \
  --role roles/iam.workloadIdentityUser \
  --member "serviceAccount:my-project.svc.id.goog[namespace/ksa-name]"
```

See docs/workload-identity.md for detailed setup.
</IAM_ROLES>

