|
74 | 74 | description: "Cloud SQL user (for IAM auth, use your Google email)" |
75 | 75 | type: string |
76 | 76 | required: false |
| 77 | + store_service_account: |
| 78 | + description: "Store service account that needs database access" |
| 79 | + type: string |
| 80 | + required: false |
77 | 81 | workload_identity_provider: |
78 | 82 | description: "Workload identity provider (required for GCP authentication)" |
79 | 83 | type: string |
@@ -225,6 +229,39 @@ jobs: |
225 | 229 | --dev-url "docker+postgres://_/${{ inputs.postgres_image }}/dev?search_path=public" \ |
226 | 230 | --latest 1 |
227 | 231 |
|
| 232 | + - name: Setup database permissions for migrations SA |
| 233 | + if: inputs.action == 'deploy' && inputs.use_cloud_sql |
| 234 | + run: | |
| 235 | + # Get access token for PostgreSQL authentication |
| 236 | + TOKEN=$(gcloud auth print-access-token) |
| 237 | + export PGUSER="${{ inputs.cloud_sql_user }}" |
| 238 | + export PGPASSWORD="$TOKEN" |
| 239 | + |
| 240 | + echo "🔐 Setting up database permissions for store service account..." |
| 241 | + |
| 242 | + # Install PostgreSQL client if not available |
| 243 | + sudo apt-get update && sudo apt-get install -y postgresql-client |
| 244 | + |
| 245 | + # Grant permissions to store service account if provided |
| 246 | + if [ -n "${{ inputs.store_service_account }}" ]; then |
| 247 | + echo "🔐 Setting up permissions for store service account: ${{ inputs.store_service_account }}" |
| 248 | + psql -h localhost -p 15432 -d ${{ inputs.cloud_sql_database }} << 'EOF' |
| 249 | + -- Grant permissions to the store service account |
| 250 | + GRANT USAGE ON SCHEMA public TO "${{ inputs.store_service_account }}"; |
| 251 | + GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO "${{ inputs.store_service_account }}"; |
| 252 | + GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO "${{ inputs.store_service_account }}"; |
| 253 | + |
| 254 | + -- Grant permissions on future tables for store SA |
| 255 | + ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "${{ inputs.store_service_account }}"; |
| 256 | + ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO "${{ inputs.store_service_account }}"; |
| 257 | + |
| 258 | + EOF |
| 259 | + else |
| 260 | + echo "ℹ️ No store service account provided, skipping additional permissions setup" |
| 261 | + fi |
| 262 | + |
| 263 | + echo "✅ Database permissions configured for store service account" |
| 264 | +
|
228 | 265 | - name: Apply migrations to ${{ inputs.environment_name }} (Traditional PostgreSQL) |
229 | 266 | if: inputs.action == 'deploy' && !inputs.use_cloud_sql |
230 | 267 | env: |
|
0 commit comments