Status: v1, normative since 2026-07-12
Audience: dtctl and any dtctl-* plugin that reads the shared
configuration. This is the state contract: everything a second binary may
rely on, and nothing more. Golden fixtures live in
sdk/session/testdata/contract/; sdk/session/contract_test.go enforces this
document. A change that breaks those tests is a contract change and must
update this spec in the same PR.
| Artifact | Path |
|---|---|
| Global config | $XDG_CONFIG_HOME/dtctl/config (~/.config/dtctl/config on Linux, ~/Library/Application Support/dtctl/config on macOS, %LOCALAPPDATA%\dtctl\config on Windows) |
| Project-local config | .dtctl.yaml, discovered upward from the working directory; used exclusively (never merged with the global file) |
| Explicit config | --config <path> flag, wins over discovery |
| OAuth file store | $XDG_DATA_HOME/dtctl/oauth-tokens/<sanitized-name>.json, mode 0600 (dir 0700) |
| Token-refresh lock | $TMPDIR/dtctl-token-refresh-<sha256[:8] of env:tokenRef>.lock |
Security note: auto-discovered .dtctl.yaml files are treated as untrusted
(the classic "checked-out repo / shared directory" scenario). Five restrictions
apply — see Config.IsLocal():
- Env-var expansion limited to the environment URL.
${VAR}references are expanded only for a context'senvironment, and only once, at load (Config.resolveLocalEnvironments), so every reader ofContext.Environment— the origin check, the client,doctor, the live-debugger handlers, spill's tenant id — sees the same resolved value without having to remember to resolve.SaveTowrites the unexpanded reference back (Config.restoreRawEnvironments) so a load-modify-save cycle does not bake one developer's expansion into a committed file. Every other field is left as-is; use--configorDTCTL_CONFIGfor a trusted config where expansion runs everywhere. - No inline tokens. A local config may reference a
token-refbut not define its value; credentials must come from the keyring / file store. - Origin binding. The environment URL in the local context must resolve to
the same hostname as the global config binding for the same
token-ref, preventing credential redirection to a foreign host. - Safety-level clamp. The context's level is reduced to
min(local, global)so a local file cannot grant itself more than the owner of the borrowed credential granted. Atoken-refwith no global binding is clamped toDefaultSafetyLevel. - Destination allowlist.
NewClientFromConfigrequires the resolved environment URL to be a bare origin — https, a.dynatrace.com/.dynatracelabs.comhost, and no userinfo, path, query or fragment (urls.IsDynatraceEnvironmentOrigin). The bare-origin shape is what keeps restriction 1 safe: expansion can fill in the destination but cannot append to it, so an unrelated host secret cannot ride out in a path or query.
Restrictions 3 and 4 share one lookup, buildGlobalBindings(), keyed by
token-ref — not by context name, since a local config is free to rename its
context while still borrowing the same credential. The clamp is resolved on
each GetEffectiveSafetyLevel() call rather than snapshotted at load time, so
it survives a --context / DTCTL_CONTEXT override. A token-ref with no
global binding yields no ceiling of its own, so restriction 4 falls back to the
default. Where several global contexts share a token-ref, the binding keeps
every bound host and the strictest level, so YAML ordering cannot widen
either.
Code-execution keys (aliases, apply hooks) are loaded for round-tripping but never honored.
Write target: config-management commands write the same file they read (see
saveConfig), so once a .dtctl.yaml is discovered it captures writes too.
Because restrictions 2–4 mean a local config can only work alongside a global
binding, config set-context and config set-credentials take --global to
write to DefaultConfigPath() regardless of discovery; without it, the two
commands that create the binding would land in the file that needs it.
YAML document. Top-level keys: apiVersion, kind, current-context,
contexts (list of {name, context}), tokens (list of {name, token}),
preferences, aliases, spill, query-limits. Per-context keys:
environment, token-ref, safety-level (readonly | readwrite-mine |
readwrite-all | dangerously-unrestricted; empty means readwrite-all),
description, hooks, spill, query-limits, usage-tracking (bool,
default off, honored only from the global config, never an auto-discovered
.dtctl.yaml; see USAGE_TRACKING.md). The Go structs in
sdk/session/config.go are the schema's source of truth;
testdata/contract/v1-full.yaml exercises every field.
query-limits keys: scan-limit-gbytes, max-result-records,
max-result-bytes, sampling-ratio. Like spill, the per-context block
overrides the top-level one per field, and an unset (zero) field means
"defer to the next layer" — so a reader that ignores the block behaves exactly
as one that never knew about it. Values must be non-negative; the merge
therefore only tightens, and lifting a configured limit is a command-line
decision (--no-query-limits), not a config one.
Semantics both binaries must share: safety-level (a readonly context means
the same thing everywhere) and token resolution order (see below).
apiVersionspellings accepted as schema v1: empty (pre-enforcement configs),v1, anddtctl.io/v1(written bydtctl config init).- An unrecognized
apiVersionis a hard load error naming the version — never a silent misread. This is the version-skew answer: "consumer N supports config schema ≤ M" is testable. - Within v1 the schema evolves additively only. Renaming or redefining an existing key requires bumping the version.
- Readers ignore unknown keys (yaml.v3 default — do not enable strict mode).
- Writers must not destroy unknown keys:
Config.SaveTografts keys unknown to the running build from the file being overwritten back into the saved document (top level, per-context and per-token matched byname, and nested structs — seesdk/session/preserve.go). Known keys are owned by the writer: deleted contexts and clearedomitemptyfields stay deleted. - Comments and key order are not preserved; only data survives.
$VAR / ${VAR} in the file expand from the process environment at load.
Shell positional/special parameters ($1, ${10}, $@, …) are preserved
verbatim so hook commands survive. Unset variables expand to the empty
string. Management commands that rewrite the file must load with
LoadWithoutExpansion so templates round-trip unexpanded.
- OS keyring service name:
dtctl— shared by every consumer; changing it strands all stored credentials. - Key formats: plain API tokens under their token-ref name; OAuth token sets
(JSON) under
oauth:<env>:<tokenRef>with<env>∈prod|dev|hard, legacy entries underoauth:<tokenRef>. - Token resolution order (in
Config.GetToken): keyring OAuth entry → keyring plain token → OAuth file store (when the keyring is unavailable orDTCTL_TOKEN_STORAGE=file) → inlinetokenvalue in the config file. DTCTL_DISABLE_KEYRING(any non-empty value) disables the keyring;DTCTL_TOKEN_STORAGE=fileforces the file store.- Deletion must clear the whole fan-out. One token ref occupies the plain
entry, an OAuth entry per environment, a
:scopescompanion for each, the pre-environment legacyoauth:<tokenRef>form, and file-store copies of all of them.Config.DeleteTokensweeps that set across both backends; anything narrower leaves live token material behind, including materialGetTokencan no longer resolve but an attacker with the file could still read. Deletion imposes no ordering against context removal:oauthKeyringNamesenumeratesprod/dev/hardunconditionally andoauthEnvironmentFromURLreturns nothing outside that set, so a context never names an entry the unconditional sweep would miss. - No consumer shells out to OS keychain tooling.
security,secret-tool, andcmdkeyreach past dtctl's own entries, and their read verbs print secrets, so they must not appear in code, docs, or the shipped skill. Presence is checked withdtctl auth status, which reports it without printing the token. - macOS keychain UX: keychain access is granted per binary, so each consumer (dtctl and every plugin) triggers its own one-time keychain-access prompt on first credential read. Expected behavior — document it, don't "fix" it.
- dtctl owns all config-file writes — context CRUD, login flows, safety-level assignment. Plugins treat the config file as read-only.
- The token store is the one shared write surface. OAuth refresh tokens
rotate on use, so any long-running consumer must persist refreshed token
sets — and must do so through the cross-process refresh lock
(
sdk/session,TokenManager), never with an unlocked read-modify-write. Concurrent unlocked refreshes double-spend the rotating refresh token and strand one side's credentials (invalid_grant). - Context overrides are session-local. The
--contextflag and theDTCTL_CONTEXTenv var override the current context in memory only. The sole way to persist a switch isdtctl ctx <name>(ordtctl config use-context). - A
${VAR}reference is written back as written.LoadFromresolves references in memory only.SaveTowrites the reference back for every value that is unchanged since load, including one whose variable was unset, so a load-modify-save cycle never puts a resolved secret on disk or blanks a credential (#697). A value the command changed is written as changed. A token that is a reference stays in the config file:set-credentialsdoes not put it in the keyring andmigrate-tokensskips it, because the keyring stores the literal and nothing expands it there.config viewshows the reference, not the resolved token.
| Variable | Meaning |
|---|---|
DTCTL_CONTEXT |
Session-local current-context override; flag --context wins over it. Exported to plugins. |
DTCTL_OUTPUT |
Default output format when -o/--output is not given (dtctl only). |
DTCTL_DISABLE_KEYRING |
Disable the OS keyring (any non-empty value). |
DTCTL_TOKEN_STORAGE |
file forces the file-based OAuth store. |
DTCTL_CLIENT_ID |
OAuth client ID; supplying it with DTCTL_CLIENT_SECRET switches auth login to the client credentials grant. Flag --client-id wins over it. |
DTCTL_CLIENT_SECRET |
OAuth client secret for that grant. Preferred over --client-secret, which is visible in the process table. |
DTCTL_ACCOUNT_URN |
Account URN sent as the RFC 8707 resource indicator by the client credentials grant. Flag --account-urn wins over it. |
Sanctioned bypass: cmd.Session. An embedded invocation can carry its own
environment and token, and then none of this contract applies to it: no config
file is read (a synthetic in-memory single-context config stands in), no keyring
is touched, and DTCTL_TOKEN, DT_API_TOKEN, DTCTL_ACCOUNT_TOKEN,
DTCTL_CONFIG, DTCTL_CONTEXT, DTCTL_PROFILE, and DTCTL_OUTPUT are unset
for the duration of the invocation so the host's identity and preferences cannot
shape a tenant's request. See
SERVICE_ENGINE_DESIGN.md.
| Fixture | Asserts |
|---|---|
v1-full.yaml |
Every known field parses; unknown fields at all levels are tolerated and survive a load-modify-save cycle |
v1-minimal.yaml |
Minimal config loads; apiVersion is optional |
future-version.yaml |
Unsupported schema version fails loudly |
The fixtures live in the sdk module (sdk/session/testdata/contract/), so
after the repo split both binaries keep testing against the same versioned
artifacts — the fixtures are the compatibility test between independently
released binaries.