Skip to content

Commit f3feee0

Browse files
bripeticcaheckjowenvbkhouriDanBlackwell
authored
Port Documentation/PackageRegistry directory contents into DocC (#8745)
Fixes #8596 and fixes #8597. --------- Co-authored-by: Joseph Heck <[email protected]> Co-authored-by: Owen Voorhees <[email protected]> Co-authored-by: Sam Khouri <[email protected]> Co-authored-by: Dan Blackwell <[email protected]> Co-authored-by: Pavel Yaskevich <[email protected]>
1 parent a38e1d6 commit f3feee0

File tree

11 files changed

+2213
-103
lines changed

11 files changed

+2213
-103
lines changed

Sources/PackageManagerDocs/Documentation.docc/Documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The Swift Package Manager lets you share your code as a package, depend on and u
3232
- <doc:ContinuousIntegration>
3333
- <doc:Plugins>
3434
- <doc:ModuleAliasing>
35+
- <doc:UsingSwiftPackageRegistry>
3536
- <doc:PackageCollections>
3637
- <doc:UsingShellCompletion>
3738
- <doc:SwiftPMAsALibrary>
@@ -56,3 +57,7 @@ The Swift Package Manager lets you share your code as a package, depend on and u
5657
- <doc:SwiftPackageRegistryCommands>
5758
- <doc:SwiftPackageCollectionCommands>
5859
- <doc:SwiftRun>
60+
61+
### Design
62+
63+
- <doc:RegistryServerSpecification>

Sources/PackageManagerDocs/Documentation.docc/PackageCollections.md

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ Learn to create, publish and use Swift package collections.
88

99
## Overview
1010

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.
2316

2417
### Using the package-collection CLI
2518

@@ -46,8 +39,9 @@ intended for package collection publishers:
4639
- [`package-collection-validate`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionValidator): Perform basic validations on a package collection
4740
- [`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
4841

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).
5145

5246
#### Input Format
5347

@@ -68,7 +62,7 @@ To begin, define the top-level metadata about the collection:
6862
Each item in the `packages` array is a package object with the following properties:
6963

7064
* `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.**
7266
* `summary`: A description of the package. **Optional.**
7367
* `keywords`: An array of keywords that the package is associated with. **Optional.**
7468
* `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
7771
* `name`: License name. [SPDX identifier](https://spdx.org/licenses/) (e.g., `Apache-2.0`, `MIT`, etc.) preferred. Omit if unknown. **Optional.**
7872
* `versions`: An array of version objects representing the most recent and/or relevant releases of the package.
7973

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-
8274
### Add versions to a package
8375

8476
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
144136
* `name`: License name. [SPDX identifier](https://spdx.org/licenses/) (e.g., `Apache-2.0`, `MIT`, etc.) preferred. Omit if unknown. **Optional.**
145137
* `author`: The package version's author. **Optional.**
146138
* `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.
148140
* `type`: The signer type. Currently the only valid value is `ADP` (Apple Developer Program).
149141
* `commonName`: The common name of the signing certificate's subject.
150142
* `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
153145

154146
### Version-specific manifests
155147

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>)
157149

158150
The keys of the `manifests` map are Swift tools (semantic) versions:
159151
* For `Package.swift`, the tools version specified in `Package.swift` should be used.
160152
* 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.
161153

162154
### Version-specific tags
163155

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.
166157

167158
### Configuration File
168159

169160
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>).
172162

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.
174164
175165
## Example
176166

@@ -300,72 +290,24 @@ and preferences such as those set by the `--trust-unsigned` and `--skip-signatur
300290
}
301291
```
302292

293+
## Protecting package collections
303294

304-
## Signing and protecting package collections
295+
### Signing a collection
305296

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.
307298
Doing this is optional.
308299
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.
309301

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>.
316303

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
362305

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.
366308
- **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>).
367309

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:
369311
- Require signature check on their collections — this defends against "signature stripping".
370312
- Restrict what certificate can be used for signing — this defends against "signature replacement".
371313

Sources/PackageManagerDocs/Documentation.docc/PackageCollections/PackageCollectionAdd.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ Added "Sample Package Collection" to your package collections.
3232

3333
### Signed package collections
3434

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:
4138

4239
```bash
4340
$ 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
5047
$ swift package-collection add https://www.example.com/packages.json --skip-signature-check
5148
```
5249
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:
5552

5653
```bash
5754
$ 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
6057

6158
Users should NOT add the package collection in this case.
6259

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>.
6661

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
6963

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.
7265

7366
```bash
7467
$ swift package-collection add https://www.example.com/packages.json
7568
The collection's signature cannot be verified due to missing configuration.
7669
```
7770
7871
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.
8173
8274
#### Unsigned package collections
8375
@@ -88,7 +80,7 @@ $ swift package-collection add https://www.example.com/packages.json
8880
The collection is not signed. If you would still like to add it please rerun 'add' with '--trust-unsigned'.
8981
```
9082
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:
9284
9385
```bash
9486
$ swift package-collection add https://www.example.com/packages.json --trust-unsigned

0 commit comments

Comments
 (0)