Skip to content

schema: validate rootfs.diff_ids as digests - #1340

Closed
arpitjain099 wants to merge 1 commit into
opencontainers:mainfrom
arpitjain099:fix/diff-ids-digest-format
Closed

arpitjain099 wants to merge 1 commit into
opencontainers:mainfrom
arpitjain099:fix/diff-ids-digest-format

Conversation

@arpitjain099

Copy link
Copy Markdown

config.md:28 is explicit about the format:

A layer DiffID is the digest over the layer's uncompressed tar archive and serialized in the descriptor digest format, e.g., sha256:a9561eb1...

but config-schema.json types the items as a bare string:

"diff_ids": {
  "type": "array",
  "items": {
    "type": "string"
  }
},

It is the one digest-shaped field in the schema set that does not $ref defs-descriptor.json#/definitions/digest. content-descriptor.json:17 and image-index-schema.json:46 both do.

Driving schema.ValidatorMediaTypeImageConfig.Validate on main, with a well formed digest first so the harness is provably discriminating:

valid digest (positive control)    -> err=<nil>
empty                              -> err=<nil>
not a digest                       -> err=<nil>
path traversal                     -> err=<nil>

After pointing the items at the shared definition, the three bad values are rejected and the good one still passes.

Verification

Four cases added to TestConfig, three expecting failure and one expecting success. The success case is there so the other three are shown to fail on the diff_ids value rather than on something else in the document. Three of the four fail on main.

go test ./... passes in both modules, including TestBackwardsCompatibilityConfig, whose corpus is real Docker 1.10.3 and 1.12.1 configs, so the tightened pattern does not reject anything the project already treats as valid. gofmt -l is clean.

config.md says a layer DiffID is "the digest over the layer's uncompressed tar
archive and serialized in the descriptor digest format", and every other
digest-shaped field in the schema set refs
defs-descriptor.json#/definitions/digest. rootfs.diff_ids items are typed as a
bare string, so an empty entry, a sentence, or a relative path all validate.

Point the items at the same definition the rest of the schemas use.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@sudo-bmitch

Copy link
Copy Markdown
Contributor

Do you maintain a project that's using this code? Is there an upstream issue this would resolve?

@arpitjain099

Copy link
Copy Markdown
Author

No on both counts, and I should say that plainly rather than imply otherwise. I do not maintain a project consuming this schema, and there is no upstream issue behind it.

What prompted it was reading the schema files against each other: rootfs.diff_ids is the only digest-shaped field in the set that does not $ref defs-descriptor.json#/definitions/digest, while config.md defines a DiffID as being "serialized in the descriptor digest format". So it looked like an oversight rather than a decision, and the effect is only on how strictly ValidatorMediaTypeImageConfig treats a config, not on any runtime path.

If the looseness there is deliberate, or you would rather this started as an issue and a discussion than a patch, I am happy to close it. No objection either way.

@sudo-bmitch

Copy link
Copy Markdown
Contributor

My goal was to get an understanding of who is using those files, because they often get out of sync with the spec and I'm not sure there is anyone that depends on them for anything more than a theoretical use case. It sounds like we're still batting a zero there.

@arpitjain099

arpitjain099 commented Sep 17, 2026 •

Copy link
Copy Markdown
Author

Understood. Closing this PR. Thanks for the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants