Harden entry safety, unify runtime config, bound document unpacking
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled

Shared-IP safety: entry autoban and entry notifications default off, and a
shared IP is treated as review evidence only. ban_user/ban_cluster refuse
reason=entry_ip_collision (also with the legacy flag set to 1), so token status
and quota are never touched; explicit admin moderation still works.

Reproducible startup: new bot/runtime_config.py and scripts/run.py load the
repository .env (or --env-file) without shell interpolation, normalize
config/DB/upstream aliases, and make the bot, Mini App, gateway, econ cap,
account admin, mk_daemon, entry admin and key notifications resolve the same
paths. "run.py <target> --check" is an offline preflight that starts nothing
and reports placeholders, missing upstream DB and invalid data directories.

Resource limits: aggregate Office decompression, a 400 read-entry cap and a
per-row XLSX cell budget stop early; truncated or corrupt archives are
reported instead of raising.

Deploy and docs: only source-backed systemd units remain, and
deploy/runtime.env.example documents the environment contract including the
0600 session-secret file rules. Removed the destructive
"cp bot/iishko_bot.py bot/grok_bot.py" instruction, the unused generated site/
snapshot and the unsupported iishko-ts staging unit; corrected .env.example,
README, ARCHITECTURE, SECURITY, docs/native-gateway.md and iishko-ts/README.md.

Tests: entry safety, runtime bootstrap, economy paths, file intake, deploy
contract, abilities_guard CLI, and a startup smoke that launches all three
components through scripts/run.py with non-loopback network blocked. Every
config reader, selfcheck included, accepts a UTF-8 BOM.

Verified on this tree: pytest 716 passed + 322 subtests, node --test 73/73,
go test and go vet clean, selfcheck --source-only ok, gitleaks worktree and
history 0 findings. No production or live-split changes are included.
This commit is contained in:
Vlad Gothbreach
2026-10-31 00:39:35 +03:00
parent 52018ca568
commit af292ff15d
52 changed files with 2858 additions and 551 deletions
+11 -5
View File
@@ -17,14 +17,16 @@ sys.path[:0] = os.environ.get("IISHKO_RUNTIME_PATHS", os.environ.get("IISHKO_APP
import key_issue_guard
from account_limits import account_uid, account_token_names
import account_balances
from runtime_config import bot_db_path, econ_state_path, gateway_db_path
_so = sys.stdout
sys.stdout = sys.stderr
try:
import grok_bot as g
finally:
sys.stdout = _so
BOT_DB = os.environ.get("IISHKO_BOT_DB") or os.environ.get("GROK_BOT_DB", "/opt/grok-bot/bot.db")
GW_DB = g.CFG['newapi_db']
BOT_DB = bot_db_path(g.CFG["bot_db"])
# Same value the imported bot resolved, so both sides share one gateway database.
GW_DB = g.CFG.get('newapi_db') or gateway_db_path()
Q = g.QUOTA_PER_UNIT
@@ -379,17 +381,21 @@ def cmd_reveal(uid, n):
return {'ok': True, 'key': 'sk-' + r['key'], 'name': r['name']}
def _read_pause_state(state_path='/opt/grok-bot/econ_cap_state.json'):
def _state_path(state_path=None):
return state_path or econ_state_path()
def _read_pause_state(state_path=None):
# [FIX-2410] чтение JSON-состояния вынесено из BEGIN IMMEDIATE-транзакции
try:
with open(state_path, encoding='utf-8') as fh:
with open(_state_path(state_path), encoding='utf-8') as fh:
state = json.load(fh)
return state if isinstance(state, dict) else {}
except (OSError, ValueError):
return {}
def _daily_pause_info(con, row, user, state=None, state_path='/opt/grok-bot/econ_cap_state.json'):
def _daily_pause_info(con, row, user, state=None, state_path=None):
if int(row['status']) != 2 or user.get('key_locked'):
return {}
try:
+8 -7
View File
@@ -41,6 +41,7 @@ import entry_admin
import miniapp_guard
import gateway_commerce
import commerce_access
from runtime_config import bot_config_path, effective_bot_config, notifications_enabled
import community_board
import account_balances
from account_limits import account_uid
@@ -70,12 +71,13 @@ def _model_metadata_rows(model_ids):
return reference or None
log = logging.getLogger("iishko-webapp")
with open(os.environ.get("GROK_BOT_CONFIG", "/opt/grok-bot/config.json"), encoding="utf-8") as config_file:
CFG = json.load(config_file)
with open(bot_config_path(), encoding="utf-8-sig") as config_file:
CFG = effective_bot_config(json.load(config_file))
BOT_TOKEN = CFG["bot_token"]
BOT_DB = os.environ.get("IISHKO_BOT_DB") or os.environ.get("GROK_BOT_DB", "/opt/grok-bot/bot.db")
BOT_DB = CFG["bot_db"]
entry_admin.BOT_DB = BOT_DB
UPTIME_DB = os.environ.get("GROK_UPTIME_DB", os.path.join(os.path.dirname(BOT_DB), "model_uptime.db"))
NEWAPI_DB = CFG.get("newapi_db", "/opt/grok-gateway/new-api/one-api.db")
NEWAPI_DB = CFG["newapi_db"]
QUOTA_PER_USD = 500000
ADMIN_IDS = {int(value) for value in os.environ.get("IISHKO_ADMIN_IDS", "").split(",") if value.strip().isdigit()}
ADMIN_IDS.update(value for value in CFG.get("admin_ids", []) if type(value) is int and value > 0)
@@ -2261,7 +2263,7 @@ async def api_support_get(req):
async def _support_notify(admin_id, text, reply_markup=None):
if os.environ.get("IISHKO_NOTIFICATIONS_ENABLED", "1") == "0":
if not notifications_enabled():
raise NotificationError(retryable=False)
payload = {"chat_id": admin_id, "text": text, "disable_web_page_preview": True}
if reply_markup:
@@ -2324,8 +2326,7 @@ async def _support_lifecycle(app):
worker = SupportOutbox(_SUPPORT, lambda: ADMIN_IDS, _support_notify)
app["support_worker"] = worker
task = None
if (os.environ.get("IISHKO_SUPPORT_DELIVERY_ENABLED", "1") != "0" and
os.environ.get("IISHKO_NOTIFICATIONS_ENABLED", "1") != "0"):
if notifications_enabled("support"):
task = asyncio.create_task(worker.run(), name="iishko-support-outbox")
app["support_task"] = task
try: