Principle:AIPentest CyberStrikeAI Configuration Loading
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Server_Lifecycle |
| Last Updated | 2026-10-19 04:10 GMT |
Overview
A configuration-loading technique that parses a YAML file into a strongly-typed config, validates guardrails, applies defaults, expands environment variables, and merges directory-loaded tool and role definitions, so the server starts from a single normalized config object.
Description
A server needs one authoritative config object covering server transport, database, MCP, auth, AI channels, robots, project, and external MCP. Configuration loading reads the YAML, validates the toolguard rules (refusing to start if they don't compile), applies defaults (session duration, audit detail size, AI channel), expands environment variables in external MCP server entries, merges tool definitions from a configured tools directory, and loads role definitions from a roles directory. The result is a single *config.Config the composition root consumes.
A companion EnsureLocalConfig copies the example config on first start, and EnsureMCPAuth bootstraps an MCP auth token if absent, so a clean clone can start without manual file editing.
Usage
Use this principle when a single binary needs to be configured by a file but also wants safe defaults, env-var expansion for secrets, and validated guardrails before startup.
Theoretical Basis
Loading is a parse-validate-default-expand-merge pipeline:
data = ReadFile(path)
cfg = yaml.Unmarshal(data)
validateToolGuardYAML(data); toolguard.Compile(cfg.EffectiveToolGuard()) -- refuse if invalid
cfg.Auth.SessionDurationHours ||= 12
cfg.Audit.MaxDetailBytes ||= 8192
cfg.NormalizeAIProviderProfiles(); cfg.ApplyDefaultAIChannel()
validateOpenAIOutputLimits(cfg.OpenAI)
cfg.Security.Tools = MergeToolsFromDir(toolsDir, inlineTools) -- directory merge
for server in cfg.ExternalMCP.Servers:
server.ExternalMCPEnable ||= true
ExpandConfigEnv(&server) -- ${VAR} / ${VAR:-default}
cfg.Roles = LoadRolesFromDir(rolesDir)
return cfg
Practical Guide
- Validate guardrails before returning the config so an invalid policy never starts the server.
- Merge directory-loaded tools after inline tools so operators can override specifics.
- Expand env vars only in external-MCP entries where secrets are expected, not globally.
- Ship an example config and auto-copy it on first start for zero-touch bootstrapping.