Skip to content

Commit 587bc61

Browse files
committed
minor cleanups, support for sni based routing in certain scenarios
Signed-off-by: Travis Glenn Hansen <[email protected]>
1 parent 525df10 commit 587bc61

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

src/KubernetesPfSenseController/Plugin/CommonTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private function getWatchCallback($stateKey, $options = [])
101101

102102
$key = $stateKey;
103103
$items = &$this->state[$key];
104+
$oldItem = null;
104105

105106
$item = $event['object'];
106107
unset($item['kind']);

src/KubernetesPfSenseController/Plugin/DNSHAProxyIngressProxy.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ public function doAction()
147147
$managedHosts = $store['managed_hosts'] ?? [];
148148

149149
foreach ($managedFrontends as $frontendName => $frontendDetails) {
150-
$primaryFrontendName = $haProxyConfig->getFrontend($frontendName)['primary_frontend'];
151-
$hostName = $pluginConfig['frontends'][$primaryFrontendName]['hostname'];
150+
$primaryFrontendName = $haProxyConfig->getFrontend($frontendName)['primary_frontend'] ?? null;
151+
if (empty($primaryFrontendName)) {
152+
continue;
153+
}
154+
$hostName = $pluginConfig['frontends'][$primaryFrontendName]['hostname'] ?? null;
155+
if (empty($hostName)) {
156+
continue;
157+
}
152158

153159
$ingress = KubernetesUtils::getResourceByNamespaceName($this->state['ingresses'], $frontendDetails['resource']['namespace'], $frontendDetails['resource']['name']);
154160
if (!empty($ingress)) {

src/KubernetesPfSenseController/Plugin/HAProxyIngressProxy.php

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ public function doAction()
177177
continue;
178178
}
179179

180+
// get the type of the shared frontend
181+
// NOTE the below do NOT correlate 100% with what is shown on the 'type' column of the 'frontends' tab.
182+
// 'https' for example is actually http + ssl offloading checked
183+
/*
184+
<option value="http">http / https(offloading)</option>
185+
<option value="https">ssl / https(TCP mode)</option>
186+
<option value="tcp">tcp</option>
187+
*/
188+
189+
/**
190+
* http - can do l7 rules such as headers, path, etc
191+
* https - can only do sni rules
192+
* tcp - cannot be used with this application
193+
*/
194+
$sharedFrontend = $haProxyConfig->getFrontend($sharedFrontendName);
195+
switch ($sharedFrontend['type']) {
196+
case "http":
197+
case "https":
198+
// move along
199+
break;
200+
default:
201+
$this->log("WARN ${sharedFrontendName} is not a supported type");
202+
continue 2;
203+
}
204+
180205
if (!$haProxyConfig->frontendExists($sharedFrontendName)) {
181206
if (!in_array($sharedFrontendName, $frontendWarning)) {
182207
//$frontendWarning[] = $sharedFrontendName;
@@ -217,7 +242,7 @@ public function doAction()
217242
//$serviceName = $path['backend']['serviceName'];
218243
//$servicePort = $path['backend']['servicePort'];
219244

220-
$path = $path['path'];
245+
$path = $path['path'] ?? "";
221246
if (empty($path)) {
222247
$path = '/';
223248
}
@@ -226,9 +251,27 @@ public function doAction()
226251
$acl = [];
227252
$acl['name'] = $aclName;
228253
$acl['expression'] = 'custom';
229-
$acl['value'] = "hdr(host) -i ${host} path_beg -i ${path}";
230-
231-
$frontend['ha_acls']['item'][] = $acl;
254+
// alter this based on shared frontend type
255+
// if tcp/ssl then do sni-based rule
256+
// https://stackoverflow.com/questions/33085240/haproxy-sni-vs-http-host-acl-check-performance
257+
// req_ssl_sni (types https and tcp both equate to type tcp in the haproxy config), type tcp requires this variant
258+
// ssl_fc_sni (this can be used only with type http)
259+
switch ($sharedFrontend['type']) {
260+
case "http":
261+
$acl['value'] = "hdr(host) -i ${host} path_beg -i ${path}";
262+
$frontend['ha_acls']['item'][] = $acl;
263+
break;
264+
case "https":
265+
$this->log("WARN unexpected behavior may occur when using a shared frontend of type https, path-based routing will not work and ssl offloading must be enabled");
266+
$acl['value'] = "req_ssl_sni -i ${host}";
267+
$frontend['ha_acls']['item'][] = $acl;
268+
break;
269+
default:
270+
// should never get here based on checks above, but just in case
271+
$this->log("WARN unsupported shared frontend type: ".$sharedFrontend['type']);
272+
continue 3;
273+
break;
274+
}
232275
}
233276

234277
// new action (tied to acl)

src/KubernetesPfSenseController/Plugin/KubernetesUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static function putListItem(&$list, $item)
193193
*/
194194
public static function getServiceIp($service)
195195
{
196-
return $service['status']['loadBalancer']['ingress'][0]['ip'];
196+
return $service['status']['loadBalancer']['ingress'][0]['ip'] ?? null;
197197
}
198198

199199
/**

src/KubernetesPfSenseController/Plugin/MetalLB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function postReadWatches()
104104
*/
105105
public function doAction()
106106
{
107-
$metalConfig = $this->state['metallb-config'];
107+
$metalConfig = $this->state['metallb-config'] ?? [];
108108
$pluginConfig = $this->getConfig();
109109

110110
if (empty($metalConfig)) {

0 commit comments

Comments
 (0)