-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(libstore): curl-based s3 #13752
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
Open
lovesegfault
wants to merge
36
commits into
NixOS:master
Choose a base branch
from
lovesegfault:curl-based-s3-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+998
−761
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1b53ede
refactor(libstore): Replace AWS SDK with curl-based S3 implementation
lovesegfault d8b4a62
feat(libstore): AWS credential provider caching
lovesegfault 5768449
test(libstore): check cred provider with forks
lovesegfault 3015bd6
refactor(libstore): misc cleanups
lovesegfault f464da4
refactor(libstore): use atomic static initializer trick in initAwsCrt()
lovesegfault 2755c24
refactor(libstore/s3): replaced mutex/condition_variable with Sync<St…
lovesegfault b67a0d9
refactor(libstore/s3): timeout protection for GetCredentials
lovesegfault 00fb46a
test(nixos/s3-binary-cache-store): remote sequential provider test
lovesegfault d3044f7
feat(libstore): pre-resolve aws creds for builtins fetchurl
lovesegfault ae05f02
test(libstore): cleanup s3 tests
lovesegfault db75f3c
refactor(libstore): factor out s3-creds-cache
lovesegfault 46dd03c
chore(libstore): empty #if/#endif
lovesegfault 6f4f6f0
test(libstore): reintroduce s3-binary-cache-store tests
lovesegfault c2ad465
chore(libstore): newlines
lovesegfault 7b7b046
refactor(libstore/s3): use ignoreExceptionInDestructor
lovesegfault 101e57a
refactor(libstore/s3-creds-cache): remove stubs
lovesegfault 52bc21f
refactor(libstore/s3): remove crtInitialized global
lovesegfault 21de20f
refactor(libstore/s3): split into aws-creds and s3-url
lovesegfault f69d2a5
chore: newlines
lovesegfault b92a411
chore(tests/nixos/s3-binary-cache-store): note on python comment
lovesegfault 5521a36
refactor(libstore/aws-creds): remove Aws/Crt/Auth from header
lovesegfault 4a33ade
refactor(libstore-tests): s3 -> s3-url
lovesegfault 75eeea8
refactor(libstore/aws-creds): rm AwsCredentialProvider class
lovesegfault 5e33d43
refactor(libstore/aws-creds): inline getOrCreateCredentialProvider
lovesegfault c5ed753
refactor(libstore/aws-creds): use concurrent_flat_map
lovesegfault 0c22f4c
refactor(libstore-tests): move s3UploadRequestConfiguration out of s3…
lovesegfault 9b520dc
refactor(libstore): move preResolveS3Credentials into aws-creds
lovesegfault 6f4dffa
refactor(libstore): preResolveS3Credentials -> preResolveAwsCredentials
lovesegfault 2789420
refactor(libstore): revert staticFT changes
lovesegfault 38886a6
test(nixos/s3-binary-cache-store): use nix/fetchurl.nix
lovesegfault e0c874f
refactor(libstore/aws-creds): handle spurious wakeups
lovesegfault 558963d
chore(libstore-tests/s3-url): rm config.hh include
lovesegfault d1b885b
chore(libstore/filetransfer): rm unused hasQuit
lovesegfault de9a766
refactor(libstore/aws-creds): use ByteCursorToStringView
lovesegfault cbfb423
refactor(libstore): adjust if/endif
lovesegfault 7bc4b0b
fix(libstore): build without s3 support
lovesegfault 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
synopsis: "Improved S3 binary cache support via HTTP" | ||
prs: [13752] | ||
issues: [13084, 12671, 11748, 12403, 5947] | ||
--- | ||
|
||
S3 binary cache operations now happen via HTTP, leveraging `libcurl`'s native AWS | ||
SigV4 authentication instead of the AWS C++ SDK, providing significant | ||
improvements: | ||
|
||
- **Reduced memory usage**: Eliminates memory buffering issues that caused | ||
segfaults with large files (>3.5GB) | ||
- **Fixed upload reliability**: Resolves AWS SDK chunking errors | ||
(`InvalidChunkSizeError`) | ||
- **Resolved OpenSSL conflicts**: No more S2N engine override issues in | ||
sandboxed builds | ||
- **Lighter dependencies**: Uses lightweight `aws-crt-cpp` instead of full | ||
`aws-cpp-sdk`, reducing build complexity | ||
|
||
The new implementation requires curl >= 7.75.0 and `aws-crt-cpp` for credential | ||
management. | ||
|
||
All existing S3 URL formats and parameters remain supported. | ||
|
||
## Breaking changes | ||
|
||
The legacy `S3BinaryCacheStore` implementation has been removed in favor of the | ||
new curl-based approach, as a result multipart uploads are no longer supported. They may be reimplemented in the future. | ||
|
||
**Migration**: No action required for most users. S3 URLs continue to work | ||
with the same syntax. Users directly using `S3BinaryCacheStore` class | ||
should migrate to standard HTTP binary cache stores with S3 endpoints. | ||
|
||
**Build requirement**: S3 support now requires curl >= 7.75.0 for AWS SigV4 | ||
authentication. Build configuration will warn if `aws-crt-cpp` is available | ||
but S3 support is disabled due to an insufficient curl version. |
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
lovesegfault marked this conversation as resolved.
Show resolved
Hide resolved
|
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,95 @@ | ||
#include "nix/store/filetransfer.hh" | ||
#include "nix/store/config.hh" | ||
#include "nix/store/s3-binary-cache-store.hh" | ||
#include "nix/store/s3-url.hh" | ||
|
||
#if NIX_WITH_S3_SUPPORT | ||
|
||
# include <gtest/gtest.h> | ||
# include <gmock/gmock.h> | ||
|
||
namespace nix { | ||
|
||
class S3FileTransferTest : public ::testing::Test | ||
{ | ||
protected: | ||
void SetUp() override | ||
{ | ||
// Clean environment for predictable tests | ||
unsetenv("AWS_ACCESS_KEY_ID"); | ||
unsetenv("AWS_SECRET_ACCESS_KEY"); | ||
unsetenv("AWS_SESSION_TOKEN"); | ||
unsetenv("AWS_PROFILE"); | ||
} | ||
}; | ||
|
||
/** | ||
* Regression test: Verify that S3 uploads are supported (not rejected with "not supported" error) | ||
* This test ensures the S3 upload functionality is properly implemented | ||
*/ | ||
TEST_F(S3FileTransferTest, s3UploadsAreSupported) | ||
{ | ||
auto ft = makeFileTransfer(); | ||
|
||
// Parse S3 URL and convert to HTTPS for curl-based transfer | ||
auto s3Url = ParsedS3URL::parse(parseURL("s3://test-bucket/test-file")); | ||
auto httpsUrl = s3Url.toHttpsUrl(); | ||
|
||
// Create a mock upload request | ||
FileTransferRequest uploadReq(httpsUrl); | ||
uploadReq.data = std::string("test data"); | ||
|
||
// This should not throw "uploading to '...' is not supported" | ||
// The request should be accepted (though it may fail later due to auth/network) | ||
bool gotNotSupportedError = false; | ||
try { | ||
ft->upload(uploadReq); | ||
} catch (const Error & e) { | ||
std::string msg = e.what(); | ||
if (msg.find("is not supported") != std::string::npos) { | ||
gotNotSupportedError = true; | ||
} | ||
} catch (...) { | ||
// Other errors are expected (no credentials, network issues, etc.) | ||
} | ||
|
||
EXPECT_FALSE(gotNotSupportedError) << "S3 uploads should be supported"; | ||
} | ||
|
||
/** | ||
* Test that S3BinaryCacheStoreConfig properly stores region parameters | ||
*/ | ||
TEST_F(S3FileTransferTest, regionParametersArePreserved) | ||
{ | ||
StringMap params; | ||
params["region"] = "us-west-2"; | ||
|
||
S3BinaryCacheStoreConfig config("s3", "test-bucket", params); | ||
|
||
EXPECT_EQ(config.cacheUri.query["region"], "us-west-2"); | ||
|
||
// Test with a different region | ||
StringMap params2; | ||
params2["region"] = "eu-central-1"; | ||
|
||
S3BinaryCacheStoreConfig config2("s3", "another-bucket", params2); | ||
EXPECT_EQ(config2.cacheUri.query["region"], "eu-central-1"); | ||
} | ||
|
||
/** | ||
* Test that S3 scheme registration works correctly | ||
*/ | ||
TEST_F(S3FileTransferTest, s3SchemeIsRegistered) | ||
{ | ||
// S3 should be registered in S3BinaryCacheStoreConfig | ||
auto s3Schemes = S3BinaryCacheStoreConfig::uriSchemes(); | ||
EXPECT_TRUE(s3Schemes.count("s3") > 0) << "S3 scheme should be registered"; | ||
|
||
// S3 should NOT be in HttpBinaryCacheStoreConfig | ||
auto httpSchemes = HttpBinaryCacheStoreConfig::uriSchemes(); | ||
EXPECT_FALSE(httpSchemes.count("s3") > 0) << "S3 should not be in HTTP config schemes"; | ||
} | ||
|
||
} // namespace nix | ||
|
||
#endif |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I test that this is now more reliable. Or how did you test this? Since we are also relying on this for our hydra build infra, have you seen any difference in upload speed?