Skip to content

Commit beb730e

Browse files
committed
Update address type
1 parent 50c1cc1 commit beb730e

File tree

9 files changed

+319
-220
lines changed

9 files changed

+319
-220
lines changed

apis/v1alpha1/nginxproxy_types.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ type NginxProxySpec struct {
6262
type NginxPlus struct {
6363
// AllowedAddresses specifies IPAddresses or CIDR blocks to the allow list for accessing the NGINX Plus API.
6464
//
65-
//nolint:lll
6665
// +optional
67-
// +kubebuilder:validation:items:XValidation:message="Address Type must be either CIDR or IPAddress",rule="(self.type=='CIDR' || self.type=='IPAddress')"
68-
AllowedAddresses []Address `json:"allowedAddresses,omitempty"`
66+
AllowedAddresses []NginxPlusAllowAddress `json:"allowedAddresses,omitempty"`
6967
}
7068

7169
// Telemetry specifies the OpenTelemetry configuration.
@@ -161,7 +159,7 @@ type RewriteClientIP struct {
161159
// +listType=map
162160
// +listMapKey=type
163161
// +kubebuilder:validation:MaxItems=16
164-
TrustedAddresses []Address `json:"trustedAddresses,omitempty"`
162+
TrustedAddresses []RewriteClientIPAddress `json:"trustedAddresses,omitempty"`
165163
}
166164

167165
// RewriteClientIPModeType defines how NGINX Gateway Fabric will determine the client's original IP address.
@@ -195,28 +193,49 @@ const (
195193
IPv6 IPFamilyType = "ipv6"
196194
)
197195

198-
// Address is a struct that specifies address type and value.
199-
type Address struct {
196+
// RewriteClientIPAddress is a struct that specifies address type and value.
197+
type RewriteClientIPAddress struct {
200198
// Type specifies the type of address.
201-
Type AddressType `json:"type"`
199+
Type RewriteClientIPAddressType `json:"type"`
202200

203201
// Value specifies the address value.
204202
Value string `json:"value"`
205203
}
206204

207-
// AddressType specifies the type of address.
205+
// RewriteClientIPAddressType specifies the type of address.
208206
// +kubebuilder:validation:Enum=CIDR;IPAddress;Hostname
209-
type AddressType string
207+
type RewriteClientIPAddressType string
210208

211209
const (
212-
// CIDRAddressType specifies that the address is a CIDR block.
213-
CIDRAddressType AddressType = "CIDR"
210+
// RewriteClientIPCIDRAddressType specifies that the address is a CIDR block.
211+
RewriteClientIPCIDRAddressType RewriteClientIPAddressType = "CIDR"
212+
213+
// RewriteClientIPIPAddressType specifies that the address is an IP address.
214+
RewriteClientIPIPAddressType RewriteClientIPAddressType = "IPAddress"
215+
216+
// RewriteClientIPHostnameAddressType specifies that the address is a Hostname.
217+
RewriteClientIPHostnameAddressType RewriteClientIPAddressType = "Hostname"
218+
)
219+
220+
// NginxPlusAllowAddress is a struct that specifies address type and value.
221+
type NginxPlusAllowAddress struct {
222+
// Type specifies the type of address.
223+
Type NginxPlusAllowAddressType `json:"type"`
214224

215-
// IPAddressType specifies that the address is an IP address.
216-
IPAddressType AddressType = "IPAddress"
225+
// Value specifies the address value.
226+
Value string `json:"value"`
227+
}
228+
229+
// NginxPlusAllowAddressType specifies the type of address.
230+
// +kubebuilder:validation:Enum=CIDR;IPAddress
231+
type NginxPlusAllowAddressType string
232+
233+
const (
234+
// NginxPlusAllowCIDRAddressType specifies that the address is a CIDR block.
235+
NginxPlusAllowCIDRAddressType NginxPlusAllowAddressType = "CIDR"
217236

218-
// HostnameAddressType specifies that the address is a Hostname.
219-
HostnameAddressType AddressType = "Hostname"
237+
// NginxPlusAllowIPAddressType specifies that the address is an IP address.
238+
NginxPlusAllowIPAddressType NginxPlusAllowAddressType = "IPAddress"
220239
)
221240

222241
// NginxLogging defines logging related settings for NGINX.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 32 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ spec:
9090
description: AllowedAddresses specifies IPAddresses or CIDR blocks
9191
to the allow list for accessing the NGINX Plus API.
9292
items:
93-
description: Address is a struct that specifies address type
94-
and value.
93+
description: NginxPlusAllowAddress is a struct that specifies
94+
address type and value.
9595
properties:
9696
type:
9797
description: Type specifies the type of address.
9898
enum:
9999
- CIDR
100100
- IPAddress
101-
- Hostname
102101
type: string
103102
value:
104103
description: Value specifies the address value.
@@ -107,9 +106,6 @@ spec:
107106
- type
108107
- value
109108
type: object
110-
x-kubernetes-validations:
111-
- message: Address Type must be either CIDR or IPAddress
112-
rule: (self.type=='CIDR' || self.type=='IPAddress')
113109
type: array
114110
type: object
115111
rewriteClientIP:
@@ -151,8 +147,8 @@ spec:
151147
Sets NGINX directive set_real_ip_from: https://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
152148
This field is required if mode is set.
153149
items:
154-
description: Address is a struct that specifies address type
155-
and value.
150+
description: RewriteClientIPAddress is a struct that specifies
151+
address type and value.
156152
properties:
157153
type:
158154
description: Type specifies the type of address.

deploy/crds.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,14 @@ spec:
675675
description: AllowedAddresses specifies IPAddresses or CIDR blocks
676676
to the allow list for accessing the NGINX Plus API.
677677
items:
678-
description: Address is a struct that specifies address type
679-
and value.
678+
description: NginxPlusAllowAddress is a struct that specifies
679+
address type and value.
680680
properties:
681681
type:
682682
description: Type specifies the type of address.
683683
enum:
684684
- CIDR
685685
- IPAddress
686-
- Hostname
687686
type: string
688687
value:
689688
description: Value specifies the address value.
@@ -692,9 +691,6 @@ spec:
692691
- type
693692
- value
694693
type: object
695-
x-kubernetes-validations:
696-
- message: Address Type must be either CIDR or IPAddress
697-
rule: (self.type=='CIDR' || self.type=='IPAddress')
698694
type: array
699695
type: object
700696
rewriteClientIP:
@@ -736,8 +732,8 @@ spec:
736732
Sets NGINX directive set_real_ip_from: https://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
737733
This field is required if mode is set.
738734
items:
739-
description: Address is a struct that specifies address type
740-
and value.
735+
description: RewriteClientIPAddress is a struct that specifies
736+
address type and value.
741737
properties:
742738
type:
743739
description: Type specifies the type of address.

internal/mode/static/state/dataplane/configuration.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ func buildPolicies(graphPolicies []*graph.Policy) []policies.Policy {
952952
return finalPolicies
953953
}
954954

955-
func convertAddresses(addresses []ngfAPIv1alpha1.Address) []string {
955+
func convertAddresses(addresses []ngfAPIv1alpha1.RewriteClientIPAddress) []string {
956956
trustedAddresses := make([]string, len(addresses))
957957
for i, addr := range addresses {
958958
trustedAddresses[i] = addr.Value
@@ -993,7 +993,12 @@ func buildNginxPlus(g *graph.Graph) NginxPlus {
993993
ngfProxy := g.NginxProxy
994994
if ngfProxy != nil && ngfProxy.Source.Spec.NginxPlus != nil {
995995
if ngfProxy.Source.Spec.NginxPlus.AllowedAddresses != nil {
996-
nginxPlusSettings.AllowedAddresses = convertAddresses(ngfProxy.Source.Spec.NginxPlus.AllowedAddresses)
996+
addresses := make([]string, len(ngfProxy.Source.Spec.NginxPlus.AllowedAddresses))
997+
for i, addr := range ngfProxy.Source.Spec.NginxPlus.AllowedAddresses {
998+
addresses[i] = addr.Value
999+
}
1000+
1001+
nginxPlusSettings.AllowedAddresses = addresses
9971002
}
9981003
}
9991004

internal/mode/static/state/dataplane/configuration_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,9 +2279,9 @@ func TestBuildConfiguration(t *testing.T) {
22792279
Spec: ngfAPIv1alpha1.NginxProxySpec{
22802280
RewriteClientIP: &ngfAPIv1alpha1.RewriteClientIP{
22812281
SetIPRecursively: helpers.GetPointer(true),
2282-
TrustedAddresses: []ngfAPIv1alpha1.Address{
2282+
TrustedAddresses: []ngfAPIv1alpha1.RewriteClientIPAddress{
22832283
{
2284-
Type: ngfAPIv1alpha1.CIDRAddressType,
2284+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
22852285
Value: "1.1.1.1/32",
22862286
},
22872287
},
@@ -2391,9 +2391,9 @@ func TestBuildConfiguration(t *testing.T) {
23912391
Source: &ngfAPIv1alpha1.NginxProxy{
23922392
Spec: ngfAPIv1alpha1.NginxProxySpec{
23932393
NginxPlus: &ngfAPIv1alpha1.NginxPlus{
2394-
AllowedAddresses: []ngfAPIv1alpha1.Address{
2395-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "127.0.0.3"},
2396-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "25.0.0.3"},
2394+
AllowedAddresses: []ngfAPIv1alpha1.NginxPlusAllowAddress{
2395+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "127.0.0.3"},
2396+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "25.0.0.3"},
23972397
},
23982398
},
23992399
},
@@ -3972,9 +3972,9 @@ func TestBuildRewriteIPSettings(t *testing.T) {
39723972
Spec: ngfAPIv1alpha1.NginxProxySpec{
39733973
RewriteClientIP: &ngfAPIv1alpha1.RewriteClientIP{
39743974
Mode: helpers.GetPointer(ngfAPIv1alpha1.RewriteClientIPModeProxyProtocol),
3975-
TrustedAddresses: []ngfAPIv1alpha1.Address{
3975+
TrustedAddresses: []ngfAPIv1alpha1.RewriteClientIPAddress{
39763976
{
3977-
Type: ngfAPIv1alpha1.CIDRAddressType,
3977+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
39783978
Value: "10.9.9.4/32",
39793979
},
39803980
},
@@ -3999,9 +3999,9 @@ func TestBuildRewriteIPSettings(t *testing.T) {
39993999
Spec: ngfAPIv1alpha1.NginxProxySpec{
40004000
RewriteClientIP: &ngfAPIv1alpha1.RewriteClientIP{
40014001
Mode: helpers.GetPointer(ngfAPIv1alpha1.RewriteClientIPModeXForwardedFor),
4002-
TrustedAddresses: []ngfAPIv1alpha1.Address{
4002+
TrustedAddresses: []ngfAPIv1alpha1.RewriteClientIPAddress{
40034003
{
4004-
Type: ngfAPIv1alpha1.CIDRAddressType,
4004+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
40054005
Value: "76.89.90.11/24",
40064006
},
40074007
},
@@ -4026,21 +4026,21 @@ func TestBuildRewriteIPSettings(t *testing.T) {
40264026
Spec: ngfAPIv1alpha1.NginxProxySpec{
40274027
RewriteClientIP: &ngfAPIv1alpha1.RewriteClientIP{
40284028
Mode: helpers.GetPointer(ngfAPIv1alpha1.RewriteClientIPModeXForwardedFor),
4029-
TrustedAddresses: []ngfAPIv1alpha1.Address{
4029+
TrustedAddresses: []ngfAPIv1alpha1.RewriteClientIPAddress{
40304030
{
4031-
Type: ngfAPIv1alpha1.CIDRAddressType,
4031+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
40324032
Value: "5.5.5.5/12",
40334033
},
40344034
{
4035-
Type: ngfAPIv1alpha1.CIDRAddressType,
4035+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
40364036
Value: "1.1.1.1/26",
40374037
},
40384038
{
4039-
Type: ngfAPIv1alpha1.CIDRAddressType,
4039+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
40404040
Value: "2.2.2.2/32",
40414041
},
40424042
{
4043-
Type: ngfAPIv1alpha1.CIDRAddressType,
4043+
Type: ngfAPIv1alpha1.RewriteClientIPCIDRAddressType,
40444044
Value: "3.3.3.3/24",
40454045
},
40464046
},
@@ -4462,8 +4462,8 @@ func TestBuildNginxPlus(t *testing.T) {
44624462
Source: &ngfAPIv1alpha1.NginxProxy{
44634463
Spec: ngfAPIv1alpha1.NginxProxySpec{
44644464
NginxPlus: &ngfAPIv1alpha1.NginxPlus{
4465-
AllowedAddresses: []ngfAPIv1alpha1.Address{
4466-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "127.0.0.3"},
4465+
AllowedAddresses: []ngfAPIv1alpha1.NginxPlusAllowAddress{
4466+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "127.0.0.3"},
44674467
},
44684468
},
44694469
},
@@ -4480,9 +4480,9 @@ func TestBuildNginxPlus(t *testing.T) {
44804480
Source: &ngfAPIv1alpha1.NginxProxy{
44814481
Spec: ngfAPIv1alpha1.NginxProxySpec{
44824482
NginxPlus: &ngfAPIv1alpha1.NginxPlus{
4483-
AllowedAddresses: []ngfAPIv1alpha1.Address{
4484-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "127.0.0.3"},
4485-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "25.0.0.3"},
4483+
AllowedAddresses: []ngfAPIv1alpha1.NginxPlusAllowAddress{
4484+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "127.0.0.3"},
4485+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "25.0.0.3"},
44864486
},
44874487
},
44884488
},
@@ -4499,8 +4499,8 @@ func TestBuildNginxPlus(t *testing.T) {
44994499
Source: &ngfAPIv1alpha1.NginxProxy{
45004500
Spec: ngfAPIv1alpha1.NginxProxySpec{
45014501
NginxPlus: &ngfAPIv1alpha1.NginxPlus{
4502-
AllowedAddresses: []ngfAPIv1alpha1.Address{
4503-
{Type: ngfAPIv1alpha1.IPAddressType, Value: "127.0.0.1"},
4502+
AllowedAddresses: []ngfAPIv1alpha1.NginxPlusAllowAddress{
4503+
{Type: ngfAPIv1alpha1.NginxPlusAllowIPAddressType, Value: "127.0.0.1"},
45044504
},
45054505
},
45064506
},

0 commit comments

Comments
 (0)