Skip to content

Commit f6371c0

Browse files
committed
fix: align credential snapshot filtering
1 parent 7b38398 commit f6371c0

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎src/openenv/validation/providers/docker.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@
4444
".validation",
4545
}
4646
_SECRET_NAME = re.compile(
47-
r"^(?:\.env(?:\..*)?|id_(?:rsa|ed25519|ecdsa)(?:\..*)?|"
47+
r"^(?:\.env(?:\..*)?|\.netrc|.*_secrets?\..*|"
48+
r"id_(?:rsa|ed25519).*|id_ecdsa(?:\..*)?|"
4849
r"credentials(?:\.json)?|secrets?|secrets\.(?:json|toml|ya?ml))$|"
49-
r"\.(?:pem|key)$",
50-
re.I,
50+
r"\.(?:pem|key|p12|pfx)$",
51+
re.I | re.S,
5152
)
5253
_TOKEN = re.compile(
5354
r"(?:hf_[A-Za-z0-9]{8,}|(?:sk|ghp|github_pat)[-_][A-Za-z0-9_-]{8,}|"
@@ -139,7 +140,7 @@ def _contained(root: Path, relative: str) -> Path:
139140

140141

141142
def _snapshot(root: Path, destination: Path, max_bytes: int, deadline: float) -> None:
142-
"""Copy source bytes, never host links, caches, credential files or run outputs."""
143+
"""Copy source bytes, excluding links, caches, known credential names and outputs."""
143144
total = 0
144145
files = 0
145146

‎tests/test_validation/test_docker_provider.py‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,11 @@ def test_build_uses_filtered_snapshot_and_returns_immutable_image(
284284
for name in (".git", ".venv", "outputs"):
285285
(tmp_path / name).mkdir()
286286
(tmp_path / name / "private").write_text("not copied")
287-
(tmp_path / ".env").write_text("HF_TOKEN=private")
288-
(tmp_path / "key.pem").write_text("private")
289287
for name in (
288+
".env",
289+
".env.local",
290+
".env.example",
291+
".netrc",
290292
"secret",
291293
"secrets",
292294
"credentials",
@@ -295,21 +297,48 @@ def test_build_uses_filtered_snapshot_and_returns_immutable_image(
295297
"secrets.toml",
296298
"secrets.yaml",
297299
"secrets.yml",
300+
"api_secret.json",
301+
"service_secrets.yaml",
302+
"_secret.json",
303+
"_secrets.yaml",
304+
"id_rsa",
305+
"id_rsa.pub",
306+
"id_rsa_backup",
307+
"id_ed25519",
308+
"id_ed25519.pub",
309+
"id_ed25519_backup",
310+
"id_ecdsa",
311+
"id_ecdsa.pub",
312+
"key.pem",
313+
"key.key",
314+
"certificate.p12",
315+
"certificate.pfx",
298316
):
299317
if uppercase_secret_names:
300318
name = name.upper()
301319
(tmp_path / name).write_text("private")
302-
(tmp_path / "secret.py").write_text("VALUE = 'source'\n")
303-
(tmp_path / "credentials.py").write_text("VALUE = 'source'\n")
320+
for name in (
321+
"secret.py",
322+
"secrets.py",
323+
"credentials.py",
324+
"secret_utils.py",
325+
"credentials_helper.py",
326+
"api_secretary.py",
327+
):
328+
(tmp_path / name).write_text("VALUE = 'source'\n")
304329

305330
def build(argv, timeout_s):
306331
assert timeout_s <= 600
307332
context = Path(argv[-1])
308333
assert set(path.name for path in context.iterdir()) == {
309334
"Dockerfile",
335+
"api_secretary.py",
310336
"credentials.py",
337+
"credentials_helper.py",
311338
"data.txt",
312339
"secret.py",
340+
"secret_utils.py",
341+
"secrets.py",
313342
}
314343
assert context != tmp_path
315344
Path(argv[argv.index("--iidfile") + 1]).write_text(IMAGE)

0 commit comments

Comments
 (0)