Add support for PROXY protocol for Streams

This commit is contained in:
Julia V Rose 2026-04-25 03:15:26 -07:00
parent 857a35ea64
commit 5965a6c461
10 changed files with 93 additions and 3 deletions

View file

@ -0,0 +1,40 @@
const migrate_name = "proxy_protocol_stream";
import { migrate as logger } from "../logger.js";
/**
* Migrate
*
* @see http://knexjs.org/#Schema
*
* @param {Object} knex
* @returns {Promise}
*/
const up = (knex) => {
logger.info(`[${migrate_name}] Migrating Up...`);
return knex.schema.table("stream", (table) => {
table.integer("enable_proxy_protocol").notNull().unsigned().defaultTo(0);
}).then(() => {
logger.info(`[${migrate_name}] stream Table altered`);
});
};
/**
* Undo Migrate
*
* @param {Object} knex
* @returns {Promise}
*/
const down = (_knex) => {
logger.info(`[${migrateName}] Migrating Down...`);
return knex.schema.table("stream", (table) => {
table.dropColumn("enable_proxy_protocol");
})
.then(() => {
logger.info(`[${migrateName}] stream Table altered`);
});
};
export { up, down };

View file

@ -12,7 +12,8 @@
"tcp_forwarding",
"udp_forwarding",
"enabled",
"meta"
"meta",
"enable_proxy_protocol"
],
"additionalProperties": false,
"properties": {
@ -70,6 +71,11 @@
"enabled": {
"$ref": "../common.json#/properties/enabled"
},
"enable_proxy_protocol": {
"description": "Enable PROXY Protocol support",
"type": "boolean",
"example": false
},
"certificate_id": {
"$ref": "../common.json#/properties/certificate_id"
},

View file

@ -41,6 +41,7 @@
"nginx_err": null
},
"enabled": true,
"enable_proxy_protocol": false,
"certificate_id": 0
}
]

View file

@ -41,6 +41,9 @@
"certificate_id": {
"$ref": "../../../components/stream-object.json#/properties/certificate_id"
},
"enable_proxy_protocol": {
"$ref": "../../../components/stream-object.json#/properties/enable_proxy_protocol",
},
"meta": {
"$ref": "../../../components/stream-object.json#/properties/meta"
},
@ -56,6 +59,7 @@
"tcp_forwarding": true,
"udp_forwarding": false,
"certificate_id": 0,
"enable_proxy_protocol": false,
"meta": {}
}
}
@ -83,6 +87,7 @@
"nginx_err": null
},
"enabled": true,
"enable_proxy_protocol": false,
"owner": {
"id": 1,
"created_on": "2024-10-09T02:33:16.000Z",

View file

@ -42,6 +42,7 @@
"nginx_err": null
},
"enabled": true,
"enableProxyProtocol": false,
"certificate_id": 0
}
}

View file

@ -48,6 +48,9 @@
"certificate_id": {
"$ref": "../../../../components/stream-object.json#/properties/certificate_id"
},
"enable_proxy_protocol": {
"$ref": "../../../../components/stream-object.json#/properties/enable_proxy_protocol",
},
"meta": {
"$ref": "../../../../components/stream-object.json#/properties/meta"
}
@ -78,6 +81,7 @@
"nginx_err": null
},
"enabled": true,
"enable_proxy_protocol": false,
"owner": {
"id": 1,
"created_on": "2024-10-09T02:33:16.000Z",

View file

@ -5,8 +5,9 @@
{% if enabled %}
{% if tcp_forwarding == 1 or tcp_forwarding == true -%}
server {
listen {{ incoming_port }} {%- if certificate %} ssl {%- endif %};
{% unless ipv6 -%} # {%- endunless -%} listen [::]:{{ incoming_port }} {%- if certificate %} ssl {%- endif %};
listen {{ incoming_port }} {%- if certificate %} ssl {%- endif %} {%- if enable_proxy_protocol == 1 %} proxy_protocol {%- endif %};
# {{ enable_proxy_protocol }}
{% unless ipv6 -%} # {%- endunless -%} listen [::]:{{ incoming_port }} {%- if certificate %} ssl {%- endif %} {%- if enable_proxy_protocol == 1 %} proxy_protocol {%- endif %};
{%- include "_certificates_stream.conf" %}

View file

@ -191,6 +191,7 @@ export interface Stream {
udpForwarding: boolean;
meta: Record<string, any>;
enabled: boolean;
enableProxyProtocol: boolean;
certificateId: number;
// Expansions:
owner?: User;

View file

@ -12,6 +12,7 @@ const fetchStream = (id: number | "new") => {
udpForwarding: false,
meta: {},
enabled: true,
enableProxyProtocol: false,
certificateId: 0,
} as Stream);
}

View file

@ -63,6 +63,7 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
tcpForwarding: data?.tcpForwarding,
udpForwarding: data?.udpForwarding,
certificateId: data?.certificateId,
enableProxyProtocol: data?.enableProxyProtocol,
meta: data?.meta || {},
} as any
}
@ -278,6 +279,35 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
</span>
</label>
</div>
<div>
<label className="row" htmlFor="enableProxyProtocol">
<span className="col">
<T id="host.flags.enable-proxy-protocol" />
</span>
<span className="col-auto">
<Field name="enableProxyProtocol" type="checkbox">
{({ field }: any) => (
<label className="form-check form-check-single form-switch">
<input
id="enableProxyProtocol"
className="form-check-input"
type="checkbox"
name={field.name}
checked={field.value}
onChange={(e: any) => {
setFieldValue(
field.name,
e.target.checked,
);
}}
/>
</label>
)}
</Field>
</span>
{/* <span class="custom-switch-description"><%- i18n('proxy-hosts', 'enable-proxy-protocol') %> <a href="https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/#introduction" target="_blank"><i class="fe fe-help-circle"></i></a></span> */}
</label>
</div>
</div>
</div>
</div>