Skip to content

Commit 0ad14cd

Browse files
committed
feat: add more security
1 parent 302463b commit 0ad14cd

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ on:
1010
branches:
1111
- main
1212

13-
permissions: read-all
13+
permissions:
14+
contents: read # Set minimal permissions
1415

1516
jobs:
1617
build:
1718
runs-on: ubuntu-latest
19+
1820
steps:
19-
- uses: actions/checkout@v4
21+
# Checkout code with SHA-pinned action and avoid persisting credentials
22+
- name: Checkout code
23+
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
24+
with:
25+
persist-credentials: false # Prevents PRs from gaining access to the repository token
26+
ref: ${{ github.ref }} # Ensure the checkout uses the exact branch/commit that triggered the workflow
2027

2128
- name: Set up Go
22-
uses: actions/setup-go@v4
29+
uses: actions/setup-go@d60b41a563a30eac31c3ec623e6ff0b3f16e1a06
2330
with:
2431
go-version: 1.23.0
2532

@@ -30,7 +37,11 @@ jobs:
3037
run: go run github.com/steebchen/prisma-client-go generate
3138

3239
- name: Build
33-
run: go build -v ./...
40+
run: |
41+
echo "Building the application..."
42+
go build -v ./...
3443
3544
- name: Test
36-
run: go test -v ./...
45+
run: |
46+
echo "Running tests..."
47+
go test -v ./...

.github/workflows/migrate.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
name: Prisma Migrations
22

33
on:
4-
workflow_dispatch: # Allows manually triggering migrations from the GitHub Actions UI
4+
workflow_dispatch: # Allows manual triggering of migrations from the GitHub Actions UI
55
push:
66
branches:
77
- main
88
paths:
9-
- "prisma/**" # Only trigger on changes to Prisma files or schema
9+
- "prisma/**" # Only trigger on changes to Prisma files or schema
1010

11-
permissions: read-all
11+
permissions:
12+
contents: read # Limit permissions to read-only by default
1213

1314
jobs:
1415
migrate:
1516
runs-on: ubuntu-latest
17+
environment: production # Ensure this matches your GitHub environment setup with protection rules
18+
1619
steps:
17-
- uses: actions/checkout@v4
20+
- name: Checkout repository
21+
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # protects against any unintentional or malicious modifications
22+
with:
23+
persist-credentials: false # Prevent PRs from gaining access to the repository token
24+
ref: ${{ github.ref }} # Ensure checkout uses the exact branch or commit that triggered the workflow
1825

1926
- name: Set up Go
20-
uses: actions/setup-go@v4
27+
uses: actions/setup-go@d60b41a563a30eac31c3ec623e6ff0b3f16e1a06
2128
with:
2229
go-version: 1.23.0
2330

@@ -30,4 +37,14 @@ jobs:
3037
- name: Run Prisma Migrations
3138
env:
3239
DATABASE_URL: ${{ secrets.DATABASE_URL }}
33-
run: go run github.com/steebchen/prisma-client-go migrate deploy
40+
run: |
41+
# Store the DATABASE_URL in a local variable to avoid exposing it directly
42+
DB_URL="$DATABASE_URL"
43+
44+
# Prevent potential injections by avoiding direct use of the environment variable
45+
if [ -z "$DB_URL" ]; then
46+
echo "DATABASE_URL is not set"
47+
exit 1
48+
fi
49+
echo "Starting Prisma migrations..."
50+
go run github.com/steebchen/prisma-client-go migrate deploy

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/workflows/* @romelgomez

0 commit comments

Comments
 (0)