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:
Joseph Doherty
2026-09-28 10:36:42 -04:00
parent 0af0672597
commit b3021e7c5f
31 changed files with 1157 additions and 77 deletions
@@ -70,6 +70,9 @@ public sealed class ScriptCompileSurface
/// <summary>Mirrors <c>ScriptGlobals.Log</c>.</summary>
public CompileLog Log => throw new NotSupportedException(CompileOnly);
/// <summary>Mirrors <c>ScriptGlobals.Files</c>.</summary>
public CompileFiles Files => throw new NotSupportedException(CompileOnly);
/// <summary>Compile-only mirror of <c>ScriptRuntimeContext</c> (the <c>Instance</c> global).</summary>
public sealed class CompileInstance
{
@@ -110,6 +113,37 @@ public sealed class ScriptCompileSurface
/// <summary>Mirrors <c>ScriptRuntimeContext.Log</c>.</summary>
public CompileLog Log => throw new NotSupportedException(CompileOnly);
/// <summary>Mirrors <c>ScriptRuntimeContext.Files</c>.</summary>
public CompileFiles Files => throw new NotSupportedException(CompileOnly);
}
/// <summary>
/// Compile-only mirror of the SiteRuntime <c>FilesAccessor</c> (design 2026-09-28) — the
/// <c>Files</c> global's read-only, allow-listed file access.
/// </summary>
public sealed class CompileFiles
{
/// <summary>Mirrors <c>FilesAccessor.ReadTextAsync</c>.</summary>
/// <param name="path">Absolute path under an allowed root.</param>
/// <param name="cancellationToken">Cancels the read.</param>
/// <returns>The file's text.</returns>
public Task<string> ReadTextAsync(string path, CancellationToken cancellationToken = default)
=> throw new NotSupportedException(CompileOnly);
/// <summary>Mirrors <c>FilesAccessor.ReadLinesAsync</c>.</summary>
/// <param name="path">Absolute path under an allowed root.</param>
/// <param name="cancellationToken">Cancels the read.</param>
/// <returns>The file's lines.</returns>
public Task<IReadOnlyList<string>> ReadLinesAsync(string path, CancellationToken cancellationToken = default)
=> throw new NotSupportedException(CompileOnly);
/// <summary>Mirrors <c>FilesAccessor.ExistsAsync</c>.</summary>
/// <param name="path">Absolute path under an allowed root.</param>
/// <param name="cancellationToken">Cancels the check.</param>
/// <returns>Whether the file exists.</returns>
public Task<bool> ExistsAsync(string path, CancellationToken cancellationToken = default)
=> throw new NotSupportedException(CompileOnly);
}
/// <summary>
@@ -342,5 +342,8 @@ public static class ScriptTrustPolicy
"System.Collections.Generic",
"System.Linq",
"System.Threading.Tasks",
// Script-facing Commons types (ScriptAlarm, ScriptFileAccessException, …) — mirrors the
// site runtime's imports so the deploy gate binds the same short names (design 2026-09-28).
"ZB.MOM.WW.ScadaBridge.Commons.Types.Scripts",
];
}