Skip to content

Commit 0e1e0cf

Browse files
committed
[Feature] add Access Token Authorization for gRPC Proxy Handler
Signed-off-by: kpango <kpango@vdaas.org>
1 parent 62c60a7 commit 0e1e0cf

File tree

18 files changed

+572
-226
lines changed

18 files changed

+572
-226
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-alpine AS base
1+
FROM golang:1.25-alpine AS base
22

33
RUN set -eux \
44
&& apk --no-cache add ca-certificates \
@@ -13,7 +13,7 @@ RUN GO111MODULE=on go mod download
1313

1414
FROM base AS builder
1515

16-
ENV APP_NAME authorization-proxy
16+
ENV APP_NAME=authorization-proxy
1717
ARG APP_VERSION='development version'
1818

1919
COPY . .
@@ -39,9 +39,9 @@ RUN ldd "/usr/bin/${APP_NAME}"\
3939
# Start From Scratch For Running Environment
4040
FROM scratch
4141
# FROM alpine:latest
42-
LABEL maintainer "cncf-athenz-maintainers@lists.cncf.io"
42+
LABEL maintainer="cncf-athenz-maintainers@lists.cncf.io"
4343

44-
ENV APP_NAME authorization-proxy
44+
ENV APP_NAME=authorization-proxy
4545

4646
# Copy certificates for SSL/TLS
4747
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

Makefile

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
# .PHONY: all clean bench bench-all profile lint test contributors update install
44
.PHONY: deps test coverage
55

6+
7+
ROOTDIR = $(eval ROOTDIR := $(shell git rev-parse --show-toplevel))$(ROOTDIR)
8+
GITHUB_ACCESS_TOKEN = $(eval GITHUB_ACCESS_TOKEN := $(shell pass github.api.ro.token))$(GITHUB_ACCESS_TOKEN)
9+
GITHUB_SHA = $(eval GITHUB_SHA := $(shell git rev-parse HEAD))$(GITHUB_SHA)
10+
GITHUB_URL = https://github.com/AthenZ/authorization-proxy
11+
EMAIL = cncf-athenz-maintainers@lists.cncf.io
12+
13+
DOCKERFILE = $(ROOTDIR)/Dockerfile
14+
DOCKER_EXTRA_OPTS = ""
15+
DOCKER_BUILDER_NAME = "athenz-builder"
16+
DOCKER_BUILDER_DRIVER = "docker-container"
17+
DOCKER_BUILDER_PLATFORM = "linux/amd64"
18+
DOCKER_IMAGE_REPO = AthenZ
19+
DOCKER_IMAGE_NAME = authorization-proxy
20+
21+
VERSION = latest
22+
23+
GOPATH := $(eval GOPATH := $(shell go env GOPATH))$(GOPATH)
24+
GOLINES_MAX_WIDTH ?= 200
25+
626
# all: clean install lint test bench
727

828
# clean:
@@ -51,3 +71,74 @@ check-license-header:
5171
# go install github.com/apache/skywalking-eyes/cmd/license-eye@latest
5272
license-eye -c .licenserc.yaml header check
5373
# license-eye -c .licenserc.yaml header fix
74+
75+
docker_build:
76+
@make DOCKER_BUILDER_NAME=$(DOCKER_BUILDER_NAME) create_buildx
77+
$(eval TMP_DIR := $(shell mktemp -d))
78+
@echo $(GITHUB_ACCESS_TOKEN) > $(TMP_DIR)/gat
79+
@chmod 600 $(TMP_DIR)/gat
80+
DOCKER_BUILDKIT=1 docker buildx build \
81+
--allow "network.host" \
82+
--build-arg BUILDKIT_MULTI_PLATFORM=1 \
83+
--build-arg EMAIL="$(EMAIL)" \
84+
--builder "$(DOCKER_BUILDER_NAME)" \
85+
--label org.opencontainers.image.revision="$(GITHUB_SHA)" \
86+
--label org.opencontainers.image.source="$(GITHUB_URL)" \
87+
--label org.opencontainers.image.title="$(DOCKER_IMAGE_REPO)/$(DOCKER_IMAGE_NAME)" \
88+
--label org.opencontainers.image.url="$(GITHUB_URL)" \
89+
--label org.opencontainers.image.version="$(VERSION)" \
90+
--memory 32G \
91+
--memory-swap 32G \
92+
--network=host \
93+
--output type=registry,oci-mediatypes=true,compression=zstd,compression-level=5,force-compression=true,push=true \
94+
--platform $(DOCKER_BUILDER_PLATFORM) \
95+
--attest type=sbom,generator=docker/buildkit-syft-scanner:edge \
96+
--provenance=mode=max \
97+
-t "$(DOCKER_IMAGE_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)" \
98+
-f $(DOCKERFILE) .
99+
docker buildx rm --force "$(DOCKER_BUILDER_NAME)"
100+
@rm -rf $(TMP_DIR)
101+
102+
103+
init_buildx:
104+
docker run \
105+
--network=host \
106+
--privileged \
107+
--rm tonistiigi/binfmt:master \
108+
--install $(DOCKER_BUILDER_PLATFORM)
109+
110+
create_buildx:
111+
-docker buildx rm --force $(DOCKER_BUILDER_NAME)
112+
docker buildx create --use \
113+
--name $(DOCKER_BUILDER_NAME) \
114+
--driver $(DOCKER_BUILDER_DRIVER) \
115+
--driver-opt=image=moby/buildkit:master \
116+
--driver-opt=network=host \
117+
--buildkitd-flags="--oci-worker-gc=false --oci-worker-snapshotter=stargz" \
118+
--platform $(DOCKER_BUILDER_PLATFORM) \
119+
--bootstrap
120+
# make add_nodes
121+
docker buildx ls
122+
docker buildx inspect --bootstrap $(DOCKER_BUILDER_NAME)
123+
sudo chown -R $(USER):$(GROUP_ID) "$(HOME)/.docker"
124+
125+
remove_buildx:
126+
-docker buildx rm --force --all-inactive
127+
sudo rm -rf $(HOME)/.docker/buildx
128+
docker buildx ls
129+
130+
do_build:
131+
@make DOCKERFILE="$(ROOTDIR)/Dockerfile" NAME="$(NAME)" DOCKER_BUILDER_NAME="$(DOCKER_BUILDER_NAME)-$(NAME)" docker_build
132+
133+
build: \
134+
remove_buildx \
135+
init_buildx \
136+
create_buildx
137+
@make NAME="authorization-proxy" do_build
138+
@make remove_buildx
139+
140+
format:
141+
find ./ -type d -name .git -prune -o -type f -regex '.*[^\.pb]\.go' -print | xargs $(GOPATH)/bin/golines -w -m $(GOLINES_MAX_WIDTH)
142+
find ./ -type d -name .git -prune -o -type f -regex '.*[^\.pb]\.go' -print | xargs $(GOPATH)/bin/gofumpt -w
143+
find ./ -type d -name .git -prune -o -type f -regex '.*[^\.pb]\.go' -print | xargs $(GOPATH)/bin/strictgoimports -w
144+
find ./ -type d -name .git -prune -o -type f -regex '.*\.go' -print | xargs $(GOPATH)/bin/goimports -w

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Client request can be authenticated and authorized by:
3434
1. Role token in the HTTP/HTTPS request header
3535
1. Role certificate on mTLS
3636

37-
Requires go 1.23 or later.
37+
Requires go 1.25 or later.
3838

3939
## Use case
4040

config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,17 @@ type AccessToken struct {
278278

279279
// CertOffsetDuration represents the certificate issue time offset when comparing with the issue time of the access token. (for usecase: new cert + old token)
280280
CertOffsetDuration string `yaml:"certOffsetDuration"`
281+
282+
// AccessTokenAuthHeader represents the request header key for extracting the access token.
283+
AccessTokenAuthHeader string `yaml:"accessTokenAuthHeader"`
281284
}
282285

283286
// RoleToken represents the configuration to control role token verification.
284287
type RoleToken struct {
285288
// Enable decides whether to verify role token.
286289
Enable bool `yaml:"enable"`
287290

288-
// RoleAuthHeader represents the HTTP header for extracting the role token.
291+
// RoleAuthHeader represents the request header key for extracting the role token.
289292
RoleAuthHeader string `yaml:"roleAuthHeader"`
290293
}
291294

go.mod

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,99 @@
11
module github.com/AthenZ/authorization-proxy/v4
22

3-
go 1.23.4
3+
go 1.25.1
44

55
replace (
6-
cloud.google.com/go => cloud.google.com/go v0.112.2
7-
github.com/golang/mock => github.com/golang/mock v1.6.0
8-
github.com/golang/protobuf => github.com/golang/protobuf v1.5.4
9-
github.com/google/go-cmp => github.com/google/go-cmp v0.6.0
10-
github.com/google/pprof => github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd
11-
github.com/prometheus/common => github.com/prometheus/common v0.48.0
12-
golang.org/x/exp => golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8
13-
golang.org/x/image => golang.org/x/image v0.15.0
14-
golang.org/x/lint => golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
15-
golang.org/x/mobile => golang.org/x/mobile v0.0.0-20240404231514-09dbf07665ed
16-
golang.org/x/mod => golang.org/x/mod v0.17.0
17-
golang.org/x/oauth2 => golang.org/x/oauth2 v0.19.0
18-
golang.org/x/term => golang.org/x/term v0.19.0
19-
golang.org/x/text => golang.org/x/text v0.14.0
20-
golang.org/x/time => golang.org/x/time v0.5.0
21-
golang.org/x/tools => golang.org/x/tools v0.20.0
22-
golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
23-
google.golang.org/api => google.golang.org/api v0.172.0
24-
google.golang.org/appengine => google.golang.org/appengine v1.6.8
25-
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20240412170617-26222e5d3d56
26-
google.golang.org/grpc => google.golang.org/grpc v1.63.2
27-
google.golang.org/protobuf => google.golang.org/protobuf v1.33.0
6+
cloud.google.com/go => cloud.google.com/go v0.123.0
7+
github.com/AthenZ/athenz-authorizer/v5 => github.com/AthenZ/athenz-authorizer/v5 v5.7.0
8+
github.com/kpango/gache/v2 => github.com/kpango/gache/v2 v2.1.1
9+
github.com/kpango/glg => github.com/kpango/glg v1.6.15
10+
github.com/mwitkow/grpc-proxy => github.com/mwitkow/grpc-proxy v0.0.0-20250813121105-2866842de9a5
11+
github.com/pkg/errors => github.com/pkg/errors v0.9.1
12+
github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.23.2
13+
github.com/prometheus/client_model => github.com/prometheus/client_model v0.6.2
14+
golang.org/x/sync => golang.org/x/sync v0.17.0
15+
google.golang.org/grpc => google.golang.org/grpc v1.75.1
16+
google.golang.org/protobuf => google.golang.org/protobuf v1.36.9
17+
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.4.0
2818
)
2919

3020
require (
31-
github.com/AthenZ/athenz-authorizer/v5 v5.7.0
21+
github.com/AthenZ/athenz-authorizer/v5 v5.0.0-00010101000000-000000000000
22+
github.com/kpango/gache/v2 v2.1.0
3223
github.com/kpango/glg v1.6.15
33-
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76
24+
github.com/mwitkow/grpc-proxy v0.0.0-00010101000000-000000000000
3425
github.com/pkg/errors v0.9.1
35-
github.com/prometheus/client_golang v1.19.1
36-
github.com/prometheus/client_model v0.5.0
37-
golang.org/x/sync v0.12.0
38-
google.golang.org/grpc v1.71.0
39-
google.golang.org/protobuf v1.36.5
26+
github.com/prometheus/client_golang v1.20.4
27+
github.com/prometheus/client_model v0.6.2
28+
golang.org/x/sync v0.17.0
29+
google.golang.org/grpc v1.75.1
30+
google.golang.org/protobuf v1.36.9
4031
gopkg.in/yaml.v2 v2.4.0
4132
)
4233

4334
require (
44-
github.com/AthenZ/athenz v1.12.13 // indirect
35+
github.com/AthenZ/athenz v1.12.26 // indirect
4536
github.com/ardielle/ardielle-go v1.5.2 // indirect
4637
github.com/beorn7/perks v1.0.1 // indirect
47-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
38+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
39+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4840
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
49-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
50-
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
51-
github.com/go-logr/logr v1.4.2 // indirect
41+
github.com/felixge/httpsnoop v1.0.4 // indirect
42+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
43+
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
44+
github.com/go-logr/logr v1.4.3 // indirect
45+
github.com/go-logr/stdr v1.2.2 // indirect
5246
github.com/goccy/go-json v0.10.5 // indirect
5347
github.com/gogo/protobuf v1.3.2 // indirect
5448
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
55-
github.com/golang/protobuf v1.5.4 // indirect
56-
github.com/google/gofuzz v1.2.0 // indirect
5749
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
50+
github.com/google/uuid v1.6.0 // indirect
51+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
5852
github.com/json-iterator/go v1.1.12 // indirect
59-
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
60-
github.com/kpango/fastime v1.1.9 // indirect
61-
github.com/kpango/gache/v2 v2.1.1 // indirect
53+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
54+
github.com/kpango/fastime v1.1.10 // indirect
6255
github.com/kr/text v0.2.0 // indirect
63-
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
56+
github.com/lestrrat-go/blackmagic v1.0.4 // indirect
57+
github.com/lestrrat-go/dsig v1.0.0 // indirect
58+
github.com/lestrrat-go/dsig-secp256k1 v1.0.0 // indirect
6459
github.com/lestrrat-go/httpcc v1.0.1 // indirect
65-
github.com/lestrrat-go/httprc/v3 v3.0.0-beta1 // indirect
66-
github.com/lestrrat-go/jwx/v3 v3.0.0 // indirect
60+
github.com/lestrrat-go/httprc/v3 v3.0.1 // indirect
61+
github.com/lestrrat-go/jwx/v3 v3.0.11 // indirect
6762
github.com/lestrrat-go/option v1.0.1 // indirect
63+
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
6864
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
69-
github.com/modern-go/reflect2 v1.0.2 // indirect
70-
github.com/prometheus/common v0.48.0 // indirect
71-
github.com/prometheus/procfs v0.12.0 // indirect
72-
github.com/segmentio/asm v1.2.0 // indirect
65+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
66+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
67+
github.com/prometheus/common v0.66.1 // indirect
68+
github.com/prometheus/procfs v0.17.0 // indirect
69+
github.com/segmentio/asm v1.2.1 // indirect
70+
github.com/theparanoids/crypki v1.20.9 // indirect
71+
github.com/valyala/fastjson v1.6.4 // indirect
7372
github.com/x448/float16 v0.8.4 // indirect
7473
github.com/zeebo/xxh3 v1.0.2 // indirect
75-
golang.org/x/crypto v0.36.0 // indirect
76-
golang.org/x/net v0.38.0 // indirect
77-
golang.org/x/sys v0.31.0 // indirect
78-
golang.org/x/text v0.23.0 // indirect
79-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e // indirect
74+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
75+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
76+
go.opentelemetry.io/otel v1.38.0 // indirect
77+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0 // indirect
78+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
79+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
80+
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
81+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
82+
go.opentelemetry.io/proto/otlp v1.8.0 // indirect
83+
go.yaml.in/yaml/v2 v2.4.3 // indirect
84+
golang.org/x/crypto v0.42.0 // indirect
85+
golang.org/x/net v0.44.0 // indirect
86+
golang.org/x/sys v0.36.0 // indirect
87+
golang.org/x/text v0.29.0 // indirect
88+
google.golang.org/genproto/googleapis/api v0.0.0-20250929231259-57b25ae835d4 // indirect
89+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4 // indirect
8090
gopkg.in/inf.v0 v0.9.1 // indirect
8191
gopkg.in/yaml.v3 v3.0.1 // indirect
82-
k8s.io/apimachinery v0.32.3 // indirect
83-
k8s.io/client-go v0.32.3 // indirect
92+
k8s.io/apimachinery v0.34.1 // indirect
93+
k8s.io/client-go v0.34.1 // indirect
8494
k8s.io/klog/v2 v2.130.1 // indirect
85-
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e // indirect
86-
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
87-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
88-
sigs.k8s.io/yaml v1.4.0 // indirect
95+
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d // indirect
96+
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
97+
sigs.k8s.io/randfill v1.0.0 // indirect
98+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
8999
)

go.mod.default

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
module github.com/AthenZ/authorization-proxy/v4
22

3-
go 1.23.4
3+
go 1.25.1
44

55
replace (
6-
cloud.google.com/go => cloud.google.com/go latest
7-
github.com/golang/mock => github.com/golang/mock latest
8-
github.com/golang/protobuf => github.com/golang/protobuf latest
9-
github.com/google/go-cmp => github.com/google/go-cmp latest
10-
github.com/google/pprof => github.com/google/pprof latest
11-
github.com/mwitkow/grpc-proxy => github.com/mwitkow/grpc-proxy 0f1106ef9c766333b9acb4b81e705da4bade7215
12-
golang.org/x/crypto => golang.org/x/crypto latest
13-
golang.org/x/exp => golang.org/x/exp latest
14-
golang.org/x/image => golang.org/x/image latest
15-
golang.org/x/lint => golang.org/x/lint latest
16-
golang.org/x/mobile => golang.org/x/mobile latest
17-
golang.org/x/mod => golang.org/x/mod latest
18-
golang.org/x/net => golang.org/x/net latest
19-
golang.org/x/oauth2 => golang.org/x/oauth2 latest
20-
golang.org/x/sync => golang.org/x/sync latest
21-
golang.org/x/sys => golang.org/x/sys latest
22-
golang.org/x/term => golang.org/x/term latest
23-
golang.org/x/text => golang.org/x/text latest
24-
golang.org/x/time => golang.org/x/time latest
25-
golang.org/x/tools => golang.org/x/tools latest
26-
golang.org/x/xerrors => golang.org/x/xerrors latest
27-
google.golang.org/api => google.golang.org/api latest
28-
google.golang.org/appengine => google.golang.org/appengine latest
29-
google.golang.org/genproto => google.golang.org/genproto latest
30-
google.golang.org/grpc => google.golang.org/grpc latest
31-
google.golang.org/protobuf => google.golang.org/protobuf latest
32-
)
33-
34-
require (
35-
github.com/AthenZ/athenz-authorizer/v5 latest
36-
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76
6+
cloud.google.com/go => cloud.google.com/go upgrade
7+
github.com/AthenZ/athenz-authorizer/v5 => github.com/AthenZ/athenz-authorizer/v5 upgrade
8+
github.com/kpango/gache/v2 => github.com/kpango/gache/v2 upgrade
9+
github.com/kpango/glg => github.com/kpango/glg upgrade
10+
github.com/mwitkow/grpc-proxy => github.com/mwitkow/grpc-proxy master
11+
github.com/pkg/errors => github.com/pkg/errors upgrade
12+
github.com/prometheus/client_golang => github.com/prometheus/client_golang upgrade
13+
github.com/prometheus/client_model => github.com/prometheus/client_model upgrade
14+
golang.org/x/sync => golang.org/x/sync upgrade
15+
google.golang.org/grpc => google.golang.org/grpc upgrade
16+
google.golang.org/protobuf => google.golang.org/protobuf upgrade
17+
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 upgrade
3718
)

0 commit comments

Comments
 (0)