You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/PackageManagerDocs/Documentation.docc/PackageCollections.md
+23-81Lines changed: 23 additions & 81 deletions
Original file line number
Diff line number
Diff line change
@@ -8,18 +8,11 @@ Learn to create, publish and use Swift package collections.
8
8
9
9
## Overview
10
10
11
-
Package collections, introduced by [SE-0291](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0291-package-collections.md), are
12
-
curated lists of packages and associated metadata that can be imported
13
-
by SwiftPM to make discovery of existing packages easier.
14
-
They are authored as static JSON documents
15
-
and can be published to the web or distributed to local file systems.
16
-
17
-
Educators and community influencers can publish
18
-
package collections to go along with course materials or blog posts, removing the friction of using
19
-
packages for the first time and the cognitive overload of deciding which packages are useful for
20
-
a particular task.
21
-
Enterprises may use collections to narrow the decision space for their internal
22
-
engineering teams, focusing them on a trusted set of vetted packages.
11
+
Package collections, introduced by [SE-0291](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0291-package-collections.md), are curated lists of packages and associated metadata that you can import to make discovery of existing packages easier.
12
+
13
+
Educators and community influencers can publish package collections to go along with course materials or blog posts, making it easier for their readers to use packages for the first time, or choosing which packages to use for a particular task.
14
+
Enterprises may use collections to provide a trusted set of packages, or a collection of packages consistently used by a team.
15
+
You can author a package collection as a static JSON document and publish it to the web or distribute it on a local file system.
23
16
24
17
### Using the package-collection CLI
25
18
@@ -46,8 +39,9 @@ intended for package collection publishers:
46
39
-[`package-collection-validate`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionValidator): Perform basic validations on a package collection
47
40
-[`package-collection-diff`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionDiff): Compare two package collections to see if their contents are different
48
41
49
-
All package collections must adhere to the [collection data format](<doc:Input-Format>) for SwiftPM to be able to consume them. The recommended way
50
-
to create package collections is to use [`package-collection-generate`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionGenerator). For custom implementations, the data models are available through the [`PackageCollectionsModel` module](https://github.com/swiftlang/swift-package-manager/tree/main/Sources/PackageCollectionsModel).
42
+
All package collections must adhere to the [collection data format](<doc:Input-Format>) for SwiftPM to be able to consume them.
43
+
The recommended way to create package collections is to use [`package-collection-generate`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionGenerator).
44
+
For custom implementations, the data models are available through the [`PackageCollectionsModel` module](https://github.com/swiftlang/swift-package-manager/tree/main/Sources/PackageCollectionsModel).
51
45
52
46
#### Input Format
53
47
@@ -68,7 +62,7 @@ To begin, define the top-level metadata about the collection:
68
62
Each item in the `packages` array is a package object with the following properties:
69
63
70
64
*`url`: The URL of the package. Currently only Git repository URLs are supported. URL should be HTTPS and may contain `.git` suffix.
71
-
*`identity`: The [identity](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#36-package-identification)<!-- TODO bp: to replace this link once PackageRegsitry/ is ported. -->of the package if published to registry. **Optional.**
65
+
*`identity`: The [identity](<doc:RegistryServerSpecification#3.6.-Package-identification>)of the package if published to a registry. **Optional.**
72
66
*`summary`: A description of the package. **Optional.**
73
67
*`keywords`: An array of keywords that the package is associated with. **Optional.**
74
68
*`readmeURL`: The URL of the package's README. **Optional.**
@@ -77,8 +71,6 @@ Each item in the `packages` array is a package object with the following propert
*`versions`: An array of version objects representing the most recent and/or relevant releases of the package.
79
73
80
-
When a package is [added to a collection](<doc:PackageCollectionAdd>), the package object will appear in the collection's `packages` array with the properties described above.
81
-
82
74
### Add versions to a package
83
75
84
76
A version object has metadata extracted from `Package.swift` and optionally additional metadata from other sources:
@@ -144,7 +136,7 @@ A version object has metadata extracted from `Package.swift` and optionally addi
*`author`: The package version's author. **Optional.**
146
138
*`name`: The author of the package version.
147
-
*`signer`: The signer of the package version. **Optional.** Refer to [documentation](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/PackageRegistryUsage.md#package-signing)<!-- TODO bp: to replace this link once PackageRegistry/ is ported. --> on package signing for details.
139
+
*`signer`: The signer of the package version. **Optional.** Refer to the [documentation](<doc:PackageSecurity#Package-signing>) on package signing for details.
148
140
*`type`: The signer type. Currently the only valid value is `ADP` (Apple Developer Program).
149
141
*`commonName`: The common name of the signing certificate's subject.
150
142
*`organizationalUnitName`: The organizational unit name of the signing certificate's subject.
@@ -153,24 +145,22 @@ A version object has metadata extracted from `Package.swift` and optionally addi
153
145
154
146
### Version-specific manifests
155
147
156
-
Package collection generators should include data from the "default" manifest `Package.swift` as well as [version-specific manifest(s)](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/Usage.md#version-specific-manifest-selection)<!-- TODO bp: to replace this link once Usage.md is ported. -->.
148
+
Package collection generators should include data from the "default" manifest `Package.swift` as well as [version-specific manifest(s)](<doc:SwiftVersionSpecificPackaging#Version-specific-Manifest-Selection>)
157
149
158
150
The keys of the `manifests` map are Swift tools (semantic) versions:
159
151
* For `Package.swift`, the tools version specified in `Package.swift` should be used.
160
152
* For version-specific manifests, the tools version specified in the filename should be used. For example, for `[email protected]` it would be `4.2`. The tools version in the manifest must match that in the filename.
161
153
162
154
### Version-specific tags
163
155
164
-
[Version-specific tags](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/Usage.md#version-specific-tag-selection)<!-- TODO bp: to replace this link once Usage.md is ported. --> are not
165
-
supported by package collections.
156
+
[Version-specific tags](<doc:SwiftVersionSpecificPackaging#Version-specific-tags-when-resolving-remote-dependencies>) are not supported by package collections.
166
157
167
158
### Configuration File
168
159
169
160
Configuration that pertains to package collections are stored in the file `~/.swiftpm/config/collections.json`.
170
-
It keeps track of user's list of configured collections
171
-
and preferences such as those set by the `--trust-unsigned` and `--skip-signature-check` flags in the [`package-collection add` command](<doc:PackageCollectionAdd>).
161
+
It keeps track of user's list of configured collections and preferences such as those set by the `--trust-unsigned` and `--skip-signature-check` flags in the [`package-collection add` command](<doc:PackageCollectionAdd>).
172
162
173
-
> Note: This file is managed through SwiftPM commands and users are not expected to edit it by hand.
163
+
> Note: This file is managed through Swift Package Manager commands and users are not expected to edit it by hand.
174
164
175
165
## Example
176
166
@@ -300,72 +290,24 @@ and preferences such as those set by the `--trust-unsigned` and `--skip-signatur
300
290
}
301
291
```
302
292
293
+
## Protecting package collections
303
294
304
-
## Signing and protecting package collections
295
+
###Signing a collection
305
296
306
-
Package collections can be signed to establish authenticity and protect their integrity.
297
+
[Sign package collections](<doc:PackageSecurity#Signed-package-collections>) to establish authenticity and protect their integrity.
307
298
Doing this is optional.
308
299
Users will be prompted for confirmation before they can add an [unsigned collection](<doc:PackageCollectionAdd#Unsigned-package-collections>).
300
+
The signing certificate you use to sign a package collection must meet a list of [requirements](<doc:PackageSecurity#Requirements-on-signing-certificate>). If these requirements are not met, the package manager returns an error.
309
301
310
-
[`package-collection-sign`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionSigner) helps publishers sign their package
311
-
collections. To generate a signature one must provide:
312
-
- The package collection file to be signed
313
-
- A code signing certificate (DER-encoded)
314
-
- The certificate's private key (PEM-encoded)
315
-
- The certificate's chain in its entirety
302
+
For more details on the security features Package manager implements, see <doc:PackageSecurity>.
316
303
317
-
A signed package collection has an extra `signature` object:
318
-
319
-
```json
320
-
{
321
-
...,
322
-
"signature": {
323
-
"signature": "<SIGNATURE>",
324
-
"certificate": {
325
-
"subject": {
326
-
"commonName": "Jane Doe",
327
-
...
328
-
},
329
-
"issuer": {
330
-
"commonName": "Sample CA",
331
-
...
332
-
}
333
-
}
334
-
}
335
-
}
336
-
```
337
-
338
-
- The signature string (represented by `"<SIGNATURE>"`) is used to verify the contents of the collection file haven't been tampered with since it was signed when SwiftPM user [adds the collection](<doc:PackageCollectionAdd#Signed-package-collections>) to their configured list of collections. It includes the certificate's public key and chain.
339
-
-`certificate` contains details extracted from the signing certificate. `subject.commonName` should be consistent with the name of the publisher so that it's recognizable by users. The root of the certificate must be [installed and trusted on users' machines](<doc:PackageCollectionAdd#Trusted-root-certificates>).
340
-
341
-
### Requirements on signing certificate
342
-
343
-
Certificates used for signing package collections must meet the following requirements, which are checked and enforced during signature generation (publishers) and verification (SwiftPM users):
344
-
- The timestamp at which signing/verification is done must fall within the signing certificate's validity period.
345
-
- The certificate's "Extended Key Usage" extension must include "Code Signing".
346
-
- The certificate must use either 256-bit EC (recommended for enhanced security) or 2048-bit RSA key.
347
-
- The certificate must not be revoked. The certificate authority must support OCSP, which means the certificate must have the "Certificate Authority Information Access" extension that includes OCSP as a method, specifying the responder's URL.
348
-
- The certificate chain is valid and root certificate must be trusted.
349
-
350
-
Non-expired, non-revoked Swift Package Collection certificates from [developer.apple.com](https://developer.apple.com) satisfy all of the criteria above.
351
-
352
-
#### Trusted root certificates
353
-
354
-
With the `package-collection-sign` tool, the root certificate provided as input for signing a collection is automatically trusted. When SwiftPM user tries to add the collection, however,
355
-
the root certificate must either be preinstalled with the OS (Apple platforms only) or found in the `~/.swiftpm/config/trust-root-certs` directory (all platforms) or shipped with
356
-
the [certificate-pinning configuration](<doc:#Protecting-package-collections>), otherwise the [signature check](<doc:PackageCollectionAdd#Signed-package-collections>) will fail.
357
-
Collection publishers should make the DER-encoded
358
-
root certificate(s) that they use downloadable so that users can adjust their setup if needed.
359
-
360
-
361
-
## Protecting package collections
304
+
### Security risks
362
305
363
-
[Signing](<doc:PackageCollectionAdd#Unsigned-package-collections>) can provide some degree of protection on package collections and reduce the risks of their contents being modified by malicious actors, but it doesn't
364
-
prevent the following attack vectors:
365
-
-**Signature stripping**: This involves attackers removing signature from a signed collection, causing it to be downloaded as an [unsigned collection](<doc:PackageCollectionAdd#Unsigned-package-collections>) and bypassing signature check. In this case, publishers should make it known that the collection is signed, and SwiftPM users should abort the `add` operation when the "unsigned" warning appears on a supposedly signed collection.
306
+
While signing can provide some degree of protection on package collections and reduce the risks of their contents being modified by malicious actors, it doesn't prevent the following attack vectors:
307
+
-**Signature stripping**: This involves attackers removing signature from a signed collection, causing it to be downloaded as an unsigned collection and bypassing signature check. In this case, publishers should make it known that the collection is signed, and SwiftPM users should abort the `add` operation when the "unsigned" warning appears on a supposedly signed collection.
366
308
-**Signature replacement**: Attackers may modify a collection then re-sign it using a different certificate, either pretend to be the same entity or as some other entity, and SwiftPM will accept it as long as the [signature is valid](<doc:PackageCollectionAdd#Signed-package-collections>).
367
309
368
-
To defend against these attacks, SwiftPM has certificate-pinning configuration that allows collection publishers to:
310
+
To defend against these attacks, package manager has certificate-pinning configuration that allows collection publishers to:
369
311
- Require signature check on their collections — this defends against "signature stripping".
370
312
- Restrict what certificate can be used for signing — this defends against "signature replacement".
Copy file name to clipboardExpand all lines: Sources/PackageManagerDocs/Documentation.docc/PackageCollections/PackageCollectionAdd.md
+10-18Lines changed: 10 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -32,12 +32,9 @@ Added "Sample Package Collection" to your package collections.
32
32
33
33
### Signed package collections
34
34
35
-
Package collection publishers may [sign a collection to protect its contents](<doc:PackageCollections#Signing-and-protecting-package-collections>) from being tampered with.
36
-
If a collection is signed, SwiftPM will check that the
37
-
signature is valid before importing it and return an error if any of these fails:
38
-
- The file's contents, signature excluded, must match what was used to generate the signature.
39
-
In other words, this checks to see if the collection has been altered since it was signed.
40
-
- The signing certificate must meet all the [requirements](<doc:PackageCollections#Requirements-on-signing-certificate>).
35
+
Publishers of a package collection may [sign a collection to protect its contents](<doc:PackageCollections#Protecting-package-collections>).
36
+
The package manager will check if a signed collection's signature is valid before importing it.
37
+
If the validation check fails, the package manager returns an error:
41
38
42
39
```bash
43
40
$ swift package-collection add https://www.example.com/bad-packages.json
@@ -50,8 +47,8 @@ Users may continue adding the collection despite the error or preemptively skip
50
47
$ swift package-collection add https://www.example.com/packages.json --skip-signature-check
51
48
```
52
49
53
-
For package collections hosted on the web, publishers may ask SwiftPM to [enforce the signature requirement](<doc:PackageCollections#Protecting-package-collections>). If a package collection is
54
-
expected to be signed but it isn't, user will see the following error message:
50
+
For package collections hosted on the web, publishers may ask the package manager to [enforce the signature requirement](<doc:PackageSecurity#Trusted-root-certificates>).
51
+
If a package collection is expected to be signed but it isn't, users will see the following error message:
55
52
56
53
```bash
57
54
$ swift package-collection add https://www.example.com/bad-packages.json
@@ -60,24 +57,19 @@ The collection is missing required signature, which means it might have been com
60
57
61
58
Users should NOT add the package collection in this case.
62
59
63
-
##### Trusted root certificates
64
-
65
-
Since generating a collection signature requires a certificate, part of the signature check involves validating the certificate and its chain and making sure that the root certificate is trusted.
60
+
For more details on signature validation, see <doc:PackageSecurity#Signed-package-collections>.
66
61
67
-
On Apple platforms, all root certificates that come preinstalled with the OS are automatically trusted. Users may include additional certificates to trust by placing
68
-
them in the `~/.swiftpm/config/trust-root-certs` directory.
62
+
##### Trusted root certificates
69
63
70
-
On non-Apple platforms, there are no trusted root certificates by default other than those shipped with the [certificate-pinning configuration](<doc:PackageCollections#Protecting-package-collections>). Only those
71
-
found in`~/.swiftpm/config/trust-root-certs` are trusted. This means that the signature check will always fail unless the `trust-root-certs` directory is set up:
64
+
The package manager [validates the certificate](<doc:PackageSecurity#Trusted-root-certificates>) of a signed collection as a part of its signature validation to make sure that the root certificate is trusted.
72
65
73
66
```bash
74
67
$ swift package-collection add https://www.example.com/packages.json
75
68
The collection's signature cannot be verified due to missing configuration.
76
69
```
77
70
78
71
Users can explicitly specify they trust a publisher and any collections they publish, by obtaining that publisher's root certificate and saving it to `~/.swiftpm/config/trust-root-certs`. The
79
-
root certificates must be DER-encoded. Since SwiftPM trusts all certificate chains under a root, depending on what roots are installed, some publishers may already be trusted implicitly and
80
-
users don't need to explicitly specify each one.
72
+
root certificates must be DER-encoded. Since the package manager trusts all certificate chains under a root, depending on what roots are installed, some publishers may already be trusted implicitly and users don't need to explicitly specify each one.
81
73
82
74
#### Unsigned package collections
83
75
@@ -88,7 +80,7 @@ $ swift package-collection add https://www.example.com/packages.json
88
80
The collection is not signed. If you would still like to add it please rerun 'add' with '--trust-unsigned'.
89
81
```
90
82
91
-
To continue user must confirm their trust by passing the `--trust-unsigned` flag:
83
+
To continue, users must confirm their trust by passing the `--trust-unsigned` flag:
92
84
93
85
```bash
94
86
$ swift package-collection add https://www.example.com/packages.json --trust-unsigned
0 commit comments