up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
@@ -9,33 +9,33 @@ using StellaOps.Scanner.EntryTrace.FileSystem;
|
||||
using StellaOps.Scanner.EntryTrace.Parsing;
|
||||
|
||||
namespace StellaOps.Scanner.EntryTrace;
|
||||
|
||||
/// <summary>
|
||||
/// Combines OCI configuration and root filesystem data into the context required by the EntryTrace analyzer.
|
||||
/// </summary>
|
||||
public static class EntryTraceImageContextFactory
|
||||
{
|
||||
private const string DefaultUser = "root";
|
||||
|
||||
public static EntryTraceImageContext Create(
|
||||
OciImageConfig config,
|
||||
IRootFileSystem fileSystem,
|
||||
EntryTraceAnalyzerOptions options,
|
||||
string imageDigest,
|
||||
string scanId,
|
||||
ILogger? logger = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(config);
|
||||
ArgumentNullException.ThrowIfNull(fileSystem);
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(imageDigest);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(scanId);
|
||||
|
||||
var environment = BuildEnvironment(config.Environment);
|
||||
var path = DeterminePath(environment, options);
|
||||
var workingDir = NormalizeWorkingDirectory(config.WorkingDirectory);
|
||||
var user = NormalizeUser(config.User);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Combines OCI configuration and root filesystem data into the context required by the EntryTrace analyzer.
|
||||
/// </summary>
|
||||
public static class EntryTraceImageContextFactory
|
||||
{
|
||||
private const string DefaultUser = "root";
|
||||
|
||||
public static EntryTraceImageContext Create(
|
||||
OciImageConfig config,
|
||||
IRootFileSystem fileSystem,
|
||||
EntryTraceAnalyzerOptions options,
|
||||
string imageDigest,
|
||||
string scanId,
|
||||
ILogger? logger = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(config);
|
||||
ArgumentNullException.ThrowIfNull(fileSystem);
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(imageDigest);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(scanId);
|
||||
|
||||
var environment = BuildEnvironment(config.Environment);
|
||||
var path = DeterminePath(environment, options);
|
||||
var workingDir = NormalizeWorkingDirectory(config.WorkingDirectory);
|
||||
var user = NormalizeUser(config.User);
|
||||
|
||||
var context = new EntryTraceContext(
|
||||
fileSystem,
|
||||
environment,
|
||||
@@ -477,132 +477,132 @@ public static class EntryTraceImageContextFactory
|
||||
|
||||
private static string CreateSignature(ImmutableArray<string> command)
|
||||
=> string.Join('\u001F', command);
|
||||
|
||||
private static ImmutableDictionary<string, string> BuildEnvironment(ImmutableArray<string> raw)
|
||||
{
|
||||
if (raw.IsDefaultOrEmpty)
|
||||
{
|
||||
return ImmutableDictionary<string, string>.Empty;
|
||||
}
|
||||
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var entry in raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entry))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var separatorIndex = entry.IndexOf('=');
|
||||
if (separatorIndex < 0)
|
||||
{
|
||||
var key = entry.Trim();
|
||||
if (key.Length > 0)
|
||||
{
|
||||
dictionary[key] = string.Empty;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
var keyPart = entry[..separatorIndex].Trim();
|
||||
if (keyPart.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var valuePart = entry[(separatorIndex + 1)..];
|
||||
dictionary[keyPart] = valuePart;
|
||||
}
|
||||
|
||||
return ImmutableDictionary.CreateRange(StringComparer.Ordinal, dictionary);
|
||||
}
|
||||
|
||||
private static ImmutableArray<string> DeterminePath(ImmutableDictionary<string, string> env, EntryTraceAnalyzerOptions options)
|
||||
{
|
||||
if (env.TryGetValue("PATH", out var pathValue) && !string.IsNullOrWhiteSpace(pathValue))
|
||||
{
|
||||
return SplitPath(pathValue);
|
||||
}
|
||||
|
||||
var fallback = string.IsNullOrWhiteSpace(options.DefaultPath)
|
||||
? EntryTraceDefaults.DefaultPath
|
||||
: options.DefaultPath;
|
||||
|
||||
return SplitPath(fallback);
|
||||
}
|
||||
|
||||
private static string NormalizeWorkingDirectory(string? workingDir)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(workingDir))
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
var text = workingDir.Replace('\\', '/').Trim();
|
||||
if (!text.StartsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
text = "/" + text;
|
||||
}
|
||||
|
||||
if (text.Length > 1 && text.EndsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
text = text.TrimEnd('/');
|
||||
}
|
||||
|
||||
return text.Length == 0 ? "/" : text;
|
||||
}
|
||||
|
||||
private static string NormalizeUser(string? user)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(user))
|
||||
{
|
||||
return DefaultUser;
|
||||
}
|
||||
|
||||
return user.Trim();
|
||||
}
|
||||
|
||||
private static ImmutableArray<string> SplitPath(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return ImmutableArray<string>.Empty;
|
||||
}
|
||||
|
||||
var builder = ImmutableArray.CreateBuilder<string>();
|
||||
foreach (var segment in value.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
if (segment.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var normalized = segment.Replace('\\', '/');
|
||||
if (!normalized.StartsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
normalized = "/" + normalized;
|
||||
}
|
||||
|
||||
if (normalized.EndsWith("/", StringComparison.Ordinal) && normalized.Length > 1)
|
||||
{
|
||||
normalized = normalized.TrimEnd('/');
|
||||
}
|
||||
|
||||
builder.Add(normalized);
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bundles the resolved entrypoint and context required for the analyzer to operate.
|
||||
/// </summary>
|
||||
public sealed record EntryTraceImageContext(
|
||||
EntrypointSpecification Entrypoint,
|
||||
EntryTraceContext Context);
|
||||
|
||||
internal static class EntryTraceDefaults
|
||||
{
|
||||
public const string DefaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
||||
}
|
||||
|
||||
private static ImmutableDictionary<string, string> BuildEnvironment(ImmutableArray<string> raw)
|
||||
{
|
||||
if (raw.IsDefaultOrEmpty)
|
||||
{
|
||||
return ImmutableDictionary<string, string>.Empty;
|
||||
}
|
||||
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var entry in raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entry))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var separatorIndex = entry.IndexOf('=');
|
||||
if (separatorIndex < 0)
|
||||
{
|
||||
var key = entry.Trim();
|
||||
if (key.Length > 0)
|
||||
{
|
||||
dictionary[key] = string.Empty;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
var keyPart = entry[..separatorIndex].Trim();
|
||||
if (keyPart.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var valuePart = entry[(separatorIndex + 1)..];
|
||||
dictionary[keyPart] = valuePart;
|
||||
}
|
||||
|
||||
return ImmutableDictionary.CreateRange(StringComparer.Ordinal, dictionary);
|
||||
}
|
||||
|
||||
private static ImmutableArray<string> DeterminePath(ImmutableDictionary<string, string> env, EntryTraceAnalyzerOptions options)
|
||||
{
|
||||
if (env.TryGetValue("PATH", out var pathValue) && !string.IsNullOrWhiteSpace(pathValue))
|
||||
{
|
||||
return SplitPath(pathValue);
|
||||
}
|
||||
|
||||
var fallback = string.IsNullOrWhiteSpace(options.DefaultPath)
|
||||
? EntryTraceDefaults.DefaultPath
|
||||
: options.DefaultPath;
|
||||
|
||||
return SplitPath(fallback);
|
||||
}
|
||||
|
||||
private static string NormalizeWorkingDirectory(string? workingDir)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(workingDir))
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
var text = workingDir.Replace('\\', '/').Trim();
|
||||
if (!text.StartsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
text = "/" + text;
|
||||
}
|
||||
|
||||
if (text.Length > 1 && text.EndsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
text = text.TrimEnd('/');
|
||||
}
|
||||
|
||||
return text.Length == 0 ? "/" : text;
|
||||
}
|
||||
|
||||
private static string NormalizeUser(string? user)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(user))
|
||||
{
|
||||
return DefaultUser;
|
||||
}
|
||||
|
||||
return user.Trim();
|
||||
}
|
||||
|
||||
private static ImmutableArray<string> SplitPath(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return ImmutableArray<string>.Empty;
|
||||
}
|
||||
|
||||
var builder = ImmutableArray.CreateBuilder<string>();
|
||||
foreach (var segment in value.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
if (segment.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var normalized = segment.Replace('\\', '/');
|
||||
if (!normalized.StartsWith("/", StringComparison.Ordinal))
|
||||
{
|
||||
normalized = "/" + normalized;
|
||||
}
|
||||
|
||||
if (normalized.EndsWith("/", StringComparison.Ordinal) && normalized.Length > 1)
|
||||
{
|
||||
normalized = normalized.TrimEnd('/');
|
||||
}
|
||||
|
||||
builder.Add(normalized);
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bundles the resolved entrypoint and context required for the analyzer to operate.
|
||||
/// </summary>
|
||||
public sealed record EntryTraceImageContext(
|
||||
EntrypointSpecification Entrypoint,
|
||||
EntryTraceContext Context);
|
||||
|
||||
internal static class EntryTraceDefaults
|
||||
{
|
||||
public const string DefaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user