Skip to content
Merged
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
32 changes: 26 additions & 6 deletions scripts/fleet/op-bws-reconcile/op_bws_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def sha(value: str) -> str:


def run(cmd, inp=None, timeout=600):
# Pin stdin on every call (#17142 defect, 2026-12-01): when no explicit
# input is given, subprocess would otherwise inherit the parent's stdin,
# and a piped parent stdin makes `op item edit` treat the pipe as a JSON
# template and fail with "[ERROR] invalid JSON provided". Calls with an
# explicit input keep the pipe (input= sets stdin itself).
if inp is None:
return subprocess.run(cmd, stdin=subprocess.DEVNULL,
capture_output=True, text=True, timeout=timeout)
return subprocess.run(cmd, input=inp, capture_output=True, text=True,
timeout=timeout)

Expand Down Expand Up @@ -225,19 +233,31 @@ def apply_copies_to_op(bws, op, names, cap):
failures.append((name, f"create rc={r.returncode}"))
continue
new_id = json.loads(r.stdout)["id"]
run(["op", "item", "edit", new_id, "--vault", "Dev",
f"Sync.counterpart={name}",
"Sync.kind=api-credential (op:API_CREDENTIAL)",
f"Sync.last-hash={h}"], timeout=300)
e = run(["op", "item", "edit", new_id, "--vault", "Dev",
f"Sync.counterpart={name}",
"Sync.kind=api-credential (op:API_CREDENTIAL)",
f"Sync.last-hash={h}"], timeout=300)
if e.returncode != 0:
failures.append((name, f"metadata stamp (op item edit) "
f"rc={e.returncode}"))
continue
note = (s.get("note") or "").rstrip()
if "sync.counterpart" not in note:
block = (f"[sync-metadata v1]\nsync.counterpart: {name}\n"
f"sync.kind: api-credential (op:API_CREDENTIAL)\n"
f"sync.last-hash: {h}")
run(["bws", "secret", "edit", s["id"], "--note",
(note + "\n\n" + block) if note else block], timeout=300)
be = run(["bws", "secret", "edit", s["id"], "--note",
(note + "\n\n" + block) if note else block],
timeout=300)
if be.returncode != 0:
failures.append((name, f"metadata stamp (bws secret edit) "
f"rc={be.returncode}"))
continue
g = run(["op", "item", "get", new_id, "--vault", "Dev",
"--format", "json"], timeout=300)
if g.returncode != 0:
failures.append((name, f"read-back rc={g.returncode}"))
continue
item = json.loads(g.stdout)
cred = next((f.get("value", "") for f in item["fields"]
if f.get("label") == "credential"), "")
Expand Down