Skip to content

Tamp Analyzers

Scott Singleton edited this page May 25, 2026 · 3 revisions

Tamp Analyzers (TAMP001–TAMP006)

The Tamp.Analyzers Roslyn analyzer family catches common build-script mistakes at compile time, before they can silently misbehave at runtime. The analyzers ship bundled inside Tamp.Core.nupkg at analyzers/dotnet/cs/ — adopters get them automatically with no separate PackageReference.

ID Rule Default severity Shipped in
TAMP001 Unobserved CommandPlan Warning Tamp.Core 1.4.2+
TAMP002 Missing Tamp entry point Info Tamp.Core 1.5.0+
TAMP003 async lambda passed to Executes(Action) Warning Tamp.Core 1.5.0+
TAMP004 Secret.Reveal() outside an approved context Warning Tamp.Core 1.6.0+
TAMP005 [FromPath] field shadowing the tool's static class Warning Tamp.Core 1.9.0+
TAMP006 Target property shadowing the tool's static class Warning Tamp.Core 1.9.0+

TAMP001 — Unobserved CommandPlan

The bug class: a CommandPlan is constructed but never returned from the lambda. The executor never runs it; the target appears to succeed without doing the work.

// Triggers TAMP001
Target Publish => _ => _
    .Executes(() =>
    {
        DotNet.NuGetPush(s => s.SetPackagePath(p));   // ← discarded; never executed
    });

Fix: return the plan.

Target Publish => _ => _
    .Executes(() => DotNet.NuGetPush(s => s.SetPackagePath(p)));

The analyzer fires when a CommandPlan-returning expression occurs as a statement (not assigned to anything, not returned).

Full reference: docs/analyzers/TAMP001.md.


TAMP002 — Missing Tamp entry point

The bug class: a Build : TampBuild-derived class has no Main method calling Execute<Build>(args). Compiles fine; produces no runnable build script.

// Triggers TAMP002
class Build : TampBuild
{
    Target Restore => _ => _.Executes(...);
    // ← missing `static int Main(string[] args) => Execute<Build>(args);`
}

Fix: add the entry point.

class Build : TampBuild
{
    public static int Main(string[] args) => Execute<Build>(args);
    Target Restore => _ => _.Executes(...);
}

The analyzer uses RegisterCompilationStartAction + state collection to inspect the whole compilation and fire once at the end if no entry point matches the expected shape.


TAMP003 — async lambda binding to Executes(Action)

The bug class: when you write Executes(async () => { await Foo(); }) against pre-1.5.0 Tamp.Core, the lambda matches the Executes(Action) overload rather than Executes(Func<Task>). The state machine becomes async void, the Task is discarded, and the target completes before the awaited work finishes.

// Triggers TAMP003 on Tamp.Core 1.4.x and earlier
.Executes(async () => { await HttpProbe.GetAsync("https://x"); });

Fix: bump to Tamp.Core 1.5.0+ — gains the Executes(Func<Task>) overload, after which the same lambda binds correctly. The analyzer auto-resolves once the new overload is present.

Full reference: docs/analyzers/TAMP003.md.


TAMP004 — Secret.Reveal() outside an approved context

The bug class: Secret.Reveal() returns cleartext. The masking primitives in Tamp.Core (Secret.ToString() returns <Secret:Name>, CommandPlan.Secrets collection masks values in process traces, runner-side env-var masking) only protect values they can see. Calling Reveal() and then logging the raw string defeats all of them.

// Triggers TAMP004
class Build : TampBuild
{
    [Secret] readonly Secret Token = null!;
    void M() => Console.WriteLine("token: " + Token.Reveal());   // ← leaked
}

The right call here is Token.ToString() (which masks) or routing the secret through a wrapper that registers it in CommandPlan.Secrets.

Approved contexts

Reveal() is expected in three contexts. The analyzer skips them:

  1. Classes whose name ends in Settings or SettingsBase — the canonical Tamp wrapper-settings shape. Every satellite uses this pattern (SignToolSignSettings, SccacheStorageSettings, MsStoreReconfigureSettings, SyftAttestSettings, etc.). The settings class is about to emit a CommandPlan argument or env var, so it has a legitimate reason to reveal the value.

  2. Tamp framework internals — namespaces Tamp.Core, Tamp.Cli, and any Tamp.NetCli.V*. These are the runner / dispatcher surfaces that must read secrets in order to spawn child processes.

  3. Test code — class names ending in Tests or namespaces containing .Tests. Test arrange/assert phases need to construct and read Secret values directly.

Everywhere else, calling Reveal() trips the analyzer.

What this replaces (and why 1.6.0 made it public)

Pre-1.6.0, Secret.Reveal() was internal and gated by per-satellite [InternalsVisibleTo("Tamp.MySatellite")] entries in Tamp.Core/AssemblyInfo.cs. Every new satellite that handled a service-principal client secret / cert password / API key required:

  1. A PR to Tamp.Core/AssemblyInfo.cs adding the IVT entry
  2. A Tamp.Core point release
  3. A nuget propagation wait (10-15 min)
  4. The satellite then declared Tamp.Core >= <new-version> in its package metadata

This was real velocity friction during onboarding waves. The IVT gate also wasn't load-bearing for actual security — any listed assembly could leak just as easily; the protection was always in ToString() + CommandPlan.Secrets masking, not in Reveal()'s visibility.

1.6.0 makes Reveal() public and uses TAMP004 to flag misuse. Net-new satellites just call secret.Reveal() directly from inside their *Settings.cs classes. Zero ceremony, zero Tamp.Core bumps. Existing satellites continue working unchanged — the IVT entries on the old assembly list remain valid but are no longer load-bearing for Reveal().

Configuring severity

Default severity is Warning. Adopters can tighten to Error for the security-team's CI build via .editorconfig:

[*.cs]
dotnet_diagnostic.TAMP004.severity = error

Or relax to Suggestion/Silent if there's a legitimate non-Settings call site (rare; usually means the design needs revisiting):

[*.cs]
dotnet_diagnostic.TAMP004.severity = none

Full reference: docs/analyzers/TAMP004.md.


TAMP005 — [FromPath] field shadowing the tool's static class

The bug class: an adopter injects a Tool reference with [FromPath("cargo")] and names the field Cargo — same identifier as the wrapper's static class (Tamp.Cargo.Cargo). C# name-resolution picks the field over the static class at the call site, so Cargo.Build(Cargo, s => ...) fails to compile with "Tool has no Build" — because the resolver looked up Build on the Tool-typed field, not the static class.

// Triggers TAMP005
using Tamp.Cargo;

class Build : TampBuild
{
    [FromPath("cargo")] readonly Tool Cargo = null!;   // ← shadows Tamp.Cargo.Cargo

    Target Compile => _ => _.Executes(() =>
        Cargo.Build(Cargo, s => s.SetRelease(true)));  // compile error: Tool has no Build
}

Fix: use a disambiguated field name. The recommended convention is <Tool>Bin (also <Tool>Tool, <Tool>Cli, <Tool>Exe — any of those four suffixes opts out of the warning).

[FromPath("cargo")] readonly Tool CargoBin = null!;

Target Compile => _ => _.Executes(() =>
    Cargo.Build(CargoBin, s => s.SetRelease(true)));   // resolves correctly

The analyzer walks the syntax tree of every [FromPath] / [FromNodeModules] -decorated field. When the field name matches a Tamp.<Family>.<Family> static class accessible from the surrounding namespace via using directives, TAMP005 fires at the field declaration with a recommended-rename diagnostic.

Same root cause as TAMP006 — different syntactic surface (field vs Target property).


TAMP006 — Target property shadowing the tool's static class

The bug class: an adopter declares a Target-typed property whose name matches the wrapper's static class (GraphQLCodegen, Trivy, etc.). Inside the property's lambda, the wrapper-class identifier is shadowed by the surrounding property's enclosing scope, so the call resolves to the Target itself rather than the facade.

// Triggers TAMP006
using Tamp.GraphQLCodegen.V5;

Target GraphQLCodegen => _ => _                       // ← shadows Tamp.GraphQLCodegen.V5.GraphQLCodegen
    .Executes(() => GraphQLCodegen.Generate(...));    // resolves to the Target, not the facade

Fix: use a verb-form name for the Target — RunGraphQLCodegen, RegenerateClient, FrontendCodegen — anything that isn't the wrapper's class name verbatim.

Target FrontendCodegen => _ => _
    .Executes(() => GraphQLCodegen.Generate(...));    // unambiguous

The analyzer uses the same shadowing-detection helper as TAMP005 — walks the syntax tree, finds Target-typed properties whose name matches any Tamp.<Family>.<Family> static class accessible in scope, fires at the property declaration.

Both TAMP005 and TAMP006 catch the same underlying mistake (an identifier in the build class shadowing the tool's class name); the analyzers run at compile time so you find out before you've staged a CI run that silently does the wrong thing.


Reflection-bound field warning suppression

Tamp also ships a diagnostic suppressor (ReflectionBoundFieldWarningSuppressor) alongside the analyzers. It silences the C# compiler's CS0649 ("field is never assigned") warning on fields decorated with Tamp's reflection-bound attributes ([Parameter], [Secret], [Solution], [GitRepository], [FromPath], [FromNodeModules], [NuGetPackage], [BuildReporter]). Those fields are populated by the framework via reflection at startup, so the compiler's "you never wrote to this" warning is a false positive.

No action needed; the suppressor activates automatically when Tamp.Core is referenced.


Roadmap

  • TAM-197 — WrapperSettingsBase in Tamp.Core with protected static Reveal(Secret). Inheritance-based blessing layered on top of TAMP004's analyzer heuristic. Backlogged.

Where next

Settings authoring style

The example(s) above use the fluent Set*-chain shape. Every wrapper verb on this page also accepts a new XxxSettings { ... } object-init form. Both produce identical CommandPlans; the fluent shape stays canonical in docs and the tamp init template. See Build Script Authoring → Two authoring styles for the side-by-side comparison.

Clone this wiki locally