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/swift-container-plugin/Documentation.docc/authentication.md
+91-2Lines changed: 91 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,101 @@ Configure the plugin to authenticate to your container registry.
6
6
7
7
Many container registries require authentication in order to push images, or even pull them.
8
8
The plugin reads your registry credentials from a `.netrc` file in your home directory.
9
-
Add a record into the `.netrc` file for each registry you use, the plugin uses the authentication by the registry you choose.
9
+
Add a record into the `.netrc` file for each registry you use.
10
+
The plugin chooses the correct record based on the hostname of the registry's authentication server.
11
+
12
+
> For some registries, such as Docker Hub [(see example)](<doc:#Docker-Hub>), the authentication server hostname might not be the same as the registry hostname you use when pushing and pulling images.
10
13
11
14
The following example shows placeholder values for the registry `registry.example.com`:
12
15
13
16
```
14
17
machine registry.example.com
15
18
login myuser
16
19
password mypassword
17
-
```
20
+
```
21
+
22
+
The following examples show how to set up the plugin for some popular registry providers.
23
+
24
+
### Docker Hub
25
+
26
+
> Don't use your Docker Hub account password to push and pull images.
27
+
> Create a Personal Access Token, which has restricted privileges, for each integration you use.
28
+
> By using separate tokens, you can monitor them independently and revoke one at any time.
29
+
To create a `.netrc` entry for Docker Hub:
30
+
31
+
1. Log into Docker Hub and [generate a Personal Access Token](https://docs.docker.com/security/for-developers/access-tokens/) for Swift Container Plugin.
32
+
33
+
2.**Set the token's access permissions to *Read & Write*.**
34
+
35
+
3. Copy the token and add it, together with your Docker ID, to your `.netrc` file under the machine name `auth.docker.io`:
36
+
37
+
The final `.netrc` entry should be similar to this:
38
+
39
+
```
40
+
machine auth.docker.io
41
+
login mydockerid
42
+
password dckr_pat_B3FwrU...
43
+
```
44
+
45
+
### GitHub Container Registry
46
+
47
+
> GitHub Container Registry only supports authentication using a [Personal Access Token (classic)](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry).
48
+
> A fine-grained personal access token cannot be used.
49
+
50
+
To create a `.netrc` entry for Github Container Registry:
51
+
52
+
1. Log into GitHub and [generate a Personal Access Token (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) for Swift Container Plugin.
53
+
54
+
2.**Select the *write:packages* scope.**
55
+
56
+
3. Copy the token and add it, together with your GitHub username, to your `.netrc` file:
57
+
58
+
The final `.netrc` entry should be similar to this:
59
+
60
+
```
61
+
machine ghcr.io
62
+
login mygithubusername
63
+
password ghp_fAOsWl...
64
+
```
65
+
66
+
### Amazon Elastic Container Registry
67
+
68
+
> Amazon Elastic Container Registry uses [short-lived authorization tokens](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html#registry-auth-token) which expire after 12 hours.
69
+
>
70
+
> To generate an ECR authentication token, you must [first install the AWS CLI tools.](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
71
+
72
+
To create a `.netrc` entry for Amazon Elastic Container Registry:
73
+
74
+
1. Use the `aws` CLI tool to [generate an authentication token](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html#registry-auth-token).
75
+
You'll need to know the name of the [AWS region](https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html) in which your registry is hosted.
76
+
Registries in different AWS regions are separate and require different authentication tokens.
77
+
78
+
For example, the following command generates a token for ECR in the `us-west-2` region:
79
+
```
80
+
aws ecr get-login-password --region us-west-2
81
+
```
82
+
83
+
2. Copy the token and add it to your `.netrc` file.
84
+
* The format of the machine name is:
85
+
86
+
```
87
+
<aws_account_id>.dkr.ecr.<region>.amazonaws.com
88
+
```
89
+
90
+
You can [find your AWS account ID](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html) in the AWS Management Console or by running the following command:
91
+
```
92
+
aws sts get-caller-identity \
93
+
--query Account \
94
+
--output text
95
+
```
96
+
* **The login name must be `AWS`**.
97
+
* The token is a large encoded string.
98
+
It must appear in the `.netrc` file as a single line, with no breaks.
99
+
100
+
The final `.netrc` entry should be similar to this:
0 commit comments