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
22 changes: 16 additions & 6 deletions pkgs/cold-store-reaper/cold_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,23 +1526,33 @@ def _s3_get_via_curl(
def _curl_fetch(self, url: str, access: str, secret: str) -> bytes:
"""GET `url` with curl, which does its own SigV4 signing
(--aws-sigv4) and reads the proxy from the environment itself.
Credentials travel in argv — the local process list sees them,
as with any credentialed CLI — but they are scrubbed from every
error this raises, and nothing here is logged.
Credentials travel in a curl config fed on stdin (--config -),
never in argv — the local process list must not see them (the
--user argv form was issue #983, the pattern #948/#970 removed
from push-fleet-feed.sh) — and never on disk. They are scrubbed
from every error this raises, and nothing here is logged.
"""
argv = [
self.curl,
"-sS",
"--fail",
"--aws-sigv4",
"aws:amz:auto:s3",
"--user",
f"{access}:{secret}",
"--config",
"-",
url,
]
config = (
'user = "'
+ f"{access}:{secret}".replace("\\", "\\\\").replace('"', '\\"')
+ '"\n'
).encode()
try:
proc = subprocess.run(
argv, capture_output=True, timeout=S3_CURL_TIMEOUT_SECONDS
argv,
input=config,
capture_output=True,
timeout=S3_CURL_TIMEOUT_SECONDS,
)
except FileNotFoundError:
raise ColdStoreError(
Expand Down
31 changes: 31 additions & 0 deletions pkgs/cold-store-reaper/tests/test_cold_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,37 @@ def test_curl_never_invoked_on_urllib_happy_path(self):
self.assertEqual(calls, [])
self.assertEqual(result["sha256"], hashlib.sha256(body).hexdigest())

def test_curl_fetch_keeps_credentials_out_of_argv(self):
"""The spawned curl argv must never carry the credentials
(issue #983): _curl_fetch feeds curl its config on stdin
(--config -) instead of passing --user in argv, where the
local process list would see the secret for up to the 900s
fallback timeout. This test is the guard for cold_store.py in
the spirit of push-fleet-feed.guard.sh (#948/#970)."""
seen = {}

def fake_run(argv, **kwargs):
seen["argv"] = argv
seen["kwargs"] = kwargs
return subprocess.CompletedProcess(argv, 0, stdout=b"payload", stderr=b"")

with mock.patch.object(cold_store.subprocess, "run", fake_run):
body = self.store._curl_fetch(
"https://store.example/supabase-backups/some/key",
"test-access-key",
"test-secret-key",
)
self.assertEqual(body, b"payload")
argv = seen["argv"]
self.assertNotIn("--user", argv)
for element in argv:
self.assertNotIn("test-access-key", element)
self.assertNotIn("test-secret-key", element)
# the credential arrives on stdin as a curl config instead
config = seen["kwargs"]["input"].decode()
self.assertIn('user = "test-access-key:test-secret-key"', config)
self.assertEqual(argv[argv.index("--config") + 1], "-")

def test_fallback_sizes_via_head_when_caller_gives_none(self):
key = self._persistent_truncation()
patcher, calls = self._stub_curl(self.BODY)
Expand Down
Loading