Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(devex): add a sensitive field to owners.yaml, warn on unknown fields (#113277)

Julian Bezd1ad29b4d3d8
diff --git a/packages/owners-yaml/CHANGELOG.md b/packages/owners-yaml/CHANGELOG.md
index e735d0f24c61..a62dca3871ad 100644
--- a/packages/owners-yaml/CHANGELOG.md
+++ b/packages/owners-yaml/CHANGELOG.md
@@ -12,6 +12,13 @@ the GitHub Release body, so add the entry here before you cut the tag.
### Added
- The resolution of a path that the resolver's tree does not hold carries `added`: the first part of the path, from the root, that the tree does not hold as a directory, and the owners of additions there. Resolved against the tree before a change, this names the new directory for every file a change adds, so a consumer can use `additions` without its own tree walk. `null` when the tree holds the path, or when the resolver reads only ownership files. SPEC sections 4 and 7.2 define it.
+- An optional `sensitive` field, at file level and in rules, marks paths where a small change can change behavior far outside the change. The nearest value wins, as for `status`. The format only states the fact; a consumer decides what to do with it, for example a review assigner that requests the owners for each change. It never makes a review required. An alias file such as `product.yaml` can set it too, so a manifest that already used a `sensitive` key for another purpose now marks its paths as sensitive. `SPEC.md` section 3.7 defines it.
+- The resolver response carries a `sensitive` member, and `Resolution` a `sensitive` field. A consumer treats a missing member as `false`.
+- `lint` warns about a sensitive path that has no owners, because a consumer has no owner to request a review from.
+
+### Changed
+
+- A field that a tool does not know is a warning, not an error, at the top level, in a rule, in `teams`, and in `codeowners`. A file that uses a field from a newer release then still passes an older `lint`. `parse_owners_file` takes an optional `warnings` list that collects them. SPEC section 3 adds the rule that an amendment only adds a field that a tool can safely ignore.
## 0.3.0
diff --git a/packages/owners-yaml/README.md b/packages/owners-yaml/README.md
index ab4fa3a1b56a..5b43baf93dab 100644
--- a/packages/owners-yaml/README.md
+++ b/packages/owners-yaml/README.md
@@ -114,6 +114,20 @@ The owners of additions from every file on the walk add up, so a nested file can
The format only names these owners. A review bot or CI check decides from the change set what counts as an addition and what to do with the list.
Point the resolver at the tree before the change, and it names the new part for you: a path the tree does not hold carries `added`, for example `"added": {"path": "products/new-thing", "additions": ["team-architecture"]}` for `products/new-thing/app.py`. That also covers a new file in an existing directory, and a file that a change replaces with a directory.
+`sensitive: true` marks paths where a small change can change behavior far outside the change, such as a CI baseline or a list of exemptions:
+
+```yaml
+version: 1
+owners: team-platform
+rules:
+ - match: '/ci/allowlist.txt'
+ sensitive: true
+```
+
+The nearest value wins, as for `status`, and a nearer file that changes the owners keeps it.
+A review bot can then request the owners of `ci/allowlist.txt` for a one-line change that it would otherwise skip as minor.
+It never makes a review required. An alias file can set it too.
+
The root file can also hold repository settings:
```yaml
@@ -130,7 +144,7 @@ teams:
```
`alias_files` names the other files that count as ownership files, such as a package manifest that already lists owners.
-Only the `owners` field of such a file is read, and an `owners.yaml` next to it wins.
+Only the `owners` and `sensitive` fields of such a file are read, and an `owners.yaml` next to it wins.
The default is `[product.yaml]`, so a repository that never declares the setting still reads its product manifests.
A declared list replaces the default, and `alias_files: []` turns alias files off.
A reader that fetches files over a network should set `alias_files: []` in a repository that has no alias files, so it does not probe two names per directory.
@@ -181,7 +195,8 @@ $ uvx owners-yaml==0.3.0 lint
`lint` fails on schema errors, a directory with two ownership files, `owners.yaml` files in reserved locations, and a rule that names a directory without the trailing `/`.
Write `docs/` for a directory, because `docs` also matches a file called `docs`.
-It warns about rule patterns that match no tracked file, and it reports coverage.
+It warns about rule patterns that match no tracked file, fields it does not know, and sensitive paths without owners, and it reports coverage.
+From the release after 0.3.0, an unknown field is a warning and not an error, so a file that uses a field from a later release still passes that `lint`. Version 0.3.0 and earlier still fail on it.
Pass the changed ownership files as arguments to check only those.
Plain `lint` does not know which teams exist, so it accepts a slug for a team that was renamed or deleted.
diff --git a/packages/owners-yaml/SPEC.md b/packages/owners-yaml/SPEC.md
index 9d3ea575b140..3e47197c6077 100644
--- a/packages/owners-yaml/SPEC.md
+++ b/packages/owners-yaml/SPEC.md
@@ -27,6 +27,7 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S
- **Consumer**: a program that uses resolutions, such as a review assigner or a coverage check.
- **Addition**: a path that a change adds to the repository, such as a new file or directory. A consumer decides which paths count as additions (section 3.6).
- **Owners of additions**: the owners that the `additions` field names for a path. They are separate from the owners of the path (section 3.6).
+- **Sensitive path**: a path whose resolution has `sensitive` set to `true` (section 3.7).
One program can have more than one of these roles. A consumer that reads ownership files itself is also a tool. It is a resolver when it computes resolutions.
@@ -49,9 +50,15 @@ An ownership file is a YAML mapping.
| `inherit` | no | boolean | Whether fields fall through from ancestor files. Default `true`. |
| `rules` | no | list of rule mappings | Per-path overrides inside this directory. |
| `additions` | no | string or list of strings | The owners of additions below the directory. |
+| `sensitive` | no | boolean | Whether a small change can change behavior far outside the change. |
The root file MAY also carry the repository settings in section 5.
-In an `owners.yaml`, any other top-level field is an error. A linter MUST report it. The field has no effect on resolution.
+
+A tool MUST ignore a field that it does not know, at the top level, in a rule, and in a repository setting.
+The field has no effect on resolution.
+A linter SHOULD report it as a warning. A linter MUST NOT report it as an error, so that a file written for a later amendment of version 1 still passes an older linter.
+An amendment of version 1 MAY add a field only when a tool that ignores the field still gives a safe result.
+A field that a tool cannot safely ignore requires a new version.
### 3.1 `owners`
@@ -66,12 +73,12 @@ In an `owners.yaml`, any other top-level field is an error. A linter MUST report
The value MUST be one of these:
-| Value | Meaning |
-| ------------ | --------------------------------------------------------------------------- |
-| `active` | Maintained code. This is the default. |
-| `deprecated` | Code that is due for removal. |
-| `generated` | Output of a generator. A consumer SHOULD NOT request reviews for this code. |
-| `vendored` | Third-party code copied into the repository. |
+| Value | Meaning |
+| ------------ | ----------------------------------------------------------------------------------------------------------------------- |
+| `active` | Maintained code. This is the default. |
+| `deprecated` | Code that is due for removal. |
+| `generated` | Output of a generator. A consumer SHOULD NOT request reviews for this code, unless the path is sensitive (section 3.7). |
+| `vendored` | Third-party code copied into the repository. |
### 3.3 `inherit`
@@ -89,6 +96,7 @@ Each rule is a mapping with these fields:
| `status` | no | as in 3.2 | Replaces the file-level status for matching paths. |
| `inherit` | no | boolean | Replaces the file-level `inherit` for matching paths. |
| `additions` | no | as in 3.6 | Appends to the file-level `additions` for matching paths. |
+| `sensitive` | no | as in 3.7 | Replaces the file-level `sensitive` for matching paths. |
1. A rule with a list of valid patterns is equal to one rule per pattern, in list order, with the same fields.
2. Within one file, every rule whose pattern matches a path applies, in file order. Each rule replaces only the fields it sets, so a later rule that sets only `status` keeps the `owners` of an earlier rule. `additions` is the exception: each matching rule appends to it (section 3.6).
@@ -131,6 +139,21 @@ A resolver that can see the repository helps with the first: resolved against th
`added` (section 4, step 6) gives the new directory and its owners of additions for any path below it.
7. A rule `match: '/docs/'` matches each path below `docs`, at any depth. It does not match `docs` itself (section 3.5, rule 4). The owners of additions for `docs` come from the other fields and rules on the walk to `docs`, as for any other path.
+### 3.7 `sensitive`
+
+`sensitive: true` marks paths where a small change can change behavior far outside the change, such as the baseline file of a CI check or a list of exemptions.
+The format only states this fact.
+A consumer decides what to do with it.
+For example, a review assigner can request the owners of a sensitive path for each change to it, whatever the size of the change.
+
+1. The value MUST be a boolean. Any other value is an error. The file or the rule then does not set `sensitive`, and its other fields still apply.
+2. The nearest value wins, as for `status`. `false` turns off a `true` from an ancestor file or from an earlier rule.
+3. `sensitive` belongs to the paths, not to their owners. A nearer file that changes the owners keeps the value of its ancestors.
+4. `sensitive` does not change `owners`. A sensitive path with no owners is still unowned. A linter SHOULD report a sensitive path that has no owners, unowned by design or not.
+5. `sensitive` does not make a review required and does not block a change. Required reviews stay with the code host, for example its CODEOWNERS file and branch protection.
+6. A consumer that does not request reviews for `status: generated` (section 3.2) SHOULD still treat a sensitive path as a path to review.
+7. An alias file MAY set `sensitive` (section 6).
+
## 4. Resolution
A consumer SHOULD get resolutions from a resolver, not by reading ownership files itself.
@@ -142,20 +165,22 @@ To resolve a path `P`:
1. Normalize `P`: replace each `\` with `/`. Then, while `P` starts with `./`, remove that `./`. Then remove every `/` at the start and at the end of `P`.
2. List the directories from the repository root down to the parent directory of `P`, root first.
-3. For each directory, find its ownership file. Skip the directory when it has none. A file that is not a YAML mapping, or that lacks `version: 1` or `owners`, counts as absent.
-4. Start with an empty result: owners unset, status unset, source unset, additions empty.
+3. For each directory, find its ownership file. Skip the directory when it has none. An `owners.yaml` that is not a YAML mapping, or that lacks `version: 1` or `owners`, counts as absent. Section 6 says when an alias file counts as absent.
+4. Start with an empty result: owners unset, status unset, sensitive unset, source unset, additions empty.
5. For each file found in step 3, in order:
- 1. Take the file-level `owners`, `status`, `inherit`, and `additions`.
- 2. For each rule in the file that matches `P`, in file order, replace each of `owners`, `status`, and `inherit` that the rule sets. Append each entry of the rule's `additions` to the file-level `additions` (section 3.4).
+ 1. Take the file-level `owners`, `status`, `inherit`, `sensitive`, and `additions`.
+ 2. For each rule in the file that matches `P`, in file order, replace each of `owners`, `status`, `inherit`, and `sensitive` that the rule sets. Append each entry of the rule's `additions` to the file-level `additions` (section 3.4).
3. If `inherit` is `false`, reset the result to empty.
4. If `owners` is `null`, set the result owners to `null` and the source to this file.
5. If `owners` is a non-empty list, set the result owners to that list and the source to this file.
6. If `status` is set, set the result status to it.
- 7. Append each entry of `additions` to the result additions, unless the result additions already contain it.
+ 7. If `sensitive` is set, set the result sensitive to it.
+ 8. Append each entry of `additions` to the result additions, unless the result additions already contain it.
6. Return the resolution:
- `owners`: the result owners, or an empty list when unset or `null`.
- `unowned_by_design`: `true` when the result owners are `null`.
- `status`: the result status, or `active` when unset.
+ - `sensitive`: the result sensitive, or `false` when unset.
- `source`: the path of the file that set the owners, or none.
- `slack`: the channel from section 5.2, for the requested purpose.
- `additions`: the result additions, in the order they were appended.
@@ -177,6 +202,8 @@ The value is the file-level value after step 5.2 applied every matching rule.
| `owners` | `null` | Owners become `null` (unowned by design). Source becomes this file. |
| `status` | set | Status becomes this value. |
| `status` | absent | No effect. |
+| `sensitive` | set | Sensitive becomes this value. |
+| `sensitive` | absent | No effect. |
| `additions` | non-empty list | The result additions gain each entry that they do not contain yet, at the end. |
| `additions` | absent or `[]` | No effect. |
@@ -190,17 +217,17 @@ flowchart TD
norm --> walk[Take the next directory, from the root to the parent of P]
walk --> has{Has an ownership file?}
has -- no --> more
- has -- yes --> take[Take the file's owners, status, inherit, and additions]
+ has -- yes --> take[Take the file's owners, status, inherit, sensitive, and additions]
take --> rule{Does a rule match P?}
- rule -- yes --> apply[For each matching rule in file order,<br/>replace the owners, status, and inherit that it sets,<br/>and append its additions]
+ rule -- yes --> apply[For each matching rule in file order,<br/>replace the owners, status, inherit, and sensitive that it sets,<br/>and append its additions]
rule -- no --> cut
apply --> cut{inherit is false?}
cut -- yes --> reset[Reset the result]
cut -- no --> merge
- reset --> merge[Merge owners, status, and additions as in 4.1]
+ reset --> merge[Merge owners, status, sensitive, and additions as in 4.1]
merge --> more{More directories?}
more -- yes --> walk
- more -- no --> done([Return owners, unowned_by_design, status, source, slack, additions, added])
+ more -- no --> done([Return owners, unowned_by_design, status, sensitive, source, slack, additions, added])
```
### 4.3 Conformance
@@ -268,7 +295,7 @@ The root file declares the alias files in `alias_files` (section 5).
5. When the root file declares `alias_files` and the declaration is valid, the alias file names are exactly the declared entries. A tool MUST NOT add `product.yaml` to a declared list. An empty declared list means the repository has no alias file.
6. When the root file declares `alias_files` and a tool ignores the declaration as invalid, the repository has no alias file. A tool MUST NOT fall back to `product.yaml` there.
7. A tool MUST NOT read a file as an ownership file unless the file is named `owners.yaml` or its name is one of the alias file names.
-8. A tool MUST read only the `owners` field of an alias file. All other fields have no effect on ownership.
+8. A tool MUST read only the `owners` and `sensitive` fields of an alias file. All other fields have no effect on ownership. A `sensitive` value that is not a boolean has no effect, because the program that owns the alias file validates it.
9. The `owners` field MUST be a list of non-empty strings. Otherwise the file counts as absent.
10. An `owners.yaml` in the same directory takes precedence. A linter SHOULD report a directory that has both.
11. When a directory holds more than one alias file, the file with the first name in `alias_files` takes precedence. A linter SHOULD report that directory.
@@ -295,7 +322,7 @@ In `owners-yaml`, both `owners resolve --json` and `python -m owners_yaml` imple
1. On success, the resolver MUST write one JSON object to standard output and exit with status 0.
2. Each key MUST be a requested path after normalization (section 4, step 1). Two requests that normalize to the same path produce one key.
-3. Each value MUST be an object with the members `owners`, `status`, `slack`, and `source`. It SHOULD also have the members `additions` and `added`. The members are:
+3. Each value MUST be an object with the members `owners`, `status`, `slack`, and `source`. It SHOULD also have the members `additions`, `added`, and `sensitive`. The members are:
| Member | Type | Value |
| ----------- | ---------------- | ---------------------------------------------------------------------------------- |
@@ -305,6 +332,7 @@ In `owners-yaml`, both `owners resolve --json` and `python -m owners_yaml` imple
| `source` | string or `null` | The repository-relative path of the file that set the owners. |
| `additions` | array of strings | The resolved owners of additions (section 3.6), in the order of section 4, step 6. |
| `added` | object or `null` | `{"path": N, "additions": [...]}` from section 4, step 6, or `null`. |
+ | `sensitive` | boolean | Whether the path is sensitive (section 3.7). |
4. A path that is unowned by design has an empty `owners` array and a non-null `source`. An unowned path has an empty `owners` array and a `null` source.
5. An unowned path is not an error.
@@ -321,7 +349,7 @@ In `owners-yaml`, both `owners resolve --json` and `python -m owners_yaml` imple
1. A consumer MUST ignore members that it does not know.
2. A resolver MAY add members to a value.
3. Removing a member, renaming it, or changing its meaning requires a new version of this specification.
-4. A consumer MUST treat a missing `additions` member as an empty array, and a missing `added` member as `null`. A resolver that predates a member leaves it out.
+4. A consumer MUST treat a missing `additions` member as an empty array, a missing `added` member as `null`, and a missing `sensitive` member as `false`. A resolver that predates a member leaves it out.
5. For the Python library, the names exported from the top-level `owners_yaml` package are the public API. Submodules can change between minor releases.
## 8. The owners-yaml reference implementation
@@ -330,7 +358,7 @@ This section describes the reference implementation. It is not part of the forma
- It reads the alias files the root `owners.yaml` declares. PostHog's own repository declares `product.yaml`.
- It removes the placeholder owner `team-CHANGEME` from every `owners` and `additions` list. Section 4 allows this removal.
-- Its linter reports schema errors, reserved locations, directories with both an `owners.yaml` and an alias file, rules that name a tracked directory without the trailing `/`, rule patterns that match no tracked file, and the number of unowned files. With `--live`, it also checks team slugs and person handles against the GitHub organization.
+- Its linter reports schema errors, unknown fields as warnings, sensitive paths that are unowned as warnings, reserved locations, directories with both an `owners.yaml` and an alias file, rules that name a tracked directory without the trailing `/`, rule patterns that match no tracked file, and the number of unowned files. With `--live`, it also checks team slugs and person handles against the GitHub organization.
- It reports `added` when its source can tell whether the repository holds a path, as its disk source does (`TreeSource`). A source that reads only the ownership files reports none. It treats a symbolic link as a file, as git does.
- Its CODEOWNERS export covers test files only: `test_*.py` and `*_test.py` for pytest, and `*.test.*` or `*.spec.*` with a `.js`, `.jsx`, `.ts`, or `.tsx` extension for Jest. The `codeowners` setting accepts these keys:
@@ -364,6 +392,8 @@ rules:
owners: null
- match: ['migrations/', 'legacy/']
owners: [team-billing, team-data]
+ - match: 'pricing/allowlist.txt'
+ sensitive: true
```
A root file with repository settings:
@@ -468,7 +498,9 @@ rules:
- **Unowned is a decision.** `owners: null` records that nobody owns a path on purpose. A consumer that checks coverage reports an unowned path. It does not report a path that is unowned by design.
- **The alias default is for old trees.** `product.yaml` is the default alias file name so that a repository written before `alias_files` existed resolves the same as it did then. A repository with no alias files sets `alias_files: []` and pays no lookups for it.
- **Owners of additions add up.** Owners are nearest-file-wins because the union tags too many teams. `additions` answers a different question: who owns additions below a directory. If a nested file could drop the owners of additions that an ancestor file names, the answer of the ancestor would not be reliable. A separate field keeps coverage checks correct: `owners` on the parent directory would claim every file below it that has no nearer owner.
-- **Routing, not approval.** The format answers "who owns this path" for review requests, alerts, and reports. It does not replace a platform's required-approval rules. `additions` is routing too: it names owners, and it does not approve or block a change.
+- **Routing, not approval.** The format answers "who owns this path" for review requests, alerts, and reports. It does not replace a platform's required-approval rules. `additions` is routing too: it names owners, and it does not approve or block a change. So is `sensitive`: it states that a small change matters, and a consumer decides what to do about it.
+- **`sensitive` is a fact, not an instruction.** A field such as "always review" would tell one kind of consumer what to do. A fact about the paths serves every consumer: a review assigner can request the owners, an approval bot can ask for a person, and a report can rank a sensitive unowned path first. It belongs to the paths and not to the owners, so a nearer file that changes the owners keeps it.
+- **Unknown fields are warnings.** A typo in an optional field, such as `staus:`, then only gives a warning. A typo in a required field, such as `owner:`, still fails, because the file then has no `owners` field. In exchange, a repository can adopt a new field before every tool that reads it upgrades. The amendment rule in section 3 keeps that safe: a field that an older tool ignores must not make its answer wrong.
- **`additions` does not default to `owners`.** An empty list means that the file names no separate owners of additions. A default would hide which directories have their own owners of additions and which only have owners.
- **One input format.** A resolver reads ownership files only. CODEOWNERS is an export target, and a source for a one-time migration into ownership files, never a second input the resolver reads. The two formats resolve differently: CODEOWNERS takes the last matching line in one file, and this format takes the nearest file, field by field. CODEOWNERS also carries owners and nothing else, so it can say nothing about status or channels. Reading both would make the answer depend on which file a tool found first.
@@ -479,3 +511,4 @@ rules:
- **1**, amended (2026-09): Section 7.1 adds the producer to the resolver request, so a consumer can reach a team's per-producer `notifications` mapping through an entrypoint. No ownership file changes meaning.
- **1**, amended (unreleased): Section 3.4 applies every matching rule, field by field. Before, the last matching rule replaced the earlier ones. Section 3.6 adds the optional `additions` field. Section 7.2 adds the `additions` member, and a consumer treats a missing member as empty (section 7.4). Section 4 step 1 removes a trailing `/`, so a request for `docs/` resolves the same as `docs`.
- **1**, amended (unreleased): Section 4, step 6 adds `added`: for a path that the repository does not hold, the first part of it that the repository does not hold as a directory, with its owners of additions. Section 7.2 adds the `added` member, and a consumer treats a missing member as `null` (section 7.4). No ownership file changes meaning.
+- **1**, amended (unreleased): Section 3 makes a field that a tool does not know a warning, not an error, so a file written for a later amendment still passes an older linter. An amendment adds a field only when a tool that ignores it still gives a safe result. Section 3.7 adds the optional `sensitive` field, and section 6 lets an alias file set it. Section 7.2 adds the `sensitive` member, and a consumer treats a missing member as `false` (section 7.4). No `owners.yaml` that was valid before changes meaning. An alias file that already used a `sensitive` key for another purpose now marks its paths as sensitive.
diff --git a/packages/owners-yaml/conformance/README.md b/packages/owners-yaml/conformance/README.md
index dab79bb68546..2179505f73af 100644
--- a/packages/owners-yaml/conformance/README.md
+++ b/packages/owners-yaml/conformance/README.md
@@ -42,9 +42,10 @@ Each resolution is a mapping with these keys:
| `source` | string or `null` | The path of the file that set the owners, or `null` when no file did. |
| `slack` | string or `null` | The channel for the purpose and the producer of the case, or `null`. |
| `additions` | list of strings | Optional, default empty. The owners of additions at the path (SPEC 3.6). |
+| `sensitive` | boolean | Optional, default `false`. Whether the path is sensitive (SPEC 3.7). |
A case never leaves out one of the first five keys, so no value is implied.
-A case that leaves out `additions` expects an empty list, so the cases that predate the field stay as they are.
+A case that leaves out `additions` expects an empty list, and a case that leaves out `sensitive` expects `false`, so the cases that predate these fields stay as they are.
An example case:
@@ -75,7 +76,7 @@ For each case in each file in `cases/`:
1. Make a new empty directory. This directory is the repository root. It is not a git repository.
2. Write each entry of `files` to its path below the root. Make the parent directories first. Write the content exactly as given.
3. Resolve each key of `expect` as given, with the `purpose` and the `producer` of the case.
-4. Compare all six keys of the result with the expected resolution. An expected resolution without `additions` expects an empty list. The order of `owners` and of `additions` is significant.
+4. Compare all seven keys of the result with the expected resolution. An expected resolution without `additions` expects an empty list, and one without `sensitive` expects `false`. The order of `owners` and of `additions` is significant.
5. The case passes when every path in `expect` passes.
Give each test a name of the form `<file name>::<case name>`, such as `nearest-file.yaml::owners null marks paths as unowned by design`.
diff --git a/packages/owners-yaml/conformance/case.schema.json b/packages/owners-yaml/conformance/case.schema.json
index 3a284f082d1a..6a712bd0190a 100644
--- a/packages/owners-yaml/conformance/case.schema.json
+++ b/packages/owners-yaml/conformance/case.schema.json
@@ -65,7 +65,8 @@
"additions": {
"type": "array",
"items": { "type": "string", "minLength": 1 }
- }
+ },
+ "sensitive": { "type": "boolean" }
}
}
}
diff --git a/packages/owners-yaml/conformance/cases/aliases.yaml b/packages/owners-yaml/conformance/cases/aliases.yaml
index 40ff96ed95e2..26c73fc7a936 100644
--- a/packages/owners-yaml/conformance/cases/aliases.yaml
+++ b/packages/owners-yaml/conformance/cases/aliases.yaml
@@ -19,7 +19,7 @@ cases:
source: products/foo/product.yaml
slack: '#team-foo'
- - name: only the owners field of product.yaml has an effect
+ - name: fields of product.yaml other than owners and sensitive have no effect
files:
owners.yaml: |
version: 1
@@ -216,3 +216,71 @@ cases:
status: active
source: products/foo/product.yaml
slack: '#team-product'
+
+ - name: an alias file can set sensitive
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ alias_files: [product.yaml]
+ products/billing/product.yaml: |
+ name: billing
+ owners:
+ - team-billing
+ sensitive: true
+ products/billing/api/owners.yaml: |
+ version: 1
+ owners: []
+ sensitive: false
+ expect:
+ products/billing/models.py:
+ owners: [team-billing]
+ unowned_by_design: false
+ status: active
+ source: products/billing/product.yaml
+ slack: '#team-billing'
+ sensitive: true
+ products/billing/api/views.py:
+ owners: [team-billing]
+ unowned_by_design: false
+ status: active
+ source: products/billing/product.yaml
+ slack: '#team-billing'
+
+ - name: an alias file without a usable owners list does not set sensitive
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ alias_files: [product.yaml]
+ products/web/product.yaml: |
+ name: web
+ sensitive: true
+ expect:
+ products/web/x.ts:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+
+ - name: an alias file ignores a sensitive value that is not a boolean
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ alias_files: [product.yaml]
+ sensitive: true
+ products/web/product.yaml: |
+ name: web
+ owners:
+ - team-web
+ sensitive: 'yes please'
+ expect:
+ products/web/x.ts:
+ owners: [team-web]
+ unowned_by_design: false
+ status: active
+ source: products/web/product.yaml
+ slack: '#team-web'
+ sensitive: true
diff --git a/packages/owners-yaml/conformance/cases/sensitive.yaml b/packages/owners-yaml/conformance/cases/sensitive.yaml
new file mode 100644
index 000000000000..fc46eea7ee5b
--- /dev/null
+++ b/packages/owners-yaml/conformance/cases/sensitive.yaml
@@ -0,0 +1,155 @@
+cases:
+ - name: a sensitive file applies to every path below it and survives a nearer owners change
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ guard/owners.yaml: |
+ version: 1
+ owners: team-guard
+ sensitive: true
+ guard/sub/owners.yaml: |
+ version: 1
+ owners: team-sub
+ expect:
+ guard/sub/x.py:
+ owners: [team-sub]
+ unowned_by_design: false
+ status: active
+ source: guard/sub/owners.yaml
+ slack: '#team-sub'
+ sensitive: true
+ x.py:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+
+ - name: a nearer file with sensitive false turns off an ancestor's true
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ sensitive: true
+ docs/owners.yaml: |
+ version: 1
+ owners: []
+ sensitive: false
+ expect:
+ docs/x.md:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+ x.py:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+ sensitive: true
+
+ - name: rules set sensitive for the paths they match and a later rule can turn it off
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ rules:
+ - match: '/guard/'
+ sensitive: true
+ - match: '/guard/test/'
+ sensitive: false
+ expect:
+ guard/baseline.txt:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+ sensitive: true
+ guard/test/test_guard.py:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+ other/x.py:
+ owners: [team-root]
+ unowned_by_design: false
+ status: active
+ source: owners.yaml
+ slack: '#team-root'
+
+ - name: inherit false drops sensitive from ancestor files
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ sensitive: true
+ island/owners.yaml: |
+ version: 1
+ owners: team-island
+ inherit: false
+ expect:
+ island/x.py:
+ owners: [team-island]
+ unowned_by_design: false
+ status: active
+ source: island/owners.yaml
+ slack: '#team-island'
+
+ - name: sensitive and generated status apply together
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ rules:
+ - match: baseline.txt
+ status: generated
+ sensitive: true
+ expect:
+ ci/baseline.txt:
+ owners: [team-root]
+ unowned_by_design: false
+ status: generated
+ source: owners.yaml
+ slack: '#team-root'
+ sensitive: true
+
+ - name: a sensitive path without owners is still unowned
+ files:
+ owners.yaml: |
+ version: 1
+ owners: []
+ rules:
+ - match: '/guard/'
+ sensitive: true
+ expect:
+ guard/x.py:
+ owners: []
+ unowned_by_design: false
+ status: active
+ source: null
+ slack: null
+ sensitive: true
+
+ - name: a sensitive value that is not a boolean has no effect and the rest of the file applies
+ files:
+ owners.yaml: |
+ version: 1
+ owners: team-root
+ sensitive: true
+ a/owners.yaml: |
+ version: 1
+ owners: team-a
+ sensitive: 'no'
+ expect:
+ a/x.py:
+ owners: [team-a]
+ unowned_by_design: false
+ status: active
+ source: a/owners.yaml
+ slack: '#team-a'
+ sensitive: true
diff --git a/packages/owners-yaml/owners.schema.json b/packages/owners-yaml/owners.schema.json
index 35153e0935b7..2ceb23d1a2ec 100644
--- a/packages/owners-yaml/owners.schema.json
+++ b/packages/owners-yaml/owners.schema.json
@@ -20,6 +20,7 @@
"items": { "$ref": "#/$defs/rule" }
},
"additions": { "$ref": "#/$defs/additions" },
+ "sensitive": { "$ref": "#/$defs/sensitive" },
"teams": {
"type": "object",
"description": "Repository settings: team slug to its channels.",
@@ -77,6 +78,10 @@
{ "type": "array", "items": { "type": "string", "minLength": 1 } }
]
},
+ "sensitive": {
+ "type": "boolean",
+ "description": "Whether a small change here can change behavior far outside the change. The nearest value wins. It never makes a review required. Default false."
+ },
"status": {
"enum": ["active", "deprecated", "generated", "vendored"],
"description": "The lifecycle of the code. Default active."
@@ -101,7 +106,8 @@
"owners": { "$ref": "#/$defs/owners" },
"status": { "$ref": "#/$defs/status" },
"inherit": { "type": "boolean" },
- "additions": { "$ref": "#/$defs/additions" }
+ "additions": { "$ref": "#/$defs/additions" },
+ "sensitive": { "$ref": "#/$defs/sensitive" }
}
},
"channel": {
diff --git a/packages/owners-yaml/owners_yaml/cli.py b/packages/owners-yaml/owners_yaml/cli.py
index 6b83b76af278..14bfd5d933c6 100644
--- a/packages/owners-yaml/owners_yaml/cli.py
+++ b/packages/owners-yaml/owners_yaml/cli.py
@@ -108,6 +108,8 @@ def cmd_who(repo_root: Path | None, path: str) -> None:
else:
click.echo("owners: (unowned)")
click.echo(f"status: {r.status}")
+ if r.sensitive:
+ click.echo("sensitive: yes")
click.echo(f"slack: {r.slack or '(none)'}")
click.echo(f"source: {r.source or '(none)'}")
@@ -333,6 +335,8 @@ def cmd_lint(live: bool, org: str | None, repo_root: Path | None, paths: tuple[s
for err in entry.errors:
errors.append(f"{rel}: {err}")
+ for warning in entry.warnings:
+ warnings.append(f"{rel}: {warning}")
owners_dirs[directory] = is_simple_owners_file(parsed)
if parsed is None:
continue
@@ -364,8 +368,16 @@ def cmd_lint(live: bool, org: str | None, repo_root: Path | None, paths: tuple[s
github = GitHubOrg(_github_org(org, settings))
errors.extend(_validate_owners_live(_live_scope(owners_by_file, paths), github))
- unowned = resolver.unowned(tracked)
- warnings.append(f"coverage: {len(unowned)} of {len(tracked)} tracked file(s) resolve to unowned")
+ unowned_count = 0
+ sensitive_without_owners: list[str] = []
+ for path in tracked:
+ resolution = resolver.resolve(path)
+ unowned_count += resolution.is_unowned
+ # A consumer acts on `sensitive` through the owners of the path, so without owners the flag does nothing.
+ if resolution.sensitive and not resolution.owners:
+ sensitive_without_owners.append(f"{path}: sensitive but has no owners")
+ warnings.append(f"coverage: {unowned_count} of {len(tracked)} tracked file(s) resolve to unowned")
+ warnings.extend(sensitive_without_owners)
for warning in warnings:
click.echo(f"⚠ {warning}")
diff --git a/packages/owners-yaml/owners_yaml/resolver.py b/packages/owners-yaml/owners_yaml/resolver.py
index 2e7699b0596f..5fa1d0c493f8 100644
--- a/packages/owners-yaml/owners_yaml/resolver.py
+++ b/packages/owners-yaml/owners_yaml/resolver.py
@@ -122,6 +122,7 @@ class Resolution:
# Set only when the resolver reads a tree and the path is not in it, such as a file that a change
# adds when the tree is the version before the change.
added: Addition | None = None
+ sensitive: bool = False
@property
def is_owned(self) -> bool:
@@ -144,6 +145,7 @@ class WireResolution(TypedDict):
source: str | None
additions: list[str]
added: WireAddition | None
+ sensitive: bool
class WireAddition(TypedDict):
@@ -159,6 +161,7 @@ def resolution_to_wire(r: Resolution) -> WireResolution:
"source": r.source,
"additions": r.additions,
"added": {"path": r.added.path, "additions": r.added.additions} if r.added is not None else None,
+ "sensitive": r.sensitive,
}
@@ -176,6 +179,7 @@ class ParsedOwnershipFile:
name: str # OWNERS_FILENAME or one of the configured alias file names
parsed: OwnersFile | None
errors: list[str] = field(default_factory=list)
+ warnings: list[str] = field(default_factory=list)
@property
def is_alias(self) -> bool:
@@ -188,6 +192,7 @@ class _Merged:
status: str | _Unset = UNSET
source: str | None = None
additions: list[str] = field(default_factory=list)
+ sensitive: bool | _Unset = UNSET
def _union(*groups: Iterable[str]) -> list[str]:
@@ -400,6 +405,7 @@ class OwnersResolver:
inherit=f.inherit,
is_alias=f.is_alias,
additions=_union(f.additions, *(rule.additions for rule in matched)),
+ sensitive=f.sensitive,
)
for rule in matched:
if not isinstance(rule.owners, _Unset):
@@ -408,6 +414,8 @@ class OwnersResolver:
contrib.status = rule.status
if not isinstance(rule.inherit, _Unset):
contrib.inherit = rule.inherit
+ if not isinstance(rule.sensitive, _Unset):
+ contrib.sensitive = rule.sensitive
return contrib
def ownership_file_paths(self, paths: list[str]) -> list[str]:
@@ -445,6 +453,9 @@ class OwnersResolver:
if not isinstance(contrib.status, _Unset):
merged.status = contrib.status
+ if not isinstance(contrib.sensitive, _Unset):
+ merged.sensitive = contrib.sensitive
+
if contrib.additions:
merged.additions = _union(merged.additions, contrib.additions)
@@ -522,6 +533,7 @@ class OwnersResolver:
unowned_by_design=unowned_by_design,
additions=merged.additions,
added=added,
+ sensitive=merged.sensitive is True,
)
def _rel(self, path: Path) -> str:
@@ -576,12 +588,19 @@ class OwnersResolver:
if not rel_dir and name != OWNERS_FILENAME:
continue
abs_path = self.repo_root / rel
+ errors: list[str] = []
+ warnings: list[str] = []
if name != OWNERS_FILENAME:
parsed = parse_alias_file_as_owners(abs_path.read_text(), path=abs_path, directory=rel_dir)
- errors: list[str] = []
else:
- parsed, errors = parse_owners_file(abs_path.read_text(), path=abs_path, directory=rel_dir)
- entries.append(ParsedOwnershipFile(path=abs_path, rel_dir=rel_dir, name=name, parsed=parsed, errors=errors))
+ parsed, errors = parse_owners_file(
+ abs_path.read_text(), path=abs_path, directory=rel_dir, warnings=warnings
+ )
+ entries.append(
+ ParsedOwnershipFile(
+ path=abs_path, rel_dir=rel_dir, name=name, parsed=parsed, errors=errors, warnings=warnings
+ )
+ )
self._parsed_ownership = entries
return entries
diff --git a/packages/owners-yaml/owners_yaml/schema.py b/packages/owners-yaml/owners_yaml/schema.py
index 9dabc486df68..33d583bafc47 100644
--- a/packages/owners-yaml/owners_yaml/schema.py
+++ b/packages/owners-yaml/owners_yaml/schema.py
@@ -1,8 +1,8 @@
"""Dataclass model, parser, and validator for ``owners.yaml``.
-Also loads an *alias* file as an ownership file: only its ``owners:`` list is read
-(``@handles`` kept, a ``team-CHANGEME``-only list treated as empty), every other field
-ignored. The root file names the alias files in ``alias_files``.
+Also loads an *alias* file as an ownership file: only its ``owners:`` list and its
+``sensitive:`` flag are read (``@handles`` kept, a ``team-CHANGEME``-only list treated as
+empty), every other field ignored. The root file names the alias files in ``alias_files``.
"""
from __future__ import annotations
@@ -24,8 +24,8 @@ OWNERS_FILENAME = "owners.yaml"
ROOT_ONLY_KEYS = {"teams", "github_org", "producers", "reserved_dirs", "codeowners", "alias_files"}
# Top-level keys allowed in owners.yaml. Rules allow the same set minus `version`
# and `rules`, plus the required `match`.
-TOP_LEVEL_KEYS = {"version", "owners", "status", "inherit", "rules", "additions"} | ROOT_ONLY_KEYS
-_RULE_KEYS = {"match", "owners", "status", "inherit", "additions"}
+TOP_LEVEL_KEYS = {"version", "owners", "status", "inherit", "rules", "additions", "sensitive"} | ROOT_ONLY_KEYS
+_RULE_KEYS = {"match", "owners", "status", "inherit", "additions", "sensitive"}
# Every alias name is one more file to read per directory, and a hosted resolver reads a root file
# it does not control, so the list has a ceiling.
MAX_ALIAS_FILES = 8
@@ -126,6 +126,7 @@ class OwnersRule:
status: str | _Unset = UNSET
inherit: bool | _Unset = UNSET
additions: list[str] = field(default_factory=list)
+ sensitive: bool | _Unset = UNSET
@dataclass
@@ -144,6 +145,10 @@ class OwnersFile:
# Names people only; what counts as an addition, and what a consumer does with them, is the
# consumer's policy.
additions: list[str] = field(default_factory=list)
+ sensitive: bool | _Unset = UNSET
+ # A field from a newer version of the format. The parser drops its value, so a tool that
+ # rewrites or moves this file would lose it.
+ has_unknown_fields: bool = False
# Root-only Slack registry: team slug -> TeamEntry. Empty everywhere but the repo-root
# file; lets a team declare its channels once instead of per file.
teams: dict[str, TeamEntry] = field(default_factory=dict)
@@ -226,7 +231,9 @@ def _validate_producer_map(
return declared if readable else {}
-def _validate_teams(value: object, producers: frozenset[str] | None, errors: list[str]) -> dict[str, TeamEntry]:
+def _validate_teams(
+ value: object, producers: frozenset[str] | None, errors: list[str], warnings: list[str]
+) -> dict[str, TeamEntry]:
"""Validate the root-only ``teams:`` registry, a mapping of team slug to its channels.
A slug registers only when it declares at least one channel. Membership of the returned
@@ -251,7 +258,7 @@ def _validate_teams(value: object, producers: frozenset[str] | None, errors: lis
declared: dict[str, str | bool | Mapping[str, str | bool]] = {}
for key, raw in entry.items():
if not isinstance(key, str) or key not in _TEAMS_ENTRY_KEYS:
- errors.append(f"{where}: unknown field '{key}'")
+ warnings.append(f"{where}: unknown field '{key}'")
elif isinstance(raw, dict):
per_producer = _validate_producer_map(raw, where, key, producers, errors)
if per_producer:
@@ -277,14 +284,14 @@ def _validate_string_list(value: object, key: str, errors: list[str]) -> list[st
return []
-def _validate_codeowners(value: object, errors: list[str]) -> CodeownersSettings:
+def _validate_codeowners(value: object, errors: list[str], warnings: list[str]) -> CodeownersSettings:
if not isinstance(value, dict):
errors.append(f"'codeowners' must be a mapping with keys {', '.join(sorted(_CODEOWNERS_KEYS))}")
return CodeownersSettings()
declared: dict[str, str] = {}
for key, raw in value.items():
if key not in _CODEOWNERS_KEYS:
- errors.append(f"codeowners: unknown field '{key}'")
+ warnings.append(f"codeowners: unknown field '{key}'")
elif not isinstance(raw, str) or not raw:
errors.append(f"codeowners: '{key}' must be a non-empty string")
elif key == "jest_root_tests":
@@ -299,7 +306,7 @@ def _validate_codeowners(value: object, errors: list[str]) -> CodeownersSettings
return CodeownersSettings(**declared)
-def _validate_settings(data: dict[object, object], errors: list[str]) -> RepoSettings:
+def _validate_settings(data: dict[object, object], errors: list[str], warnings: list[str]) -> RepoSettings:
"""Read the root-only repo settings. An invalid value is reported and left at its default."""
github_org: str | None = None
if "github_org" in data:
@@ -347,7 +354,9 @@ def _validate_settings(data: dict[object, object], errors: list[str]) -> RepoSet
errors.append(f"alias_files: at most {MAX_ALIAS_FILES} names are allowed")
alias_files = []
- codeowners = _validate_codeowners(data["codeowners"], errors) if "codeowners" in data else CodeownersSettings()
+ codeowners = (
+ _validate_codeowners(data["codeowners"], errors, warnings) if "codeowners" in data else CodeownersSettings()
+ )
return RepoSettings(
github_org=github_org,
producers=producers,
@@ -364,10 +373,10 @@ def _validate_status(value: object, where: str, errors: list[str]) -> str | _Uns
return UNSET
-def _validate_inherit(value: object, where: str, errors: list[str]) -> bool | _Unset:
+def _validate_bool(value: object, key: str, where: str, errors: list[str]) -> bool | _Unset:
if isinstance(value, bool):
return value
- errors.append(f"{where}: 'inherit' must be a boolean")
+ errors.append(f"{where}: '{key}' must be a boolean")
return UNSET
@@ -401,7 +410,7 @@ def _rule_match_patterns(raw_match: object, where: str, errors: list[str]) -> li
return patterns if ok else []
-def _parse_rule(raw: object, index: int, errors: list[str]) -> list[OwnersRule]:
+def _parse_rule(raw: object, index: int, errors: list[str], warnings: list[str]) -> list[OwnersRule]:
"""Parse one physical rule entry into one ``OwnersRule`` per ``match`` pattern
(a list ``match`` explodes here so resolver/fmt/lint keep seeing single-pattern
rules). Returns ``[]`` on a schema error."""
@@ -411,17 +420,20 @@ def _parse_rule(raw: object, index: int, errors: list[str]) -> list[OwnersRule]:
return []
for key in raw:
if key not in _RULE_KEYS:
- errors.append(f"{where}: unknown field '{key}'")
+ warnings.append(f"{where}: unknown field '{key}'")
patterns = _rule_match_patterns(raw.get("match"), where, errors)
if not patterns:
return []
owners = _validate_owners_value(raw["owners"], where, errors) if "owners" in raw else UNSET
status = _validate_status(raw["status"], where, errors) if "status" in raw else UNSET
- inherit = _validate_inherit(raw["inherit"], where, errors) if "inherit" in raw else UNSET
+ inherit = _validate_bool(raw["inherit"], "inherit", where, errors) if "inherit" in raw else UNSET
additions = _validate_additions(raw["additions"], where, errors) if "additions" in raw else []
+ sensitive = _validate_bool(raw["sensitive"], "sensitive", where, errors) if "sensitive" in raw else UNSET
return [
- OwnersRule(match=pattern, owners=owners, status=status, inherit=inherit, additions=additions)
+ OwnersRule(
+ match=pattern, owners=owners, status=status, inherit=inherit, additions=additions, sensitive=sensitive
+ )
for pattern in patterns
]
@@ -431,13 +443,22 @@ def _is_version_one(value: object) -> bool:
return type(value) is int and value == 1
-def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersFile | None, list[str]]:
+def parse_owners_file(
+ text: str, *, path: Path, directory: str, warnings: list[str] | None = None
+) -> tuple[OwnersFile | None, list[str]]:
"""Parse and validate ``owners.yaml`` contents.
Returns ``(file, errors)``. ``file`` is None only when the document itself is
unusable (bad YAML, not a mapping, missing required fields).
+
+ A field the format does not define has no effect, so a newer file still resolves
+ with an older tool. It is reported to ``warnings`` when the caller passes a list.
"""
errors: list[str] = []
+ if warnings is None:
+ warnings = []
+ # Every warning the parser emits is an unknown field, so the count tells whether the file has one.
+ warnings_before = len(warnings)
try:
data = yaml.safe_load(text)
except yaml.YAMLError as exc:
@@ -447,7 +468,7 @@ def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersF
for key in data:
if key not in TOP_LEVEL_KEYS:
- errors.append(f"unknown top-level field '{key}'")
+ warnings.append(f"unknown top-level field '{key}'")
version_ok = _is_version_one(data.get("version"))
if not version_ok:
@@ -465,10 +486,12 @@ def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersF
if "status" in data:
file.status = _validate_status(data["status"], "status", errors)
if "inherit" in data:
- inherit = _validate_inherit(data["inherit"], "inherit", errors)
+ inherit = _validate_bool(data["inherit"], "inherit", "inherit", errors)
file.inherit = True if isinstance(inherit, _Unset) else inherit
if "additions" in data:
file.additions = _validate_additions(data["additions"], "additions", errors)
+ if "sensitive" in data:
+ file.sensitive = _validate_bool(data["sensitive"], "sensitive", "sensitive", errors)
# Repo-wide settings and the team registry are single lookups, so they only make sense at
# the root; a nested file carrying them would silently do nothing.
@@ -476,9 +499,9 @@ def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersF
for key in sorted(ROOT_ONLY_KEYS & data.keys()):
errors.append(f"'{key}' is only allowed in the repo-root owners.yaml")
else:
- file.settings = _validate_settings(data, errors)
+ file.settings = _validate_settings(data, errors, warnings)
if "teams" in data:
- file.teams = _validate_teams(data["teams"], file.settings.producers, errors)
+ file.teams = _validate_teams(data["teams"], file.settings.producers, errors, warnings)
if "rules" in data:
raw_rules = data["rules"]
@@ -486,7 +509,8 @@ def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersF
errors.append("'rules' must be a list")
else:
for i, raw_rule in enumerate(raw_rules):
- file.rules.extend(_parse_rule(raw_rule, i, errors))
+ file.rules.extend(_parse_rule(raw_rule, i, errors, warnings))
+ file.has_unknown_fields = len(warnings) > warnings_before
# A missing version or owners makes the file unusable for resolution.
if not version_ok or "owners" not in data:
@@ -496,7 +520,10 @@ def parse_owners_file(text: str, *, path: Path, directory: str) -> tuple[OwnersF
def parse_alias_file_as_owners(text: str, *, path: Path, directory: str) -> OwnersFile | None:
"""Load an alias file as an ownership file, or None if it has no
- usable ``owners:`` list."""
+ usable ``owners:`` list.
+
+ An alias file is a manifest that another program owns and validates, so a
+ ``sensitive`` value that is not a boolean has no effect instead of an error."""
try:
data = yaml.safe_load(text)
except yaml.YAMLError:
@@ -507,7 +534,14 @@ def parse_alias_file_as_owners(text: str, *, path: Path, directory: str) -> Owne
if not isinstance(raw, list) or not all(isinstance(x, str) and x for x in raw):
return None
owners = normalize_owners(raw)
- return OwnersFile(path=path, directory=directory, owners=owners, is_alias=True)
+ sensitive = data.get("sensitive")
+ return OwnersFile(
+ path=path,
+ directory=directory,
+ owners=owners,
+ is_alias=True,
+ sensitive=sensitive if isinstance(sensitive, bool) else UNSET,
+ )
def match_is_glob(match: str) -> bool:
@@ -519,11 +553,11 @@ def match_is_glob(match: str) -> bool:
def is_simple_owners_file(parsed: OwnersFile | None, *, allow_anchored_rules: bool = False) -> bool:
"""Whether a file is "simple" — mechanically relocatable, nothing but ownership.
- Both callers agree that status/``inherit: false``/``additions`` (and being an
- alias file) disqualify a file. So does a ``teams:`` registry:
+ Both callers agree that status/``inherit: false``/``additions``/``sensitive``, a field
+ this version does not know (and being an alias file) disqualify a file. So does a ``teams:`` registry:
it is root-only content relocation would strand. So does any rule carrying
more than match+owners: relocation only preserves owners, so rule-level
- ``status``/``inherit``/``additions`` must pin the file. They differ on rules:
+ ``status``/``inherit``/``additions``/``sensitive`` must pin the file. They differ on rules:
- lint's consolidation suggestions (``allow_anchored_rules=False``) only fold
files whose entire content is one non-empty ``owners:`` list;
@@ -532,9 +566,18 @@ def is_simple_owners_file(parsed: OwnersFile | None, *, allow_anchored_rules: bo
"""
if parsed is None or parsed.is_alias:
return False
- if parsed.inherit is False or parsed.status is not UNSET or parsed.teams or parsed.additions:
+ if (
+ parsed.inherit is False
+ or parsed.status is not UNSET
+ or parsed.sensitive is not UNSET
+ or parsed.has_unknown_fields
+ or parsed.teams
+ or parsed.additions
+ ):
return False
- if any(r.status is not UNSET or r.inherit is not UNSET or r.additions for r in parsed.rules):
+ if any(
+ r.status is not UNSET or r.inherit is not UNSET or r.sensitive is not UNSET or r.additions for r in parsed.rules
+ ):
return False
if allow_anchored_rules:
return not any(match_is_glob(r.match) for r in parsed.rules)
diff --git a/packages/owners-yaml/resolution.schema.json b/packages/owners-yaml/resolution.schema.json
index e758f5a8fa36..912e9a24c223 100644
--- a/packages/owners-yaml/resolution.schema.json
+++ b/packages/owners-yaml/resolution.schema.json
@@ -38,6 +38,10 @@
"additions": { "type": "array", "items": { "type": "string", "minLength": 1 } }
},
"description": "When the resolver reads a tree that does not hold the path: the part of the path nearest the root that the tree lacks, and the owners of additions at that part. Null when the tree holds the path or the resolver reads no tree. A consumer treats a missing member as null."
+ },
+ "sensitive": {
+ "type": "boolean",
+ "description": "Whether the path is sensitive (SPEC section 3.7). A resolver that predates the member leaves it out, and a consumer treats that as false."
}
}
}
diff --git a/packages/owners-yaml/tests/test_conformance.py b/packages/owners-yaml/tests/test_conformance.py
index 7ffe7896ba36..9ce03b5eeebd 100644
--- a/packages/owners-yaml/tests/test_conformance.py
+++ b/packages/owners-yaml/tests/test_conformance.py
@@ -56,10 +56,11 @@ def test_conformance_case(tmp_path: Path, case: ConformanceCase) -> None:
"source": resolution.source,
"slack": resolution.slack,
"additions": resolution.additions,
+ "sensitive": resolution.sensitive,
}
- # A case that leaves `additions` out expects none, so the cases written before the field
- # existed also check that nothing leaks into it.
- expected = {path: {"additions": [], **resolution} for path, resolution in case.expect.items()}
+ # A case that leaves `additions` or `sensitive` out expects the default, so the cases written
+ # before a field existed also check that nothing leaks into it.
+ expected = {path: {"additions": [], "sensitive": False, **resolution} for path, resolution in case.expect.items()}
assert actual == expected
diff --git a/packages/owners-yaml/tests/test_owners.py b/packages/owners-yaml/tests/test_owners.py
index 3a14aab63181..e711fb0ac8a3 100644
--- a/packages/owners-yaml/tests/test_owners.py
+++ b/packages/owners-yaml/tests/test_owners.py
@@ -26,6 +26,7 @@ from owners_yaml.schema import (
_RULE_KEYS,
DEFAULT_ALIAS_FILES,
TOP_LEVEL_KEYS,
+ UNSET,
CodeownersSettings,
TeamEntry,
is_simple_owners_file,
@@ -170,6 +171,22 @@ def test_json_schema_accepts_the_same_keys_as_the_parser() -> None:
assert set(schema["$defs"]["rule"]["properties"]) == _RULE_KEYS
+ "fragment",
+ [
+ "sensitive: 'true'\n",
+ "sensitive: 1\n",
+ "rules:\n - match: '/*'\n sensitive: [true]\n",
+ ],
+)
+def test_malformed_sensitive_is_a_schema_error_and_sets_nothing(tmp_path: Path, fragment: str) -> None:
+ file, errors = parse_owners_file(
+ "version: 1\nowners: [team-a]\n" + fragment, path=tmp_path / "owners.yaml", directory=""
+ )
+ assert any("'sensitive' must be a boolean" in e for e in errors), errors
+ assert file is not None and file.sensitive is UNSET and all(r.sensitive is UNSET for r in file.rules)
+
+
@pytest.mark.parametrize(
"fragment",
[
@@ -200,7 +217,6 @@ def test_malformed_additions_is_a_schema_error_and_adds_nobody(tmp_path: Path, f
("alias_files: [a, b, c, d, e, f, g, h, i]\n", "at most 8 names"),
("alias_files: [a.yaml, b.yaml, a.yaml]\n", "is listed twice"),
("alias_files: [a, b, c, d, e, f, g, h, a]\n", "at most 8 names"),
- ("codeowners:\n jest_dir: web\n", "codeowners: unknown field 'jest_dir'"),
],
)
def test_invalid_repo_settings_are_schema_errors(tmp_path: Path, settings_yaml: str, needle: str) -> None:
@@ -220,7 +236,6 @@ def test_invalid_repo_settings_are_schema_errors(tmp_path: Path, settings_yaml:
("teams: [team-a]\n", "'teams' must be a mapping"),
("teams:\n team-a:\n slack: 'no-hash'\n", "must be a string starting with '#' or false"),
("teams:\n team-a:\n notifications: 'no-hash'\n", "must be a string starting with '#' or false"),
- ("teams:\n team-a:\n channel: '#a'\n", "unknown field 'channel'"),
("teams:\n team-a: '#a'\n", "entry must be a mapping"),
("teams:\n '@alice':\n slack: '#a'\n", "not @handles"),
("teams:\n 123:\n slack: '#a'\n", "slug must be a string"),
@@ -314,8 +329,19 @@ def test_a_repo_without_a_producers_list_accepts_any_producer(tmp_path: Path) ->
assert file is not None and file.teams == {"team-a": TeamEntry(notifications={"reviewbot": "#a-bots"})}
-def test_teams_registry_pins_file_as_non_simple(tmp_path: Path) -> None:
- text = "version: 1\nowners: [team-a]\nteams:\n team-a:\n slack: '#a'\n"
+ "fragment",
+ [
+ "teams:\n team-a:\n slack: '#a'\n",
+ "sensitive: true\n",
+ "rules:\n - match: '/a/'\n sensitive: false\n",
+ "reviewers: [team-c]\n",
+ "rules:\n - match: '/a/'\n reviewers: [team-c]\n",
+ ],
+ ids=["teams-registry", "file-sensitive", "rule-sensitive", "file-unknown-field", "rule-unknown-field"],
+)
+def test_content_beyond_owners_pins_file_as_non_simple(tmp_path: Path, fragment: str) -> None:
+ text = "version: 1\nowners: [team-a]\n" + fragment
file, _ = parse_owners_file(text, path=tmp_path / "owners.yaml", directory="")
assert file is not None
assert is_simple_owners_file(file) is False
@@ -850,6 +876,7 @@ def test_json_entrypoint_resolves_against_an_explicit_repo_root(registry_repo: P
"source": "reg/owners.yaml",
"additions": [],
"added": {"path": "reg/x.py", "additions": []},
+ "sensitive": False,
}
}
jsonschema = pytest.importorskip("jsonschema")
@@ -1108,6 +1135,43 @@ def test_cli_lint_reports_no_alias_conflict_the_resolver_does_not_see(tmp_path:
assert "has both" not in result.output
+ "root_yaml,warning",
+ [
+ ("reviewers: [team-c]\n", "unknown top-level field 'reviewers'"),
+ ("rules:\n - match: '/web/'\n reviewers: [team-c]\n", "rules[0]: unknown field 'reviewers'"),
+ ("teams:\n team-a:\n email: [email protected]\n", "teams['team-a']: unknown field 'email'"),
+ ("codeowners:\n jest_dir: web\n", "codeowners: unknown field 'jest_dir'"),
+ ],
+)
+def test_cli_lint_warns_on_an_unknown_field_without_failing(tmp_path: Path, root_yaml: str, warning: str) -> None:
+ # A newer version of the format can add a field, and an older linter must still pass that file.
+ _write(tmp_path, "owners.yaml", "version: 1\nowners: [team-a]\n" + root_yaml)
+ _write(tmp_path, "web/app.ts", "")
+
+ result = CliRunner().invoke(main, ["lint", "--repo-root", str(tmp_path)])
+
+ assert result.exit_code == 0, result.output
+ assert f"⚠ owners.yaml: {warning}" in result.output
+
+
[email protected]("guard_owners", ["[]", "null"], ids=["unowned", "unowned-by-design"])
+def test_cli_lint_warns_on_a_sensitive_path_without_owners(tmp_path: Path, guard_owners: str) -> None:
+ _write(
+ tmp_path,
+ "owners.yaml",
+ f"version: 1\nowners: []\nrules:\n - match: '/guard/'\n owners: {guard_owners}\n sensitive: true\n",
+ )
+ _write(tmp_path, "guard/baseline.txt", "")
+ _write(tmp_path, "web/app.ts", "")
+
+ result = CliRunner().invoke(main, ["lint", "--repo-root", str(tmp_path)])
+
+ assert result.exit_code == 0, result.output
+ assert "⚠ guard/baseline.txt: sensitive but has no owners" in result.output
+ assert "web/app.ts: sensitive" not in result.output
+
+
@pytest.mark.parametrize(
"match,error",
[
diff --git a/tools/hogli-commands/hogli_commands/product/checks.py b/tools/hogli-commands/hogli_commands/product/checks.py
index 46a942367b82..8c4a1d7d301d 100644
--- a/tools/hogli-commands/hogli_commands/product/checks.py
+++ b/tools/hogli-commands/hogli_commands/product/checks.py
@@ -1172,6 +1172,11 @@ class ProductYamlCheck(ProductCheck):
elif not isinstance(owners, list) or not all(isinstance(o, str) for o in owners):
result.issues.append("product.yaml 'owners' must be a list of strings")
+ # The owners resolver ignores a value that is not a boolean, so a typo here would silently leave the paths
+ # not sensitive.
+ if "sensitive" in data and not isinstance(data["sensitive"], bool):
+ result.issues.append("product.yaml 'sensitive' must be true or false")
+
if result.issues:
result.lines = [f"✗ {len(result.issues)} issue(s)"] + [f" → {i}" for i in result.issues]
else:
diff --git a/tools/hogli-commands/hogli_commands/tests/test_checks.py b/tools/hogli-commands/hogli_commands/tests/test_checks.py
index b69731a32632..3dbf259e506d 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_checks.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_checks.py
@@ -1257,6 +1257,12 @@ class TestProductYamlCheck:
result = yaml_check.run(ctx)
assert any("missing 'name'" in i for i in result.issues)
+ @pytest.mark.parametrize("value,valid", [("true", True), ("false", True), ("'true'", False), ("yes please", False)])
+ def test_sensitive_must_be_boolean(self, tmp_path: Path, value: str, valid: bool) -> None:
+ ctx = _make_yaml_ctx(tmp_path, f"name: My product\nowners:\n - team-foo\nsensitive: {value}\n")
+ result = yaml_check.run(ctx)
+ assert (not result.issues) is valid, result.issues
+
class TestProductYamlOwnersCheck:
def test_skip_when_no_owners(self, tmp_path: Path) -> None: