|
5 | 5 |
|
6 | 6 | package v1alpha1 |
7 | 7 |
|
8 | | -// GeoIP defines GeoIP enrichment and access control configuration. |
9 | | -type GeoIP struct { |
10 | | - // Source configures how the client IP is extracted before being passed to the provider. |
11 | | - // If unset, Envoy falls back to using the immediate downstream connection address. |
12 | | - // |
13 | | - // +optional |
14 | | - Source *GeoIPSource `json:"source,omitempty"` |
15 | | - |
16 | | - // Provider defines the GeoIP provider configuration. |
17 | | - Provider GeoIPProvider `json:"provider"` |
18 | | - |
19 | | - // Access defines the GeoIP based access control configuration. |
20 | | - // |
21 | | - // +optional |
22 | | - Access *GeoIPAccessControl `json:"access,omitempty"` |
23 | | -} |
24 | | - |
25 | | -// GeoIPSource configures how Envoy determines the client IP address that is passed to the provider. |
26 | | -// +kubebuilder:validation:XValidation:rule="self.type == 'XFF' ? has(self.xff) && !has(self.header) : self.type == 'Header' ? has(self.header) && !has(self.xff) : true",message="When type is XFF, xff must be set (and header unset). When type is Header, header must be set (and xff unset)." |
27 | | -type GeoIPSource struct { |
28 | | - // +kubebuilder:validation:Enum=XFF;Header |
29 | | - // +kubebuilder:validation:Required |
30 | | - Type GeoIPSourceType `json:"type"` |
31 | | - |
32 | | - // XFF configures extraction based on the X-Forwarded-For header chain. |
33 | | - // |
34 | | - // +optional |
35 | | - XFF *GeoIPXFFSource `json:"xff,omitempty"` |
36 | | - |
37 | | - // Header configures extraction from a custom header. |
38 | | - // |
39 | | - // +optional |
40 | | - Header *GeoIPHeaderSource `json:"header,omitempty"` |
41 | | -} |
42 | | - |
43 | | -// GeoIPSourceType enumerates supported client IP sources. |
44 | | -type GeoIPSourceType string |
45 | | - |
46 | | -const ( |
47 | | - // GeoIPSourceTypeXFF instructs Envoy to honor the X-Forwarded-For header count. |
48 | | - GeoIPSourceTypeXFF GeoIPSourceType = "XFF" |
49 | | - // GeoIPSourceTypeHeader instructs Envoy to read a custom request header. |
50 | | - GeoIPSourceTypeHeader GeoIPSourceType = "Header" |
51 | | -) |
52 | | - |
53 | | -// GeoIPXFFSource configures trusted hop count for XFF parsing. |
54 | | -type GeoIPXFFSource struct { |
55 | | - // TrustedHops defines the number of trusted hops from the right side of XFF. |
56 | | - // Defaults to 0 when unset. |
57 | | - // |
58 | | - // +optional |
59 | | - TrustedHops *uint32 `json:"trustedHops,omitempty"` |
60 | | -} |
61 | | - |
62 | | -// GeoIPHeaderSource configures extraction from a custom header. |
63 | | -type GeoIPHeaderSource struct { |
64 | | - // HeaderName is the HTTP header that carries the client IP. |
65 | | - // |
66 | | - // +kubebuilder:validation:MinLength=1 |
67 | | - HeaderName string `json:"headerName"` |
68 | | -} |
69 | | - |
70 | 8 | // GeoIPProvider defines provider-specific settings. |
71 | 9 | // +kubebuilder:validation:XValidation:rule="self.type == 'MaxMind' ? has(self.MaxMind) : true",message="MaxMind must be set when type is MaxMind" |
72 | 10 | type GeoIPProvider struct { |
@@ -123,42 +61,6 @@ type GeoIPMaxMind struct { |
123 | 61 | AnonymousIPDBPath *string `json:"anonymousIpDbPath,omitempty"` |
124 | 62 | } |
125 | 63 |
|
126 | | -// GeoIPAccessControl defines GeoIP-based allow/deny lists. |
127 | | -type GeoIPAccessControl struct { |
128 | | - // DefaultAction defines how to handle requests that do not match any rule or lack GeoIP data. |
129 | | - // Defaults to Allow when unset. |
130 | | - // |
131 | | - // +optional |
132 | | - DefaultAction *AuthorizationAction `json:"defaultAction,omitempty"` |
133 | | - |
134 | | - // Rules evaluated in order. The first matching rule's action applies. |
135 | | - // |
136 | | - // +optional |
137 | | - Rules []GeoIPRule `json:"rules,omitempty"` |
138 | | -} |
139 | | - |
140 | | -// GeoIPRule defines a single GeoIP allow/deny rule. |
141 | | -// +kubebuilder:validation:XValidation:rule="has(self.countries) || has(self.regions) || has(self.cities)",message="At least one of countries, regions, or cities must be specified" |
142 | | -type GeoIPRule struct { |
143 | | - // Action is reused from Authorization rules (Allow or Deny). |
144 | | - Action AuthorizationAction `json:"action"` |
145 | | - |
146 | | - // Countries is a list of ISO 3166-1 alpha-2 country codes. |
147 | | - // |
148 | | - // +optional |
149 | | - Countries []string `json:"countries,omitempty"` |
150 | | - |
151 | | - // Regions refines matching to ISO 3166-2 subdivisions. |
152 | | - // |
153 | | - // +optional |
154 | | - Regions []GeoIPRegion `json:"regions,omitempty"` |
155 | | - |
156 | | - // Cities refines matching to specific city names. |
157 | | - // |
158 | | - // +optional |
159 | | - Cities []GeoIPCity `json:"cities,omitempty"` |
160 | | -} |
161 | | - |
162 | 64 | // GeoIPRegion selects a region within a country. |
163 | 65 | // +kubebuilder:validation:XValidation:rule="has(self.countryCode) && has(self.regionCode)",message="countryCode and regionCode must both be set" |
164 | 66 | type GeoIPRegion struct { |
@@ -193,3 +95,31 @@ type GeoIPCity struct { |
193 | 95 | // +kubebuilder:validation:MinLength=1 |
194 | 96 | CityName string `json:"cityName"` |
195 | 97 | } |
| 98 | + |
| 99 | +// GeoIPAnonymousMatch matches anonymous network signals emitted by the GeoIP provider. |
| 100 | +type GeoIPAnonymousMatch struct { |
| 101 | + // IsAnonymous matches whether the client IP is considered anonymous. |
| 102 | + // |
| 103 | + // +optional |
| 104 | + IsAnonymous *bool `json:"isAnonymous,omitempty"` |
| 105 | + |
| 106 | + // IsVPN matches whether the client IP is detected as VPN. |
| 107 | + // |
| 108 | + // +optional |
| 109 | + IsVPN *bool `json:"isVPN,omitempty"` |
| 110 | + |
| 111 | + // IsHosting matches whether the client IP belongs to a hosting provider. |
| 112 | + // |
| 113 | + // +optional |
| 114 | + IsHosting *bool `json:"isHosting,omitempty"` |
| 115 | + |
| 116 | + // IsTor matches whether the client IP belongs to a Tor exit node. |
| 117 | + // |
| 118 | + // +optional |
| 119 | + IsTor *bool `json:"isTor,omitempty"` |
| 120 | + |
| 121 | + // IsProxy matches whether the client IP belongs to a public proxy. |
| 122 | + // |
| 123 | + // +optional |
| 124 | + IsProxy *bool `json:"isProxy,omitempty"` |
| 125 | +} |
0 commit comments