Skip to content

Commit f81afcd

Browse files
authored
chore: refactoring and test implementations for authorization webhook (#54)
* chore: initial refactoring progress * tests: wrote more test for contextual authorizer * tests: finish up contextual authorizer tests * tests: add test to the webhook framework * tests: provdie test for union logic * chore: skip test requirement for util for now * chore: running in the local setup revealed some bugs * chore: address review comments * chore: more review comments and minor improvements * chore: update Dockerfile for build arguments and enhance logging in root command
1 parent d96ef5a commit f81afcd

34 files changed

+4033
-1816
lines changed

.github/workflows/pipeline.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ jobs:
1818
with:
1919
imageTagName: ghcr.io/platform-mesh/rebac-authz-webhook
2020
useTask: true
21-
coverageThresholdFile: 0
22-
coverageThresholdPackage: 0
23-
coverageThresholdTotal: 0
21+
useLocalCoverageConfig: true
22+
coverageThresholdTotal: 80

.mockery.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ recursive: false
66
require-template-schema-exists: true
77
template: testify
88
template-schema: '{{.Template}}.schema.json'
9-
dir: 'pkg/resolver/mocks'
9+
dir: 'pkg/handler/mocks'
1010
pkgname: mocks
1111
structname: '{{.InterfaceName}}'
12+
filename: '{{.InterfaceName}}.go'
1213
packages:
13-
k8s.io/apimachinery/pkg/api/meta:
14-
config:
15-
include-interface-regex: RESTMapper
16-
filename: restmapper.go
17-
sigs.k8s.io/controller-runtime/pkg/kcp:
14+
github.com/openfga/api/proto/openfga/v1:
1815
config:
19-
filename: kcp.go
16+
include-interface-regex: OpenFGAServiceClient
2017
sigs.k8s.io/controller-runtime/pkg/client:
2118
config:
22-
include-interface-regex: Client
23-
filename: k8sclient.go
24-
github.com/openfga/api/proto/openfga/v1:
19+
include-interface-regex: ^Client
20+
sigs.k8s.io/controller-runtime/pkg/cluster:
2521
config:
26-
dir: 'pkg/handler/mocks'
27-
include-interface-regex: OpenFGAServiceClient
28-
filename: openfgaclient.go
22+
include-interface-regex: Cluster
23+
sigs.k8s.io/multicluster-runtime/pkg/manager:
24+
config:
25+
include-interface-regex: Manager

.testcoverage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exclude:
2+
paths:
3+
- ^pkg/handler/mocks # exclude generated mock files
4+
- main\.go$ # skip covering main.go
5+
- ^cmd # skip covering cmd directory
6+
- ^pkg/authorization/response\.go$
7+
- ^pkg/util

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
FROM golang:1.25 AS builder
22

3-
ENV GOSUMDB=off
4-
5-
RUN git config --global credential.helper store
6-
RUN --mount=type=secret,id=org_token echo "https://gha:$(cat /run/secrets/org_token)@github.com" > /root/.git-credentials
3+
ARG TARGETOS
4+
ARG TARGETARCH
75

86
WORKDIR /app
97

108
COPY go.mod go.mod
119
COPY go.sum go.sum
1210

11+
RUN go mod download
12+
1313
COPY . .
1414

15-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o rebac-authz-webhook main.go
15+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o rebac-authz-webhook main.go
1616

1717
FROM gcr.io/distroless/static:nonroot
1818
WORKDIR /

0 commit comments

Comments
 (0)