Skip to content

Commit 82a86f4

Browse files
committed
Basic AuthenticationFilter examples
1 parent 846717f commit 82a86f4

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

.gitleaksignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
890fddb787ff3560b9b743647a36b649d498ae51:internal/state/graph/secret_test.go:private-key:35
55
890fddb787ff3560b9b743647a36b649d498ae51:internal/state/change_processor_test.go:private-key:211
66
internal/controller/state/graph/config_maps_test.go:private-key:35
7+
examples/basic-authentication/basic-auth.yaml:generic-api-key:8
8+
examples/basic-authentication/basic-auth.yaml:generic-api-key:31
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Basic Authentication
2+
3+
This directory contains the YAML files used in the [Basic Authentication](https://docs.nginx.com/nginx-gateway-fabric/traffic-management/basic-authentication/) guide.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: basic-auth1
5+
type: Opaque
6+
data:
7+
# Base64 of "htpasswd -bn user1 password1"
8+
auth: dXNlcjE6JGFwcjEkWEFKeU5yekgkY0Rjdy9YMVBCZTFmTjltQVBweXpxMA==
9+
---
10+
apiVersion: gateway.nginx.org/v1alpha1
11+
kind: AuthenticationFilter
12+
metadata:
13+
name: basic-auth1
14+
spec:
15+
type: Basic
16+
basic:
17+
secretRef:
18+
name: basic-auth1
19+
realm: "Restricted basic-auth1"
20+
onFailure:
21+
statusCode: 401
22+
scheme: Basic
23+
---
24+
apiVersion: v1
25+
kind: Secret
26+
metadata:
27+
name: basic-auth2
28+
type: Opaque
29+
data:
30+
# Base64 of "htpasswd -bn user2 password2"
31+
auth: dXNlcjI6JGFwcjEkd0lKUUpjZEUkSXUuYjVhMlBGODdtQi5zT0x4aUg5MQ==
32+
---
33+
apiVersion: gateway.nginx.org/v1alpha1
34+
kind: AuthenticationFilter
35+
metadata:
36+
name: basic-auth2
37+
spec:
38+
type: Basic
39+
basic:
40+
secretRef:
41+
name: basic-auth2
42+
realm: "Restricted basic-auth2"
43+
onFailure:
44+
statusCode: 401
45+
scheme: Basic
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: cafe-routes
5+
spec:
6+
parentRefs:
7+
- name: cafe-gateway
8+
rules:
9+
- matches:
10+
# Coffee with Basic Auth via basic-auth1
11+
- path:
12+
type: PathPrefix
13+
value: /coffee1
14+
# Additional coffee path with same auth
15+
- path:
16+
type: PathPrefix
17+
value: /coffee2
18+
backendRefs:
19+
- name: coffee
20+
port: 80
21+
filters:
22+
- type: ExtensionRef
23+
extensionRef:
24+
group: gateway.nginx.org
25+
kind: AuthenticationFilter
26+
name: basic-auth1
27+
# Tea with Basic Auth via basic-auth2
28+
- matches:
29+
- path:
30+
type: PathPrefix
31+
value: /tea
32+
backendRefs:
33+
- name: tea
34+
port: 80
35+
filters:
36+
- type: ExtensionRef
37+
extensionRef:
38+
group: gateway.nginx.org
39+
kind: AuthenticationFilter
40+
name: basic-auth2
41+
# Latte without authentication
42+
- matches:
43+
- path:
44+
type: PathPrefix
45+
value: /latte
46+
backendRefs:
47+
- name: latte
48+
port: 80
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: coffee
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: coffee
10+
template:
11+
metadata:
12+
labels:
13+
app: coffee
14+
spec:
15+
containers:
16+
- name: coffee
17+
image: nginxdemos/nginx-hello:plain-text
18+
ports:
19+
- containerPort: 8080
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: coffee
25+
spec:
26+
ports:
27+
- port: 80
28+
targetPort: 8080
29+
protocol: TCP
30+
name: http
31+
selector:
32+
app: coffee
33+
---
34+
apiVersion: apps/v1
35+
kind: Deployment
36+
metadata:
37+
name: tea
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: tea
43+
template:
44+
metadata:
45+
labels:
46+
app: tea
47+
spec:
48+
containers:
49+
- name: tea
50+
image: nginxdemos/nginx-hello:plain-text
51+
ports:
52+
- containerPort: 8080
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: tea
58+
spec:
59+
ports:
60+
- port: 80
61+
targetPort: 8080
62+
protocol: TCP
63+
name: http
64+
selector:
65+
app: tea
66+
---
67+
apiVersion: apps/v1
68+
kind: Deployment
69+
metadata:
70+
name: latte
71+
spec:
72+
replicas: 1
73+
selector:
74+
matchLabels:
75+
app: latte
76+
template:
77+
metadata:
78+
labels:
79+
app: latte
80+
spec:
81+
containers:
82+
- name: latte
83+
image: nginxdemos/nginx-hello:plain-text
84+
ports:
85+
- containerPort: 8080
86+
---
87+
apiVersion: v1
88+
kind: Service
89+
metadata:
90+
name: latte
91+
spec:
92+
ports:
93+
- port: 80
94+
targetPort: 8080
95+
protocol: TCP
96+
name: http
97+
selector:
98+
app: latte
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: cafe-gateway
5+
spec:
6+
gatewayClassName: nginx
7+
listeners:
8+
- name: http
9+
port: 80
10+
protocol: HTTP
11+
allowedRoutes:
12+
namespaces:
13+
from: Same

0 commit comments

Comments
 (0)