ADJCJH commited on
Commit
d598e49
·
verified ·
1 Parent(s): 1ec221d

Sync final env readiness check 23060aa

Browse files
README.md CHANGED
@@ -142,7 +142,7 @@ The browser UI and `GET /api/submission/gate` expose the same fail-closed final
142
  `scripts/live_env_handoff.py` creates a redacted B2/Genblaze credential handoff report so final proof setup can be checked without printing keys.
143
  `scripts/genblaze_contract_check.py` verifies the installed Genblaze/B2 SDK import and signature contract without reading environment variables or credential files, catching package/API drift before live keys are entered.
144
  `scripts/docker_smoke.py` verifies the Docker image builds, starts in local/mock mode, passes API smoke, and uses `.dockerignore` to keep local env files out of the build context.
145
- `scripts/final_env_wizard.py` creates a local git-ignored `.env.final.local` with 0600 permissions, can prefill non-secret B2/default values, reads existing local values as defaults, and uses hidden prompts for credential values.
146
  `scripts/b2_key_scope_checklist.py` creates a no-secret B2 app-key scope checklist for the dedicated bucket, prefix, required upload capability, S3 SDK compatibility flag, forbidden permissions, and stop conditions before a key is created.
147
  `scripts/run_b2_live_proof.py` verifies the Backblaze B2 storage path independently with mock generation, so T020 can close before Genblaze credentials are ready.
148
  `scripts/devpost_form_kit.py` turns the safe packet into field-by-field Devpost copy with length checks, a strict final gate, and an in-app Devpost Kit through `GET /api/judge/devpost`.
 
142
  `scripts/live_env_handoff.py` creates a redacted B2/Genblaze credential handoff report so final proof setup can be checked without printing keys.
143
  `scripts/genblaze_contract_check.py` verifies the installed Genblaze/B2 SDK import and signature contract without reading environment variables or credential files, catching package/API drift before live keys are entered.
144
  `scripts/docker_smoke.py` verifies the Docker image builds, starts in local/mock mode, passes API smoke, and uses `.dockerignore` to keep local env files out of the build context.
145
+ `scripts/final_env_wizard.py` creates a local git-ignored `.env.final.local` with 0600 permissions, can prefill non-secret B2/default values, reads existing local values as defaults, and uses hidden prompts for credential values. Its `--check-only` mode is a no-secret readiness preflight for git-ignore status, `.env.final.local` presence, chmod `0600`, missing or placeholder variable names, and B2 region derivation.
146
  `scripts/b2_key_scope_checklist.py` creates a no-secret B2 app-key scope checklist for the dedicated bucket, prefix, required upload capability, S3 SDK compatibility flag, forbidden permissions, and stop conditions before a key is created.
147
  `scripts/run_b2_live_proof.py` verifies the Backblaze B2 storage path independently with mock generation, so T020 can close before Genblaze credentials are ready.
148
  `scripts/devpost_form_kit.py` turns the safe packet into field-by-field Devpost copy with length checks, a strict final gate, and an in-app Devpost Kit through `GET /api/judge/devpost`.
docs/todo.md CHANGED
@@ -49,3 +49,4 @@ python3 scripts/task.py doing T020 --note "Live B2 proof in progress"
49
  | T090 | Final closeout status is now available through `/api/judge/final-closeout`, a judge-mode UI panel/link, API smoke, and public Space HTML marker validation. |
50
  | T091 | Final closeout public sync now accepts both pre-final fail-closed and final-ready all-green states, validates the API against raw evidence, and keeps the UI next command visible. |
51
  | T092 | No-secret live credential handoff regenerated from `.env.final.local`; remaining local credential blockers are narrowed to `b2_key_id`, `b2_application_key`, and `genblaze_api_key`. |
 
 
49
  | T090 | Final closeout status is now available through `/api/judge/final-closeout`, a judge-mode UI panel/link, API smoke, and public Space HTML marker validation. |
50
  | T091 | Final closeout public sync now accepts both pre-final fail-closed and final-ready all-green states, validates the API against raw evidence, and keeps the UI next command visible. |
51
  | T092 | No-secret live credential handoff regenerated from `.env.final.local`; remaining local credential blockers are narrowed to `b2_key_id`, `b2_application_key`, and `genblaze_api_key`. |
52
+ | T093 | Final env `--check-only` now performs no-secret readiness preflight for git-ignore, chmod `0600`, missing/placeholder names, B2 region derivation, and `B2_APP_KEY` alias handling. |
docs/verification.md CHANGED
@@ -85,6 +85,8 @@ Use the CI result as public repo evidence for the non-secret local gate. It does
85
 
86
  Evidence files written by `scripts/api_smoke.py --evidence-out` are checked before writing and fail closed if they contain secret-like field names, bearer tokens, signed URL parameters, or GMI-style key values.
87
 
 
 
88
  The final sponsor proof has a preflight wrapper:
89
 
90
  ```bash
 
85
 
86
  Evidence files written by `scripts/api_smoke.py --evidence-out` are checked before writing and fail closed if they contain secret-like field names, bearer tokens, signed URL parameters, or GMI-style key values.
87
 
88
+ `python scripts/final_env_wizard.py --check-only` is intentionally safe to run in CI and locally. In CI it proves the target env file is git-ignored; locally it also reports `.env.final.local` presence, chmod `0600`, missing required variable names, placeholder names, B2 region derivation, and `ready_for_live_entry` without printing credential values.
89
+
90
  The final sponsor proof has a preflight wrapper:
91
 
92
  ```bash
scripts/final_env_wizard.py CHANGED
@@ -19,6 +19,7 @@ ROOT = Path(__file__).resolve().parents[1]
19
  DEFAULT_OUTPUT = ROOT / ".env.final.local"
20
  DEFAULT_B2_SETUP = ROOT / "docs" / "assets" / "b2-live-setup.json"
21
  SAFE_ENV_RE = re.compile(r"^[A-Za-z0-9_./:@%+=,-]+$")
 
22
 
23
  NEXT_COMMANDS = [
24
  "python scripts/live_env_handoff.py --env-file .env.final.local --strict",
@@ -45,7 +46,13 @@ FIELDS = [
45
  EnvField("B2_REGION", "Backblaze B2 region", required=False),
46
  EnvField("B2_BUCKET", "Backblaze B2 bucket name"),
47
  EnvField("B2_KEY_ID", "Backblaze B2 application key id"),
48
- EnvField("B2_APPLICATION_KEY", "Backblaze B2 application key", secret=True),
 
 
 
 
 
 
49
  EnvField("B2_PUBLIC_BASE_URL", "Optional B2 public base URL", required=False),
50
  EnvField(
51
  "GENBLAZE_API_KEY",
@@ -64,10 +71,19 @@ def normalize(value: str | None) -> str:
64
  return (value or "").strip()
65
 
66
 
 
 
 
 
 
 
 
 
 
67
  def env_lookup(field: EnvField, environ: Mapping[str, str]) -> str:
68
  for name in (field.name, *field.aliases):
69
  value = normalize(environ.get(name))
70
- if value:
71
  return value
72
  return ""
73
 
@@ -308,11 +324,34 @@ def target_is_git_ignored(root: Path, path: Path) -> bool:
308
  def build_check(root: Path = ROOT, output: Path = DEFAULT_OUTPUT) -> dict[str, object]:
309
  output = output.resolve()
310
  ignored = target_is_git_ignored(root, output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  return {
312
  "schema": "proofframe.final_env_wizard_check.v1",
313
  "ok": ignored,
314
  "output": str(output),
315
  "git_ignored": ignored,
 
 
 
316
  "required_fields": [field.name for field in FIELDS if field.required],
317
  "secret_fields": [
318
  name
@@ -320,6 +359,20 @@ def build_check(root: Path = ROOT, output: Path = DEFAULT_OUTPUT) -> dict[str, o
320
  if field.secret
321
  for name in (field.name, *field.mirror_to)
322
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  "policy": (
324
  "The wizard writes only to a git-ignored local env file and command output lists "
325
  "variable names only, never credential values."
 
19
  DEFAULT_OUTPUT = ROOT / ".env.final.local"
20
  DEFAULT_B2_SETUP = ROOT / "docs" / "assets" / "b2-live-setup.json"
21
  SAFE_ENV_RE = re.compile(r"^[A-Za-z0-9_./:@%+=,-]+$")
22
+ PLACEHOLDERS = {"", "placeholder", "change-me", "changeme", "todo", "tbd", "none", "null", "..."}
23
 
24
  NEXT_COMMANDS = [
25
  "python scripts/live_env_handoff.py --env-file .env.final.local --strict",
 
46
  EnvField("B2_REGION", "Backblaze B2 region", required=False),
47
  EnvField("B2_BUCKET", "Backblaze B2 bucket name"),
48
  EnvField("B2_KEY_ID", "Backblaze B2 application key id"),
49
+ EnvField(
50
+ "B2_APPLICATION_KEY",
51
+ "Backblaze B2 application key",
52
+ secret=True,
53
+ aliases=("B2_APP_KEY",),
54
+ mirror_to=("B2_APP_KEY",),
55
+ ),
56
  EnvField("B2_PUBLIC_BASE_URL", "Optional B2 public base URL", required=False),
57
  EnvField(
58
  "GENBLAZE_API_KEY",
 
71
  return (value or "").strip()
72
 
73
 
74
+ def has_real_value(value: str | None) -> bool:
75
+ normalized = normalize(value).strip('"').strip("'")
76
+ if normalized.lower() in PLACEHOLDERS:
77
+ return False
78
+ if normalized.startswith("<") and normalized.endswith(">"):
79
+ return False
80
+ return bool(normalized)
81
+
82
+
83
  def env_lookup(field: EnvField, environ: Mapping[str, str]) -> str:
84
  for name in (field.name, *field.aliases):
85
  value = normalize(environ.get(name))
86
+ if has_real_value(value):
87
  return value
88
  return ""
89
 
 
324
  def build_check(root: Path = ROOT, output: Path = DEFAULT_OUTPUT) -> dict[str, object]:
325
  output = output.resolve()
326
  ignored = target_is_git_ignored(root, output)
327
+ env_file_present = output.exists()
328
+ values = parse_env_file(output) if env_file_present else {}
329
+ missing_required_names = [
330
+ field.name for field in FIELDS if field.required and not env_lookup(field, values)
331
+ ]
332
+ placeholder_names: list[str] = []
333
+ seen_placeholders: set[str] = set()
334
+ for field in FIELDS:
335
+ if not (field.required or field.secret):
336
+ continue
337
+ for name in (field.name, *field.aliases, *field.mirror_to):
338
+ if name in values and not has_real_value(values.get(name)) and name not in seen_placeholders:
339
+ placeholder_names.append(name)
340
+ seen_placeholders.add(name)
341
+ mode = output.stat().st_mode & 0o777 if env_file_present else None
342
+ mode_ok = mode == 0o600 if env_file_present else False
343
+ b2_endpoint = env_lookup(next(field for field in FIELDS if field.name == "B2_ENDPOINT_URL"), values)
344
+ b2_region_value = env_lookup(next(field for field in FIELDS if field.name == "B2_REGION"), values)
345
+ b2_region_derived = region_from_b2_endpoint(b2_endpoint)
346
+ b2_region_ok = bool(b2_region_value or b2_region_derived)
347
  return {
348
  "schema": "proofframe.final_env_wizard_check.v1",
349
  "ok": ignored,
350
  "output": str(output),
351
  "git_ignored": ignored,
352
+ "env_file_present": env_file_present,
353
+ "env_file_mode": oct(mode) if mode is not None else None,
354
+ "env_file_mode_ok": mode_ok,
355
  "required_fields": [field.name for field in FIELDS if field.required],
356
  "secret_fields": [
357
  name
 
359
  if field.secret
360
  for name in (field.name, *field.mirror_to)
361
  ],
362
+ "present_required_names": [
363
+ field.name for field in FIELDS if field.required and env_lookup(field, values)
364
+ ],
365
+ "missing_required_names": missing_required_names,
366
+ "placeholder_names": placeholder_names,
367
+ "b2_region": {
368
+ "present": bool(b2_region_value),
369
+ "derived_from_endpoint": b2_region_derived,
370
+ "ok": b2_region_ok,
371
+ },
372
+ "ready_for_live_entry": bool(
373
+ ignored and env_file_present and mode_ok and not missing_required_names and b2_region_ok
374
+ ),
375
+ "next_commands": NEXT_COMMANDS,
376
  "policy": (
377
  "The wizard writes only to a git-ignored local env file and command output lists "
378
  "variable names only, never credential values."
tasks.json CHANGED
@@ -209,6 +209,15 @@
209
  "done_criteria": "",
210
  "notes": "Generated docs/assets/live-credential-handoff.* from .env.final.local without printing values; non-secret B2 bucket/endpoint and backend modes are present, and remaining secret blockers are narrowed to b2_key_id, b2_application_key, and genblaze_api_key."
211
  },
 
 
 
 
 
 
 
 
 
212
  {
213
  "id": "T030",
214
  "title": "Run browser smoke test",
 
209
  "done_criteria": "",
210
  "notes": "Generated docs/assets/live-credential-handoff.* from .env.final.local without printing values; non-secret B2 bucket/endpoint and backend modes are present, and remaining secret blockers are narrowed to b2_key_id, b2_application_key, and genblaze_api_key."
211
  },
212
+ {
213
+ "id": "T093",
214
+ "title": "Harden final env readiness preflight",
215
+ "phase": "P4 Submit",
216
+ "owner": "reviewer",
217
+ "status": "done",
218
+ "done_criteria": "",
219
+ "notes": "final_env_wizard.py --check-only now reports git-ignore status, .env.final.local presence, chmod 0600 status, missing required names, placeholder names, B2 region derivation, and ready_for_live_entry without printing credential values; B2_APP_KEY is accepted and mirrored as a B2_APPLICATION_KEY alias."
220
+ },
221
  {
222
  "id": "T030",
223
  "title": "Run browser smoke test",
tests/test_final_env_wizard.py CHANGED
@@ -22,7 +22,10 @@ def test_final_env_wizard_check_requires_ignored_output(tmp_path):
22
 
23
  assert report["ok"] is True
24
  assert report["git_ignored"] is True
 
 
25
  assert "B2_APPLICATION_KEY" in report["secret_fields"]
 
26
  assert "GMI_API_KEY" in report["secret_fields"]
27
 
28
 
@@ -35,6 +38,78 @@ def test_final_env_wizard_check_fails_for_unignored_output(tmp_path):
35
  assert report["git_ignored"] is False
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def test_final_env_wizard_collects_from_env_and_mirrors_gmi_key():
39
  values = final_env_wizard.collect_values(
40
  from_env=True,
@@ -120,6 +195,7 @@ def test_final_env_wizard_collects_missing_values_only_and_mirrors_gmi_key(tmp_p
120
  assert filled_names == [
121
  "B2_KEY_ID",
122
  "B2_APPLICATION_KEY",
 
123
  "GENBLAZE_API_KEY",
124
  "GMI_API_KEY",
125
  ]
 
22
 
23
  assert report["ok"] is True
24
  assert report["git_ignored"] is True
25
+ assert report["env_file_present"] is False
26
+ assert report["ready_for_live_entry"] is False
27
  assert "B2_APPLICATION_KEY" in report["secret_fields"]
28
+ assert "B2_APP_KEY" in report["secret_fields"]
29
  assert "GMI_API_KEY" in report["secret_fields"]
30
 
31
 
 
38
  assert report["git_ignored"] is False
39
 
40
 
41
+ def test_final_env_wizard_check_reports_existing_env_readiness_without_values(tmp_path):
42
+ (tmp_path / ".gitignore").write_text(".env.*\n!.env.final.example\n", encoding="utf-8")
43
+ env_path = tmp_path / ".env.final.local"
44
+ env_path.write_text(
45
+ "\n".join(
46
+ [
47
+ "PROOFFRAME_STORAGE_BACKEND=b2",
48
+ "PROOFFRAME_GENERATION_BACKEND=genblaze",
49
+ "B2_ENDPOINT_URL=https://s3.us-west-004.backblazeb2.com",
50
+ "B2_BUCKET=proofframe-demo-a6b4e49",
51
+ "B2_KEY_ID=least-privilege-key-id",
52
+ "B2_APP_KEY=secret-b2-key",
53
+ "GENBLAZE_API_KEY=secret-gmi-key",
54
+ "GENBLAZE_IMAGE_MODEL=seedream-5.0-lite",
55
+ ]
56
+ )
57
+ + "\n",
58
+ encoding="utf-8",
59
+ )
60
+ os.chmod(env_path, 0o600)
61
+
62
+ report = final_env_wizard.build_check(tmp_path, env_path)
63
+ serialized = json.dumps(report)
64
+
65
+ assert report["ok"] is True
66
+ assert report["env_file_present"] is True
67
+ assert report["env_file_mode_ok"] is True
68
+ assert report["missing_required_names"] == []
69
+ assert report["placeholder_names"] == []
70
+ assert report["b2_region"]["derived_from_endpoint"] == "us-west-004"
71
+ assert report["ready_for_live_entry"] is True
72
+ assert "secret-b2-key" not in serialized
73
+ assert "secret-gmi-key" not in serialized
74
+
75
+
76
+ def test_final_env_wizard_check_reports_missing_and_placeholder_names(tmp_path):
77
+ (tmp_path / ".gitignore").write_text(".env.*\n!.env.final.example\n", encoding="utf-8")
78
+ env_path = tmp_path / ".env.final.local"
79
+ env_path.write_text(
80
+ "\n".join(
81
+ [
82
+ "PROOFFRAME_STORAGE_BACKEND=b2",
83
+ "PROOFFRAME_GENERATION_BACKEND=genblaze",
84
+ "B2_ENDPOINT_URL=s3.us-west-004.backblazeb2.com",
85
+ "B2_BUCKET=proofframe-demo-a6b4e49",
86
+ "B2_KEY_ID=todo",
87
+ "B2_APPLICATION_KEY=",
88
+ "GENBLAZE_API_KEY=<paste-key>",
89
+ "GENBLAZE_IMAGE_MODEL=seedream-5.0-lite",
90
+ ]
91
+ )
92
+ + "\n",
93
+ encoding="utf-8",
94
+ )
95
+ os.chmod(env_path, 0o644)
96
+
97
+ report = final_env_wizard.build_check(tmp_path, env_path)
98
+
99
+ assert report["env_file_mode_ok"] is False
100
+ assert report["missing_required_names"] == [
101
+ "B2_KEY_ID",
102
+ "B2_APPLICATION_KEY",
103
+ "GENBLAZE_API_KEY",
104
+ ]
105
+ assert set(report["placeholder_names"]) >= {
106
+ "B2_KEY_ID",
107
+ "B2_APPLICATION_KEY",
108
+ "GENBLAZE_API_KEY",
109
+ }
110
+ assert report["ready_for_live_entry"] is False
111
+
112
+
113
  def test_final_env_wizard_collects_from_env_and_mirrors_gmi_key():
114
  values = final_env_wizard.collect_values(
115
  from_env=True,
 
195
  assert filled_names == [
196
  "B2_KEY_ID",
197
  "B2_APPLICATION_KEY",
198
+ "B2_APP_KEY",
199
  "GENBLAZE_API_KEY",
200
  "GMI_API_KEY",
201
  ]