Skip to content

Commit 0cd436e

Browse files
committed
PROXY protocol working for proxy hosts. Testing on stream, redirection and 404 hosts
1 parent 2feb6cc commit 0cd436e

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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('enable_proxy_protocol').notNull().unsigned().defaultTo(0);
18+
proxy_host.string('load_balancer_ip').notNull().defaultTo('');
19+
})
20+
.then(() => {
21+
logger.info('[' + migrate_name + '] proxy_host Table altered');
22+
});
23+
24+
};
25+
26+
/**
27+
* Undo Migrate
28+
*
29+
* @param {Object} knex
30+
* @param {Promise} Promise
31+
* @returns {Promise}
32+
*/
33+
exports.down = function (knex/*, Promise*/) {
34+
return knex.schema.table('proxy_host', (proxy_host) => {
35+
proxy_host.dropColumn('enable_proxy_protocol');
36+
proxy_host.dropColumn('load_balancer_ip');
37+
})
38+
.then(function () {
39+
logger.info('[' + migrate_name + '] MIGRATING DOWN proxy_host Table altered');
40+
});
41+
42+
// logger.warn('[' + migrate_name + '] You can\'t migrate down this one.');
43+
// return Promise.resolve(true);
44+
};

backend/migrations/22021009153423_proxy_protocol.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const logger = require('../logger').migrate;
1111
* @returns {Promise}
1212
*/
1313
exports.up = function (knex/*, Promise*/) {
14-
logger.info('[' + migrate_name + '] Migrating Up...');
14+
logger.info('[' + migrate_name + '] Migrating Up...');
1515

16-
return knex.schema.table('proxy_host', function (proxy_host) {
17-
proxy_host.integer('enable_proxy_protocol').notNull().unsigned().defaultTo(0);
18-
proxy_host.string('load_balancer_ip').notNull().defaultTo('');
19-
})
20-
.then(() => {
21-
logger.info('[' + migrate_name + '] proxy_host Table altered');
22-
});
16+
return knex.schema.table('proxy_host', function (proxy_host) {
17+
proxy_host.integer('enable_proxy_protocol').notNull().unsigned().defaultTo(0);
18+
proxy_host.string('load_balancer_ip').notNull().defaultTo('');
19+
})
20+
.then(() => {
21+
logger.info('[' + migrate_name + '] proxy_host Table altered - PROXY protocol added');
22+
});
2323

2424
};
2525

@@ -30,7 +30,15 @@ exports.up = function (knex/*, Promise*/) {
3030
* @param {Promise} Promise
3131
* @returns {Promise}
3232
*/
33-
exports.down = function (knex, Promise) {
34-
logger.warn('[' + migrate_name + '] You can\'t migrate down this one.');
35-
return Promise.resolve(true);
33+
exports.down = function (knex/*, Promise*/) {
34+
return knex.schema.table('proxy_host', (proxy_host) => {
35+
proxy_host.dropColumn('enable_proxy_protocol');
36+
proxy_host.dropColumn('load_balancer_ip');
37+
})
38+
.then(function () {
39+
logger.info('[' + migrate_name + '] MIGRATING DOWN proxy_host Table altered - PROXY protocol removed');
40+
});
41+
42+
// logger.warn('[' + migrate_name + '] You can\'t migrate down this one.');
43+
// return Promise.resolve(true);
3644
};

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ENV SUPPRESS_NO_CONFIG_WARNING=1 \
2424
MODSEC_ENABLE="0" \
2525
MODSEC_ADMIN_PANEL="0" \
2626
CROWDSEC_UPDATE_DIR='/cs-update' \
27+
CROWDSEC_TEMPLATES='/crowdsec/templates' \
2728
GEOLITE_DB_GRAB="0" \
2829
GEOLITE2_DB_GRAB="0" \
2930
GEOIP_DIR="/geoip_db" \

frontend/js/app/nginx/proxy/form.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ module.exports = Mn.View.extend({
172172
data.block_exploits = !!data.block_exploits;
173173
data.caching_enabled = !!data.caching_enabled;
174174
data.allow_websocket_upgrade = !!data.allow_websocket_upgrade;
175+
data.enable_proxy_protocol = !!data.enable_proxy_protocol;
175176
data.http2_support = !!data.http2_support;
176177
data.hsts_enabled = !!data.hsts_enabled;
177178
data.hsts_subdomains = !!data.hsts_subdomains;

scripts/frontend-build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ if hash docker 2>/dev/null; then
1111
docker pull "${DOCKER_IMAGE}"
1212
cd "${DIR}/.."
1313
echo -e "${BLUE}${CYAN}Building Frontend ...${RESET}"
14-
docker run --rm -e CI=true -v "$(pwd)/frontend:/app/frontend" -v "$(pwd)/global:/app/global" -w /app/frontend "$DOCKER_IMAGE" sh -c "yarn install && yarn build && yarn build && chown -R $(id -u):$(id -g) /app/frontend"
14+
docker run --rm -e CI=true -v "$(pwd)/frontend:/app/frontend" -v "$(pwd)/global:/app/global" \
15+
-w /app/frontend "$DOCKER_IMAGE" sh \
16+
-c "yarn install && yarn build && yarn build && chown -R $(id -u):$(id -g) /app/frontend"
1517
echo -e "${BLUE}${GREEN}Building Frontend Complete${RESET}"
1618
else
1719
echo -e "${RED}❯ docker command is not available${RESET}"

0 commit comments

Comments
 (0)