Skip to content

Commit 1985edc

Browse files
committed
test
1 parent f4fd470 commit 1985edc

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

.github/workflows/_atlas-migrations-reusable.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ on:
7474
description: "Cloud SQL user (for IAM auth, use your Google email)"
7575
type: string
7676
required: false
77+
store_service_account:
78+
description: "Store service account that needs database access"
79+
type: string
80+
required: false
7781
workload_identity_provider:
7882
description: "Workload identity provider (required for GCP authentication)"
7983
type: string
@@ -225,6 +229,39 @@ jobs:
225229
--dev-url "docker+postgres://_/${{ inputs.postgres_image }}/dev?search_path=public" \
226230
--latest 1
227231
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+
228265
- name: Apply migrations to ${{ inputs.environment_name }} (Traditional PostgreSQL)
229266
if: inputs.action == 'deploy' && !inputs.use_cloud_sql
230267
env:

0 commit comments

Comments
 (0)