Skip to content

Commit 93bc6a2

Browse files
authored
Merge pull request #6 from reugn/develop
v0.5.0
2 parents f57820b + a0bc034 commit 93bc6a2

43 files changed

Lines changed: 1596 additions & 401 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ on:
88
branches:
99
- master
1010

11+
permissions:
12+
contents: read
13+
1114
jobs:
1215
test:
1316
runs-on: ubuntu-latest
1417
strategy:
1518
matrix:
16-
go-version: [1.21.x]
19+
go-version: [ 1.25.x ]
1720
steps:
18-
- name: Setup Go
19-
uses: actions/setup-go@v5
20-
with:
21-
go-version: ${{ matrix.go-version }}
21+
- name: Setup Go
22+
uses: actions/setup-go@v6
23+
with:
24+
go-version: ${{ matrix.go-version }}
2225

23-
- name: Checkout code
24-
uses: actions/checkout@v4
26+
- name: Checkout code
27+
uses: actions/checkout@v6
2528

26-
- name: Test
27-
run: go test ./...
29+
- name: Test
30+
run: go test ./...

.github/workflows/docker.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,32 @@ jobs:
1818

1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v6
22+
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
2228

2329
- name: Log in to the Container registry
24-
uses: docker/login-action@v2
30+
uses: docker/login-action@v3
2531
with:
2632
registry: ${{ env.REGISTRY }}
2733
username: ${{ github.actor }}
2834
password: ${{ secrets.GITHUB_TOKEN }}
2935

3036
- name: Extract metadata (tags, labels) for Docker
3137
id: meta
32-
uses: docker/metadata-action@v4
38+
uses: docker/metadata-action@v5
3339
with:
3440
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3541

3642
- name: Build and push Docker image
37-
uses: docker/build-push-action@v4
43+
uses: docker/build-push-action@v6
3844
with:
3945
context: .
46+
platforms: linux/amd64,linux/arm64
4047
push: true
4148
tags: ${{ steps.meta.outputs.tags }}
42-
labels: ${{ steps.meta.outputs.labels }}
49+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/golangci-lint.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: golangci-lint
33
on:
44
push:
55
branches:
6-
- master
6+
- '**'
77
pull_request:
88

99
permissions:
@@ -15,14 +15,18 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout code
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v6
1919

20-
- uses: actions/setup-go@v5
20+
- name: Get go version from go.mod
21+
run: |
22+
echo "GO_VERSION=$(grep '^go ' go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
23+
24+
- name: Setup-go
25+
uses: actions/setup-go@v6
2126
with:
22-
go-version: '1.22'
23-
cache: false
24-
25-
- name: golangci-lint
26-
uses: golangci/golangci-lint-action@v4
27+
go-version: ${{ env.GO_VERSION }}
28+
29+
- name: Run golangci-lint
30+
uses: golangci/golangci-lint-action@v9
2731
with:
28-
version: v1.56
32+
version: v2.7.2

.golangci.yml

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,62 @@
1+
version: "2"
2+
run:
3+
timeout: 2m
14
linters:
2-
disable-all: true
5+
default: none
36
enable:
47
- dupl
58
- errcheck
69
- errorlint
7-
- exportloopref
810
- funlen
9-
- gci
1011
- goconst
1112
- gocritic
1213
- gocyclo
13-
- gofmt
14-
- goimports
15-
- gosimple
14+
- gosec
1615
- govet
1716
- ineffassign
1817
- lll
1918
- misspell
19+
- nolintlint
2020
- prealloc
2121
- revive
2222
- staticcheck
23-
- stylecheck
24-
- typecheck
23+
- thelper
24+
- tparallel
2525
- unconvert
2626
- unparam
2727
- unused
28-
29-
issues:
30-
exclude-rules:
31-
- path: _test\.go
32-
linters:
33-
- unparam
34-
- funlen
28+
exclusions:
29+
generated: lax
30+
presets:
31+
- comments
32+
- common-false-positives
33+
- legacy
34+
- std-error-handling
35+
rules:
36+
- linters:
37+
- funlen
38+
- unparam
39+
path: _test\.go
40+
- linters:
41+
- revive
42+
path: internal/http/
43+
text: "var-naming.*package names"
44+
- linters:
45+
- revive
46+
path: internal/util/hash/
47+
text: "var-naming.*package names"
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$
52+
formatters:
53+
enable:
54+
- gci
55+
- gofmt
56+
- goimports
57+
exclusions:
58+
generated: lax
59+
paths:
60+
- third_party$
61+
- builtin$
62+
- examples$

Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
# syntax=docker/dockerfile:1.2
2-
FROM golang:alpine3.19 AS build
1+
# syntax=docker/dockerfile:1.4
2+
FROM golang:1.25-alpine AS build
33
RUN apk --no-cache add gcc g++ make git
44
WORKDIR /go/src/app
5+
COPY go.mod go.sum ./
6+
RUN go mod download
57
COPY . .
6-
RUN go get ./...
7-
WORKDIR /go/src/app/cmd/auth
8-
RUN GOOS=linux go build -ldflags="-s -w" -o ./bin/auth
8+
RUN GOOS=linux go build -ldflags="-s -w" -o ./bin/auth ./cmd/auth
99

10-
FROM alpine:3.19.1
10+
FROM alpine:3.23
11+
RUN addgroup -g 1000 appgroup && adduser -u 1000 -G appgroup -D appuser
1112
WORKDIR /app
12-
COPY --from=build /go/src/app/cmd/auth/bin /app
13+
COPY --from=build /go/src/app/bin/auth /app
1314
COPY --from=build /go/src/app/config /app/
1415
COPY ./secrets ./secrets
16+
RUN chown -R appuser:appgroup /app
1517
ENV AUTH_SERVER_LOCAL_CONFIG_PATH=local_repository_config.yml
18+
USER appuser
1619

1720
EXPOSE 8081
1821
ENTRYPOINT ["/app/auth", "-c", "service_config.yml"]

README.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ The `auth-server` project aims to address these concerns by serving as a transpa
3636
3737
2. The proxy server routes this request to `auth-server` to issue a token.
3838
Response body:
39-
`{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODg5MzMyNTIsImlhdCI6MTU4ODkyOTY1MiwidXNlciI6ImFkbWluIiwicm9sZSI6MX0.LUx9EYsfBZGwbEsofBTT_5Lo3Y_3lk7T8pWLv3bw-XKVOqb_GhaRkVE90QR_sI-bWTkYCFIG9cPYmMXzmPLyjbofgsqTOzH6OaXi3IqxwZRtRGFtuqMoqXkakX5n38mvI3XkIOwFkNosHrpMtIq-HdqB3tfiDJc3YMsYfPbqyRBnBYJu2K51NslGQSiqKSnS_4KeLeaqqdpC7Zdb9Fo-r7EMn3FFuyPEab1iBsrcUYG3qnsKkvDhaq_jEGHflao7dEPEWaiGvJywXWaKR6XyyGtVx0H-OPfgvh1vUCLUUci2K3xE-IxjfRrHx3dSzdqFgJq_n4bVXpO9iNVYOZLccQ","token_type":"Bearer","expires_in":3600000}`
39+
`{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...","token_type":"Bearer","expires_in":3600000}`
4040
4141
3. The user sends an authenticated request to the proxy server:
4242
```
4343
GET /foo HTTP/1.1
4444
Host: localhost:8081
45-
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODg5MzMyNTIsImlhdCI6MTU4ODkyOTY1MiwidXNlciI6ImFkbWluIiwicm9sZSI6MX0.LUx9EYsfBZGwbEsofBTT_5Lo3Y_3lk7T8pWLv3bw-XKVOqb_GhaRkVE90QR_sI-bWTkYCFIG9cPYmMXzmPLyjbofgsqTOzH6OaXi3IqxwZRtRGFtuqMoqXkakX5n38mvI3XkIOwFkNosHrpMtIq-HdqB3tfiDJc3YMsYfPbqyRBnBYJu2K51NslGQSiqKSnS_4KeLeaqqdpC7Zdb9Fo-r7EMn3FFuyPEab1iBsrcUYG3qnsKkvDhaq_jEGHflao7dEPEWaiGvJywXWaKR6XyyGtVx0H-OPfgvh1vUCLUUci2K3xE-IxjfRrHx3dSzdqFgJq_n4bVXpO9iNVYOZLccQ
45+
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
4646
```
4747
4848
4. Proxy invokes `auth-server` as an authentication/authorization middleware. In case the token was successfully authenticated/authorized, the request will be routed to the target service. Otherwise, an auth error code will be returned to the client.
4949
5050
## Installation and Prerequisites
51-
* `auth-server` is written in Golang.
51+
* `auth-server` is written in Go (1.24+).
5252
To install the latest stable version of Go, visit the [releases page](https://golang.org/dl/).
5353
5454
* Read the following [instructions](./secrets/README.md) to generate keys required to sign the token. Specify the location of the generated certificates in the service configuration file. An example of the configuration file can be found [here](config/service_config.yml).
@@ -60,15 +60,50 @@ To install the latest stable version of Go, visit the [releases page](https://go
6060
6161
* To run the project using Docker, visit their [page](https://www.docker.com/get-started) to get started. Docker images are available under the [GitHub Packages](https://github.com/reugn/auth-server/packages).
6262
63-
* Install `docker-compose` to get started with the examples.
63+
* Install Docker to get started with the examples.
64+
65+
## Configuration
66+
67+
### Proxy Providers
68+
69+
The `proxy` setting in your configuration determines how `auth-server` parses incoming requests to extract the original method and URI. This is important when running behind a reverse proxy that may modify or forward request details via headers.
70+
71+
| Provider | Description | Headers Used |
72+
|----------|-------------|--------------|
73+
| `direct` | No proxy, use actual request values | None |
74+
| `nginx` | Nginx with `auth_request` module | `X-Forwarded-Method`, `X-Forwarded-Uri` |
75+
| `traefik` | Traefik with ForwardAuth middleware | `X-Forwarded-Method`, `X-Forwarded-Uri`, `X-Forwarded-Prefix` |
76+
| `envoy` | Envoy with ext_authz filter | `X-Original-*`, `X-Envoy-Original-*`, `X-Forwarded-*` (priority order) |
77+
| `haproxy` | HAProxy with external auth | `X-Forwarded-Method`, `X-Forwarded-Uri`, `X-Original-URI` |
78+
| `kong` | Kong API Gateway | `X-Forwarded-Method`, `X-Forwarded-Path`, `X-Forwarded-Prefix` |
79+
80+
Example configuration:
81+
```yaml
82+
proxy: direct # or nginx, traefik, envoy, haproxy, kong
83+
```
6484

6585
## Examples
6686
Examples are available under the [examples](examples) folder.
6787

68-
To run `auth-server` as a [Traefik](https://docs.traefik.io/) middleware:
69-
```
88+
### Traefik
89+
Run `auth-server` as a [Traefik](https://docs.traefik.io/) ForwardAuth middleware:
90+
```sh
7091
cd examples/traefik
71-
docker-compose up -d
92+
docker compose up -d
93+
```
94+
95+
### Nginx
96+
Run `auth-server` with [Nginx](https://nginx.org/) using the `auth_request` module:
97+
```sh
98+
cd examples/nginx
99+
docker compose up -d
100+
```
101+
102+
### Envoy
103+
Run `auth-server` with [Envoy](https://www.envoyproxy.io/) using the `ext_authz` filter:
104+
```sh
105+
cd examples/envoy
106+
docker compose up -d
72107
```
73108

74109
## License

cmd/auth/main.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log/slog"
56
"os"
67

@@ -12,7 +13,7 @@ import (
1213
)
1314

1415
const (
15-
version = "0.4.0"
16+
version = "0.5.0"
1617
)
1718

1819
func run() int {
@@ -50,21 +51,32 @@ func run() int {
5051
return server.Start()
5152
}
5253

53-
err := rootCmd.Execute()
54-
if err != nil {
54+
if err := rootCmd.Execute(); err != nil {
5555
return 1
5656
}
5757
return 0
5858
}
5959

60+
// readConfiguration reads the configuration file and returns the configuration.
6061
func readConfiguration(path string) (*config.Service, error) {
62+
// read the configuration file
6163
data, err := os.ReadFile(path)
6264
if err != nil {
63-
return nil, err
65+
return nil, fmt.Errorf("failed to read configuration file %s: %w", path, err)
6466
}
67+
68+
// unmarshal the configuration data
6569
config := config.NewServiceDefault()
66-
err = yaml.Unmarshal(data, config)
67-
return config, err
70+
if err := yaml.Unmarshal(data, config); err != nil {
71+
return nil, fmt.Errorf("failed to unmarshal configuration data: %w", err)
72+
}
73+
74+
// validate the configuration
75+
if err := config.Validate(); err != nil {
76+
return nil, fmt.Errorf("invalid configuration: %w", err)
77+
}
78+
79+
return config, nil
6880
}
6981

7082
func main() {

config/service_config.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
---
2+
# Supported signing methods: RS256, RS384, RS512
23
signing-method: RS256
3-
proxy: traefik
4+
5+
# Supported proxy providers: direct, nginx, traefik, envoy, haproxy, kong
6+
# Use 'direct' when accessing auth-server without a reverse proxy.
7+
proxy: direct
8+
9+
# Supported repository providers: local, aerospike, vault
410
repository: local
11+
12+
# HTTP server configuration
513
http:
6-
host: 0.0.0.0
7-
port: 8081
8-
rate:
9-
tps: 1024
10-
size: 1024
11-
white-list: []
14+
host: 0.0.0.0
15+
port: 8081
16+
rate:
17+
tps: 1024
18+
size: 1024
19+
white-list: [ ]
20+
21+
# Secret configuration
1222
secret:
13-
private-path: secrets/privkey.pem
14-
public-path: secrets/cert.pem
23+
private-path: secrets/privkey.pem
24+
public-path: secrets/cert.pem
25+
26+
# Logger configuration
1527
logger:
16-
level: INFO
17-
format: PLAIN
28+
level: INFO
29+
format: PLAIN

0 commit comments

Comments
 (0)