cmc/cleberg.net

My personal web garden & blog.

clone: git clone https://gitbay.org/cmc/cleberg.net.git

main: content/blog/2023-06-08-self-hosting-baikal.org · raw

  1#+date:        [2023-06-08 Thu 00:00:00]
  2#+title:       Self-Hosting Guide: Baikal
  3#+description: How to deploy Baikal for self-hosted CalDAV and CardDAV.
  4#+slug:        self-hosting-baikal
  5#+filetags:    :linux:self-hosting:
  6
  7* What is Baikal?
  8
  9[[https://sabre.io/baikal/][Baikal]] is a lightweight CalDAV + CardDAV
 10server that you can self-host on your own machine. While I have tried (&
 11failed) to get this CalDAV + CardDAV server running before, it was quite
 12easy this time. Not really sure what I did differently this time, but
 13I'm documenting my process here to ensure I don't forget.
 14
 15* Installation
 16
 17First, create a folder on your server and open a =docker-compose.yml=
 18file for editing:
 19
 20#+begin_src sh
 21mkdir baikal && cd baikal
 22nano docker-compose.yml
 23#+end_src
 24
 25Within this file, you'll need to paste the information below. You can
 26customize the =ports= section to use any port on your server to pass
 27through to port 80 in the container. You can also edit the =volumes=
 28section to use docker volumes instead of local folders.
 29
 30#+begin_src conf
 31version: "2"
 32services:
 33  baikal:
 34    image: ckulka/baikal:nginx
 35    restart: always
 36    ports:
 37      - "8567:80"
 38    volumes:
 39      - ./config:/var/www/baikal/config
 40      - ./data:/var/www/baikal/Specific
 41#+end_src
 42
 43Once finished with editing, save and close the file. Then, launch the
 44docker container:
 45
 46#+begin_src sh
 47sudo docker-compose up -d
 48#+end_src
 49
 50* Initial Setup
 51
 52As long as no issues came up when starting the container, you should be
 53able to visit the server's set-up page at =http://<server_ip>:<port>=.
 54The application will ask you to create an administrator account and
 55choose the database type for your storage. Personally, I opted to use
 56SQLite.
 57
 58Make sure the administrator credentials are adequate to protect against
 59common attacks.
 60
 61* Creating Users
 62
 63Once you've set up the application, you will be greeted by the Dashboard
 64page, which will show the version of the app, status of the
 65admin/CalDAV/CardDAV services, and the number of users, calendars,
 66events, address books, and contacts.
 67
 68To create a new user, navigate to the =Users and resources= page. This
 69process is as simple as entering a username, password, and email.
 70
 71Once a user has been created, you can create any number of calendars and
 72address books for user, as well as inspect their information.
 73
 74* Setting Up a Public URL
 75
 76Once your application is working locally, you can open access remotely
 77via a URL by using a reverse-proxy like Nginx.
 78
 79As a prerequisite, you must own a domain name and set up DNS records to
 80point a domain name to the server hosting Baikal.
 81
 82Start by navigating to your web server's configuration directory and
 83create a new file for this application.
 84
 85#+begin_src sh
 86cd /etc/nginx/sites-available/
 87nano dav
 88#+end_src
 89
 90Within this file, paste in the configuration from below and change
 91=dav.example.com= to match the URL you'll be using.
 92
 93#+begin_src conf
 94server {
 95        if ($host ~ ^[^.]+\.example\.com$) {
 96                return 301 https://$host$request_uri;
 97        }
 98
 99        listen [::]:80;
100        listen 80;
101        server_name dav.example.com;
102        return 404;
103}
104
105server {
106        listen [::]:443 ssl http2;
107        listen 443 ssl http2;
108        server_name dav.example.com;
109        access_log  /var/log/nginx/dav.access.log;
110        error_log   /var/log/nginx/dav.error.log;
111
112        location / {
113                proxy_http_version 1.1;
114                proxy_pass http://localhost:8567;
115                proxy_set_header Host $host;
116        }
117
118        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
119        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
120        include /etc/letsencrypt/options-ssl-nginx.conf;
121        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
122}
123#+end_src
124
125For Nginx on Ubuntu, you'll need to symlink the configuration file to
126the =sites-enabled= directory and then restart Nginx.
127
128#+begin_src sh
129sudo ln -s /etc/nginx/sites-available/dav /etc/nginx/sites-enabled/dav
130sudo systemctl restart nginx.service
131#+end_src
132
133At this point, the Baikal server should be available over the internet
134at the URL configured above!
135
136* Configuring Clients
137
138Lastly, configuring clients and applications is essential to making sure
139the DAV server is being fully utilized.
140
141You can also use the =Users and resources= page to inspect a user's
142personal link to their calendars and address books by clicking the info
143(i) button. It will show a URI like
144=/dav.php/calendars/your-user/default/=.
145
146However, I found that the following URL works for most applications:
147=/dav.php/principals/your-user/=.
148
149I used the =principals= URL above for Thunderbird (calendar, tasks, and
150contacts), as well as iOS (calendar, tasks, and contacts) and everything
151works flawlessly so far.
152
153Syncing is quick between the server and clients, and I haven't seen any
154disruptions in the service or data integrity.