fix: classify upstream failures and prevent empty billed responses
This commit is contained in:
1 parent
b455d8d79f
commit
9acc69d4c7
28 files changed
+1449
-131
No files matched your search
@@ -46,6 +46,9 @@ GATEWAY_DEFAULT_MODEL_CONCURRENCY=4
|
||||
GATEWAY_DEFAULT_KEY_CONCURRENCY=4
|
||||
TASK_MAX_QUEUED_PER_MODEL=100
|
||||
MOYI_TASK_WORKER_INTERVAL_MS=1000
|
||||
# Accepted async tasks retry polling for up to this duration, then release
|
||||
# their wallet hold with an unknown-result timeout (upstream is not cancelled).
|
||||
MOYI_TASK_PROVIDER_TIMEOUT_MS=3600000
|
||||
|
||||
# Registration requires a valid invitation AND an email/SMS verification code.
|
||||
# Unconfigured channels fail closed; admins can still create user accounts.
|
||||
|
||||
@@ -52,8 +52,14 @@ def updated_environment(original, account, password):
|
||||
require(password.strip() and not any(ord(char) < 32 or ord(char) == 127 for char in password),
|
||||
"Password must be nonblank and cannot contain control characters.")
|
||||
require(password != "admin123", "The development default password is not allowed.")
|
||||
# Append effective overrides, then ask Compose to validate them. Do not parse
|
||||
# or rewrite arbitrary existing dotenv values, which may be multiline/quoted.
|
||||
# Replace the two owner settings in place before appending the effective
|
||||
# values. Compose accepts later overrides, but duplicate assignments make
|
||||
# the resulting dotenv file ambiguous and can silently mask a real secret.
|
||||
# Do not parse or rewrite arbitrary existing dotenv values, which may be
|
||||
# multiline/quoted.
|
||||
lines = [line for line in original.splitlines() if not re.match(
|
||||
r"^\s*(?:export\s+)?(?:ADMIN_ACCOUNT|ADMIN_PASSWORD)\s*=", line)]
|
||||
original = "\n".join(lines)
|
||||
values = {"ADMIN_ACCOUNT": account, "ADMIN_PASSWORD": password}
|
||||
return original.rstrip("\r\n") + "\n\n# Owner credentials set by admin_credentials.py\n" + "".join(
|
||||
key + "=" + json.dumps(value, ensure_ascii=False).replace("$", "$$") + "\n"
|
||||
|
||||
@@ -66,6 +66,16 @@ def load_config(env_file, mode):
|
||||
fail("Environment file missing. Run: python3 deploy.py init")
|
||||
if os.name != "nt" and stat.S_IMODE(env_file.stat().st_mode) & 0o077:
|
||||
fail("Environment file must be private. Run chmod 600 on it.")
|
||||
# A later empty assignment silently overrides an earlier valid secret in
|
||||
# Compose. Reject duplicates before resolving or starting any container.
|
||||
seen = set()
|
||||
for line in env_file.read_text(encoding="utf-8-sig").splitlines():
|
||||
match = re.match(r"^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=", line)
|
||||
if match:
|
||||
key = match.group(1)
|
||||
if key in seen:
|
||||
fail("Duplicate environment setting: " + key + ". Keep exactly one assignment; values are not printed.")
|
||||
seen.add(key)
|
||||
config = execute(compose_command(env_file, mode) + ["config", "--format", "json"], capture=True)
|
||||
resolved = json.loads(config)
|
||||
# Compose serializes literal '$' as '$$' for re-parseable config output.
|
||||
|
||||
@@ -52,6 +52,7 @@ services:
|
||||
GATEWAY_QUEUE_POLL_MS: ${GATEWAY_QUEUE_POLL_MS:-100}
|
||||
TASK_MAX_QUEUED_PER_MODEL: ${TASK_MAX_QUEUED_PER_MODEL:-100}
|
||||
MOYI_TASK_WORKER_INTERVAL_MS: ${MOYI_TASK_WORKER_INTERVAL_MS:-1000}
|
||||
MOYI_TASK_PROVIDER_TIMEOUT_MS: ${MOYI_TASK_PROVIDER_TIMEOUT_MS:-3600000}
|
||||
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-10}
|
||||
DB_POOL_MIN_IDLE: ${DB_POOL_MIN_IDLE:-2}
|
||||
JAVA_OPTS: ${JAVA_OPTS:--Xms256m -Xmx1536m -XX:+ExitOnOutOfMemoryError}
|
||||
|
||||
@@ -37,6 +37,25 @@ def configuration():
|
||||
|
||||
|
||||
class DeploymentTests(unittest.TestCase):
|
||||
def test_duplicate_empty_secret_is_rejected_before_compose(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
env_file = Path(directory) / ".env.cloud"
|
||||
env_file.write_text("TRIPO_API_KEY=private-test-value\nTRIPO_API_KEY=\n", encoding="utf-8")
|
||||
env_file.chmod(0o600)
|
||||
with patch.object(deploy, "execute") as execute:
|
||||
with self.assertRaisesRegex(ValueError, "Duplicate environment setting: TRIPO_API_KEY") as error:
|
||||
deploy.load_config(env_file, "https")
|
||||
self.assertNotIn("private-test-value", str(error.exception))
|
||||
execute.assert_not_called()
|
||||
|
||||
def test_commented_assignment_does_not_override_secret(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
env_file = Path(directory) / ".env.cloud"
|
||||
env_file.write_text("# TRIPO_API_KEY=\nTRIPO_API_KEY=private-test-value\n", encoding="utf-8")
|
||||
env_file.chmod(0o600)
|
||||
with patch.object(deploy, "execute", return_value=json.dumps(configuration())):
|
||||
self.assertEqual(deploy.load_config(env_file, "https"), configuration())
|
||||
|
||||
def test_proxy_replaces_forwarding_headers_for_verification_limits(self):
|
||||
routes = (DIRECTORY / "nginx" / "routes.conf").read_text(encoding="utf-8")
|
||||
self.assertEqual(routes.count('proxy_set_header Forwarded "";'), 2)
|
||||
|
||||
Reference in new issue
Block a user