Fix wslc image pull command when invoked in network logon session (#40713)

yao-msft committed Jun 5, 2026 at 11:03 UTC fab0aa6ff96b57a8497f3beeb341d2f63ba6f150
1 file changed +10 -2
src/windows/wslc/services/WinCredStorage.cpp
+10 -2
@@ -53,7 +53,11 @@ std::pair<std::string, std::string> WinCredStorage::Get(const std::string& serve
53 unique_credential cred;
54 if (!CredReadW(targetName.c_str(), CRED_TYPE_GENERIC, 0, &cred))
55 {
56 - THROW_LAST_ERROR_IF(GetLastError() != ERROR_NOT_FOUND);
56 + auto error = GetLastError();
57 +
58 + // Credential Manager is unavailable under network logon session (e.g. an SSH network logon),
59 + // Treat it like "no credential found" so anonymous pull/push can proceed.
60 + THROW_LAST_ERROR_IF(error != ERROR_NOT_FOUND && error != ERROR_NO_SUCH_LOGON_SESSION);
61 return {};
62 }
63
@@ -94,7 +98,11 @@ std::vector<std::wstring> WinCredStorage::List()
98 unique_credential_array creds;
99 if (!CredEnumerateW(filter.c_str(), 0, &count, &creds))
100 {
97 - THROW_LAST_ERROR_IF(GetLastError() != ERROR_NOT_FOUND);
101 + auto error = GetLastError();
102 +
103 + // Credential Manager is unavailable under network logon session (e.g. an SSH network logon),
104 + // Treat it like "no credential found" so anonymous pull/push can proceed.
105 + THROW_LAST_ERROR_IF(error != ERROR_NOT_FOUND && error != ERROR_NO_SUCH_LOGON_SESSION);
106 return {};
107 }
108