fix(ack): remove temp Docker config dir after crane image check #2158
@Vedant-Agarwal is attempting to deploy a commit to the Harbor Framework Team on Vercel.
A member of the Team first needs to authorize it.
Enjoy a better diff viewing experience by clicking one of these URLs:
✅ Devin Review: No Issues Found
Devin Review analyzed this PR and found no bugs or issues to report.
<!-- devin-review-badge-begin -->
<a href="https://app.devin.ai/review/harbor-framework/harbor/pull/2158" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open in Devin Review">
</picture>
</a>
<!-- devin-review-badge-end -->
@KunWuLuan do you want to take a look at this since ack.py is added/used by your team at alibaba? It's fine if it's not legit and not worth merging.
The leak is easy to confirm: in the crane fallback of _image_exists, tempfile.mkdtemp(prefix="crane-docker-config-") gets a config.json with registry credentials written into it and is never removed — every image check leaves one behind. The buildkit paths in the same file already shutil.rmtree their temp configs; this PR just adds the same cleanup in a finally, and the unit test asserts the dir is gone after _image_exists returns.
@kobe0938 In case it helps unblock this while KunWuLuan is busy: I don't think ACK-specific context is strictly needed to review it. The temp DOCKER_CONFIG dir is created by harbor itself (tempfile.mkdtemp(prefix="crane-docker-config-")) and holds a config.json with registry auth — and the buildkit paths in this same file already shutil.rmtree their temp configs on the same success/failure paths. The PR just applies that existing pattern to the crane fallback, so there's no ACK behavior change, only cleanup of a credential-bearing directory. Branch is conflict-free and checks are green.
/lgtm
Approved these changes.
Approved these changes.
KunWuLuan
Vedant-Agarwal
What
ACKEnvironment._image_exists's crane fallback writes registry credentials into a temp Docker config dir (tempfile.mkdtemp(prefix="crane-docker-config-"),ack.py:726) and setsDOCKER_CONFIGto it — but never removes it. Every image-existence check via crane therefore leaks a credential-bearing directory on disk (a base64 registry auth inconfig.json), on both the success and exception paths.Why it's a real bug
The two sibling buildkit paths in the same file already clean up their temp Docker config / build dirs (
shutil.rmtreeatack.py:984and afinally: shutil.rmtree(...)at:1001). Only the crane path omits cleanup — a clear sibling-consistency gap, with a mild security angle (credentials left on disk).Fix
Track the temp dir and remove it in a
finally(mirroring the buildkit paths). String content aside, this just ensures the credential dir is always reclaimed.Test
Added
tests/unit/environments/test_ack.py— forces the crane path with registry auth (mocked subprocess) and asserts the tempDOCKER_CONFIGdir is gone afterward. It fails without the fix (mutation-checked) and passes with it.ruffclean.<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/harbor-framework/harbor/pull/2158" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open in Devin Review">
</picture>
</a>
<!-- devin-review-badge-end -->