Section 18.2.2

Figure 2: configuration example as a semantic object

Definition

A configuration example as a semantic object is a sample configuration file in a figure, read for what it makes a program do rather than for its text: for each possible input, which rule applies and which action follows. A configuration file sets a program’s behavior without changing its code. Its syntax decides which texts are well formed. Its semantics, the meaning that the program gives a well-formed text, decides the action for each input. Two programs can parse one file identically and still act differently.

Where it fits

Main entry: JSON (§12.26).

The JSON entry notes that JSON (JavaScript Object Notation) defines only syntax; YAML (YAML Ain’t Markup Language), another common configuration format, is the same in this respect. A successful parse yields a tree of names and values. The meaning comes from two further layers: a schema, which lists the permitted fields with their types and ranges, and the program’s resolution rule, which decides the outcome when several rules match the same input.

Take two rules: a global rule that allows every device, written first, and a rule that denies device A, written second. A request from device A matches both.

The same parsed file therefore allows A under first match and denies A under most specific match and deny overrides.

Many configurations arrange rules in tiers, for example rules for one device, then rules for a class of devices such as one manufacturer’s products, then a global default. Resolution then runs separately for each kind of event, such as a connection request or a data transfer: the most specific tier that has a matching rule for that kind of event decides, and a tier with no such rule passes the decision down to the next tier. If the rule for device A covers only connection requests, a data transfer from A is decided by the class tier or by the global default. A common design takes every setting of a decision from the deciding rule and never combines settings from different tiers, so each decision traces to one rule written as a whole, never to a mixture that nobody wrote.

Two failures produce no error message. A rule whose lookup key is written in a different form from the key the program computes, for example a device address with a different letter case or byte order §4.21, never matches, and a less specific tier silently decides instead. And a reserved value can change the meaning of a field: in an 8-bit field, the all-ones value 255 may mean “no limit” rather than a limit of 255, as the entry on threshold and sentinel semantics §15.37 explains. All rules and values in this entry’s examples are invented.

Limits and common mistakes

RFC 8259 leaves the behavior of a JSON object with duplicate names unpredictable [29], and YAML forbids duplicate keys, yet many parsers of both formats silently keep the last value. A strict loader rejects duplicates; the duplicate JSON key entry explains the risk.

A field left out of the file takes a default value that the file does not show, and that default decides as much as any written rule.

The number 300 does not fit an 8-bit field, which holds 0 to 255. A loader must reject it rather than keep only its low 8 bits, which would store 300−256=44300 - 256 = 44.

Naming an event in a configuration does not show that the program has code that checks that event. A test should show that each rule can match and that it changes the outcome.

Questions answered

What happens when two rules match?

When two rules match one input, the outcome is decided by the resolution rule of the configuration language, not by the text or layout of the file; if the language states no such rule, the file has no defined meaning for that input. Common resolution rules are first match (the earliest matching rule in the file wins), most specific match (the rule that covers the fewest inputs wins, such as a rule for one device over a rule for all devices), priority (the highest number wins, and a stated tie rule settles equal numbers) and deny overrides (any matching rule that denies wins).

Take a global rule that allows every device, written first, and a later rule that denies device A. First match allows A, while most specific match and deny overrides deny A. Where rules sit in tiers, such as per device, per class of device and global, the decision is made separately for each kind of event, and a tier with no rule for that kind of event passes the decision to the next tier. A safe configuration language states its resolution rule, takes every setting of a decision from the one rule that decides, and rejects at load time any two rules that can match the same input and that the resolution rule cannot order.

Related entries: Threshold and sentinel semantics (§15.37), State transition guard (§8.34), Boundary-value testing (§10.31), Duplicate JSON key (§15.20), JSON Schema (§12.27), Secure default (§1.47), Truncation and extension (§4.19). Further reading: [29].