Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release image

on:
release:
types: [published]

permissions:
contents: read
packages: write

env:
IMAGE: ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Verify release tag is on main
run: |
git merge-base --is-ancestor "$GITHUB_SHA" origin/main || {
echo "::error::Release ${GITHUB_REF_NAME} does not point to a commit on main"
exit 1
}

- uses: docker/setup-buildx-action@v3

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest

- id: ts
run: echo "value=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"

- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
BUILD_TIMESTAMP=${{ steps.ts.outputs.value }}
GROUP_ID=${{ vars.GROUP_ID }}
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ These require Go 1.26.3+ locally or can be run inside the builder container:
```bash
make build # produce oauth2-auth-code-proxy binary (requires Go 1.26.3+ locally)
make docker # build Docker image locally (recommended — bundles correct toolchain)
make docker-local # Dockerfile.local: creds.yaml + certs/ baked in, local use only (never push)
make test # go test -race with coverage
make lint # golangci-lint v2
make mocks # regenerate mockery mocks
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /oauth2-auth-code-proxy /oauth2-auth-code-proxy
COPY certs/tls.crt /etc/oauth2-auth-code-proxy/tls.crt
COPY certs/tls.key /etc/oauth2-auth-code-proxy/tls.key

EXPOSE 80 30045

Expand Down
13 changes: 13 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024-2026 The MathWorks, Inc.
# Local-only image: bakes creds.yaml and certs/ into the public image.
# Contains secrets — never push this image. Build with `make docker-local`.
ARG BASE_IMAGE=ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy:latest
FROM ${BASE_IMAGE}

COPY creds.yaml /etc/oauth2-auth-code-proxy/creds.yaml
COPY certs/tls.crt /etc/oauth2-auth-code-proxy/certs/tls.crt
COPY certs/tls.key /etc/oauth2-auth-code-proxy/certs/tls.key

ENV OAUTH_CREDS_FILE=/etc/oauth2-auth-code-proxy/creds.yaml \
OAUTH_TLS_CERT_FILE=/etc/oauth2-auth-code-proxy/certs/tls.crt \
OAUTH_TLS_KEY_FILE=/etc/oauth2-auth-code-proxy/certs/tls.key
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GROUP_ID ?=
PKG := $(MODULE)/internal/app
LDFLAGS := -X '$(PKG).Version=$(VERSION)' -X '$(PKG).BuildTime=$(BUILD_TS)' -X '$(PKG).ModuleName=$(MODULE)'

.PHONY: all build test lint cyclo fmt mocks swagger licenses coverage coverage-html coverage-report clean docker i18n certs
.PHONY: all build test lint cyclo fmt mocks swagger licenses coverage coverage-html coverage-report clean docker docker-local i18n certs

all: fmt build test lint cyclo

Expand Down Expand Up @@ -47,14 +47,21 @@ coverage-report: test
@echo "Summary:"
@go tool cover -func=coverage.out | grep total:

docker: certs
docker:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIMESTAMP=$(BUILD_TS) \
--build-arg GROUP_ID=$(GROUP_ID) \
-t ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy:$(VERSION) \
-t ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy:latest .

# Local-only image with creds.yaml and certs/ baked in. Never push it.
docker-local: docker certs
@test -f creds.yaml || { echo "creds.yaml not found at repo root (see README \"Credentials File\")"; exit 1; }
docker build -f Dockerfile.local \
--build-arg BASE_IMAGE=ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy:$(VERSION) \
-t oauth2-auth-code-proxy-local:latest .

licenses:
@go-licenses report . --include_tests 2>/dev/null | grep -v "$(shell go list -m)" | sort > /tmp/licenses.csv
@echo "# Third-Party Software Notices" > THIRD_PARTY_NOTICES.md
Expand Down
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,57 @@ The container listens on port 30045 by default (matching existing OAuth redirect
docker build -t oauth2-auth-code-proxy .
```

The Dockerfile is a self-contained multi-stage build: it compiles the Go binary from source and produces a minimal `scratch`-based image (~10 MB) containing only the static binary and CA certificates.
The Dockerfile is a self-contained multi-stage build: it compiles the Go binary from source and produces a minimal `scratch`-based image (~10 MB) containing only the static binary and CA certificates. It contains no credentials or TLS certificates — provide those at runtime via mounts and environment variables.

### Local Image with Your Own Credentials and Certs

For local testing, `Dockerfile.local` builds on top of the public image and bakes in your `creds.yaml` and TLS certificate, so the container runs without mounts or environment variables.

> **Warning:** this image contains your OAuth client secret and TLS private key. Never push or share it.

Place the files at the repo root (both paths are gitignored):

```
oauth2-auth-code-proxy/
├── creds.yaml # OAuth app config (see Credentials File below)
└── certs/
├── tls.crt # certificate (PEM)
└── tls.key # private key (PEM)
```

To use your own certificate, copy it in under exactly these names; its SANs must match the hostname clients connect to. If `certs/` is absent, `make docker-local` generates a self-signed certificate for `localhost` and `127.0.0.1`.

Build and run:

```bash
make docker-local

docker run -d --name oauth2-proxy -p 80:80 oauth2-auth-code-proxy-local:latest
```

Without `make`, build the public image first, then the local image on top of it:

```bash
docker build -t oauth2-auth-code-proxy:base .

docker build -f Dockerfile.local \
--build-arg BASE_IMAGE=oauth2-auth-code-proxy:base \
-t oauth2-auth-code-proxy-local:latest .
```

To skip compiling, set `BASE_IMAGE` to a published release instead, e.g. `ghcr.io/mathworks-ref-arch/container-images/oauth2-auth-code-proxy:<version>`.

To generate a self-signed certificate without `make` (in Git Bash, prefix the command with `MSYS_NO_PATHCONV=1`):

```bash
mkdir -p certs
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
-keyout certs/tls.key -out certs/tls.crt -days 3650 -nodes \
-subj "/CN=oauth2-auth-code-proxy" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
```

Rebuild the image whenever `creds.yaml` or the certificate changes.

### Standalone Binary

Expand Down Expand Up @@ -351,6 +401,7 @@ make swagger # regenerate OpenAPI 3.1 spec
make mocks # regenerate mockery mocks
make coverage-html # generate coverage.html
make docker # build container image locally
make docker-local # local-only image with creds.yaml + certs/ baked in (never push)
make fmt # format code
make clean # remove build artifacts
```
Expand Down
17 changes: 13 additions & 4 deletions doc/MATLAB.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@ Generate a local TLS certificate (one-time, idempotent):
make certs
```

This creates `certs/tls.crt` and `certs/tls.key` with SANs for `localhost` and `127.0.0.1`. The cert is gitignored but persists across rebuilds.
This creates `certs/tls.crt` and `certs/tls.key` with SANs for `localhost` and `127.0.0.1`. The cert is gitignored and is not baked into the Docker image — mount it at runtime.

Build and run the Docker image (the `docker` target depends on `certs`):
Build and run the Docker image, mounting the cert directory:

```bash
make docker

docker run -d --name oauth2-proxy-test \
-p 30045:30045 -p 80:80 \
-v "$(pwd)/creds.yaml:/etc/oauth2-auth-code-proxy/creds.yaml:ro" \
-v "$(pwd)/certs:/etc/oauth2-auth-code-proxy/certs:ro" \
-e OAUTH_CREDS_FILE=/etc/oauth2-auth-code-proxy/creds.yaml \
-e OAUTH_TLS_CERT_FILE=/etc/oauth2-auth-code-proxy/tls.crt \
-e OAUTH_TLS_KEY_FILE=/etc/oauth2-auth-code-proxy/tls.key \
-e OAUTH_TLS_CERT_FILE=/etc/oauth2-auth-code-proxy/certs/tls.crt \
-e OAUTH_TLS_KEY_FILE=/etc/oauth2-auth-code-proxy/certs/tls.key \
oauth2-auth-code-proxy:latest
```

Alternatively, `make docker-local` builds a local-only image (`Dockerfile.local`) with `creds.yaml` and `certs/` baked in, so no mounts or env vars are needed. It runs `make certs` automatically. That image contains your secrets, so never push it:

```bash
make docker-local

docker run -d --name oauth2-proxy-test -p 30045:30045 -p 80:80 oauth2-auth-code-proxy-local:latest
```

Connect from MATLAB using the local cert file:

```matlab
Expand Down
Loading