Design documents provide detailed implementation guidance for CCM’s resource types, providers, and internal components. They are intended for developers contributing to CCM or those seeking to understand specific implementation details.
For end-user documentation on how to use resources, see Resources.
Note
These design documents are largely written with AI assistance and reviewed before publication.
Contents
Each design document covers:
Purpose and scope: What the component does and its responsibilities
Architecture: How the component fits into CCM’s overall design
Implementation details: Key data structures, interfaces, and algorithms
Provider contracts: Requirements for implementing new providers
Testing considerations: How to test the component
Available Documents
Archive Type: Archive resource for downloading and extracting archives
Apply Type: Apply resource for composing manifests from reusable parts
Multiple actions are joined with “. " (e.g., “Would have downloaded. Would have extracted”).
Desired State Validation
After applying changes (in non-noop mode), the type verifies the archive reached the desired state by calling Status() again and checking all conditions. If validation fails, ErrDesiredStateFailed is returned.
Subsections of Archive Type
HTTP Provider
This document describes the implementation details of the HTTP archive provider for downloading and extracting archives from HTTP/HTTPS URLs.
Provider Selection
The HTTP provider is selected when:
The URL scheme is http or https
The archive file extension is supported (.tar.gz, .tgz, .tar, .zip)
The required extraction tool (tar or unzip) is available in PATH
The IsManageable() function checks these conditions and returns a priority of 1 if all are met.
Operations
Download
Process:
Parse the URL and add Basic Auth credentials if username/password provided
Create HTTP request with custom headers (if specified)
Execute GET request via util.HttpGetResponse()
Verify HTTP 200 status code
Create temporary file in the same directory as the target
Timing: Checksum is verified after download completes but before the atomic rename. This ensures:
Corrupted downloads are never placed at the target path
Temp file is cleaned up on mismatch
Clear error message with both expected and actual checksums
Security Considerations
Credential Handling
Credentials in URL are redacted in log messages via util.RedactUrlCredentials()
Basic Auth header is set by Go’s http.Request.SetBasicAuth(), not manually constructed
Archive Extraction
Extraction uses system tar/unzip commands
No path traversal protection beyond what the tools provide
ExtractParent must be an absolute path (validated in model)
Temporary Files
Created with os.CreateTemp() using pattern <archive-name>-*
Deferred removal ensures cleanup on all exit paths
Ownership set before content written
Platform Support
The provider is Unix-only due to:
Dependency on util.GetFileOwner() which uses syscall for UID/GID resolution
Dependency on util.ChownFile() for ownership management
Timeouts
Operation
Timeout
Configurable
HTTP Download
1 minute (default in HttpGetResponse)
No
Archive Extraction
1 minute
No
Large archives may require increased timeouts in future versions.
Apply Type
This document describes the design of the apply resource type for composing manifests from smaller reusable manifests.
Overview
The apply resource resolves and executes a child manifest within the parent manifest’s execution context. The child manifest shares the parent’s manager and session, allowing resource ordering and subscribe relationships across manifest boundaries.
Key behaviors:
Noop strengthening: A parent in noop mode forces all children into noop mode, regardless of the child’s noop property
Health check strengthening: Same semantics as noop; health check mode can only be strengthened, never weakened
Recursion depth limiting: Nested apply resources are capped at a configurable maximum depth (default 10) to prevent infinite loops
Transitive trust control: The allow_apply property prevents a child manifest from containing its own apply resources
Provider Interface
Apply providers must implement the ApplyProvider interface:
Exceeding the maximum depth returns an error before iterating any child resources.
Transitive Trust
The allow_apply property controls whether a child manifest may contain its own apply resources. When allow_apply is false, the child manifest is scanned for apply resources after resolution but before execution. If any are found, an error is returned.
This provides a mechanism to limit the trust boundary when including manifests authored by others.
allow_apply value
Child contains apply resources
Result
true (default)
Yes
Allowed
true (default)
No
Allowed
false
Yes
Error
false
No
Allowed
Data Handling
The data property provides key-value data to the child manifest. This data is passed through the WithOverridingResolvedData option and merged into the resolved data after the child manifest’s own data resolution.
External data (CLI overrides) always persists through the merge. The parent’s original data is restored after child execution via the state save/restore mechanism.
Subscribe Behavior
Apply resources support the standard subscribe property. Subscribe targets use the apply#name format:
The provider only strengthens noop mode, never weakens it. If the parent manager is already in noop mode, the child inherits that regardless of its own noop property. If the parent is not in noop mode and the resource sets noop: true, the provider enables noop on the manager before resolution.
Parent noop
Resource noop
Action
true
false
No change, parent noop already active
true
true
No change, parent noop already active
false
true
Enable noop on manager
false
false
No change
Health check mode follows the same strengthening pattern. The effective health check mode is true if either the parent or the resource sets it.
Execute Options:
The provider builds these options to control child manifest behavior:
Option
Condition
Purpose
WithSkipSession()
Always
Reuse parent session instead of creating a new one
WithCurrentDepth(n)
Always
Track recursion depth for nested apply resources
WithOverridingResolvedData
data property is set
Merge resource data into the child’s resolved data
WithDenyApplyResources()
allow_apply is false
Prevent child from containing apply resources
State Capture and Restore
The provider saves three pieces of manager state before manifest resolution and restores them after execution via defer. This ensures restoration runs even if resolution or execution fails.
Field
Capture
Restore
Noop mode
mgr.NoopMode()
mgr.SetNoopMode(saved)
Working directory
mgr.WorkingDirectory()
mgr.SetWorkingDirectory(saved)
Data
mgr.Data()
mgr.SetData(saved)
State capture happens before any resolve or mutation calls. This ordering is critical because ResolveManifestUrl mutates the manager’s working directory and data during resolution.
Restoration ensures that subsequent resources in the parent manifest see the original manager state. Without it, a child manifest’s working directory and data changes would leak into sibling resources.
Path Resolution
The resource name property specifies a file path relative to the parent manifest’s directory. During resolution, ResolveManifestFilePath joins relative paths with the manager’s current working directory before opening the file.
For nested apply resources, each level sets the working directory to its own manifest’s parent directory. The state restore ensures the working directory returns to the correct value after each child completes.
/opt/ccm/manifest.yaml WD = /opt/ccm/
apply: sub/manifest.yaml resolves to /opt/ccm/sub/manifest.yaml
WD = /opt/ccm/sub/
apply: lib/manifest.yaml resolves to /opt/ccm/sub/lib/manifest.yaml
WD = /opt/ccm/sub/lib/
(restore WD to /opt/ccm/sub/)
(restore WD to /opt/ccm/)
Child Resource Inspection
After execution, the provider iterates over child resources to count outcomes using the shared session:
Outcome
Detection method
Effect
Failed
mgr.IsResourceFailed
Increment fail count
Changed
mgr.ShouldRefresh
Increment change count
Skipped
Neither
Remainder
The provider builds an ApplyState with the total resource count and reports the outcome:
Child result
Provider behavior
All resources succeeded
Log informational message, return state
Some resources changed
Log warning with counts, return state
Any resource failed
Log error, return error with failure count
Logging
The provider creates a child user logger with a manifest key set to the resource name. All child resource log output includes this key, providing attribution for which parent apply resource triggered the execution.
Exec Type
This document describes the design of the exec resource type for executing commands.
Overview
The exec resource executes commands with idempotency controls:
Creates: Skip execution if a file exists
OnlyIf / Unless: Guard commands that gate execution based on exit code
Refresh Only: Only execute when triggered by a subscribed resource
Exit Codes: Validate success via configurable return codes
Provider Interface
Exec providers must implement the ExecProvider interface:
Subscribe takes precedence over all other idempotency checks - if a subscribed resource changed, the command executes regardless of creates file existence or guard command results.
Exit Code Validation
By default, exit code 0 indicates success. The returns property customizes acceptable codes:
Queries current state normally (checks creates file)
Evaluates guard commands (onlyif/unless) - these run even in noop mode
Evaluates subscribe triggers
Logs what actions would be taken
Sets appropriate NoopMessage:
“Would have executed”
“Would have executed via subscribe”
Reports Changed: true if execution would occur
Does not call provider Execute method
Desired State Validation
After execution (in non-noop mode), the type verifies success:
func (t*Type) isDesiredState(properties, status) bool {
// Creates file check takes precedenceifproperties.Creates!=""&&status.CreatesSatisfied {
returntrue }
// Guard checks only apply before execution (ExitCode is nil)ifstatus.ExitCode==nil {
ifproperties.OnlyIf!=""&& !status.OnlyIfSatisfied {
returntrue// onlyif guard failed, don't run }
ifproperties.Unless!=""&&status.UnlessSatisfied {
returntrue// unless guard succeeded, don't run }
}
// Refresh-only without execution is stableifstatus.ExitCode==nil&&properties.RefreshOnly {
returntrue }
// Check exit code against acceptable returnsreturns:= []int{0}
if len(properties.Returns) > 0 {
returns = properties.Returns }
ifstatus.ExitCode!=nil {
returnslices.Contains(returns, *status.ExitCode)
}
returnfalse}
Guard checks are gated on ExitCode == nil because after execution, the exit code determines success. The post-execution isDesiredState() call must not re-evaluate guards, which would produce incorrect results since guard state is only set on initialStatus.
If the exit code is not in the acceptable returns list, an ErrDesiredStateFailed error is returned.
Command vs Name
The command property is optional. If not specified, the name is used as the command:
# These are equivalent:- exec:
- /usr/bin/myapp --config /etc/myapp.conf:
- exec:
- run-myapp:
command: /usr/bin/myapp --config /etc/myapp.conf
Using a descriptive name with explicit command is recommended for clarity.
Environment and Path
Commands can be configured with custom environment:
This document describes the implementation details of the Posix exec provider for executing commands without a shell.
Provider Selection
The Posix provider is the default exec provider. It is always available and returns priority 1 for all exec resources unless a different provider is explicitly requested via the provider property.
To use the shell provider instead, specify provider: shell in the resource properties.
Comparison with Shell Provider
Feature
Posix
Shell
Shell invocation
No
Yes (/bin/sh -c)
Pipes (|)
Not supported
Supported
Redirections (>, <)
Not supported
Supported
Shell builtins (cd, export)
Not supported
Supported
Glob expansion
Not supported
Supported
Command substitution ($(...))
Not supported
Supported
Argument parsing
shellquote.Split()
Passed as single string
Security
Lower attack surface
Shell injection possible
When to use Posix (default):
Simple commands with arguments
When shell features are not needed
For better security (no shell injection risk)
When to use Shell:
Commands with pipes, redirections, or shell builtins
Complex command strings
When shell expansion is required
Operations
Execute
Process:
Determine command source (Command property or Name if Command is empty)
Parse command string into words using shellquote.Split()
Extract command (first word) and arguments (remaining words)
Execute via CommandRunner.ExecuteWithOptions()
Optionally log output line-by-line if LogOutput is enabled
Command Parsing:
The command string is parsed using github.com/kballard/go-shellquote, which handles:
Syntax
Example
Result
Simple words
echo hello world
["echo", "hello", "world"]
Single quotes
echo 'hello world'
["echo", "hello world"]
Double quotes
echo "hello world"
["echo", "hello world"]
Escaped spaces
echo hello\ world
["echo", "hello world"]
Mixed quoting
echo "it's a test"
["echo", "it's a test"]
Execution Options:
Option
Source
Description
Command
First word after parsing
Executable path or name
Args
Remaining words
Command arguments
Cwd
properties.Cwd
Working directory
Environment
properties.Environment
Additional env vars (KEY=VALUE format)
Path
properties.Path
Search path for executables
Timeout
properties.ParsedTimeout
Maximum execution time
Output Logging:
When LogOutput: true is set and a user logger is provided:
The model validates exec properties before execution:
Property
Validation
name
Must be parseable by shellquote (balanced quotes)
timeout
Must be valid duration format (e.g., 30s, 5m)
subscribe
Each entry must be type#name format
path
Each directory must be absolute (start with /)
environment
Each entry must be KEY=VALUE format with non-empty key and value
Platform Support
The Posix provider works on all platforms supported by Go’s os/exec package. It does not use any platform-specific system calls directly.
The command runner (model.CommandRunner) handles the actual process execution, which may have platform-specific implementations.
Security Considerations
No Shell Injection
Unlike the shell provider, the posix provider does not invoke a shell. Arguments are passed directly to the executable, preventing shell injection attacks:
# Safe with posix provider - $USER is passed literally, not expanded- exec:
- /bin/echo $USER:
provider: posix # Default# Potentially dangerous with shell provider - $USER is expanded- exec:
- /bin/echo $USER:
provider: shell
Path Validation
The path property only accepts absolute directory paths, preventing path traversal via relative paths.
Environment Validation
Environment variables must have non-empty keys and values, preventing injection of empty or malformed entries.
Shell Provider
This document describes the implementation details of the Shell exec provider for executing commands via /bin/sh.
Provider Selection
The Shell provider is selected when provider: shell is explicitly specified in the resource properties. It has a lower priority (99) than the Posix provider (1), so it is never automatically selected.
Availability: The provider checks for the existence of /bin/sh via util.FileExists(). If /bin/sh does not exist, the provider is not available.
Comparison with Posix Provider
Feature
Shell
Posix
Shell invocation
Yes (/bin/sh -c)
No
Pipes (|)
Supported
Not supported
Redirections (>, <, >>)
Supported
Not supported
Shell builtins (cd, export, source)
Supported
Not supported
Glob expansion (*.txt, ?)
Supported
Not supported
Command substitution ($(...), `...`)
Supported
Not supported
Variable expansion ($VAR, ${VAR})
Supported
Not supported
Logical operators (&&, ||)
Supported
Not supported
Argument parsing
Passed as single string
shellquote.Split()
Security
Shell injection possible
Lower attack surface
When to use Shell:
Commands with pipes: cat file.txt | grep pattern | sort
Commands with redirections: echo "data" > /tmp/file
Commands with shell builtins: cd /tmp && pwd
Commands with variable expansion: echo $HOME
Complex one-liners with logical operators
When to use Posix (default):
Simple commands with arguments
When shell features are not needed
For better security (no shell injection risk)
Operations
Execute
Process:
Determine command source (Command property or Name if Command is empty)
Validate command is not empty
Execute via CommandRunner.ExecuteWithOptions() with /bin/sh -c "<command>"
Optionally log output line-by-line if LogOutput is enabled
Execution Method:
The entire command string is passed to the shell as a single argument:
/bin/sh -c "<entire command string>"
This allows the shell to interpret all shell syntax, including:
Pipes and redirections
Variable expansion
Glob patterns
Command substitution
Logical operators
Execution Options:
Option
Value
Description
Command
/bin/sh
Shell executable path
Args
["-c", "<command>"]
Shell flag and command string
Cwd
properties.Cwd
Working directory
Environment
properties.Environment
Additional env vars (KEY=VALUE format)
Path
properties.Path
Search path for executables
Timeout
properties.ParsedTimeout
Maximum execution time
Output Logging:
When LogOutput: true is set and a user logger is provided:
The shell provider uses the same idempotency mechanisms as the posix provider:
Creates File
If creates is specified and the file exists, the command does not run:
- exec:
- extract-archive:
command: cd /opt && tar -xzf /tmp/app.tar.gzprovider: shellcreates: /opt/app/bin/app
Guard Commands
If onlyif is specified, the command only runs when the guard exits 0. If unless is specified, the command only runs when the guard exits non-zero. Guard commands are executed via /bin/sh -c and can use shell features:
This allows manifests bundled with their source files to use relative paths.
Noop Mode
In noop mode, the file type:
Queries current state normally
Computes content checksums
Logs what actions would be taken
Sets appropriate NoopMessage:
“Would have created the file”
“Would have created directory”
“Would have removed the file”
Reports Changed: true if changes would occur
Does not call provider Store/CreateDirectory methods
Does not remove files
Desired State Validation
After applying changes (in non-noop mode), the type verifies the file reached the desired state by calling Status() again and checking all attributes match. If validation fails, ErrDesiredStateFailed is returned.
Subsections of File Type
Posix Provider
This document describes the implementation details of the Posix file provider for managing files and directories on Unix-like systems.
Provider Selection
The Posix provider is the default and only file provider. It is always available and returns priority 1 for all file resources.
Operations
Store (Create/Update File)
Process:
Verify parent directory exists
Parse file mode from octal string
Open source file if source property is set
Create temporary file in the same directory as target
Set file permissions on temp file
Write content (from source file or contents property)
This allows manifests to use relative paths for source files bundled with the manifest.
Platform Support
The Posix provider uses Unix-specific system calls:
Operation
System Call
Get file owner/group
syscall.Stat_t (UID/GID from stat)
Set ownership
os.Chown() β chown(2)
Set permissions
os.Chmod() β chmod(2)
The provider has separate implementations for Unix and Windows (file_unix.go, file_windows.go in internal/util), with Windows returning errors for ownership operations.
Security Considerations
Atomic Writes
Files are written atomically via temp file + rename. This prevents:
Partial file reads during write
Corruption if process is interrupted
Race conditions with concurrent readers
Permission Ordering
Permissions and ownership are set on the temp file before rename:
Chmod - Set permissions
Write content
Chown - Set ownership
Rename to target
This ensures the file never exists at the target path with incorrect permissions.
Path Validation
File paths must be absolute and clean (no . or .. components):
iffilepath.Clean(p.Name) !=p.Name {
returnfmt.Errorf("file path must be absolute")
}
Required Properties
Owner, group, and mode are required properties and cannot be empty, preventing accidental creation of files with default/inherited permissions.
Package Type
This document describes the design of the package resource type for managing software packages.
Overview
The package resource manages software packages with two aspects:
Existence: Whether the package is installed or absent
Version: The specific version installed (when applicable)
Provider Interface
Package providers must implement the PackageProvider interface:
βββββββββββββββββββββββββββββββββββββββββββ
β Get current state via Status() β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Is ensure = "latest"? β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
Yes β No
βΌ β
βββββββββββββββββββββββ β
β Is package absent? β β
βββββββββββββββ¬ββββββββ β
Yes β No β
βΌ βΌ β
ββββββββββ ββββββββββ
βInstall β βUpgrade β
βlatest β βlatest β
ββββββββββ ββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β Is desired state met? β
βββββββββββββββ¬ββββββββββββ
Yes β No
βΌ β
βββββββββββββ β
β No change β βΌ
βββββββββββββ (Phase 2)
Phase 2: Handle Ensure Values
βββββββββββββββββββββββββββ
β What is desired ensure? β
βββββββββββββββ¬ββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β absent β present β <version>
βΌ βΌ βΌ
ββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Uninstall β β Is absent? β β Is absent? β
ββββββββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
Yes β No Yes β No
βΌ βΌ βΌ βΌ
ββββββββββ ββββββββββ ββββββββββ ββββββββββββββ
βInstall β βNo β βInstall β βCompare β
β β βchange β βversion β βversions β
ββββββββββ ββββββββββ ββββββββββ βββββββ¬βββββββ
β
ββββββββββββββββββΌβββββββββββββββββ
β current < β current = β current >
βΌ βΌ βΌ
βββββββββββββ βββββββββββββ βββββββββββββ
β Upgrade β β No change β β Downgrade β
βββββββββββββ βββββββββββββ βββββββββββββ
Version Comparison
The VersionCmp method compares two version strings:
Return Value
Meaning
-1
versionA < versionB (upgrade needed)
0
versionA == versionB (no change)
1
versionA > versionB (downgrade needed)
Version comparison is delegated to the provider, allowing platform-specific version parsing (e.g., RPM epoch handling, Debian revision suffixes).
Idempotency
The package resource is idempotent through state comparison:
Decision Table
Desired
Current State
Action
ensure: present
installed (any version)
None
ensure: present
absent
Install
ensure: absent
absent
None
ensure: absent
installed
Uninstall
ensure: latest
absent
Install latest
ensure: latest
installed
Upgrade (always runs)
ensure: <version>
same version
None
ensure: <version>
older version
Upgrade
ensure: <version>
newer version
Downgrade
ensure: <version>
absent
Install
Special Case: ensure: latest
When ensure: latest is used:
The package manager determines what “latest” means
Upgrade is always called when the package exists (package manager is idempotent)
The type cannot verify if “latest” was achieved (package managers may report stale data)
Desired state validation only checks that the package is not absent
Package Name Validation
Package names are validated to prevent injection attacks:
Allowed Characters:
Alphanumeric (a-z, A-Z, 0-9)
Period (.), underscore (_), plus (+)
Colon (:), tilde (~), hyphen (-)
Rejected:
Shell metacharacters (;, |, &, $, etc.)
Whitespace
Quotes and backticks
Path separators
Version strings (when ensure is a version) are also validated for dangerous characters.
Noop Mode
In noop mode, the package type:
Queries current state normally
Computes version comparison
Logs what actions would be taken
Sets appropriate NoopMessage:
“Would have installed latest”
“Would have upgraded to latest”
“Would have installed version X”
“Would have upgraded to X”
“Would have downgraded to X”
“Would have uninstalled”
Reports Changed: true if changes would occur
Does not call provider Install/Upgrade/Downgrade/Uninstall methods
Desired State Validation
After applying changes (in non-noop mode), the type verifies the package reached the desired state:
func (t*Type) isDesiredState(properties, state) bool {
switchproperties.Ensure {
case"present":
// Any installed version is acceptablereturnstate.Ensure!="absent"case"absent":
returnstate.Ensure=="absent"case"latest":
// Cannot verify "latest", just check not absentreturnstate.Ensure!="absent"default:
// Specific version must matchreturnVersionCmp(state.Ensure, properties.Ensure, false) ==0 }
}
If the desired state is not reached, an ErrDesiredStateFailed error is returned.
Subsections of Package Type
APT Provider
This document describes the implementation details of the APT package provider for Debian-based systems.
Environment
All commands are executed with the following environment variables to ensure non-interactive operation:
Variable
Value
Purpose
DEBIAN_FRONTEND
noninteractive
Prevents dpkg from prompting for user input
APT_LISTBUGS_FRONTEND
none
Suppresses apt-listbugs prompts
APT_LISTCHANGES_FRONTEND
none
Suppresses apt-listchanges prompts
Concurrency
A global package lock (model.PackageGlobalLock) is held during all command executions to prevent concurrent apt/dpkg operations within the same process. This prevents lock contention on /var/lib/dpkg/lock.
Helper methods: LessThan, GreaterThan, Equal, etc.
DNF Provider
This document describes the implementation details of the DNF package provider for RHEL/Fedora-based systems.
Concurrency
A global package lock (model.PackageGlobalLock) is held during all command executions to prevent concurrent dnf/rpm operations within the same process. This prevents lock contention on the RPM database.
Target directory must exist with rendered template files
absent
Managed files must be removed from the target
Template Engines
Two template engines are supported:
Engine
Library
Default Delimiters
Description
go
Go text/template
{{ / }}
Standard Go templates
jet
Jet templating
[[ / ]]
Jet template language
The engine defaults to jet if not specified. Delimiters can be customized via left_delimiter and right_delimiter properties.
Properties
Property
Type
Required
Description
source
string
Yes
Source template directory path or URL
engine
string
No
Template engine: go or jet (default: jet)
skip_empty
bool
No
Skip empty files in rendered output
left_delimiter
string
No
Custom left template delimiter
right_delimiter
string
No
Custom right template delimiter
purge
bool
No
Remove files in target not present in source
data
map[string]any
No
Custom data that replaces Hiera data for template rendering
post
[]map[string]string
No
Post-processing: glob pattern to command mapping
# Render configuration templates using Jet engine- scaffold:
- /etc/app:
ensure: presentsource: templates/appengine: jetpurge: true# Render with Go templates and custom delimiters- scaffold:
- /etc/myservice:
ensure: presentsource: templates/myserviceengine: goleft_delimiter: "<<"right_delimiter: ">>"# With post-processing commands- scaffold:
- /opt/app:
ensure: presentsource: templates/apppost:
- "*.go": "go fmt {}"# With custom data replacing Hiera data- scaffold:
- /etc/app:
ensure: presentsource: templates/appengine: jetdata:
app_name: myappversion: "{{ Facts.version }}"port: 8080
Custom Data
The data property allows supplying custom data that completely replaces the Hiera-resolved data for template rendering. When data is set and non-empty, templates receive only the custom data via data instead of the Hiera-resolved data from the manifest.
This is useful when a scaffold resource needs data that differs from or is unrelated to the global Hiera data, or when you want to provide a self-contained data set for a specific scaffold.
Behavior
When data is not set or empty: templates receive the Hiera-resolved data from the manager as normal.
When data is set and non-empty: env.Data is replaced with the custom data before calling Status() and Scaffold(). The custom data is used consistently throughout the entire apply cycle.
facts remain available regardless of whether custom data is provided.
Template Resolution in Data Values
String values in the data map support template expressions that are resolved during property template resolution. Both keys and values can contain templates:
Non-string values (integers, booleans, lists, maps) are preserved as-is without template resolution.
Apply Logic
βββββββββββββββββββββββββββββββββββββββββββ
β Get template environment from manager β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Custom data set? Override env.Data β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Get current state via Status() β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Is current state desired state? β
βββββββββββββββββββ¬ββββββββββββββββββββββββ
Yes β No
βΌ β
βββββββββββββ β
β No change β β
βββββββββββββ β
βΌ
βββββββββββββββββββββββββββ
β What is desired ensure? β
βββββββββββββββ¬ββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β absent β present
βΌ βΌ
βββββββββββββ βββββββββββββ
β Noop? β β Noop? β
βββββββ¬ββββββ βββββββ¬ββββββ
Yes β No Yes β No
βΌ β βΌ β
βββββββββββββββ βββββββββββββββ
β Set noop ββ β Set noop ββ
β message ββ β message ββ
βββββββββββββββ βββββββββββββββ
βΌ βΌ
βββββββββββββββββ βββββββββββββββββββββββ
β Remove all β β Scaffold β
β managed files β β (render templates) β
β and empty dirsβ β β
βββββββββββββββββ βββββββββββββββββββββββ
Idempotency
The scaffold resource determines idempotency by rendering templates in noop mode and comparing results against the target directory.
State Checks
Ensure absent: Target must not exist, or no managed files remain on disk (Changed and Stable lists empty). Purged files (files not belonging to the scaffold) do not affect this check.
Ensure present: The Changed list must be empty, and the Purged list must be empty when purge is enabled (all files are stable). When purge is disabled, purged files do not affect stability.
Decision Table
For ensure: absent, purged files never affect stability since they don’t belong to the scaffold. For ensure: present, purged files only affect stability when purge is enabled.
When ensure: absent, the Status method filters Changed and Stable lists to only include files that actually exist on disk, so the state reflects reality after removal rather than what the scaffold would create.
Desired
Target Exists
Changed Files
Purged Files
Purge Enabled
Stable?
absent
No
N/A
N/A
N/A
Yes
absent
Yes
None
Any
N/A
Yes (no managed files on disk)
absent
Yes
Some
Any
N/A
No (managed files remain)
present
Yes
None
None
Any
Yes
present
Yes
None
Some
No
Yes (purged files ignored)
present
Yes
None
Some
Yes
No (purge needed)
present
Yes
Some
Any
Any
No (render needed)
present
No
N/A
N/A
Any
No (target missing)
Source Resolution
The source property is resolved relative to the manager’s working directory when it is a relative path:
This allows manifests bundled with template directories to use relative paths. URL sources (with a scheme) are passed through unchanged.
Path Validation
Target paths (the resource name) must be:
Absolute (start with /)
Canonical (no . or .. components, filepath.Clean(path) == path)
Post-Processing
The post property defines commands to run on rendered files. Each entry is a map where the key is a glob pattern matched against the file’s basename and the value is a command to execute. Use {} as a placeholder for the file’s full path; if omitted, the path is appended as the last argument.
Post-processing runs immediately after each file is rendered. Validation ensures neither keys nor values are empty.
Noop Mode
In noop mode, the scaffold type queries the current state via Status() and reports what would change without modifying the filesystem. Neither Scaffold() nor Remove() are called.
For ensure: present, the affected count is the number of changed files plus purged files (when purge is enabled). For ensure: absent, the affected count is the number of changed and stable files plus purged files (when purge is enabled).
Desired
Affected Count
Message
present
Changed + Purged (if purge enabled)
Would have changed N scaffold files
absent
Changed + Stable + Purged (if purge enabled)
Would have removed N scaffold files
Changed is set to true only when the affected count is greater than zero. When the resource is already in the desired state, Changed is false and NoopMessage is empty.
Desired State Validation
After applying changes (in non-noop mode), the type verifies the scaffold reached the desired state by checking the changed and purged file lists. If validation fails, ErrDesiredStateFailed is returned.
Subsections of Scaffold Type
Choria Provider
This document describes the implementation details of the Choria scaffold provider for rendering template directories using the choria-io/scaffold library.
Provider Selection
The Choria provider is the default and only scaffold provider. It is always available and returns priority 1 for all scaffold resources.
Operations
Scaffold (Render Templates)
Process:
Check if target directory exists
Configure scaffold with source, target, engine, delimiters, post-processing, and skip_empty settings
Create scaffold instance using the appropriate engine (scaffold.New() for Go, scaffold.NewJet() for Jet)
Call Render() (real mode) or RenderNoop() (noop mode)
Categorize results into changed, stable, and purged file lists
Scaffold Configuration:
Config Field
Source Property
Description
TargetDirectory
Name
Target directory for rendered files
SourceDirectory
Source
Source template directory
MergeTargetDirectory
(always true)
Merge into existing target directory
Post
Post
Post-processing commands
SkipEmpty
SkipEmpty
Skip empty rendered files
CustomLeftDelimiter
LeftDelimiter
Custom template left delimiter
CustomRightDelimiter
RightDelimiter
Custom template right delimiter
Engine Selection:
Engine
Constructor
Default Delimiters
go
scaffold.New()
{{ / }}
jet
scaffold.NewJet()
[[ / ]]
Result Categorization:
Scaffold Action
Metadata List
Description
FileActionEqual
Stable
File content unchanged
FileActionAdd
Changed
New file created
FileActionUpdate
Changed
Existing file modified
FileActionRemove
Purged
File removed from target
File paths in the metadata lists are absolute paths, constructed by joining the target directory with the relative path from the scaffold result.
Purge Behavior:
When purge is enabled and a file has FileActionRemove, the provider deletes the file from disk during Scaffold(). In noop mode, the removal is logged but not performed. When purge is disabled, purged files are only tracked in metadata and not removed.
Status
Process:
Perform a dry-run render (noop mode) to determine what the scaffold would do
When ensure is absent, filter Changed and Stable lists to only include files that actually exist on disk
The noop render reports what would happen if the scaffold were applied. For ensure: present, this is the desired output β it shows what needs to change. For ensure: absent, the raw render output is misleading after removal (it would show files to be added), so the lists are filtered to reflect what managed files actually remain on disk.
State Detection:
Target Directory
Ensure Value
Metadata
Exists
present
Changed, stable, and purged file lists from render
Exists
absent
Changed and stable filtered to files on disk, purged from render
Does not exist
Any
Empty metadata, TargetExists: false
Remove
Process:
Collect managed files from the state’s Changed and Stable lists (purged files are not removed as they don’t belong to the scaffold)
Stop when no more empty directories can be removed
Best-effort removal of the target directory (only succeeds if empty)
File Removal Order:
Files are collected from two metadata lists:
Changed - Files that were added or modified
Stable - Files that were unchanged
Purged files are not removed because they are unrelated to the scaffold and may belong to other processes.
Directory Cleanup:
For each removed file:
Track its parent directory
Repeat:
For each tracked directory:
Skip if it is the target directory itself
Skip if not empty
Remove the directory
Track its parent directory
Until no more directories removed
Best-effort: remove the target directory (fails silently if not empty)
The target directory is removed if empty after all managed files and subdirectories are cleaned up. If unrelated files remain (purged files), the directory is preserved.
Error Handling:
Condition
Behavior
Non-absolute file path
Return error immediately
File removal fails
Log error, continue with remaining files
Directory removal fails
Log error, continue with remaining directories
File does not exist
Silently skip (os.IsNotExist check)
Target directory removal fails
Log at debug level, no error returned
Template Environment
Templates receive the full templates.Env environment, which provides access to:
facts - System facts for the managed node
data - Hiera-resolved configuration data, or custom data when the resource’s data property is set
Template helper functions
When the scaffold resource has a data property set, env.Data is replaced with the custom data before the provider’s Status() and Scaffold() methods are called. The provider receives the already-resolved environment and does not need to handle this override itself.
This allows templates to generate host-specific configurations based on facts and hierarchical data.
Logging
The provider wraps the CCM logger in a scaffold-compatible interface:
This adapter translates the scaffold library’s Debugf/Infof calls to CCM’s structured logging.
Platform Support
The Choria provider is platform-independent. It uses the choria-io/scaffold library for template rendering, which operates on standard filesystem operations. No platform-specific system calls are used.
Service Type
This document describes the design of the service resource type for managing system services.
Overview
The service resource manages system services with two independent dimensions:
Running state: Whether the service is currently running or stopped
Enabled state: Whether the service starts automatically at boot
These are managed independently, allowing combinations like “running but disabled” or “stopped but enabled”.
Provider Interface
Service providers must implement the ServiceProvider interface:
The Status method returns a ServiceState containing:
typeServiceStatestruct {
CommonResourceStateMetadata*ServiceMetadata}
typeServiceMetadatastruct {
Namestring// Service nameProviderstring// Provider name (e.g., "systemd")Enabledbool// Whether service starts at bootRunningbool// Whether service is currently running}
The Ensure field in CommonResourceState is set to:
If the desired state is not reached, an ErrDesiredStateFailed error is returned.
Service Name Validation
Service names are validated to prevent injection attacks:
Allowed Characters:
Alphanumeric (a-z, A-Z, 0-9)
Period (.), underscore (_), plus (+)
Colon (:), tilde (~), hyphen (-)
Rejected:
Shell metacharacters (;, |, &, etc.)
Whitespace
Path separators
Noop Mode
In noop mode, the service type:
Queries current state normally
Logs what actions would be taken
Sets appropriate NoopMessage (e.g., “Would have started”, “Would have enabled”)
Reports Changed: true if changes would occur
Does not call provider Start/Stop/Restart/Enable/Disable methods
Subsections of Service Type
Systemd Provider
This document describes the implementation details of the Systemd service provider for managing system services via systemctl.
Provider Selection
The Systemd provider is selected when systemctl is found in the system PATH. The provider checks for the executable using util.ExecutableInPath("systemctl").
Availability Check:
Searches PATH for systemctl
Returns priority 1 if found
Returns unavailable if not found
Concurrency
A global service lock (model.ServiceGlobalLock) is held during all systemctl command executions to prevent concurrent systemd operations within the same process. This prevents race conditions when multiple service resources are managed simultaneously.
The provider performs a systemctl daemon-reload once per provider instance before any service operations. This ensures systemd picks up any unit file changes made by other resources (e.g., file resources managing unit files).
Integration points - Factory functions and registry
CLI commands - User-facing command line interface
JSON schemas - Validation for manifests and API requests
Documentation - User and design documentation
CCM Studio - Web-based manifest designer
File Checklist
File
Action
Purpose
model/resource_<type>.go
Create
Properties, state, metadata structs
model/resource_<type>_test.go
Create
Property validation tests
model/resource.go
Modify
Add case to factory function
resources/<type>/<type>.go
Create
Provider interface definition
resources/<type>/type.go
Create
Resource type implementation
resources/<type>/type_test.go
Create
Resource type tests
resources/<type>/provider_mock_test.go
Generate
Mock provider for tests
resources/<type>/<provider>/factory.go
Create
Provider factory
resources/<type>/<provider>/<provider>.go
Create
Provider implementation
resources/<type>/<provider>/<provider>_test.go
Create
Provider tests
resources/resources.go
Modify
Add case to NewResourceFromProperties
cmd/ensure_<type>.go
Create
CLI command handler
cmd/ensure.go
Modify
Register CLI command
internal/fs/schemas/manifest.json
Modify
Add resource schema definitions
internal/fs/schemas/resource_ensure_request.json
Modify
Add API request schema
docs/content/resources/<type>.md
Create
User documentation
docs/content/design/<type>/_index.md
Create
Design documentation
docs/content/design/<type>/<provider>.md
Create
Provider documentation
Step 1: Model Definitions
Create model/resource_<type>.go with the following components.
Constants
const (
// ResourceStatus<Type>Protocol is the protocol identifier for <type> resource stateResourceStatus<Type>Protocol = "io.choria.ccm.v1.resource.<type>.state"// <Type>TypeName is the type name for <type> resources <Type>TypeName = "<type>")
Properties Struct
The properties struct must satisfy model.ResourceProperties:
type <Type>ResourcePropertiesstruct {
CommonResourceProperties`yaml:",inline"`// All string fields are automatically template-resolved by default.// Use struct tags to control resolution behavior.Urlstring`json:"url" yaml:"url"`Checksumstring`json:"checksum,omitempty" yaml:"checksum,omitempty"`// Fields that must not be template-resolvedDelimiterstring`json:"delimiter,omitempty" yaml:"delimiter,omitempty" template:"-"`// Fields deferred until after control evaluationContentstring`json:"content,omitempty" yaml:"content,omitempty" template:"deferred"`// ...}
Key points:
Embed CommonResourceProperties with yaml:",inline" tag
Use JSON and YAML struct tags for serialization
In Validate(), call p.CommonResourceProperties.Validate() first, then add type-specific validation
Template resolution is handled automatically via reflection - see the Template Resolution section for details
ResolveDeferredTemplates() is called after control evaluation (if/unless). Override it only if you have template:"deferred" fields that need post-processing (e.g. filepath.Clean). The default no-op from CommonResourceProperties is sufficient for most types. See the file resource for an example where Contents and Source are deferred
State Struct
The state struct must satisfy model.ResourceState:
type <Type>Metadatastruct {
Namestring`json:"name" yaml:"name"`Providerstring`json:"provider,omitempty" yaml:"provider,omitempty"`// Add fields describing current system state}
type <Type>Statestruct {
CommonResourceStateMetadata*<Type>Metadata`json:"metadata,omitempty"`}
Embedding *base.Base provides implementations for Apply(), Healthcheck(), Type(), Name(), Properties(), and NewTransactionEvent(). The type must implement:
See resources/archive/type.go for a complete constructor example.
ApplyResource Method
The ApplyResource method (part of base.EmbeddedResource) contains the core logic. It should follow this pattern:
Get initial state via provider.Status()
Check if already in desired state (implement isDesiredState() helper)
If stable, call t.FinalizeState() and return early
Apply changes, respecting t.mgr.NoopMode()
Get final state and verify desired state was achieved
Call t.FinalizeState() with appropriate flags
See resources/archive/type.go:ApplyResource() for a complete example.
Provider Selection Methods
The SelectProvider() method should use registry.FindSuitableProvider() to select an appropriate provider. See resources/archive/type.go for the standard implementation pattern.
if !noop {
// Make actual changest.log.Info("Applying changes")
err = p.SomeAction(ctx, properties)
} else {
t.log.Info("Skipping changes as noop")
noopMessage = "Would have applied changes"}
Error Handling
Use sentinel errors from model/errors.go:
var (
ErrResourceInvalid = errors.New("resource invalid")
ErrProviderNotFound = errors.New("provider not found")
ErrNoSuitableProvider = errors.New("no suitable provider")
ErrDesiredStateFailed = errors.New("desired state not achieved")
)
Wrap errors with context:
err:=os.Remove(path)
iferr!=nil {
returnfmt.Errorf("could not remove file: %w", err)
}
Template Resolution
Template resolution uses a reflection-based struct walker (templates.ResolveStructTemplates) that automatically resolves {{ expression }} placeholders in all string-typed fields. The walker recurses into all composite types including slices, maps, nested structs, and pointer fields.
By default, all fields are template-resolved. You control behavior with the template struct tag:
Tag
Behavior
(none)
Resolved during ResolveTemplates() (phase 1)
template:"-"
Never resolved - use for enum values, literal delimiters, resource references, or fields evaluated separately (like control expressions)
template:"deferred"
Skipped in phase 1, resolved during ResolveDeferredTemplates() (phase 2, after control evaluation)
template:"resolve_keys"
For map fields, also resolve map keys (rebuilds the map). By default only map values are resolved
Fields tagged json:"-" are automatically skipped (these are internal computed fields like ParsedTimeout).
Supported types (resolved recursively):
string and named string types (e.g. type MyType string)
[]string, []any
map[string]string, map[string]any, map[string][]string, and other map variants with string keys
[]map[string]string, []map[string]any
Nested and embedded structs, *struct pointers
any / interface{} fields holding any of the above
Arbitrary nesting depth
Types that are not resolved: bool, int, float, time.Duration, []byte / yaml.RawMessage, nil pointers.
Implementation pattern - most resource types need only:
The resolveRegistrations call (inherited from CommonResourceProperties) handles RegisterWhenStable entries which need special typed resolution for the Port field.
Deferred resolution is used for fields whose template evaluation may fail when the resource would be skipped by a control (if/unless). Tag these fields with template:"deferred" and override ResolveDeferredTemplates():
This method is called by base.Base after control evaluation passes, so templates are only evaluated for resources that will actually be applied. Because deferred resolution happens at apply time rather than during manifest parsing, templates using functions like file() can access content created by earlier resources in the same run. The default no-op implementation inherited from CommonResourceProperties is sufficient for types that have no template:"deferred" fields.
Provider Selection
Providers declare manageability via IsManageable on the factory (see model.ProviderFactory in Step 3). Multiple providers can match; the one with highest priority is selected.
Documentation
Create user documentation in docs/content/resources/<type>.md covering:
Overview and use cases
Ensure states table
Properties table with descriptions
Usage examples (manifest, CLI, API)
Create design documentation in docs/content/design/<type>/_index.md covering:
Provider interface specification
State checking logic
Apply logic flowchart
Create provider documentation in docs/content/design/<type>/<provider>.md covering:
Provider selection criteria
Platform requirements
Implementation details
CCM Studio
CCM Studio is a web-based manifest designer. After adding a new resource type, update CCM Studio to support it:
Note
CCM Studio is a closed-source project. The maintainers will complete this step.
Add the new resource type to the resource palette
Create property editors for type-specific fields
Add validation matching the JSON schema definitions
Update any resource type documentation or help text
Docs Style Guide
This guide describes the writing conventions used throughout the CCM documentation. Follow these rules when adding or editing pages.
All sections apply to every documentation page. The Page structure section applies only to resource reference pages under resources/.
Voice and tone
Write in plain, direct North American English.
Use the present tense and active voice: “The service resource manages system services,” not “System services are managed by the service resource.”
Address the reader implicitly. Do not use “you” or “we”. State facts and give instructions: “Specify commands with their full path,” not “You should specify commands with their full path.”
Keep sentences short. One idea per sentence.
Do not editorialize or use filler (“Note that,” “It is important to,” “Simply”).
Do not use emojis.
Do not use em dashes. Use commas, periods, or semicolons instead.
Page structure
Every resource page follows this order:
Front matter: TOML (+++) with title, description, toc = true, and weight.
Opening paragraph: One or two sentences stating what the resource does.
Callout: A warning or note about common pitfalls, using > [!info] syntax.
Primary example: A tabbed block (Manifest / CLI / API Request) showing typical usage.
Brief explanation: One or two sentences describing what the example does.
Ensure values: Table of valid ensure states.
Properties: Table of all properties with short descriptions.
Additional sections: Provider notes, idempotency, authentication, behavioral details as needed.
Not every example needs all three tabs. Secondary examples deeper in a page may show only the most relevant format.
YAML
Use realistic but minimal values.
Quote version strings and octal modes: "5.9", "0644".
CLI
Use nohighlight as the fence language.
Use backslash continuations for long commands.
Add a brief comment above the command when context is needed.
JSON
Use json as the fence language.
Always include the protocol and type fields in API examples.
Callouts
Use the > [!info] blockquote syntax for warnings and notes:
> [!info] Warning
> Use absolute file paths and primary group names.
> [!info] Note
> The provider will not run `apt update` before installing a package.
Use Warning for constraints the reader must follow to avoid errors. Use Note for supplementary information. A custom label may replace Warning or Note when it adds clarity, such as > [!info] Default Hierarchy.
Descriptions and explanations
After a tabbed example block, add one or two sentences explaining what the example does and why.
Describe behavior, not implementation: “The command runs only if /tmp/hello does not exist,” not “The code checks whether the file exists and skips execution if found.”
When describing how multiple options interact, use a truth table.
Terminology
Use “resource,” “provider,” “property,” “manifest” consistently.
Refer to ensure states and property names in backticks: present, name, ensure.
Reference other resources using the type#name notation in backticks: package#httpd.
When cross-referencing other documentation pages, use relative Hugo links.
General formatting
No trailing whitespace.
One blank line between sections.
No blank line between a heading and its first paragraph.
Wrap inline code, file paths, command names, property names, and values in backticks.
Do not use bold or italic for emphasis in reference content. Reserve bold for definition list terms within prose.