Skip to content

Commit 2916ff3

Browse files
snordmannjwklijnsmaSBado
committed
Add support for proxy_protocol in proxy_hosts and streams
Closes #1114 Related To #1882 Related To #3537 Related To #3618 Co-authored-by: jwklijnsma <[email protected]> Co-authored-by: SBado <[email protected]>
1 parent ee41bb5 commit 2916ff3

File tree

32 files changed

+281
-28
lines changed

32 files changed

+281
-28
lines changed

backend/internal/nginx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ const internalNginx = {
156156
{ssl_forced: host.ssl_forced}, {caching_enabled: host.caching_enabled}, {block_exploits: host.block_exploits},
157157
{allow_websocket_upgrade: host.allow_websocket_upgrade}, {http2_support: host.http2_support},
158158
{hsts_enabled: host.hsts_enabled}, {hsts_subdomains: host.hsts_subdomains}, {access_list: host.access_list},
159-
{certificate: host.certificate}, host.locations[i]);
159+
{certificate: host.certificate}, {proxy_protocol_enabled: host.proxy_protocol_enabled},
160+
{loadbalancer_address: host.loadbalancer_address}, host.locations[i]);
160161

161162
if (locationCopy.forward_host.indexOf('/') > -1) {
162163
const splitted = locationCopy.forward_host.split('/');
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const migrate_name = 'proxy_protocol';
2+
const logger = require('../logger').migrate;
3+
4+
/**
5+
* Migrate
6+
*
7+
* @see http://knexjs.org/#Schema
8+
*
9+
* @param {Object} knex
10+
* @param {Promise} Promise
11+
* @returns {Promise}
12+
*/
13+
exports.up = function (knex/*, Promise*/) {
14+
logger.info('[' + migrate_name + '] Migrating Up...');
15+
16+
return knex.schema.table('proxy_host', function (proxy_host) {
17+
proxy_host.integer('proxy_protocol_enabled').notNull().defaultTo(0);
18+
proxy_host.string('loadbalancer_address').notNull().defaultTo('');
19+
})
20+
.then(() => {
21+
logger.info('[' + migrate_name + '] proxy_host Table altered');
22+
23+
return knex.schema.table('stream', function (stream) {
24+
stream.integer('proxy_protocol_enabled').notNull().defaultTo(0);
25+
stream.string('loadbalancer_address').notNull().defaultTo('');
26+
})
27+
.then(() => {
28+
logger.info('[' + migrate_name + '] stream Table altered');
29+
});
30+
});
31+
32+
};
33+
34+
/**
35+
* Undo Migrate
36+
*
37+
* @param {Object} knex
38+
* @param {Promise} Promise
39+
* @returns {Promise}
40+
*/
41+
exports.down = function (knex/*, Promise*/) {
42+
return knex.schema.table('proxy_host', function (proxy_host) {
43+
proxy_host.dropColumn('proxy_protocol_enabled');
44+
proxy_host.dropColumn('loadbalancer_address');
45+
})
46+
.then(function () {
47+
logger.info('[' + migrate_name + '] proxy_host Table altered');
48+
return knex.schema.table('stream', function (stream) {
49+
stream.dropColumn('proxy_protocol_enabled');
50+
stream.dropColumn('loadbalancer_address');
51+
})
52+
.then(function () {
53+
logger.info('[' + migrate_name + '] stream Table altered');
54+
});
55+
});
56+
};

backend/models/proxy_host.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const boolFields = [
2121
'enabled',
2222
'hsts_enabled',
2323
'hsts_subdomains',
24+
'proxy_protocol_enabled',
2425
];
2526

2627
class ProxyHost extends Model {

backend/models/stream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const boolFields = [
1313
'is_deleted',
1414
'tcp_forwarding',
1515
'udp_forwarding',
16+
'proxy_protocol_enabled',
1617
];
1718

1819
class Stream extends Model {

backend/schema/common.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@
110110
"caching_enabled": {
111111
"description": "Should we cache assets",
112112
"type": "boolean"
113+
},
114+
"proxy_protocol_enabled": {
115+
"description": "Should the proxy_procotol be enabled",
116+
"type": "boolean"
117+
},
118+
"loadbalancer_address": {
119+
"description": "Hostname, IP or CIDR range of the load balancer",
120+
"type": "string",
121+
"minLength": 0,
122+
"maxLength": 255
113123
}
114124
}
115125
}

backend/schema/components/proxy-host-object.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"locations",
2424
"hsts_enabled",
2525
"hsts_subdomains",
26-
"certificate"
26+
"certificate",
27+
"proxy_protocol_enabled",
28+
"loadbalancer_address"
2729
],
2830
"additionalProperties": false,
2931
"properties": {
@@ -137,6 +139,12 @@
137139
}
138140
]
139141
},
142+
"proxy_protocol_enabled": {
143+
"$ref": "../common.json#/properties/proxy_protocol_enabled"
144+
},
145+
"loadbalancer_address": {
146+
"$ref": "../common.json#/properties/loadbalancer_address"
147+
},
140148
"owner": {
141149
"$ref": "./user-object.json"
142150
},

backend/schema/components/stream-object.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "object",
33
"description": "Stream object",
4-
"required": ["id", "created_on", "modified_on", "owner_user_id", "incoming_port", "forwarding_host", "forwarding_port", "tcp_forwarding", "udp_forwarding", "enabled", "meta"],
4+
"required": ["id", "created_on", "modified_on", "owner_user_id", "incoming_port", "forwarding_host", "forwarding_port", "tcp_forwarding", "udp_forwarding", "enabled", "meta", "proxy_protocol_enabled", "loadbalancer_address"],
55
"additionalProperties": false,
66
"properties": {
77
"id": {
@@ -55,6 +55,12 @@
5555
},
5656
"meta": {
5757
"type": "object"
58+
},
59+
"proxy_protocol_enabled": {
60+
"$ref": "../common.json#/properties/proxy_protocol_enabled"
61+
},
62+
"loadbalancer_address": {
63+
"$ref": "../common.json#/properties/loadbalancer_address"
5864
}
5965
}
6066
}

backend/schema/paths/nginx/proxy-hosts/get.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
"enabled": true,
5151
"locations": null,
5252
"hsts_enabled": false,
53-
"hsts_subdomains": false
53+
"hsts_subdomains": false,
54+
"proxy_protocol_enabled": false,
55+
"loadbalancer_address": ""
5456
}
5557
]
5658
}

backend/schema/paths/nginx/proxy-hosts/hostID/get.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
"enabled": true,
5151
"locations": null,
5252
"hsts_enabled": false,
53-
"hsts_subdomains": false
53+
"hsts_subdomains": false,
54+
"proxy_protocol_enabled": false,
55+
"loadbalancer_address": ""
5456
}
5557
}
5658
},

backend/schema/paths/nginx/proxy-hosts/hostID/put.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@
7979
},
8080
"locations": {
8181
"$ref": "../../../../components/proxy-host-object.json#/properties/locations"
82+
},
83+
"proxy_protocol_enabled": {
84+
"$ref": "../../../../components/proxy-host-object.json#/properties/proxy_protocol_enabled"
85+
},
86+
"loadbalancer_address": {
87+
"$ref": "../../../../components/proxy-host-object.json#/properties/loadbalancer_address"
8288
}
8389
}
8490
}
@@ -116,6 +122,8 @@
116122
"enabled": true,
117123
"hsts_enabled": false,
118124
"hsts_subdomains": false,
125+
"proxy_protocol_enabled": false,
126+
"loadbalancer_address": "",
119127
"owner": {
120128
"id": 1,
121129
"created_on": "2024-10-07T22:43:55.000Z",

0 commit comments

Comments
 (0)