Skip to content
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
4 changes: 4 additions & 0 deletions docs/rcon-investigation.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Traditional UDP RCON compatibility investigation

Current authenticated mode-bridge implementation and its disabled activation
gate are documented in [rcon-mode-bridge.md](rcon-mode-bridge.md). The historical
investigations below retain their original evidence and scope.

Investigation date: 2026-10-26. Server baseline:
`9e3ce3e17532574bbe25e24cbff0174df94c802d`.
No real credential was read or used. No remote runtime was contacted or changed.
Expand Down
112 changes: 112 additions & 0 deletions docs/rcon-mode-bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Authenticated RCON mode bridge

Baseline: protected master `701a7c5df46c5723705dad0408afa44fb89b0ad9`.
The previous `change_mode` preflight remains nonmutating for console, command
buffers and GSC. Authenticated UDP and Source RCON have a separate native ingress
for exactly `change_mode promod`, `change_mode zombies`, or `change_mode` status.
Both registration and ingress require power 100. A command-power metadata change
cannot lower the native floor. No console/GSC invocation inherits an ambient
"authenticated" flag.

Only the authenticated ingress submits a fixed packet over nonblocking Linux
`SOCK_SEQPACKET` to `/run/cod4-mode-bridge/control.sock`. The engine checks the
host peer is UID zero. No path, executable, image reference, shell, Docker API,
password, account name or arbitrary argv crosses this interface. The host validates
kernel peer credentials against the current production container and executable.
No endpoint is mounted or activated by this change. Windows fails closed.

UDP framing is checked against the complete original payload, including ignored
newline/NUL suffixes and truncation, before accepting a mode command. Source
requests are checked against their complete packet frame. Modes reject quotes,
comments, separators, controls and extra arguments. Mode request logging omits raw
arguments. The existing UDP password and Source account authentication remain
responsible for authenticating the administrator.

Authentication hardening found necessary during this investigation:

- Unregistered commands/cvars no longer bypass low-power Source/Webadmin checks
via `Cmd_GetPower == -1`. Registered command permissions remain unchanged.
- Source login identity comes from the exact record returned by `Auth_Authorize`,
not a second username/SteamID-handle lookup. Zero-ID account logins are rejected;
the authenticated master-console login remains supported.
- Webadmin carries the exact matched session record through dispatch and logout;
numeric or duplicate names cannot select another account.
- Sub-100 password administrators cannot reset equal/higher-ranked accounts;
power-100 recovery remains available.
- Source command early exits restore the old invoker and redirect state.

## Asynchronous feedback

Initial output is **submitted**, with an unpredictable operation ID; it is not
acceptance or success. There is no synchronous controller/Docker wait in the game
loop. The frame poll accepts only bounded fixed-enum replies matching that ID.
Embedded NUL, truncated, malformed or mismatched replies are discarded.

After host preflight accepts a durable operation, the engine queues a fixed player
broadcast and acknowledges on the next normal game frame. The host then recreates
the runtime. An engine that disappears cannot cancel the accepted host job; a
still-running engine that fails notification acknowledgment causes denial before
mutation. Network delivery of the notice is not a guaranteed player receipt.

The initiating UDP endpoint receives a safe asynchronous update where possible.
Source clients can poll the status command. The host survives process replacement
and the replacement engine refreshes status; after reconnecting, use:

```text
/rcon change_mode
```

Status reports operation ID, mode, phase and a fixed explanation. Accepted/pending
is never completion. Success requires host verification; `rolled_back` means the
transition failed and the previous exact runtime was verified restored.
`recovery_required` requires operator intervention. Availability is the last host
response and is revalidated for every request.

## Trust and qualification

The qualified engine, native plugins, installed GSC and private authentication
configuration are trusted code/authority. Direct GSC execution cannot submit a
mode request, but a malicious mod that steals or changes the existing credential
can authenticate normally. The bridge is not a sandbox for a compromised game
process. Host authority is still restricted to the two approved immutable images.
Command-policy managers and credential administrators belong to authentication
TCB; do not delegate that authority to untrusted accounts.

Classic UDP RCON is plaintext and has no cryptographic packet nonce. Durable host
request IDs prevent host-request replay/duplicates; they do not repair captured
UDP credentials or network-packet replay. Activation requires protected
administrative transport and explicit operator acceptance of the legacy protocol
boundary. No password is forwarded to the host or added to status/logging.

See workspace `docs/authenticated-mode-bridge.md` for host trust, locking, rollback,
threat model and the gated installation/qualification procedure. Both modes need
independent actual-client qualification, and both images must contain protocol
`C4M1`. No production bridge installation, merge or deployment is automatic.

## Checks

```sh
make -j4
python3 -m unittest discover -s tests -p 'test_*.py'
python3 tests/run_map_rotation.py
python3 tests/run_map_voting.py
```

Native policy fixtures execute the actual bridge, framing, authentication,
Source/Web console, role-reset and session-record functions. Loopback RCON tests
execute the production parser/authentication path, including invalid framing,
unauthenticated requests and numeric-name identity binding. Live-game compatibility
uses the existing disposable Promod/BTD/allied runners with the host endpoint
absent; this verifies disabled-bridge compatibility, not an enabled production
transition. Complete real-image RCON round trips and external rollback remain
operator qualification gates after reviewed merges.

Rollback: retain the host CLI, remove the bridge socket mount/stop the host bridge
only with operator authorization, and revert the focused feature through review.
Do not undo authentication repairs merely to disable switching. Keep production
on its existing approved image until separate activation approval.

Local review evidence (2026-10-27): engine unit suite 79 tests, one optional
client-checkout skip; map rotation/voting checks passed. Protected baselines:
engine `701a7c5df46c5723705dad0408afa44fb89b0ad9`, workspace `b77684d`,
configuration `9f0fa1a0b0c1483ea20a89fc7beaf26c9b7c2201`.
38 changes: 30 additions & 8 deletions src/hl2rcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "g_sv_shared.h"
#include "sv_auth.h"
#include "q_platform.h"
#include "sv_mode_bridge.h"
#include "sapi.h"

#include <stdint.h>
Expand Down Expand Up @@ -193,6 +194,8 @@ qboolean HL2Rcon_SourceRconAuth(netadr_t *from, msg_t *msg, rconUser_t* user){
char buf[MAX_STRING_CHARS];
char stringlinebuf[MAX_STRING_CHARS];
uint64_t steamid;
int authorized_index;
authData_admin_t *authorized;

//packetlen =
MSG_ReadLong(msg);
Expand Down Expand Up @@ -233,15 +236,19 @@ qboolean HL2Rcon_SourceRconAuth(netadr_t *from, msg_t *msg, rconUser_t* user){
goto badrcon;
}

if(Auth_Authorize(username, password) < 0)
authorized_index = Auth_Authorize(username, password);
authorized = authorized_index < 0 ? NULL : Auth_GetAdminFromIndex(authorized_index);
if(!authorized || authorized->steamid == 0)
{
goto badrcon;
}
/* Bind identity to the verified record, never parse a login as a handle. */
steamid = authorized->steamid;
username = authorized->username;

Com_Printf(CON_CHANNEL_DONT_FILTER,"Rcon login from: %s Name: %s\n", NET_AdrToString (from), username);

Cmd_EndTokenizedString();
steamid = Auth_GetSteamID(username);
}else{
steamid = 0;
username = "console";
Expand Down Expand Up @@ -490,7 +497,7 @@ void HL2Rcon_ExecuteConsoleCommand(const char* command, uint64_t steamid)
while ( command[i] != ' ' && command[i] != '\0' && command[i] != '\n' && i < 32 ){
i++;
}
if(i > 29 || i < 3) return;
if(i > 29 || i < 3) goto cleanup;

Q_strncpyz(cmd,command,i+1);

Expand All @@ -502,7 +509,7 @@ void HL2Rcon_ExecuteConsoleCommand(const char* command, uint64_t steamid)
// start redirecting all print outputs to the packet

powercmd = Cmd_GetPower(cmd);
if(powercmd > power)
if(powercmd < 0 || powercmd > power)
{
Com_Printf(CON_CHANNEL_DONT_FILTER,"Insufficient permissions! Power: %d Needed: %d\n", power, powercmd);
}else{
Expand All @@ -519,6 +526,7 @@ void HL2Rcon_ExecuteConsoleCommand(const char* command, uint64_t steamid)
}
}

cleanup:
Com_EndRedirect();
Cmd_SetCurrentInvokerInfo(oldpower, oldinvokerclnum, oldinvokersteamid, oldinvokername);

Expand All @@ -529,6 +537,7 @@ void HL2Rcon_ExecuteConsoleCommand(const char* command, uint64_t steamid)
int HL2Rcon_SourceRconEvent(netadr_t *from, msg_t *msg, int connectionId){

int packettype;
int packetstart, packetlen, commandstart;
int type;
int8_t team;
int8_t clientnum;
Expand Down Expand Up @@ -560,8 +569,8 @@ int HL2Rcon_SourceRconEvent(netadr_t *from, msg_t *msg, int connectionId){

while(msg->readcount < msg->cursize)
{
//packetlen =
MSG_ReadLong(msg);
packetstart = msg->readcount;
packetlen = MSG_ReadLong(msg);

user->lastpacketid = MSG_ReadLong(msg);

Expand Down Expand Up @@ -592,19 +601,32 @@ int HL2Rcon_SourceRconEvent(netadr_t *from, msg_t *msg, int connectionId){

case SERVERDATA_EXECCOMMAND:

commandstart = msg->readcount;
command = MSG_ReadString(msg, stringbuf, sizeof(stringbuf));

//Pop the end of body byte
MSG_ReadByte(msg);

Com_Printf(CON_CHANNEL_DONT_FILTER,"Rcon from: %s command: %s\n", NET_AdrToString(from), command);
Com_Printf(CON_CHANNEL_DONT_FILTER,"Rcon from: %s command: %s\n", NET_AdrToString(from),
SV_RconModeCommand(command) ? "change_mode request (arguments omitted)" : command);

sourceRcon.redirectUser = connectionId+1;
sourceRcon.writeerror = 0;

if(user->steamid != 0 || strcmp(user->rconUsername, "console") == 0)
{
HL2Rcon_ExecuteConsoleCommand(command, user->steamid);
int power = user->steamid ? Auth_GetClPowerBySteamID(user->steamid) : 100;
Com_BeginRedirect(sv_outputbuf, sizeof(sv_outputbuf), HL2Rcon_SourceRconFlushRedirect);
if (SV_RconModeIngress(command, power, NULL,
packetlen >= 10 && packetlen <= msg->cursize-packetstart-4 &&
msg->readcount == packetstart+4+packetlen &&
msg->data[msg->readcount-1] == 0 &&
SV_RconModeFraming(msg->data+commandstart, msg->readcount-commandstart-1))) {
Com_EndRedirect();
} else {
Com_EndRedirect();
HL2Rcon_ExecuteConsoleCommand(command, user->steamid);
}
}
sourceRcon.redirectUser = 0;
if(sourceRcon.writeerror)
Expand Down
23 changes: 18 additions & 5 deletions src/sv_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,32 @@ authData_t auth_admins;
#define AUTH_DEFAULT_POWER 1


const char* Auth_FindSessionID(const char* sessionid)
authData_admin_t* Auth_FindSessionAdmin(const char* sessionid)
{
int i;
authData_admin_t *user;

if(strlen(sessionid) != 64)
if(!sessionid || strlen(sessionid) != 64)
{
return NULL;
}

for(i = 0, user = auth_admins.admins; i < MAX_AUTH_ADMINS; i++, user++){

if(!Q_stricmp(user->sessionid, sessionid))
if(user->steamid && *user->username && !Q_stricmp(user->sessionid, sessionid))
{
return user->username;
return user;
}
}
return NULL;

}

const char* Auth_FindSessionID(const char* sessionid)
{
authData_admin_t *user = Auth_FindSessionAdmin(sessionid);
return user ? user->username : NULL;
}
const char* Auth_GetSessionId(const char* username, const char *password)
{
int handle;
Expand Down Expand Up @@ -351,7 +356,7 @@ void Auth_ListAdmins_f( void ){
authData_admin_t* Auth_GetAdminFromIndex( int index )
{

if(index >= MAX_AUTH_ADMINS)
if(index < 0 || index >= MAX_AUTH_ADMINS)
{
return NULL;
}
Expand Down Expand Up @@ -435,6 +440,14 @@ void Auth_ChangePasswordByMasterAdmin_f()
Com_Printf(CON_CHANNEL_DONT_FILTER,"Admin %s not found.\n",Cmd_Argv(1));
return;
}
/* Password administration cannot take over an equal/higher-ranked account.
* Full-power operators retain account recovery authority. */
if (Cmd_GetInvokerPower() != 100 &&
Auth_GetClPowerBySteamID(id) >= Cmd_GetInvokerPower())
{
Com_PrintError(CON_CHANNEL_DONT_FILTER, "Cannot reset an account at or above your own permission level.\n");
return;
}
Auth_ChangeAdminPassword( id, Cmd_Argv(2) );
}

Expand Down
1 change: 1 addition & 0 deletions src/sv_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ qboolean Auth_InfoAddAdmin(const char* line);
void Auth_WriteAdminConfig(char* buffer, int size);

const char* Auth_FindSessionID(const char* sessionid);
authData_admin_t* Auth_FindSessionAdmin(const char* sessionid);
const char* Auth_GetSessionId(const char* username, const char *password);
void Auth_ApplyUndercoverStatus(client_t* cl);
void Auth_StoreUndercoverStatus(client_t* cl);
Expand Down
4 changes: 2 additions & 2 deletions src/sv_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,8 @@ void SV_LoadMapFromBsp()

void SV_DoHostMigration_f();

/* Artifact selection/recreation belongs to the external operator, never GSC or
* a client-supplied command. Until that boundary is qualified, fail closed. */
/* Generic console/GSC execution remains a nonmutating preflight. Only the
* authenticated raw RCON ingress may submit to the qualified host controller. */
static void SV_ChangeMode_f(void)
{
const char *mode;
Expand Down
10 changes: 9 additions & 1 deletion src/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "xac_helper.h"
#include "db_load.h"
#include "sec_crypto.h"
#include "sv_mode_bridge.h"

#include <string.h>
#include <stdarg.h>
Expand Down Expand Up @@ -1530,9 +1531,15 @@ __optimize3 __regparm2 static void SVC_RemoteCommand( netadr_t *from, msg_t *msg
while(cmd_aux[0] == ' ')//Skipping space after the password
cmd_aux++;

Com_Printf (CON_CHANNEL_SERVER,"Rcon from %s: %s\n", NET_AdrToString (from), cmd_aux );
Com_Printf (CON_CHANNEL_SERVER,"Rcon from %s: %s\n", NET_AdrToString (from),
SV_RconModeCommand(cmd_aux) ? "change_mode request (arguments omitted)" : cmd_aux );

Com_BeginRedirect (sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect);
if (SV_RconModeIngress(cmd_aux, 100, from,
SV_RconModeFraming(msg->data + 8, msg->cursize - 8))) {
Com_EndRedirect();
return;
}
#ifdef PUNKBUSTER
if(!Q_stricmpn(cmd_aux, "pb_sv_", 6)){

Expand Down Expand Up @@ -4107,6 +4114,7 @@ SV_PreFrame
*/
void SV_PreFrame()
{
SV_ModeBridgeFrame();
SV_BotManagerFrame();
SV_UpdateBots();
if ( cvar_modifiedFlags & 0x404 )
Expand Down
Loading
Loading