Skip to content

Commit a2c8c4f

Browse files
committed
Clarify mediaType and artifactType syntax
Signed-off-by: Brandon Mitchell <[email protected]>
1 parent 39ab2d5 commit a2c8c4f

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

descriptor.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The following fields contain the primary properties that constitute a Descriptor
1919
- **`mediaType`** *string*
2020

2121
This REQUIRED property contains the media type of the referenced content.
22-
Values MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2].
22+
Values MUST comply with the [media type syntax](media-types.md#media-type-syntax).
2323

2424
The OCI image specification defines [several of its own MIME types](media-types.md) for resources defined in the specification.
2525

@@ -56,7 +56,7 @@ The following fields contain the primary properties that constitute a Descriptor
5656

5757
This OPTIONAL property contains the type of an artifact when the descriptor points to an artifact.
5858
This is the value of the config descriptor `mediaType` when the descriptor references an [image manifest](manifest.md).
59-
If defined, the value MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
59+
If defined, the value MUST comply with the [media type syntax](media-types.md#media-type-syntax).
6060

6161
Descriptors pointing to [`application/vnd.oci.image.manifest.v1+json`](manifest.md) SHOULD include the extended field `platform`, see [Image Index Property Descriptions](image-index.md#image-index-property-descriptions) for details.
6262

@@ -214,8 +214,5 @@ In the following example, the descriptor indicates the type of artifact it is re
214214
[rfc4634-s4.1]: https://tools.ietf.org/html/rfc4634#section-4.1
215215
[rfc4634-s4.2]: https://tools.ietf.org/html/rfc4634#section-4.2
216216
[rfc4648-s4]: https://tools.ietf.org/html/rfc4648#section-4
217-
[rfc6838]: https://tools.ietf.org/html/rfc6838
218-
[rfc6838-s4.2]: https://tools.ietf.org/html/rfc6838#section-4.2
219217
[rfc7230-s2.7]: https://tools.ietf.org/html/rfc7230#section-2.7
220218
[sha256-vs-sha512]: https://groups.google.com/a/opencontainers.org/forum/#!topic/dev/hsMw7cAwrZE
221-
[iana]: https://www.iana.org/assignments/media-types/media-types.xhtml

image-index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For the media type(s) that this document is compatible with, see the [matrix][ma
2525
- **`artifactType`** *string*
2626

2727
This OPTIONAL property contains the type of an artifact when the manifest is used for an artifact.
28-
If defined, the value MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
28+
If defined, the value MUST comply with the [media type syntax](media-types.md#media-type-syntax).
2929

3030
- **`manifests`** *array of objects*
3131

@@ -183,8 +183,5 @@ These values SHOULD match (or be similar to) their analog listed in [the Go Lang
183183

184184
[dag]: https://en.wikipedia.org/wiki/Merkle_tree
185185
[go-environment2]: https://golang.org/doc/install/source#environment
186-
[iana]: https://www.iana.org/assignments/media-types/media-types.xhtml
187186
[matrix]: media-types.md#compatibility-matrix
188187
[referrers-api]: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#listing-referrers
189-
[rfc6838]: https://tools.ietf.org/html/rfc6838
190-
[rfc6838-s4.2]: https://tools.ietf.org/html/rfc6838#section-4.2

manifest.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Unlike the [image index](image-index.md), which contains information about a set
3030

3131
This OPTIONAL property contains the type of an artifact when the manifest is used for an artifact.
3232
This MUST be set when `config.mediaType` is set to the [empty value](#guidance-for-an-empty-descriptor).
33-
If defined, the value MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
33+
If defined, the value MUST comply with the [media type syntax](media-types.md#media-type-syntax).
3434
Implementations storing or copying image manifests MUST NOT error on encountering an `artifactType` that is unknown to the implementation.
3535

3636
- **`config`** *[descriptor](descriptor.md)*
@@ -53,7 +53,7 @@ Unlike the [image index](image-index.md), which contains information about a set
5353
Manifests for container images concerned with portability SHOULD use one of the above media types.
5454
Manifests for artifacts concerned with portability SHOULD use `config.mediaType` as described in [Guidelines for Artifact Usage](#guidelines-for-artifact-usage).
5555

56-
If the manifest uses a different media type than the above, it MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
56+
If the manifest uses a different media type than the above, it MUST comply with the [media type syntax](media-types.md#media-type-syntax).
5757

5858
To set an effectively null or empty config and maintain portability see the [guidance for an empty descriptor](#guidance-for-an-empty-descriptor) below, and `DescriptorEmptyJSON` of the reference code.
5959

@@ -89,7 +89,7 @@ Unlike the [image index](image-index.md), which contains information about a set
8989

9090
Entries in this field will frequently use the `+gzip` types.
9191

92-
If the manifest uses a different media type than the above, it MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
92+
If the manifest uses a different media type than the above, it MUST comply with the [media type syntax](media-types.md#media-type-syntax).
9393

9494
See [Guidelines for Artifact Usage](#guidelines-for-artifact-usage) for other uses of the `layers`.
9595

@@ -260,7 +260,4 @@ The decision tree below and the associated examples MAY be used to design new ar
260260
_Implementers note:_ artifacts have historically been created without an `artifactType` field, and tooling to work with artifacts should fallback to the `config.mediaType` value.
261261

262262
[dag]: https://en.wikipedia.org/wiki/Merkle_tree
263-
[iana]: https://www.iana.org/assignments/media-types/media-types.xhtml
264263
[referrers-api]: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#listing-referrers
265-
[rfc6838]: https://tools.ietf.org/html/rfc6838
266-
[rfc6838-s4.2]: https://tools.ietf.org/html/rfc6838#section-4.2

media-types.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ The following media types identify a ["Layer" with distribution restrictions](la
1818
- `application/vnd.oci.image.layer.nondistributable.v1.tar+gzip`: ["Layer", as a tar archive with distribution restrictions](layer.md#gzip-media-types) compressed with [gzip][rfc1952]
1919
- `application/vnd.oci.image.layer.nondistributable.v1.tar+zstd`: ["Layer", as a tar archive with distribution restrictions](layer.md#zstd-media-types) compressed with [zstd][rfc8478]
2020

21+
## Media Type Syntax
22+
23+
Media types values MUST comply with [RFC 6838][rfc6838], including the [naming requirements in its section 4.2][rfc6838-s4.2], and MAY be registered with [IANA][iana].
24+
Media types values MUST have a top-level type and subtype name, separated by a `/`, without any parameters.
25+
26+
The following regular expression may be used to validate media types:
27+
28+
```regexp
29+
^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}$
30+
```
31+
2132
## Media Type Conflicts
2233

2334
[Blob](image-layout.md) retrieval methods MAY return media type metadata.
@@ -86,5 +97,8 @@ The following figure shows how the above media types reference each other:
8697
[Descriptors](descriptor.md) are used for all references.
8798
The image-index being a "fat manifest" references a list of image manifests per target platform. An image manifest references exactly one target configuration and possibly many layers.
8899

89-
[rfc1952]: https://tools.ietf.org/html/rfc1952
90-
[rfc8478]: https://tools.ietf.org/html/rfc8478
100+
[iana]: https://www.iana.org/assignments/media-types/media-types.xhtml
101+
[rfc1952]: https://tools.ietf.org/html/rfc1952
102+
[rfc6838]: https://tools.ietf.org/html/rfc6838
103+
[rfc6838-s4.2]: https://tools.ietf.org/html/rfc6838#section-4.2
104+
[rfc8478]: https://tools.ietf.org/html/rfc8478

schema/descriptor_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ func TestDescriptor(t *testing.T) {
259259
fail: true,
260260
},
261261

262+
// expected failure: artifactType does not match pattern (parameters not allowed)
263+
{
264+
descriptor: `
265+
{
266+
"mediaType": "application/vnd.oci.image.manifest.v1+json",
267+
"artifactType": "foo/star.bar;version=1.0",
268+
"size": 7682,
269+
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270"
270+
}
271+
`,
272+
fail: true,
273+
},
274+
262275
// expected success: data field is present and has base64 content
263276
{
264277
descriptor: `

schema/manifest_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,30 @@ func TestManifest(t *testing.T) {
336336
`,
337337
fail: false,
338338
},
339+
340+
// invalid artifactType value
341+
{
342+
manifest: `
343+
{
344+
"schemaVersion": 2,
345+
"mediaType" : "application/vnd.oci.image.manifest.v1+json",
346+
"artifactType": "application/vnd.example+type;revision=1.5",
347+
"config": {
348+
"mediaType": "application/vnd.oci.empty.v1+json",
349+
"size": 2,
350+
"digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
351+
},
352+
"layers": [
353+
{
354+
"mediaType": "application/vnd.example+type;revision=1.5",
355+
"size": 675598,
356+
"digest": "sha256:9d3dd9504c685a304985025df4ed0283e47ac9ffa9bd0326fddf4d59513f0827"
357+
}
358+
]
359+
}
360+
`,
361+
fail: true,
362+
},
339363
} {
340364
r := strings.NewReader(tt.manifest)
341365
err := schema.ValidatorMediaTypeManifest.Validate(r)

0 commit comments

Comments
 (0)