-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Port Documentation/PackageRegistry
directory contents into DocC
#8745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bripeticca
wants to merge
26
commits into
swiftlang:main
Choose a base branch
from
bripeticca:docs/registryusage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
10d9fc0
Initial porting for package registry usage docs
bripeticca b2e00f1
Augment package-registry command overviews, change links
bripeticca 7b2575d
Move registry spec + begin security porting
bripeticca 3243972
Merge branch 'main' into registryusage
bripeticca 15b7e74
Merge branch 'main' into registryusage
bripeticca eaf3429
Update package-registry set overview and replace uses of SwiftPM
bripeticca c434003
Update package-registry command overviews + update links in registry …
bripeticca c1b9af0
Refactor to 1 sentence per line
bripeticca b0d0f12
Merge branch 'main' into registryusage
bripeticca 5296e28
More porting of security topics + cleanup
bripeticca f55fc06
Some more refactoring of security-related topics
bripeticca d215e94
Finish porting security topics
bripeticca 7092272
Cleanup
bripeticca 00d372d
Address PR comments
bripeticca 6683333
Address PR comment
bripeticca cb78c30
Merge branch 'swiftlang:main' into docs/registryusage
bripeticca 41789ce
Migrates plugin documentation into DocC (#8766)
heckj 644a28c
Command plugins should respect --build-system selection (#8779)
owenv 0349b3b
Update Package.swift dependency
bkhouri 07cd5a4
Add support for a `--sanitize=fuzzer` flag (#8729)
DanBlackwell 46b7d84
[Commands] Migrate: Don't attempt to cache manifest with temporary fe…
xedin 6f20f53
[Package{Model, Graph}] Make it possible to mark modules as implicit
xedin 162e07a
[Commands] Migrate: Exclude implicit modules from migration
xedin b9b188e
Address PR comment
bripeticca 4fdfecd
Merge branch 'main' into registryusage
bripeticca 44694a8
Merge branch 'main' into registryusage
bripeticca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,11 @@ Learn to create, publish and use Swift package collections. | |
|
||
## Overview | ||
|
||
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 can be imported | ||
by SwiftPM to make discovery of existing packages easier. | ||
They are authored as static JSON documents | ||
and can be published to the web or distributed to local file systems. | ||
|
||
Educators and community influencers can publish | ||
package collections to go along with course materials or blog posts, removing the friction of using | ||
packages for the first time and the cognitive overload of deciding which packages are useful for | ||
a particular task. | ||
Enterprises may use collections to narrow the decision space for their internal | ||
engineering teams, focusing them on a trusted set of vetted packages. | ||
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 package manager can import to make discovery of existing packages easier. | ||
|
||
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. | ||
Enterprises may use collections to provide a trusted set of packages, or a collection of packages consistently used by a team. | ||
Author a package collection as a static JSON document and publish it to the web or distribute it on a local file system. | ||
|
||
### Using the package-collection CLI | ||
|
||
|
@@ -46,8 +39,9 @@ intended for package collection publishers: | |
- [`package-collection-validate`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionValidator): Perform basic validations on a package collection | ||
- [`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 | ||
|
||
All package collections must adhere to the [collection data format](<doc:Input-Format>) for SwiftPM to be able to consume them. 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). For custom implementations, the data models are available through the [`PackageCollectionsModel` module](https://github.com/swiftlang/swift-package-manager/tree/main/Sources/PackageCollectionsModel). | ||
All package collections must adhere to the [collection data format](<doc:Input-Format>) for SwiftPM to be able to consume them. | ||
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). | ||
For custom implementations, the data models are available through the [`PackageCollectionsModel` module](https://github.com/swiftlang/swift-package-manager/tree/main/Sources/PackageCollectionsModel). | ||
|
||
#### Input Format | ||
|
||
|
@@ -68,7 +62,7 @@ To begin, define the top-level metadata about the collection: | |
Each item in the `packages` array is a package object with the following properties: | ||
|
||
* `url`: The URL of the package. Currently only Git repository URLs are supported. URL should be HTTPS and may contain `.git` suffix. | ||
* `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.** | ||
* `identity`: The [identity](<doc:RegistryServerSpecification#3.6.-Package-identification>) of the package if published to registry. **Optional.** | ||
* `summary`: A description of the package. **Optional.** | ||
* `keywords`: An array of keywords that the package is associated with. **Optional.** | ||
* `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 | |
* `name`: License name. [SPDX identifier](https://spdx.org/licenses/) (e.g., `Apache-2.0`, `MIT`, etc.) preferred. Omit if unknown. **Optional.** | ||
* `versions`: An array of version objects representing the most recent and/or relevant releases of the package. | ||
|
||
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. | ||
|
||
### Add versions to a package | ||
|
||
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 | |
* `name`: License name. [SPDX identifier](https://spdx.org/licenses/) (e.g., `Apache-2.0`, `MIT`, etc.) preferred. Omit if unknown. **Optional.** | ||
* `author`: The package version's author. **Optional.** | ||
* `name`: The author of the package version. | ||
* `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. | ||
* `signer`: The signer of the package version. **Optional.** Refer to the [documentation](<doc:PackageSecurity#Package-signing>) on package signing for details. | ||
* `type`: The signer type. Currently the only valid value is `ADP` (Apple Developer Program). | ||
* `commonName`: The common name of the signing certificate's subject. | ||
* `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 | |
|
||
### Version-specific manifests | ||
|
||
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. -->. | ||
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>) | ||
|
||
The keys of the `manifests` map are Swift tools (semantic) versions: | ||
* For `Package.swift`, the tools version specified in `Package.swift` should be used. | ||
* 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. | ||
|
||
### Version-specific tags | ||
|
||
[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 | ||
supported by package collections. | ||
[Version-specific tags](<doc:SwiftVersionSpecificPackaging#Version-specific-tags-when-resolving-remote-dependencies>) are not supported by package collections. | ||
|
||
### Configuration File | ||
|
||
Configuration that pertains to package collections are stored in the file `~/.swiftpm/config/collections.json`. | ||
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>). | ||
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>). | ||
|
||
> Note: This file is managed through SwiftPM commands and users are not expected to edit it by hand. | ||
> Note: This file is managed through Swift Package Manager commands and users are not expected to edit it by hand. | ||
|
||
## Example | ||
|
||
|
@@ -300,72 +290,24 @@ and preferences such as those set by the `--trust-unsigned` and `--skip-signatur | |
} | ||
``` | ||
|
||
## Protecting package collections | ||
|
||
## Signing and protecting package collections | ||
### Signing a collection | ||
|
||
Package collections can be signed to establish authenticity and protect their integrity. | ||
[Sign package collections](<doc:PackageSecurity#Signed-package-collections>) to establish authenticity and protect their integrity. | ||
Doing this is optional. | ||
Users will be prompted for confirmation before they can add an [unsigned collection](<doc:PackageCollectionAdd#Unsigned-package-collections>). | ||
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. | ||
|
||
[`package-collection-sign`](https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionSigner) helps publishers sign their package | ||
collections. To generate a signature one must provide: | ||
- The package collection file to be signed | ||
- A code signing certificate (DER-encoded) | ||
- The certificate's private key (PEM-encoded) | ||
- The certificate's chain in its entirety | ||
For more details on the security features Package manager implements, see <doc:PackageSecurity>. | ||
|
||
A signed package collection has an extra `signature` object: | ||
|
||
```json | ||
{ | ||
..., | ||
"signature": { | ||
"signature": "<SIGNATURE>", | ||
"certificate": { | ||
"subject": { | ||
"commonName": "Jane Doe", | ||
... | ||
}, | ||
"issuer": { | ||
"commonName": "Sample CA", | ||
... | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- 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. | ||
- `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>). | ||
|
||
### Requirements on signing certificate | ||
|
||
Certificates used for signing package collections must meet the following requirements, which are checked and enforced during signature generation (publishers) and verification (SwiftPM users): | ||
- The timestamp at which signing/verification is done must fall within the signing certificate's validity period. | ||
- The certificate's "Extended Key Usage" extension must include "Code Signing". | ||
- The certificate must use either 256-bit EC (recommended for enhanced security) or 2048-bit RSA key. | ||
- 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. | ||
- The certificate chain is valid and root certificate must be trusted. | ||
|
||
Non-expired, non-revoked Swift Package Collection certificates from [developer.apple.com](https://developer.apple.com) satisfy all of the criteria above. | ||
|
||
#### Trusted root certificates | ||
|
||
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, | ||
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 | ||
the [certificate-pinning configuration](<doc:#Protecting-package-collections>), otherwise the [signature check](<doc:PackageCollectionAdd#Signed-package-collections>) will fail. | ||
Collection publishers should make the DER-encoded | ||
root certificate(s) that they use downloadable so that users can adjust their setup if needed. | ||
|
||
|
||
## Protecting package collections | ||
### Security risks | ||
|
||
[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 | ||
prevent the following attack vectors: | ||
- **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. | ||
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: | ||
- **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. | ||
- **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>). | ||
|
||
To defend against these attacks, SwiftPM has certificate-pinning configuration that allows collection publishers to: | ||
To defend against these attacks, package manager has certificate-pinning configuration that allows collection publishers to: | ||
- Require signature check on their collections — this defends against "signature stripping". | ||
- Restrict what certificate can be used for signing — this defends against "signature replacement". | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.