Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add even more features #1855

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [FEATURE] Add configurable limit for SecRequestBodyNoFilesLimit in ModSecurity via the `MODSECURITY_REQ_BODY_NO_FILES_LIMIT` setting
- [FEATURE] Add multi-user support in `Auth basic` plugin
- [FEATURE] Add support for TCP toggle listening in server-stream configuration (now UDP doesn't replace TCP when activated)
- [FEATURE] Made `LISTEN_STREAM_PORT` and `LISTEN_STREAM_PORT_SSL` settings multiples to allow listening on multiple ports
- [DEPRECATION] Remove `X-XSS-Protection` header from the `header` plugin as it is deprecated
- [DEPS] Updated coreruleset-v4 version to v4.10.0

Expand Down
30 changes: 15 additions & 15 deletions src/common/confs/server-stream/server-stream.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ server {
server_name '{{ SERVER_NAME.split(" ")[0] }}';

# listen
{% if LISTEN_STREAM == "yes" +%}
{% if USE_TCP == "yes" %}
listen 0.0.0.0:{{ LISTEN_STREAM_PORT }} reuseport{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% endif %}
{% if USE_UDP == "yes" %}
listen 0.0.0.0:{{ LISTEN_STREAM_PORT }} udp reuseport{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% endif %}
{% endif %}
{% if USE_IPV6 == "yes" +%}
{% if USE_TCP == "yes" %}
listen [::]:{{ LISTEN_STREAM_PORT }} reuseport{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% endif %}
{% if USE_UDP == "yes" %}
listen [::]:{{ LISTEN_STREAM_PORT }} udp reuseport{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% endif %}
{% if LISTEN_STREAM == "yes" %}
{%- set protocols = [] %}
{%- if USE_TCP == "yes" %}{% if protocols.append("tcp") %}{% endif %}{% endif %}
{%- if USE_UDP == "yes" %}{% if protocols.append("udp") %}{% endif %}{% endif %}

{%- for k, listen_stream_port in all.items() if k.startswith("LISTEN_STREAM_PORT") and not k.startswith("LISTEN_STREAM_PORT_SSL") %}
{% for proto in protocols %}
{% set udp_directive = " udp" if proto == "udp" else "" %}
{% set proxy_directive = " proxy_protocol" if USE_PROXY_PROTOCOL == "yes" else "" %}
listen 0.0.0.0:{{ listen_stream_port }}{{ udp_directive }} reuseport{{ proxy_directive }};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ listen_stream_port }}{{ udp_directive }} reuseport{{ proxy_directive }};
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}

# custom config
Expand Down
10 changes: 7 additions & 3 deletions src/common/confs/server-stream/ssl-certificate-stream-lua.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ ssl_dhparam /etc/nginx/dhparam;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
{% endif %}

listen 0.0.0.0:{{ LISTEN_STREAM_PORT_SSL }} ssl {% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% if USE_IPV6 == "yes" +%}
listen [::]:{{ LISTEN_STREAM_PORT_SSL }} ssl {% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol {% endif %};
{% if LISTEN_STREAM == "yes" %}
{% for k, port in all.items() if k.startswith("LISTEN_STREAM_PORT_SSL") %}
listen 0.0.0.0:{{ port }} ssl{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol{% endif %};
{% if USE_IPV6 == "yes" %}
listen [::]:{{ port }} ssl{% if USE_PROXY_PROTOCOL == "yes" %} proxy_protocol{% endif %};
{% endif %}
{% endfor %}
{% endif %}

ssl_certificate_by_lua_block {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def upgrade() -> None:
with op.batch_alter_table("bw_services_settings") as batch_op:
batch_op.create_foreign_key("bw_services_settings_ibfk_1", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

# Update bw_settings.default from String(4096) to TEXT
op.alter_column("bw_settings", "default", existing_type=mysql.VARCHAR(length=4096), type_=sa.TEXT(), existing_nullable=True)
# Update bw_instances.status from Enum("loading", "up", "down", name="instance_status_enum") to Enum("loading", "up", "down", "failover", name="instance_status_enum")
op.alter_column(
"bw_instances",
"status",
existing_type=mysql.ENUM("loading", "up", "down", name="instance_status_enum"),
type_=mysql.ENUM("loading", "up", "down", "failover", name="instance_status_enum"),
existing_nullable=False,
)

# Drop bw_ui_users.id column
op.drop_column("bw_ui_users", "id")
Expand Down Expand Up @@ -91,7 +97,13 @@ def downgrade() -> None:
with op.batch_alter_table("bw_services_settings") as batch_op:
batch_op.create_foreign_key("bw_services_settings_ibfk_1", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

op.alter_column("bw_settings", "default", existing_type=sa.TEXT(), type_=mysql.VARCHAR(length=4096), existing_nullable=True)
op.alter_column(
"bw_instances",
"status",
existing_type=mysql.ENUM("loading", "up", "down", "failover", name="instance_status_enum"),
type_=mysql.ENUM("loading", "up", "down", name="instance_status_enum"),
existing_nullable=False,
)

# Re-add bw_ui_users.id and index on username
op.add_column("bw_ui_users", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def upgrade():
batch_op.drop_column("obfuscation_file")
batch_op.drop_column("obfuscation_checksum")

# Update bw_settings.default from String(4096) to TEXT
op.alter_column("bw_settings", "default", existing_type=mysql.VARCHAR(length=4096), type_=sa.TEXT(), existing_nullable=True)

# bw_instances changes
with op.batch_alter_table("bw_instances") as batch_op:
batch_op.add_column(sa.Column("name", sa.String(256), nullable=True))
Expand Down Expand Up @@ -389,6 +392,9 @@ def downgrade():
op.create_primary_key("bw_settings_pkey", "bw_settings", ["id", "name"])
op.create_unique_constraint("id", "bw_settings", ["id"])

# Update bw_settings.default from TEXT to String(4096)
op.alter_column("bw_settings", "default", existing_type=sa.TEXT(), type_=mysql.VARCHAR(length=4096), existing_nullable=True)

# bw_jobs revert: drop run_async, add success and last_run
with op.batch_alter_table("bw_jobs") as batch_op:
batch_op.drop_column("run_async")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ def upgrade() -> None:
with op.batch_alter_table("bw_services_settings") as batch_op:
batch_op.create_foreign_key("bw_services_settings_ibfk_1", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

# Update bw_settings.default from String(4096) to TEXT
op.alter_column("bw_settings", "default", existing_type=mysql.VARCHAR(length=4096), type_=sa.TEXT(), existing_nullable=True)
# Update bw_instances.status from Enum("loading", "up", "down", name="instance_status_enum") to Enum("loading", "up", "down", "failover", name="instance_status_enum")
op.alter_column(
"bw_instances",
"status",
existing_type=mysql.ENUM("loading", "up", "down", name="instance_status_enum"),
type_=mysql.ENUM("loading", "up", "down", "failover", name="instance_status_enum"),
existing_nullable=False,
)

# Drop bw_ui_users.id column
op.drop_column("bw_ui_users", "id")
Expand Down Expand Up @@ -91,7 +97,13 @@ def downgrade() -> None:
with op.batch_alter_table("bw_services_settings") as batch_op:
batch_op.create_foreign_key("bw_services_settings_ibfk_1", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

op.alter_column("bw_settings", "default", existing_type=sa.TEXT(), type_=mysql.VARCHAR(length=4096), existing_nullable=True)
op.alter_column(
"bw_instances",
"status",
existing_type=mysql.ENUM("loading", "up", "down", "failover", name="instance_status_enum"),
type_=mysql.ENUM("loading", "up", "down", name="instance_status_enum"),
existing_nullable=False,
)

# Re-add bw_ui_users.id and index on username
op.add_column("bw_ui_users", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def upgrade():
batch_op.drop_column("obfuscation_file")
batch_op.drop_column("obfuscation_checksum")

# Update bw_settings.default from String(4096) to TEXT
op.alter_column("bw_settings", "default", existing_type=mysql.VARCHAR(length=4096), type_=sa.TEXT(), existing_nullable=True)

# bw_instances changes
with op.batch_alter_table("bw_instances") as batch_op:
batch_op.add_column(sa.Column("name", sa.String(256), nullable=True))
Expand Down Expand Up @@ -389,6 +392,9 @@ def downgrade():
op.create_primary_key("bw_settings_pkey", "bw_settings", ["id", "name"])
op.create_unique_constraint("id", "bw_settings", ["id"])

# Update bw_settings.default from TEXT to String(4096)
op.alter_column("bw_settings", "default", existing_type=sa.TEXT(), type_=mysql.VARCHAR(length=4096), existing_nullable=True)

# bw_jobs revert: drop run_async, add success and last_run
with op.batch_alter_table("bw_jobs") as batch_op:
batch_op.drop_column("run_async")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def upgrade():
batch_op.alter_column("creation_date", existing_type=sa.DateTime(timezone=True), nullable=False)
batch_op.alter_column("last_seen", existing_type=sa.DateTime(timezone=True), nullable=False)

# Update bw_settings.default from String(4096) to TEXT
op.alter_column("bw_settings", "default", existing_type=sa.String(4096), type_=sa.Text, existing_nullable=True)

# Update version
op.execute("UPDATE bw_metadata SET version = '1.6.0-beta' WHERE id = 1")

Expand Down Expand Up @@ -336,6 +339,9 @@ def downgrade():
op.drop_table("bw_ui_users")
op.rename_table("bw_ui_users_old", "bw_ui_users")

# Reverse bw_settings.default from TEXT to String(4096)
op.alter_column("bw_settings", "default", existing_type=sa.Text, type_=sa.String(4096), existing_nullable=True)

# 4. Drop new UI and templates tables
op.drop_table("bw_template_custom_configs")
op.drop_table("bw_template_settings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ def upgrade() -> None:
with op.batch_alter_table("bw_jobs_cache") as batch_op:
batch_op.create_foreign_key("bw_jobs_cache_service_id_fkey", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

# Update bw_instances.status from Enum("loading", "up", "down", name="instance_status_enum") to Enum("loading", "up", "down", "failover", name="instance_status_enum")
op.execute("ALTER TYPE instance_status_enum ADD VALUE 'failover'")
op.alter_column(
"bw_instances",
"status",
existing_type=postgresql.ENUM("loading", "up", "down", name="instance_status_enum", create_type=False),
type_=postgresql.ENUM("loading", "up", "down", "failover", name="instance_status_enum", create_type=False),
existing_nullable=False,
)

# Update the version in bw_metadata
op.execute("UPDATE bw_metadata SET version = '1.6.0-rc1' WHERE id = 1")

Expand Down Expand Up @@ -283,5 +293,15 @@ def downgrade() -> None:
with op.batch_alter_table("bw_jobs_cache") as batch_op:
batch_op.create_foreign_key("bw_jobs_cache_service_id_fkey", "bw_services", ["service_id"], ["id"], onupdate="CASCADE", ondelete="CASCADE")

# Update bw_instances.status from Enum("loading", "up", "down", "failover", name="instance_status_enum") to Enum("loading", "up", "down", name="instance_status_enum")
op.execute("ALTER TYPE instance_status_enum DROP VALUE 'failover'")
op.alter_column(
"bw_instances",
"status",
existing_type=postgresql.ENUM("loading", "up", "down", "failover", name="instance_status_enum", create_type=False),
type_=postgresql.ENUM("loading", "up", "down", name="instance_status_enum", create_type=False),
existing_nullable=False,
)

# Revert version
op.execute("UPDATE bw_metadata SET version = '1.6.0-beta' WHERE id = 1")
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ def upgrade() -> None:
op.drop_table("bw_jobs_cache")
op.rename_table("bw_jobs_cache_new", "bw_jobs_cache")

# --- bw_instances ---
# Old schema:
# status: sa.Enum("loading", "up", "down", name="instance_status_enum")
# New schema:
# status: Enum("loading", "up", "down", "failover", name="instance_status_enum")
op.create_table(
"bw_instances_new",
sa.Column("hostname", sa.String(256), primary_key=True),
sa.Column("name", sa.String(256), nullable=False, default="manual instance"),
sa.Column("port", sa.Integer, nullable=False),
sa.Column("server_name", sa.String(256), nullable=False),
sa.Column("type", sa.Enum("static", "container", "pod", name="instance_type_enum"), nullable=False, default="static"),
sa.Column("status", sa.Enum("loading", "up", "down", "failover", name="instance_status_enum"), nullable=False, default="loading"),
sa.Column("method", sa.Enum("ui", "scheduler", "autoconf", "manual", "wizard", name="methods_enum"), nullable=False, default="manual"),
sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False),
sa.Column("last_seen", sa.DateTime(timezone=True), nullable=False),
)

op.execute(
"""
INSERT INTO bw_instances_new (hostname, name, port, server_name, type, status, method, creation_date, last_seen)
SELECT hostname, name, port, server_name, type, status, method, creation_date, last_seen FROM bw_instances
"""
)

op.drop_table("bw_instances")
op.rename_table("bw_instances_new", "bw_instances")

# Re-enable foreign keys
op.execute("PRAGMA foreign_keys=ON;")

Expand Down
2 changes: 1 addition & 1 deletion src/common/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
PLUGIN_TYPES_ENUM = Enum("core", "external", "ui", "pro", name="plugin_types_enum")
PRO_STATUS_ENUM = Enum("active", "invalid", "expired", "suspended", name="pro_status_enum")
INSTANCE_TYPE_ENUM = Enum("static", "container", "pod", name="instance_type_enum")
INSTANCE_STATUS_ENUM = Enum("loading", "up", "down", name="instance_status_enum")
INSTANCE_STATUS_ENUM = Enum("loading", "up", "down", "failover", name="instance_status_enum")
Base = declarative_base()


Expand Down
6 changes: 4 additions & 2 deletions src/common/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@
"id": "listen-stream-port",
"label": "Listen stream port",
"regex": "^[0-9]+$",
"type": "text"
"type": "text",
"multiple": "listen-stream-ports"
},
"LISTEN_STREAM_PORT_SSL": {
"context": "multisite",
Expand All @@ -278,7 +279,8 @@
"id": "listen-stream-port-ssl",
"label": "Listen stream port ssl",
"regex": "^[0-9]+$",
"type": "text"
"type": "text",
"multiple": "listen-stream-ports-ssl"
},
"USE_TCP": {
"context": "multisite",
Expand Down
17 changes: 15 additions & 2 deletions src/scheduler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ def healthcheck_job():
continue

if resp["msg"] == "loading":
if db_instance["status"] == "failover":
HEALTHCHECK_LOGGER.warning(f"Instance {db_instance['hostname']} is in failover mode, skipping sending config ...")
continue

HEALTHCHECK_LOGGER.info(f"Instance {bw_instance.endpoint} is loading, sending config ...")
api_caller = ApiCaller([bw_instance])
api_caller.send_files(CUSTOM_CONFIGS_PATH, "/custom_configs")
Expand Down Expand Up @@ -809,9 +813,18 @@ def check_plugin_changes(_type: Literal["external", "pro"] = "external"):
status = responses.get(db_instance["hostname"], {"status": "down"}).get("status", "down")
if status == "success":
success = True
ret = SCHEDULER.db.update_instance(db_instance["hostname"], "up" if status == "success" else "down")
ret = SCHEDULER.db.update_instance(
db_instance["hostname"],
(
"up"
if status == "success"
else ("failover" if responses.get(db_instance["hostname"], {}).get("msg") == "config check failed" else "down")
),
)
if ret:
LOGGER.error(f"Couldn't update instance {db_instance['hostname']} status to down in the database: {ret}")
LOGGER.error(
f"Couldn't update instance {db_instance['hostname']} status to {'up' if status == 'success' else 'down'} in the database: {ret}"
)

if status == "success":
found = False
Expand Down
6 changes: 3 additions & 3 deletions src/ui/app/templates/instances.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
{% if instance.status == "up" %}
<span id="status-{{ instance.hostname }}"
class="badge rounded-pill bg-label-primary">Up</span>
{% elif instance.status == "down" %}
{% elif instance.status == "loading" %}
<span id="status-{{ instance.hostname }}"
class="badge rounded-pill bg-label-danger">Down</span>
class="badge rounded-pill bg-label-warning">Loading</span>
{% else %}
<span id="status-{{ instance.hostname }}"
class="badge rounded-pill bg-label-warning">Loading</span>
class="badge rounded-pill bg-label-danger">{{ instance.status | title }}</span>
{% endif %}
</td>
<td>
Expand Down
Loading