feat(scripts): read-only, allow-listed Files global for site scripts; Delmia test receiver parses recipe files
Script file access (design docs/plans/2026-09-28-script-file-access-design.md): Files.ReadTextAsync / ReadLinesAsync / ExistsAsync on site ScriptGlobals (+ Instance.Files), backed by the site-singleton ScriptFileReader. The one host-mediated exception to the System.IO ban - scripts still never name a System.IO type. OFF by default: ScadaBridge:SiteRuntime:ScriptFileAccess:AllowedRoots (empty = every call throws Disabled) + MaxFileBytes (1 MiB, validated 1..64 MiB, roots must be absolute). Guard: fully qualified, no device paths / ADS, canonical path strictly inside a root (directory-boundary match), no reparse point on the file or any directory below the root, size cap before and during the read. Errors are one Commons type, ScriptFileAccessException(+ScriptFileAccessFailure); Commons.Types.Scripts joins the default script imports on every surface so it binds by short name. Mirrored on ScriptCompileSurface (CompileFiles, parity-pinned) and the Test Run sandbox (binds, refuses Disabled). Inbound (central) scripts do not get it. Rig: docker/recipes (sample RecipeValueName,RecipeValue files incl. an invalid one) bind-mounted read-only at /app/recipes on both site-a nodes with AllowedRoots [/app/recipes]. The TestMesMachine SimDelmiaRecipe simulator now reads + parses the downloaded file, converts each value to its recipe tag's type and loads it all-or-nothing (14 new TestDelmiaReceiver attributes); verify-mes-test-machine.sh group A covers accept / re-download / invalid lines / NotFound / OutsideAllowedRoots, VERIFY_GROUPS selects groups (rig: AD).
This commit is contained in:
@@ -96,6 +96,46 @@ public class SandboxScriptHost
|
||||
/// <c>Log</c> and <c>Instance.Log</c> are the same object here too.
|
||||
/// </summary>
|
||||
public SandboxLog Log => Instance.Log;
|
||||
|
||||
/// <summary>
|
||||
/// Sandbox mirror of the site runtime's <c>Files</c> global (design 2026-09-28), so a script
|
||||
/// that reads a file BINDS in the Test Run editor. The central sandbox has no access to a
|
||||
/// site node's filesystem, so every call throws the same
|
||||
/// <see cref="ScriptFileAccessException"/> (<see cref="ScriptFileAccessFailure.Disabled"/>) a
|
||||
/// site without configured roots throws — a script's own error handling runs as it would there.
|
||||
/// </summary>
|
||||
public SandboxFilesAccessor Files => Instance.Files;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sandbox mirror of the SiteRuntime <c>FilesAccessor</c>: binds identically, refuses at run time.
|
||||
/// </summary>
|
||||
public class SandboxFilesAccessor
|
||||
{
|
||||
private const string Message =
|
||||
"Files.* reads the SITE node's filesystem (under ScadaBridge:SiteRuntime:ScriptFileAccess:AllowedRoots), " +
|
||||
"which the central Test Run sandbox cannot reach — deploy to a site to exercise file-reading scripts.";
|
||||
|
||||
/// <summary>Mirrors <c>FilesAccessor.ReadTextAsync</c>; always refused in the sandbox.</summary>
|
||||
/// <param name="path">The file path.</param>
|
||||
/// <param name="cancellationToken">Unused in the sandbox.</param>
|
||||
/// <returns>Never returns.</returns>
|
||||
public Task<string> ReadTextAsync(string path, CancellationToken cancellationToken = default)
|
||||
=> throw new ScriptFileAccessException(ScriptFileAccessFailure.Disabled, Message);
|
||||
|
||||
/// <summary>Mirrors <c>FilesAccessor.ReadLinesAsync</c>; always refused in the sandbox.</summary>
|
||||
/// <param name="path">The file path.</param>
|
||||
/// <param name="cancellationToken">Unused in the sandbox.</param>
|
||||
/// <returns>Never returns.</returns>
|
||||
public Task<IReadOnlyList<string>> ReadLinesAsync(string path, CancellationToken cancellationToken = default)
|
||||
=> throw new ScriptFileAccessException(ScriptFileAccessFailure.Disabled, Message);
|
||||
|
||||
/// <summary>Mirrors <c>FilesAccessor.ExistsAsync</c>; always refused in the sandbox.</summary>
|
||||
/// <param name="path">The file path.</param>
|
||||
/// <param name="cancellationToken">Unused in the sandbox.</param>
|
||||
/// <returns>Never returns.</returns>
|
||||
public Task<bool> ExistsAsync(string path, CancellationToken cancellationToken = default)
|
||||
=> throw new ScriptFileAccessException(ScriptFileAccessFailure.Disabled, Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,6 +303,9 @@ public class SandboxInstanceContext
|
||||
/// </summary>
|
||||
public SandboxLog Log { get; } = new();
|
||||
|
||||
/// <summary>Sandbox mirror of <c>ScriptRuntimeContext.Files</c> (design 2026-09-28); always refuses.</summary>
|
||||
public SandboxFilesAccessor Files { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SandboxInstanceContext.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user