fix(s3): explicit Garage imported-object key layout and read-only integrity probe
This commit is contained in:
1 parent
d3db1bcc36
commit
568fd9438e
5 files changed
+88
-2
No files matched your search
@@ -58,10 +58,55 @@ sec.Set("Endpoint", "https://storage.example.com");
|
||||
ExpectInvalid(badHttp, "UseSSL mismatch must fail closed");
|
||||
sec.Set("UseSSL", true);
|
||||
Check(OGLS3StorageOptions.Read(badHttp).Enabled, "Explicit HTTPS config must validate");
|
||||
Check(OGLS3StorageOptions.Read(badHttp).ObjectKeyLayout == "canonical",
|
||||
"S3 canonical object key layout must be the default");
|
||||
sec.Set("ObjectKeyLayout", "wrong-format");
|
||||
ExpectInvalid(badHttp, "Unsupported object key layout was accepted");
|
||||
sec.Set("ObjectKeyLayout", "garage-legacy");
|
||||
Check(OGLS3StorageOptions.Read(badHttp).ObjectKeyLayout == "garage-legacy",
|
||||
"Explicit Garage legacy layout could not be selected");
|
||||
sec.Set("ObjectKeyLayout", "canonical");
|
||||
sec.Set("MaxRetryAttempts", 0);
|
||||
ExpectInvalid(badHttp, "Unbounded/invalid retry value was accepted");
|
||||
Console.WriteLine("S3 configuration, fail-closed opt-in and secret-safe validation: PASS");
|
||||
|
||||
// Explicit read-only operator smoke against the already-migrated Garage
|
||||
// bucket. Does NOT create, upload, delete or mutate a S3 object or SQL row.
|
||||
// Examples: dotnet run -- --garage-readonly <sha256> [<sha256> ...]
|
||||
if (args.Length >= 2 && args[0] == "--garage-readonly")
|
||||
{
|
||||
Check(args.Length <= 14, "Garage probe supports at most twelve samples");
|
||||
string ep = Environment.GetEnvironmentVariable("OGL_S3_ENDPOINT") ?? "";
|
||||
string bucketName = Environment.GetEnvironmentVariable("OGL_S3_BUCKET") ?? "";
|
||||
Check(Uri.TryCreate(ep, UriKind.Absolute, out Uri? epUri), "Garage endpoint not configured");
|
||||
var garage = NewConfig(true);
|
||||
var cg = garage.Configs["OGLS3Storage"]!;
|
||||
cg.Set("Endpoint", ep);
|
||||
cg.Set("Bucket", bucketName);
|
||||
cg.Set("Region", "garage");
|
||||
cg.Set("ForcePathStyle", true);
|
||||
cg.Set("UseSSL", epUri!.Scheme == Uri.UriSchemeHttps);
|
||||
cg.Set("ObjectKeyLayout", "garage-legacy");
|
||||
cg.Set("ConnectionTimeoutSeconds", 5);
|
||||
cg.Set("RequestTimeoutSeconds", 30);
|
||||
cg.Set("MaxRetryAttempts", 2);
|
||||
using var realGarage = new OGLS3ObjectStore(OGLS3StorageOptions.Read(garage));
|
||||
realGarage.CheckBucket();
|
||||
int number = 0;
|
||||
foreach (string hash in args.Skip(1))
|
||||
{
|
||||
Check(hash.Length == 64 && hash.All(c => c is >= '0' and <= '9' or >= 'a' and <= 'f'),
|
||||
"Garage probe only accepts 64-byte lowercase hex digests");
|
||||
Check(realGarage.Exists(hash), "Garage imported object missing");
|
||||
byte[] payload = realGarage.Get(hash)!;
|
||||
Check(payload != null && Convert.ToHexString(SHA256.HashData(payload)).ToLowerInvariant() == hash,
|
||||
"Garage imported object content checksum mismatch");
|
||||
Console.WriteLine($"Garage read-only provider sample {++number}: PASS ({payload.Length} bytes)");
|
||||
}
|
||||
Console.WriteLine("Real Garage S3 provider read-only bucket, HEAD, GET, SHA256: PASS");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Contains("--s3-integration", StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine("Isolated S3 integration tests not requested; no S3 network requests made.");
|
||||
@@ -123,6 +168,28 @@ try
|
||||
Check(store.Get(hash)!.SequenceEqual(sample), "GET modified binary data");
|
||||
Check(store.Put(sample) == hash, "Idempotent conditional write failed");
|
||||
}
|
||||
// Migrated Garage FSAssets objects use sha256/xx/hash, never the
|
||||
// canonical assets/sha256/xx/yy/hash key. Exercise read + write.
|
||||
var garageConfig = NewConfig(true);
|
||||
var garageSettings = garageConfig.Configs["OGLS3Storage"]!;
|
||||
garageSettings.Set("Endpoint", endpoint);
|
||||
garageSettings.Set("Bucket", bucket);
|
||||
garageSettings.Set("Region", "us-east-1");
|
||||
garageSettings.Set("ForcePathStyle", true);
|
||||
garageSettings.Set("UseSSL", false);
|
||||
garageSettings.Set("ObjectKeyLayout", "garage-legacy");
|
||||
using (var garageStore = new OGLS3ObjectStore(OGLS3StorageOptions.Read(garageConfig)))
|
||||
{
|
||||
byte[] garageBytes = Encoding.UTF8.GetBytes("garage-legacy-" + Guid.NewGuid());
|
||||
string garageHash = Convert.ToHexString(SHA256.HashData(garageBytes)).ToLowerInvariant();
|
||||
Check(garageStore.Put(garageBytes) == garageHash, "Garage legacy PUT hash mismatch");
|
||||
string garageKey = "sha256/" + garageHash[..2] + "/" + garageHash;
|
||||
objects.Add(garageKey);
|
||||
Check(garageStore.Exists(garageHash), "Garage legacy HEAD failed");
|
||||
Check(garageStore.Get(garageHash)!.SequenceEqual(garageBytes), "Garage legacy GET failed");
|
||||
Check(!store.Exists(garageHash), "Canonical layout silently found Garage legacy key");
|
||||
}
|
||||
|
||||
byte[] tampered = { 42, 0, 1, 253 };
|
||||
string falseHash = new string('b', 64);
|
||||
string badKey = "assets/sha256/bb/bb/" + falseHash;
|
||||
|
||||
@@ -82,10 +82,14 @@ namespace OpenGenesisLINK.Addons.AssetService
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static string Key(string hash)
|
||||
private string Key(string hash)
|
||||
{
|
||||
ValidateHash(hash);
|
||||
return "assets/sha256/" + hash.Substring(0, 2) + "/" + hash.Substring(2, 2) + "/" + hash;
|
||||
// Strictly configured layout: do not implicitly mask missing S3 blobs
|
||||
// by falling back to another prefix or to live FSAssets.
|
||||
return options.ObjectKeyLayout == "garage-legacy"
|
||||
? "sha256/" + hash.Substring(0, 2) + "/" + hash
|
||||
: "assets/sha256/" + hash.Substring(0, 2) + "/" + hash.Substring(2, 2) + "/" + hash;
|
||||
}
|
||||
|
||||
private CancellationTokenSource Timeout()
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
Endpoint = http://127.0.0.1:9000
|
||||
Bucket = ogl-assets
|
||||
Region = us-east-1
|
||||
; canonical (default) or garage-legacy (one-off migrated Garage bucket)
|
||||
ObjectKeyLayout = canonical
|
||||
AccessKey =
|
||||
SecretKey =
|
||||
ForcePathStyle = true
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace OpenGenesisLINK.Addons.AssetService
|
||||
public string Endpoint { get; private set; }
|
||||
public string Bucket { get; private set; }
|
||||
public string Region { get; private set; }
|
||||
// Explicit compatibility for objects from the 2026 Garage FSAssets importer.
|
||||
// The default always remains the canonical assets/sha256 layout.
|
||||
public string ObjectKeyLayout { get; private set; }
|
||||
public string AccessKey { get; private set; }
|
||||
public string SecretKey { get; private set; }
|
||||
public bool ForcePathStyle { get; private set; }
|
||||
@@ -36,6 +39,7 @@ namespace OpenGenesisLINK.Addons.AssetService
|
||||
Endpoint = section.GetString("Endpoint", "http://127.0.0.1:9000").Trim(),
|
||||
Bucket = section.GetString("Bucket", "ogl-assets").Trim(),
|
||||
Region = section.GetString("Region", "us-east-1").Trim(),
|
||||
ObjectKeyLayout = section.GetString("ObjectKeyLayout", "canonical").Trim(),
|
||||
ForcePathStyle = section.GetBoolean("ForcePathStyle", true),
|
||||
ConnectionTimeoutSeconds = section.GetInt("ConnectionTimeoutSeconds", 10),
|
||||
RequestTimeoutSeconds = section.GetInt("RequestTimeoutSeconds", 60),
|
||||
@@ -73,6 +77,9 @@ namespace OpenGenesisLINK.Addons.AssetService
|
||||
if (!ssl && !IsPrivateEndpoint(endpoint.Host))
|
||||
throw new InvalidOperationException("Plain HTTP S3 requires a loopback or private IP Endpoint; use HTTPS otherwise.");
|
||||
|
||||
if (options.ObjectKeyLayout != "canonical" && options.ObjectKeyLayout != "garage-legacy")
|
||||
throw new InvalidOperationException("OGL S3 ObjectKeyLayout must be canonical or garage-legacy.");
|
||||
|
||||
if (String.IsNullOrWhiteSpace(options.Bucket) ||
|
||||
options.Bucket.Length > 63 ||
|
||||
options.Bucket.IndexOfAny(new[] { '/', '\\', ' ', ':', '@' }) >= 0 ||
|
||||
|
||||
@@ -232,3 +232,9 @@ separatem Metadatenbank-Klon.
|
||||
|
||||
**Diese Erweiterung ist bewusst deaktiviert. Die bisherige
|
||||
FSAssets-Installation arbeitet ohne neue Dienste und ohne S3-Zugangsdaten.**
|
||||
|
||||
## Migration der Garage-Objekte (Bestand November 2026)
|
||||
|
||||
Der vorhandene FSAssets→Garage-Importer schreibt **absichtlich ein anderes Objektlayout** als der neue Provider: `sha256/xx/<sha256>` statt `assets/sha256/xx/yy/<sha256>`. Ohne explizite Einstellung erhält der Provider bei Bestandsobjekten 404. Nur für eine **isolierte** Garage-Testinstanz darf `ObjectKeyLayout = garage-legacy` aktiviert werden; der Standard bleibt `canonical`. GET/HEAD/PUT verwenden dann ausschließlich diesen alten Pfad; der Provider hat **keinen stillen Fallback** in den anderen Prefix oder auf FSAssets. Eine normale NexTopia-SIM verwendet derzeit den externen ROBUST-AssetService, daher reicht die lokale Installation der OGL-DLL nicht: Für einen regional begrenzten S3-Canary müssen der RegionAssetConnector und die Metadatenquelle isoliert konfiguriert und geprüft werden.
|
||||
|
||||
Wichtig: Der gemeldete Importbestand enthält 827 wegen Digest-Abweichung verworfene Quelldateien. Vor einem tatsächlichen Region-Cutover müssen die von NexTopia benötigten Asset-UUIDs mit der SQL-Hash-Metadatenquelle abgeglichen und im konfigurierten S3-Prefix als vollständige gültige Payload verifiziert werden. Dieser Hinweis ist keine Freigabe zum produktiven Cutover.
|
||||
Reference in new issue
Block a user