|
1 |
| -# Custom CA Certificate Support |
| 1 | +# CA Certificates Configuration |
2 | 2 |
|
3 |
| -This guide explains how to configure Gitea Mirror to work with self-signed certificates or custom Certificate Authorities (CAs). |
4 |
| - |
5 |
| -> **📁 This is the certs directory!** Place your `.crt` certificate files directly in this directory and they will be automatically loaded when the Docker container starts. |
| 3 | +This document explains how to configure custom Certificate Authority (CA) certificates for Gitea Mirror when connecting to self-signed or privately signed Gitea instances. |
6 | 4 |
|
7 | 5 | ## Overview
|
8 | 6 |
|
9 |
| -When connecting to a Gitea instance that uses self-signed certificates or certificates from a private CA, you need to configure the application to trust these certificates. Gitea Mirror supports mounting custom CA certificates that will be automatically configured for use. |
| 7 | +When your Gitea instance uses a self-signed certificate or a certificate signed by a private Certificate Authority (CA), you need to configure Gitea Mirror to trust these certificates. |
10 | 8 |
|
11 |
| -## Configuration Steps |
| 9 | +## Common SSL/TLS Errors |
12 | 10 |
|
13 |
| -### 1. Prepare Your CA Certificates |
| 11 | +If you encounter any of these errors, you need to configure CA certificates: |
14 | 12 |
|
15 |
| -You're already in the right place! Simply copy your CA certificate(s) into this `certs` directory with `.crt` extension: |
| 13 | +- `UNABLE_TO_VERIFY_LEAF_SIGNATURE` |
| 14 | +- `SELF_SIGNED_CERT_IN_CHAIN` |
| 15 | +- `UNABLE_TO_GET_ISSUER_CERT_LOCALLY` |
| 16 | +- `CERT_UNTRUSTED` |
| 17 | +- `unable to verify the first certificate` |
16 | 18 |
|
17 |
| -```bash |
18 |
| -# From the project root: |
19 |
| -cp /path/to/your/ca-certificate.crt ./certs/ |
| 19 | +## Configuration by Deployment Method |
20 | 20 |
|
21 |
| -# Or if you're already in the certs directory: |
22 |
| -cp /path/to/your/ca-certificate.crt . |
23 |
| -``` |
| 21 | +### Docker |
24 | 22 |
|
25 |
| -You can add multiple CA certificates - they will all be combined into a single bundle. |
| 23 | +#### Method 1: Volume Mount (Recommended) |
26 | 24 |
|
27 |
| -### 2. Mount Certificates in Docker |
| 25 | +1. Create a certificates directory: |
| 26 | + ```bash |
| 27 | + mkdir -p ./certs |
| 28 | + ``` |
28 | 29 |
|
29 |
| -Edit your `docker-compose.yml` file to mount the certificates. You have two options: |
| 30 | +2. Copy your CA certificate(s): |
| 31 | + ```bash |
| 32 | + cp /path/to/your-ca-cert.crt ./certs/ |
| 33 | + ``` |
30 | 34 |
|
31 |
| -**Option 1: Mount individual certificates from certs directory** |
32 |
| -```yaml |
33 |
| -services: |
34 |
| - gitea-mirror: |
35 |
| - # ... other configuration ... |
36 |
| - volumes: |
37 |
| - - gitea-mirror-data:/app/data |
38 |
| - - ./certs:/app/certs:ro # Mount CA certificates directory |
39 |
| -``` |
| 35 | +3. Update `docker-compose.yml`: |
| 36 | + ```yaml |
| 37 | + version: '3.8' |
| 38 | + services: |
| 39 | + gitea-mirror: |
| 40 | + image: raylabs/gitea-mirror:latest |
| 41 | + volumes: |
| 42 | + - ./data:/app/data |
| 43 | + - ./certs:/usr/local/share/ca-certificates:ro |
| 44 | + environment: |
| 45 | + - NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/your-ca-cert.crt |
| 46 | + ``` |
40 | 47 |
|
41 |
| -**Option 2: Mount system CA bundle (if your CA is already installed system-wide)** |
42 |
| -```yaml |
43 |
| -services: |
44 |
| - gitea-mirror: |
45 |
| - # ... other configuration ... |
46 |
| - volumes: |
47 |
| - - gitea-mirror-data:/app/data |
48 |
| - - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro |
49 |
| -``` |
| 48 | +4. Restart the container: |
| 49 | + ```bash |
| 50 | + docker-compose down && docker-compose up -d |
| 51 | + ``` |
50 | 52 |
|
51 |
| -> **Note**: Use Option 2 if you've already added your CA certificate to your system's certificate store using `update-ca-certificates` or similar commands. |
| 53 | +#### Method 2: Custom Docker Image |
52 | 54 |
|
53 |
| -> **System CA Bundle Locations**: |
54 |
| -> - Debian/Ubuntu: `/etc/ssl/certs/ca-certificates.crt` |
55 |
| -> - RHEL/CentOS/Fedora: `/etc/pki/tls/certs/ca-bundle.crt` |
56 |
| -> - Alpine Linux: `/etc/ssl/certs/ca-certificates.crt` |
57 |
| -> - macOS: `/etc/ssl/cert.pem` |
| 55 | +Create a `Dockerfile`: |
58 | 56 |
|
59 |
| -### 3. Start the Container |
| 57 | +```dockerfile |
| 58 | +FROM raylabs/gitea-mirror:latest |
60 | 59 |
|
61 |
| -Start or restart your container: |
| 60 | +# Copy CA certificates |
| 61 | +COPY ./certs/*.crt /usr/local/share/ca-certificates/ |
62 | 62 |
|
| 63 | +# Update CA certificates |
| 64 | +RUN update-ca-certificates |
| 65 | + |
| 66 | +# Set environment variable |
| 67 | +ENV NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/your-ca-cert.crt |
| 68 | +``` |
| 69 | + |
| 70 | +Build and use: |
63 | 71 | ```bash
|
64 |
| -docker-compose up -d |
| 72 | +docker build -t my-gitea-mirror . |
65 | 73 | ```
|
66 | 74 |
|
67 |
| -The container will automatically: |
68 |
| -1. Detect any `.crt` files in `/app/certs` (Option 1) OR detect mounted system CA bundle (Option 2) |
69 |
| -2. For Option 1: Combine certificates into a CA bundle |
70 |
| -3. Configure Node.js to use these certificates via `NODE_EXTRA_CA_CERTS` |
| 75 | +### Native/Bun |
| 76 | + |
| 77 | +#### Method 1: Environment Variable |
| 78 | + |
| 79 | +```bash |
| 80 | +export NODE_EXTRA_CA_CERTS=/path/to/your-ca-cert.crt |
| 81 | +bun run start |
| 82 | +``` |
71 | 83 |
|
72 |
| -You should see log messages like: |
| 84 | +#### Method 2: .env File |
73 | 85 |
|
74 |
| -**For Option 1 (individual certificates):** |
| 86 | +Add to your `.env` file: |
75 | 87 | ```
|
76 |
| -Custom CA certificates found, configuring Node.js to use them... |
77 |
| -Adding certificate: my-ca.crt |
78 |
| -NODE_EXTRA_CA_CERTS set to: /app/certs/ca-bundle.crt |
| 88 | +NODE_EXTRA_CA_CERTS=/path/to/your-ca-cert.crt |
| 89 | +``` |
| 90 | + |
| 91 | +#### Method 3: System CA Store |
| 92 | + |
| 93 | +**Ubuntu/Debian:** |
| 94 | +```bash |
| 95 | +sudo cp your-ca-cert.crt /usr/local/share/ca-certificates/ |
| 96 | +sudo update-ca-certificates |
79 | 97 | ```
|
80 | 98 |
|
81 |
| -**For Option 2 (system CA bundle):** |
| 99 | +**RHEL/CentOS/Fedora:** |
| 100 | +```bash |
| 101 | +sudo cp your-ca-cert.crt /etc/pki/ca-trust/source/anchors/ |
| 102 | +sudo update-ca-trust |
82 | 103 | ```
|
83 |
| -System CA bundle mounted, configuring Node.js to use it... |
84 |
| -NODE_EXTRA_CA_CERTS set to: /etc/ssl/certs/ca-certificates.crt |
| 104 | + |
| 105 | +**macOS:** |
| 106 | +```bash |
| 107 | +sudo security add-trusted-cert -d -r trustRoot \ |
| 108 | + -k /Library/Keychains/System.keychain your-ca-cert.crt |
85 | 109 | ```
|
86 | 110 |
|
87 |
| -## Testing & Troubleshooting |
| 111 | +### LXC Container (Proxmox VE) |
| 112 | + |
| 113 | +1. Enter the container: |
| 114 | + ```bash |
| 115 | + pct enter <container-id> |
| 116 | + ``` |
| 117 | + |
| 118 | +2. Create certificates directory: |
| 119 | + ```bash |
| 120 | + mkdir -p /usr/local/share/ca-certificates |
| 121 | + ``` |
| 122 | + |
| 123 | +3. Copy your CA certificate: |
| 124 | + ```bash |
| 125 | + cat > /usr/local/share/ca-certificates/your-ca.crt |
| 126 | + ``` |
| 127 | + (Paste certificate content and press Ctrl+D) |
| 128 | + |
| 129 | +4. Update the systemd service: |
| 130 | + ```bash |
| 131 | + cat >> /etc/systemd/system/gitea-mirror.service << EOF |
| 132 | + Environment="NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/your-ca.crt" |
| 133 | + EOF |
| 134 | + ``` |
| 135 | +
|
| 136 | +5. Reload and restart: |
| 137 | + ```bash |
| 138 | + systemctl daemon-reload |
| 139 | + systemctl restart gitea-mirror |
| 140 | + ``` |
88 | 141 |
|
89 |
| -### Disable TLS Verification (Testing Only) |
| 142 | +## Multiple CA Certificates |
90 | 143 |
|
91 |
| -For testing purposes only, you can disable TLS verification entirely: |
| 144 | +### Option 1: Bundle Certificates |
92 | 145 |
|
93 |
| -```yaml |
94 |
| -environment: |
95 |
| - - GITEA_SKIP_TLS_VERIFY=true |
| 146 | +```bash |
| 147 | +cat ca-cert1.crt ca-cert2.crt ca-cert3.crt > ca-bundle.crt |
| 148 | +export NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.crt |
96 | 149 | ```
|
97 | 150 |
|
98 |
| -**WARNING**: This is insecure and should never be used in production! |
| 151 | +### Option 2: System CA Store |
99 | 152 |
|
100 |
| -### Common Issues |
| 153 | +```bash |
| 154 | +# Copy all certificates |
| 155 | +cp *.crt /usr/local/share/ca-certificates/ |
| 156 | +update-ca-certificates |
| 157 | +``` |
101 | 158 |
|
102 |
| -1. **Certificate not recognized**: Ensure your certificate file has a `.crt` extension |
103 |
| -2. **Connection still fails**: Check that the certificate is in PEM format |
104 |
| -3. **Multiple certificates needed**: Add all required certificates (root and intermediate) to the certs directory |
| 159 | +## Verification |
105 | 160 |
|
106 |
| -### Verifying Certificate Loading |
| 161 | +### 1. Test Gitea Connection |
| 162 | +Use the "Test Connection" button in the Gitea configuration section. |
107 | 163 |
|
108 |
| -Check the container logs to confirm certificates are loaded: |
| 164 | +### 2. Check Logs |
109 | 165 |
|
| 166 | +**Docker:** |
110 | 167 | ```bash
|
111 |
| -docker-compose logs gitea-mirror | grep "CA certificates" |
| 168 | +docker logs gitea-mirror |
112 | 169 | ```
|
113 | 170 |
|
114 |
| -## Security Considerations |
| 171 | +**Native:** |
| 172 | +Check terminal output |
115 | 173 |
|
116 |
| -- Always use proper CA certificates in production |
117 |
| -- Never disable TLS verification in production environments |
118 |
| -- Keep your CA certificates secure and limit access to the certs directory |
119 |
| -- Regularly update certificates before they expire |
| 174 | +**LXC:** |
| 175 | +```bash |
| 176 | +journalctl -u gitea-mirror -f |
| 177 | +``` |
120 | 178 |
|
121 |
| -## Example Setup |
| 179 | +### 3. Manual Certificate Test |
122 | 180 |
|
123 |
| -Here's a complete example for a self-hosted Gitea with custom CA: |
| 181 | +```bash |
| 182 | +openssl s_client -connect your-gitea-domain.com:443 -CAfile /path/to/ca-cert.crt |
| 183 | +``` |
124 | 184 |
|
125 |
| -1. Copy your Gitea server's CA certificate to this directory: |
126 |
| - ```bash |
127 |
| - cp /etc/ssl/certs/my-company-ca.crt ./certs/ |
128 |
| - ``` |
| 185 | +## Best Practices |
129 | 186 |
|
130 |
| -2. Update `docker-compose.yml`: |
131 |
| - ```yaml |
132 |
| - services: |
133 |
| - gitea-mirror: |
134 |
| - image: ghcr.io/raylabshq/gitea-mirror:latest |
135 |
| - volumes: |
136 |
| - - gitea-mirror-data:/app/data |
137 |
| - - ./certs:/app/certs:ro |
138 |
| - environment: |
139 |
| - - GITEA_URL=https://gitea.mycompany.local |
140 |
| - - GITEA_TOKEN=your-token |
141 |
| - # ... other configuration ... |
142 |
| - ``` |
| 187 | +1. **Certificate Security** |
| 188 | + - Keep CA certificates secure |
| 189 | + - Use read-only mounts in Docker |
| 190 | + - Limit certificate file permissions |
| 191 | + - Regularly update certificates |
143 | 192 |
|
144 |
| -3. Start the service: |
145 |
| - ```bash |
146 |
| - docker-compose up -d |
147 |
| - ``` |
| 193 | +2. **Certificate Management** |
| 194 | + - Use descriptive certificate filenames |
| 195 | + - Document certificate purposes |
| 196 | + - Track certificate expiration dates |
| 197 | + - Maintain certificate backups |
| 198 | +
|
| 199 | +3. **Production Deployment** |
| 200 | + - Use proper SSL certificates when possible |
| 201 | + - Consider Let's Encrypt for public instances |
| 202 | + - Implement certificate rotation procedures |
| 203 | + - Monitor certificate expiration |
| 204 | +
|
| 205 | +## Troubleshooting |
148 | 206 |
|
149 |
| -The application will now trust your custom CA when connecting to your Gitea instance. |
| 207 | +### Certificate not being recognized |
| 208 | +- Ensure the certificate is in PEM format |
| 209 | +- Check that `NODE_EXTRA_CA_CERTS` points to the correct file |
| 210 | +- Restart the application after adding certificates |
| 211 | +
|
| 212 | +### Still getting SSL errors |
| 213 | +- Verify the complete certificate chain is included |
| 214 | +- Check if intermediate certificates are needed |
| 215 | +- Ensure the certificate matches the server hostname |
| 216 | +
|
| 217 | +### Certificate expired |
| 218 | +- Check validity: `openssl x509 -in cert.crt -noout -dates` |
| 219 | +- Update with new certificate from your CA |
| 220 | +- Restart Gitea Mirror after updating |
| 221 | +
|
| 222 | +## Certificate Format |
| 223 | +
|
| 224 | +Certificates must be in PEM format. Example: |
| 225 | +
|
| 226 | +``` |
| 227 | +-----BEGIN CERTIFICATE----- |
| 228 | +MIIDXTCCAkWgAwIBAgIJAKl8bUgMdErlMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV |
| 229 | +[... certificate content ...] |
| 230 | +-----END CERTIFICATE----- |
| 231 | +``` |
| 232 | +
|
| 233 | +If your certificate is in DER format, convert it: |
| 234 | +```bash |
| 235 | +openssl x509 -inform der -in certificate.cer -out certificate.crt |
| 236 | +``` |
0 commit comments