Skip to content

Commit 957fb8a

Browse files
committed
Improve how to deploy a collection
1 parent fc8c78e commit 957fb8a

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

content/deployment/how-to/deploy.md

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,67 @@ weight: 1
77

88
This guide will help you deploy an Open Terms Archive collection to a server.
99

10+
> **Note**: This guide is intended for both Open Terms Archive organization members and external contributors. Some steps marked with [🔒 **Specific to Open Terms Archive organization members**] are only relevant for organization members as they involve access to the organization's shared password database. External contributors should adapt these steps to their own security practices while following the same deployment principles.
11+
12+
## Prerequisites
13+
14+
Before starting, ensure you have:
15+
16+
- A server with admin access
17+
- All collections repositories created, if not, see the [guide to create repositories]({{< relref "collections/how-to/create-repositories" >}}).
18+
- A GitHub user account dedicated to bot-related actions (commit entries in versions and snapshots repositories, report issues when tracking fails, publish releases, …)
19+
1020
## 1. Configure the server
1121

1222
First, ensure your server provides unsupervised access:
1323

14-
1. Check the SSH host key:
24+
1. Check the SSH host key and get the SSH fingerprint by running the following command on your local machine:
25+
1526
```shell
16-
ssh-keyscan --type=ed25519 <server_address>
27+
ssh-keyscan -t ed25519 <server_address>
1728
```
18-
If no Ed25519 key appears, generate one on the server:
29+
30+
If no Ed25519 key appears, generate one by running the following commands on the server:
31+
1932
```shell
20-
sudo ssh-keygen --type=ed25519 --file=/etc/ssh/ssh_host_ed25519_key
33+
sudo ssh-keygen -t ed25519 --file=/etc/ssh/ssh_host_ed25519_key
2134
sudo systemctl restart ssh
2235
```
2336

24-
2. Create a non-root user if needed:
37+
> **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.
38+
39+
2. Create a dedicated user account specifically for deployment purposes, by running the following commands on the server:
40+
2541
```shell
2642
adduser <user>
2743
usermod --append --groups=sudo <user>
2844
```
2945

30-
3. Grant passwordless sudo access:
46+
> **Note**: The `adduser` command might not be installed by default on your system. It can be installed with `sudo apt-get install adduser`.
47+
48+
3. Configure sudo access for this user, by running the following command on the server:
49+
3150
```shell
3251
# Add to /etc/sudoers:
3352
<user> ALL=(ALL) NOPASSWD:ALL
3453
```
3554

55+
> **Note**: While passwordless sudo access does reduce security compared to requiring a password, it is essential for full automation in deployment workflows with Ansible. The deployment process requires system-level operations (like installing packages and configuring services) that must be executed without manual intervention. To mitigate security risks, this configuration is limited to a dedicated deployment user that should only be used for deployment purposes, and the server must be properly secured with SSH key authentication.
56+
3657
## 2. Set up the deployment configuration
3758

3859
1. Clone the collection declarations repository:
60+
3961
```shell
4062
git clone https://github.com/OpenTermsArchive/<collection_id>-declarations.git
4163
```
4264

43-
2. Configure the inventory file `deployment/inventory.yml`:
65+
2. Configure the inventory file `deployment/inventory.yml` with your server's IP address, deployment user (from step 1), and server fingerprint (from step 1):
66+
4467
```yaml
45-
<host>: "your.server.ip"
46-
ansible_user: "your_username"
47-
ed25519_fingerprint: "your_ssh_fingerprint"
68+
<host>: "server_ip"
69+
ansible_user: "deployment_user"
70+
ed25519_fingerprint: "server_ssh_fingerprint"
4871
```
4972
5073
3. Add the server fingerprint to GitHub:
@@ -53,7 +76,8 @@ First, ensure your server provides unsupervised access:
5376

5477
## 3. Configure SSH deployment keys
5578

56-
1. On the server, generate a deployment key:
79+
1. On the server, generate a deployment key, which will be used by the continuous deployment workflow to deploy the collection:
80+
5781
```shell
5882
ssh-keygen --type=ed25519 --quiet --passphrase="" --file=~/.ssh/ota-deploy
5983
cat ~/.ssh/ota-deploy.pub >> ~/.ssh/authorized_keys
@@ -63,19 +87,19 @@ First, ensure your server provides unsupervised access:
6387
- Go to the repository secrets
6488
- Create `SERVER_SSH_KEY` with the private key content
6589

66-
3. Back up the keys:
67-
- Store both public and private keys in the shared password database
68-
- Create an entry titled "Deployment SSH key" in the collection folder
90+
3. [🔒 **Specific to Open Terms Archive organization members**] Back up the keys in the shared password database:
91+
- Create an entry titled "Deployment SSH Key" in the collection folder
92+
- Store both public and private keys in this entry
6993

70-
## 4. Set up GitHub permissions
94+
## 4. Set up GitHub permissions for bot user
7195

7296
1. Create a fine-grained GitHub token:
7397
- Log in as OTA-Bot
7498
- Create a new token at github.com/settings/personal-access-tokens/new
7599
- Set repository access for both declarations and versions repos
76100
- Grant "Contents" and "Issues" write permissions
77101

78-
2. Back up the token:
102+
2. [🔒 **Specific to Open Terms Archive organization members**] Back up the token:
79103
- Store it in the shared password database under "GitHub Token"
80104

81105
3. Get the token approved:
@@ -85,29 +109,36 @@ First, ensure your server provides unsupervised access:
85109

86110
1. Generate and store a vault key:
87111
- Generate a secure password without quotes/backticks
88-
- Store it in the password database
89112
- Create `deployment/vault.key` with the password
90113
- Add it as `ANSIBLE_VAULT_KEY` in GitHub secrets
91114

92-
2. Store GitHub token:
93-
```
115+
2. Store GitHub token (from step 4):
116+
117+
```shell
94118
# In deployment/.env:
95119
OTA_ENGINE_GITHUB_TOKEN=your_token
96120
```
97121

98122
3. Encrypt the `.env` file:
123+
99124
```shell
100125
ansible-vault encrypt .env
101126
```
102127

128+
4. [🔒 **Specific to Open Terms Archive organization members**] Back up the vault key in the shared password database:
129+
- Create an entry titled "Vault Key" in the collection folder
130+
- Store the vault key in this entry
131+
103132
## 6. Set up collection-specific SSH key
104133

105-
1. Generate a new key:
134+
1. Generate a new key, which will be used by the Open Terms Archive engine to push changes to the collection on GitHub:
135+
106136
```shell
107-
ssh-keygen --type=ed25519 --comment=[email protected] --passphrase="" --file=./<collection_name>-key
137+
ssh-keygen -t ed25519 -C [email protected] -N "" -f ./<collection_name>-key
108138
```
109139

110-
2. Encrypt and store the private key:
140+
2. Encrypt the private key:
141+
111142
```shell
112143
# Copy private key to deployment/github-bot-private-key
113144
ansible-vault encrypt github-bot-private-key
@@ -117,29 +148,40 @@ First, ensure your server provides unsupervised access:
117148
- Go to github.com/settings/ssh/new
118149
- Add the public key with title "<collection_name> collection"
119150

151+
4. [🔒 **Specific to Open Terms Archive organization members**] Back up the key in the shared password database:
152+
- Create an entry titled "OTA-Bot GitHub SSH key" in the collection folder
153+
- Store both public and private keys in this entry
154+
120155
## 7. Configure email notifications
121156

122157
1. Generate SMTP credentials:
123158
- Create a new SMTP key in Brevo
124159
- Name it "<collection_name> collection"
125160

126161
2. Store the credentials:
162+
127163
```shell
128164
# In deployment/.env:
129165
OTA_ENGINE_SMTP_PASSWORD=your_smtp_key
130166
```
131167

132168
3. Encrypt the `.env` file:
169+
133170
```shell
134171
ansible-vault encrypt .env
135172
```
136173

174+
4. [🔒 **Specific to Open Terms Archive organization members**] Back up the credentials in the shared password database:
175+
- Create an entry titled "SMTP Key" in the collection folder
176+
- Store the credentials in this entry
177+
137178
## 8. Test the deployment
138179

139180
1. Via GitHub Actions:
140181
- Check that the `deploy` action completes successfully
141182

142183
2. Via local deployment:
184+
143185
```shell
144186
cd <collection_id>-declarations/deployment
145187
ansible-galaxy collection install --requirements-file requirements.yml

0 commit comments

Comments
 (0)