-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add registry authentication in runtime #40123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kvega005
merged 49 commits into
microsoft:feature/wsl-for-apps
from
kvega005:user/kevinve/registry
Apr 13, 2026
Merged
Changes from 22 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
7d41e66
Add local registry, auth, and push image
kvega005 638ebfa
Fix test
kvega005 7fd4026
delete cleanup registry storage
kvega005 1fdb1b2
Do not use volume
kvega005 15d30b6
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
kvega005 35e6322
Undo entry point fix (getting checked in seperately)
kvega005 b278c0a
undo entry point fix
kvega005 b988783
Fix formatting
kvega005 783ae7b
Address copilot comment
kvega005 ead90fc
Use packaged wslc-registry
kvega005 ce78d51
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 5156db5
Address copilot comments
kvega005 31b5ad5
Address more copilot comments
kvega005 4cfd98c
Merge branch 'user/kevinve/registry' of https://github.com/kvega005/W…
kvega005 6305c58
Fix push and Pulll tests
kvega005 22cb648
Fix formatting
kvega005 3a0ba44
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 83b39f2
Address suggestion
kvega005 a17819e
Address suggestions
kvega005 ba6c3de
Merge branch 'user/kevinve/registry' of https://github.com/kvega005/W…
kvega005 e329ac7
address suggestions
kvega005 868f69e
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 3256f5d
Address copilot comments
kvega005 2d4dce9
Merge branch 'user/kevinve/registry' of https://github.com/kvega005/W…
kvega005 9177765
Remove wslc local registry
kvega005 0fa5505
formatting fix
kvega005 7b41634
Add script and docker file to generate test images.
kvega005 aaed20e
Address base64 encode feedback
kvega005 65aed10
Add Auth to SDK
kvega005 adab0ce
remove unneeded code
kvega005 3d0bad5
Address custom headers suggestion
kvega005 10491ee
Make regitsry auth required
kvega005 404a05e
Nit update script
kvega005 965f832
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 2f35e77
Fix formatting
kvega005 71081bb
Update comment
kvega005 1734d51
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 a40b27d
Fix tests
kvega005 bc989e5
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
kvega005 7f59f8f
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 d1455e0
Merge branch 'user/kevinve/registry' of https://github.com/kvega005/W…
kvega005 ef6f192
Fix tests
kvega005 d14cfec
Added back removed test + cleanup
kvega005 f4c1f39
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
kvega005 c945517
Fix empty auth
kvega005 498588b
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 baabcd9
Fix clang-format violations in test files
f6ea418
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
kvega005 61dd8b4
Merge branch 'feature/wsl-for-apps' into user/kevinve/registry
kvega005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLCLocalRegistry.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of WSLCLocalRegistry. | ||
|
|
||
| --*/ | ||
|
kvega005 marked this conversation as resolved.
Outdated
|
||
| #include "WSLCLocalRegistry.h" | ||
|
|
||
| using wsl::windows::common::RunningWSLCContainer; | ||
| using wsl::windows::common::WSLCContainerLauncher; | ||
| using wsl::windows::common::WSLCLocalRegistry; | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr auto c_registryImage = "wslc-registry:latest"; | ||
|
|
||
| std::vector<std::string> BuildRegistryEnv(const std::string& username, const std::string& password, USHORT port) | ||
| { | ||
| std::vector<std::string> env = { | ||
| std::format("REGISTRY_HTTP_ADDR=0.0.0.0:{}", port), | ||
| }; | ||
|
|
||
| if (!username.empty()) | ||
| { | ||
| env.push_back(std::format("USERNAME={}", username)); | ||
| env.push_back(std::format("PASSWORD={}", password)); | ||
| } | ||
|
|
||
| return env; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| WSLCLocalRegistry::WSLCLocalRegistry( | ||
| IWSLCSession& session, RunningWSLCContainer&& container, std::string&& username, std::string&& password, std::string&& serverAddress) : | ||
| m_session(wil::com_ptr<IWSLCSession>(&session)), | ||
| m_username(std::move(username)), | ||
| m_password(std::move(password)), | ||
| m_serverAddress(std::move(serverAddress)), | ||
| m_container(std::move(container)) | ||
| { | ||
| } | ||
|
|
||
| WSLCLocalRegistry::~WSLCLocalRegistry() | ||
| { | ||
| // Delete the container first while the session is still active. | ||
| m_container.Reset(); | ||
|
kvega005 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| WSLCLocalRegistry WSLCLocalRegistry::Start(IWSLCSession& session, const std::string& username, const std::string& password, USHORT port) | ||
| { | ||
| auto env = BuildRegistryEnv(username, password, port); | ||
|
|
||
| WSLCContainerLauncher launcher(c_registryImage, {}, {}, env); | ||
| launcher.SetEntrypoint({"/entrypoint.sh"}); | ||
| launcher.AddPort(port, port, AF_INET); | ||
|
|
||
| auto container = launcher.Launch(session, WSLCContainerStartFlagsNone); | ||
| return WSLCLocalRegistry(session, std::move(container), std::string(username), std::string(password), std::format("127.0.0.1:{}", port)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLCLocalRegistry.h | ||
|
|
||
| Abstract: | ||
|
|
||
| Helper class that starts a local Docker registry:3 container inside a WSLC | ||
| session, optionally configured with htpasswd basic authentication. Intended | ||
| for use in both unit tests and E2E tests that need a private registry without | ||
| an external dependency. | ||
|
|
||
| --*/ | ||
|
|
||
| #pragma once | ||
| #include "WSLCContainerLauncher.h" | ||
| #include "WslcCredentialStore.h" | ||
|
|
||
| namespace wsl::windows::common { | ||
|
|
||
| class WSLCLocalRegistry | ||
| { | ||
| public: | ||
| NON_COPYABLE(WSLCLocalRegistry); | ||
| DEFAULT_MOVABLE(WSLCLocalRegistry); | ||
| ~WSLCLocalRegistry(); | ||
|
|
||
| static WSLCLocalRegistry Start(IWSLCSession& Session, const std::string& Username = {}, const std::string& Password = {}, USHORT Port = 5000); | ||
|
kvega005 marked this conversation as resolved.
Outdated
|
||
|
|
||
| std::string GetServerAddress() | ||
| { | ||
| return m_serverAddress; | ||
| } | ||
|
|
||
| std::string GetAuthHeader() | ||
| { | ||
| return BuildRegistryAuthHeader(m_username, m_password, m_serverAddress); | ||
| } | ||
|
|
||
| private: | ||
| WSLCLocalRegistry(IWSLCSession& session, RunningWSLCContainer&& container, std::string&& username, std::string&& password, std::string&& serverAddress); | ||
|
|
||
| wil::com_ptr<IWSLCSession> m_session; | ||
| std::string m_serverAddress; | ||
| std::string m_username; | ||
| std::string m_password; | ||
| RunningWSLCContainer m_container; | ||
| }; | ||
|
|
||
| } // namespace wsl::windows::common | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WslcCredentialStore.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of credential store helpers. | ||
|
|
||
| --*/ | ||
|
|
||
| #include "WslcCredentialStore.h" | ||
| #include <nlohmann/json.hpp> | ||
| #include <wincrypt.h> | ||
|
|
||
|
kvega005 marked this conversation as resolved.
Outdated
|
||
| namespace { | ||
|
|
||
| std::string Base64Encode(const std::string& input) | ||
|
kvega005 marked this conversation as resolved.
Outdated
|
||
| { | ||
| DWORD base64Size = 0; | ||
| THROW_IF_WIN32_BOOL_FALSE(CryptBinaryToStringA( | ||
| reinterpret_cast<const BYTE*>(input.c_str()), static_cast<DWORD>(input.size()), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &base64Size)); | ||
|
|
||
| auto buffer = std::make_unique<char[]>(base64Size); | ||
| THROW_IF_WIN32_BOOL_FALSE(CryptBinaryToStringA( | ||
| reinterpret_cast<const BYTE*>(input.c_str()), | ||
| static_cast<DWORD>(input.size()), | ||
| CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, | ||
| buffer.get(), | ||
| &base64Size)); | ||
|
|
||
| return std::string(buffer.get()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| std::string wsl::windows::common::BuildRegistryAuthHeader(const std::string& username, const std::string& password, const std::string& serverAddress) | ||
| { | ||
| nlohmann::json authJson = {{"username", username}, {"password", password}, {"serveraddress", serverAddress}}; | ||
|
|
||
| return Base64Encode(authJson.dump()); | ||
| } | ||
|
|
||
| std::string wsl::windows::common::BuildRegistryAuthHeader(const std::string& identityToken, const std::string& serverAddress) | ||
| { | ||
| nlohmann::json authJson = {{"identitytoken", identityToken}, {"serveraddress", serverAddress}}; | ||
|
|
||
| return Base64Encode(authJson.dump()); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WslcCredentialStore.h | ||
|
|
||
| Abstract: | ||
|
|
||
| Helpers for building Docker/OCI registry credential payloads. | ||
|
|
||
| --*/ | ||
|
|
||
| #pragma once | ||
| #include <string> | ||
|
|
||
| namespace wsl::windows::common { | ||
|
|
||
| // Builds the base64-encoded X-Registry-Auth header value used by Docker APIs | ||
| // (PullImage, PushImage, etc.) from the given credentials. | ||
| std::string BuildRegistryAuthHeader(const std::string& username, const std::string& password, const std::string& serverAddress); | ||
|
|
||
| // Builds the base64-encoded X-Registry-Auth header value from an identity token | ||
| // returned by Authenticate(). | ||
| std::string BuildRegistryAuthHeader(const std::string& identityToken, const std::string& serverAddress); | ||
|
|
||
| // TODO: Implement credential storage using WinCred | ||
|
|
||
| } // namespace wsl::windows::common |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.