Skip to content

Commit e97317a

Browse files
committed
Improve how to deploy a collection
1 parent db43488 commit e97317a

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

content/deployment/how-to/deploy.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ First, ensure your server provides unsupervised access:
2525
1. Check the SSH host key and get the SSH fingerprint by running the following command on your local machine:
2626

2727
```shell
28-
ssh-keyscan -t ed25519 <server_address>
28+
ssh-keyscan -t ed25519 <server_address> | grep -v '^#' | cut -d' ' -f3
29+
```
30+
31+
You should get an output that should be saved for later use as `<server_ssh_fingerprint>`. It will look like this:
32+
33+
```shell
34+
AAAAC3NzaC1lZDI1NTE5AAAAIGvJ9Al5cU7WwQ9a2m5oRmd3XjTzGQ1nBNiYFLm0TtB5
2935
```
3036

3137
If no Ed25519 key appears, generate one by running the following commands on the server:
@@ -37,16 +43,26 @@ First, ensure your server provides unsupervised access:
3743

3844
> **Note**: A server fingerprint is a unique identifier for your server's SSH key. It helps verify that you're connecting to the correct server and not a malicious one. The fingerprint is a hash of the server's public key and is used to prevent man-in-the-middle attacks. You'll need this fingerprint in the next steps for secure deployment.
3945
40-
2. Create a dedicated user account specifically for deployment purposes, by running the following commands on the server:
46+
2. Connect to the server and create a dedicated user account specifically for deployment purposes, by running the following commands:
4147

4248
```shell
43-
adduser <deployment_user>
49+
adduser --disabled-password <deployment_user>
4450
usermod --append --groups=sudo <deployment_user>
4551
```
4652

53+
> **Note**: The `--disabled-password` option creates a user account that cannot log in with a password unless one is explicitly set later. This is a security measure since the deployment process will use SSH keys for authentication instead of passwords.
54+
4755
> **Note**: The `adduser` command might not be installed by default on your system. It can be installed with `sudo apt-get install adduser`.
4856
49-
3. Configure passwordless sudo access for this user, by adding the following line to the `/etc/sudoers` file on the server:
57+
3. Create and configure the SSH directory for the deployment user by running these commands on the server:
58+
59+
```shell
60+
sudo mkdir /home/<deployment_user>/.ssh
61+
sudo chmod 700 /home/<deployment_user>/.ssh
62+
sudo chown <deployment_user>:<deployment_user> /home/<deployment_user>/.ssh
63+
```
64+
65+
4. Configure passwordless sudo access for this deployment user, by adding the following line to the `/etc/sudoers` file on the server:
5066

5167
```shell
5268
<deployment_user> ALL=(ALL) NOPASSWD:ALL
@@ -73,20 +89,20 @@ First, ensure your server provides unsupervised access:
7389
```
7490
7591
3. Add the server fingerprint to GitHub, to allow the deployment workflow to uniquely identify the server:
76-
- Go to `https://github.com/<organization>/<collection_id>-declarations/settings/secrets/actions`
92+
- Go to `https://github.com/<organization>/<collection_id>-declarations/settings/secrets/actions/new`
7793
- Create a new secret named `SERVER_FINGERPRINT` with your Ed25519 fingerprint
7894

7995
## 3. Configure SSH deployment keys
8096

8197
1. On the server, generate a deployment key, which will be used by the continuous deployment workflow to connect to the server to deploy the collection:
8298

8399
```shell
84-
ssh-keygen -t ed25519 -N "" -f ~/.ssh/ota-deploy
85-
cat ~/.ssh/ota-deploy.pub >> ~/.ssh/authorized_keys
100+
ssh-keygen -t ed25519 -N "" -f /home/<deployment_user>/.ssh/ota-deploy
101+
cat /home/<deployment_user>/.ssh/ota-deploy.pub >> /home/<deployment_user>/.ssh/authorized_keys
86102
```
87103

88104
2. Add the private key to GitHub, to allow the deployment workflow to connect to the server:
89-
- Go to `https://github.com/<organization>/<collection_id>-declarations/settings/secrets/actions`
105+
- Go to `https://github.com/<organization>/<collection_id>-declarations/settings/secrets/actions/new`
90106
- Create a new secret named `SERVER_SSH_KEY` with the private key content
91107

92108
{{< showIfParam "ota" >}}
@@ -98,13 +114,17 @@ First, ensure your server provides unsupervised access:
98114
1. Log in as the user account dedicated to bot-related actions in GitHub
99115

100116
2. Create a fine-grained GitHub token:
101-
- Create a new token at github.com/settings/personal-access-tokens/new
102-
- Set repository access for both declarations and versions repositories
103-
- Grant "Contents" and "Issues" write permissions
117+
- Go to [https://github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new)
118+
- Select an option for the "Resource owner", it can be the organization or the user account
119+
- Set the expiration date to "No expiration"
120+
- If the resource owner is an organization, in "Repository access", select "Only select repositories" and select the `<collection_id>-declarations` and `<collection_id>-versions` repositories
121+
- If the resource owner is a user account, in "Repository access", select "All repositories"
122+
- In "Permissions", select "Repository permissions" and grant "Contents" and "Issues" "Read and write" permissions
123+
- Click on "Generate token"
104124

105-
3. If relevant, get the token approved by having an organization admin approve the token request
125+
3. If the resource owner is an organization, have an organization admin approve the token request. This step is not needed if the resource owner is a user account.
106126

107-
4. Keep this token for the next steps
127+
4. Keep this token for later use as `<github_token>`
108128

109129
{{< showIfParam "ota" >}}
110130
5. Back up the token in the shared password database by creating an entry titled "GitHub Token" in the collection folder and storing the token in this entry
@@ -127,7 +147,7 @@ This section uses [Ansible Vault](https://docs.ansible.com/ansible/latest/vault_
127147
2. Store the GitHub token, generated in the previous section, in `deployment/.env`:
128148

129149
```shell
130-
OTA_ENGINE_GITHUB_TOKEN=your_token
150+
OTA_ENGINE_GITHUB_TOKEN=<github_token>
131151
```
132152

133153
3. Encrypt the `.env` file by running the following command inside the `deployment` folder of the collection:
@@ -158,13 +178,24 @@ This section uses [Ansible Vault](https://docs.ansible.com/ansible/latest/vault_
158178

159179
## 6. Set up collection-specific SSH key
160180

161-
1. Generate a new key, which will be used by the Open Terms Archive engine to perform actions on GitHub as the bot user:
181+
1. On your local machine, generate a new key, which will be used by the Open Terms Archive engine to perform actions on GitHub as the bot user:
162182

163183
```shell
164184
ssh-keygen -t ed25519 -C [email protected] -N "" -f ./<collection_name>-key
165185
```
166186

167-
2. Store the private key in `deployment/github-bot-private-key`
187+
2. Store the private key by replacing the whole content of `deployment/github-bot-private-key` with the content of the private key file you just generated (`./<collection_name>-key`). Make sure to include the entire key, including the "-----BEGIN OPENSSH PRIVATE KEY-----" and "-----END OPENSSH PRIVATE KEY-----" lines, with the newline at the end of the file. It should look like this:
188+
189+
```shell
190+
-----BEGIN OPENSSH PRIVATE KEY-----
191+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gt
192+
ZWQyNTUxOQAAACDXr7PSaRM0YeIrCZ3NEyyMy7nzzvTWQ78EoUmsRt6W0wAAAJiKDTHV
193+
ig0x1QAAAAdzc2gtZWQyNTUxOQAAACDXr7PSaRM0YeIrCZ3NEyyMy7nzzvTWQ78EoUms
194+
Rt6W0wAAAECrEN7xyX4h8r5wP0Adtz3WqIS8Su8D6UnyCm9tZyNNdavi89JpEzRh4isJ
195+
nc0TLIzLufPO9NZDvwShSayG3pbTAAAAE2Zha2VAdGVzdC5sb2NhbAECAwQFBgc=
196+
-----END OPENSSH PRIVATE KEY-----
197+
198+
```
168199

169200
3. Encrypt the private key file by running the following command inside the `deployment` folder of the collection:
170201

@@ -175,7 +206,8 @@ This section uses [Ansible Vault](https://docs.ansible.com/ansible/latest/vault_
175206
4. Commit the changes to the repository
176207

177208
5. Add the public key to bot user's GitHub account:
178-
- Go to github.com/settings/ssh/new
209+
- Still logged in as the user account dedicated to bot-related actions in GitHub
210+
- Go to [https://github.com/settings/ssh/new](https://github.com/settings/ssh/new)
179211
- Add the public key with title "<collection_name> collection"
180212

181213
{{< showIfParam "ota" >}}
@@ -231,4 +263,8 @@ This section describes how to configure the engine to use a specific SMTP server
231263
ansible-playbook opentermsarchive.deployment.deploy
232264
```
233265

266+
> **Note**: The local deployment will only work if your personal SSH key is authorized to connect to the deployment user on the server. If you haven't done this yet, follow these steps:
267+
> 1. On your local machine, copy your public SSH key
268+
> 2. Connect to the server and paste the key at the end of the `/home/<deployment_user>/.ssh/authorized_keys` file
269+
234270
If all steps complete successfully, your collection should now be properly deployed and running.

0 commit comments

Comments
 (0)