Skip to content

Commit

Permalink
Merge pull request #7 from cerberauth/create-docker-images
Browse files Browse the repository at this point in the history
build: add dockerfile and push to ghcr
  • Loading branch information
emmanuelgautier authored Oct 4, 2023
2 parents 4f5a18f + fe52325 commit f3aea1c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
list-challenges:
runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- uses: actions/checkout@v4

- id: set-matrix
run: echo "matrix=$(ls challenges/ | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT

docker-build-push:
needs: list-challenges
runs-on: ubuntu-latest

permissions:
packages: write

strategy:
matrix:
challenge: ${{ fromJson(needs.list-challenges.outputs.matrix) }}

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./challenges/${{ matrix.challenge }}
push: ${{ github.ref == 'refs/heads/main' }}
tags: ghcr.io/cerberauth/api-vulns-challenges/${{ matrix.challenge }}:latest
cache-from: type=registry,ref=ghcr.io/cerberauth/api-vulns-challenges/${{ matrix.challenge }}:latest
cache-to: type=inline
23 changes: 23 additions & 0 deletions challenges/jwt-alg-none-bypass/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.21 AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./

RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o /jwt-alg-none-bypass .

FROM gcr.io/distroless/static-debian11:nonroot AS runner

WORKDIR /

COPY --from=builder --chown=nonroot:nonroot /jwt-alg-none-bypass /usr/bin/jwt-alg-none-bypass

EXPOSE 8080

USER nonroot:nonroot

ENTRYPOINT ["jwt-alg-none-bypass", "serve"]
CMD ["jwt-alg-none-bypass"]
3 changes: 1 addition & 2 deletions challenges/jwt-alg-none-bypass/serve/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RunServer() {
}

if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}

return []byte("my_secret_key"), nil
Expand All @@ -45,6 +45,5 @@ func RunServer() {
}
})

log.Println("starting server")
log.Fatal(http.ListenAndServe(":8080", nil))
}
23 changes: 23 additions & 0 deletions challenges/jwt-weak-hmac-secret/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.21 AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . ./

RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o /jwt-weak-hmac-secret .

FROM gcr.io/distroless/static-debian11:nonroot AS runner

WORKDIR /

COPY --from=builder --chown=nonroot:nonroot /jwt-weak-hmac-secret /usr/bin/jwt-weak-hmac-secret

EXPOSE 8080

USER nonroot:nonroot

ENTRYPOINT ["jwt-weak-hmac-secret", "serve"]
CMD ["jwt-weak-hmac-secret"]
3 changes: 1 addition & 2 deletions challenges/jwt-weak-hmac-secret/serve/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func RunServer() {
tokenString := strings.TrimSpace(parts[1])
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}

return []byte("secret"), nil
Expand All @@ -40,6 +40,5 @@ func RunServer() {
}
})

log.Println("starting server")
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit f3aea1c

Please sign in to comment.