arnefandCopilot daa51d62b1 Add calendar/address-book sharing backend
Introduce internal/db, a small SQLite-backed store (pure-Go
modernc.org/sqlite, no CGO) at <data_dir>/nidus.db holding
calendar_shares and addressbook_shares grant tables (owner, resource
name, shared-with user, read/write permission). This is the first step
towards user management and a web UI: a real datastore that a future
admin CLI/UI can build on, instead of the static config.yaml.

Wire sharing into the CalDAV/CardDAV backends:
- ListCalendars/ListAddressBooks now also include resources shared with
  the requesting user, exposed under the synthetic local name
  "<owner>~<name>" in the grantee's own home-set — no separate account,
  no data copying, the object still physically lives under the owner's
  store.Store namespace.
- All read paths (Get/List/QueryCalendarObjects, address book
  equivalents) resolve the synthetic name back to (owner, real name) and
  require any share (read or write) to exist.
- All write paths (Put/Delete object, DeleteCalendar/AddressBook)
  additionally require a write-permission share; read-only shares get a
  403 Forbidden.
- CreateCalendar/CreateAddressBook remain scoped to the acting user's own
  namespace — sharing an existing collection is done via ShareCalendar/
  ShareAddressBook, not by creating one directly in someone else's name.

Add internal/db/shares_test.go (grant/lookup/update/unshare/list
semantics) and internal/{caldav,carddav}/backend_test.go (shared
calendar/address book visibility, write permission enforcement,
unauthorized access rejection). Update README (features, new "Sharing
calendars and address books" section, project layout, dependencies) and
copilot-instructions.md to document the new package and sharing model.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-18 20:10:31 +02:00
wip
2026-04-23 21:56:59 +02:00
wip
2026-04-23 21:56:59 +02:00
wip
2026-04-23 21:56:59 +02:00
wip
2026-04-23 21:56:59 +02:00

DAV Server

A self-hosted CalDAV, CardDAV, and WebDAV server written in Go.

Features

Protocol Use case
CalDAV Calendars — sync with Apple Calendar, Thunderbird, GNOME Calendar, …
CardDAV Contacts — sync with Apple Contacts, GNOME Contacts, …
WebDAV General file access via Finder, Windows Explorer, Nautilus, …
  • HTTP Basic Auth with bcrypt password storage
  • Per-user isolated collections
  • Calendar/address book sharing — grant other users read or write access to your calendars/address books
  • Auto-discovery via /.well-known/caldav and /.well-known/carddav
  • Optional TLS (or use a reverse proxy)
  • Structured logging (text or JSON)
  • Graceful shutdown
  • Docker & Docker Compose support

Quick start

1. Install dependencies

go mod tidy

2. Generate password hashes

go run ./tools/hashpwd mysecretpassword
# Outputs: $2b$12$...

3. Create your config.yaml

Copy the example config and edit it — config.yaml is git-ignored so your real credentials/domain never get committed:

cp config.example.yaml config.yaml

Replace the placeholder hashes with your real bcrypt hashes:

users:
  alice:
    password: "$2b$12$<hash generated above>"
    display_name: "Alice Smith"
    email: "alice@example.com"
    calendars:
      - personal
      - work
    address_books:
      - contacts

4. Run the server

make run
# or
go run ./cmd/server -config config.yaml

The server starts at http://localhost:8080.


Docker

# Build and start
docker compose up --build

# Or build manually
docker build -t davserver .
docker run -p 8080:8080 \
  -v ./config.yaml:/app/config.yaml:ro \
  -v dav-data:/app/data \
  davserver

Client configuration

Apple Calendar / Contacts (macOS / iOS)

  1. Go to Settings → Calendar → Accounts → Add Account → Other → Add CalDAV Account
  2. Enter:
    • Server: http://yourserver:8080
    • Username: alice
    • Password: your plaintext password
  3. The app will auto-discover calendars at /cal/.

Same flow for CardDAV with Contacts app.

Thunderbird

  1. Install the TbSync add-on + CalDAV & CardDAV provider
  2. Add a new account and point it at http://yourserver:8080/.well-known/caldav

GNOME Calendar / Evolution

Use the GNOME Online Accounts panel:

  • Server: http://yourserver:8080
  • Check CalDAV / CardDAV as appropriate

API endpoints

Path Description
/.well-known/caldav Redirects to /cal/
/.well-known/carddav Redirects to /card/
/cal/ CalDAV principal (same URL for every user; resolved via Basic Auth)
/cal/home/ Calendar home-set (lists the user's calendars)
/cal/home/<calendar>/ Calendar collection
/card/ CardDAV principal (same URL for every user; resolved via Basic Auth)
/card/home/ Address book home-set (lists the user's address books)
/card/home/<book>/ Address book collection
/files/ WebDAV file storage (same URL for every user; resolved via Basic Auth)
/healthz Health check (unauthenticated)

Note: the home segment is a fixed literal (not a username or real resource) — it exists only to give the calendar/address-book home-set the path depth that the underlying CalDAV/CardDAV library expects when classifying resources by URL. Clients should never need to construct these URLs by hand; they're discovered automatically via .well-known + current-user-principal + calendar-home-set / addressbook-home-set properties.


Sharing calendars and address books

A user can grant another user read or write access to one of their own calendars or address books. Shared resources show up automatically in the grantee's own home-set alongside their own calendars — no separate account or extra client configuration needed.

Sharing grants are stored in a small SQLite database at <data_dir>/nidus.db (not in config.yaml). There's no CLI or web UI for managing shares yet — the initial backend groundwork lives in internal/db (see ShareCalendar, UnshareCalendar, ShareAddressBook, UnshareAddressBook), which a future admin CLI or web UI will call into.

A calendar that alice shares with bob appears in bob's calendar home-set as /cal/home/alice~work/ (i.e. <owner>~<calendar name>) — the data itself still physically lives under alice's own storage; nothing is copied. The same scheme applies to address books under /card/home/. Read-only shares reject any write (PUT/DELETE) with 403 Forbidden.


TLS / Reverse proxy

Self-signed certificate (development)

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

Update config.yaml:

tls:
  enabled: true
  cert_file: cert.pem
  key_file:  key.pem
dav.example.com {
    reverse_proxy localhost:8080
}

Configuration reference

server:
  host: "0.0.0.0"
  port: 8080
  base_url: "https://dav.example.com"   # used in DAV responses

auth:
  realm: "My DAV Server"

storage:
  data_dir: "./data"   # all user data lives here

logging:
  level: "info"    # debug | info | warn | error
  format: "text"   # text | json

tls:
  enabled: false
  cert_file: ""
  key_file:  ""

users:
  <username>:
    password: "<bcrypt hash>"
    display_name: "Full Name"
    email: "user@example.com"
    calendars:       # pre-created calendar names
      - personal
    address_books:   # pre-created address book names
      - contacts

Project layout

caldav-server/
├── cmd/server/          # main entrypoint
├── internal/
│   ├── auth/            # HTTP Basic Auth middleware
│   ├── caldav/          # CalDAV backend
│   ├── carddav/         # CardDAV backend
│   ├── config/          # YAML config loader
│   ├── db/              # SQLite store (calendar/address book shares)
│   ├── store/           # filesystem storage layer
│   └── webdav/          # WebDAV file handler
├── tools/hashpwd/       # bcrypt password hasher CLI
├── config.example.yaml  # sample configuration (copy to config.yaml)
├── Dockerfile
├── docker-compose.yaml
└── Makefile

Running tests

make test
# or
go test ./... -race

Dependencies

Package Purpose
github.com/emersion/go-webdav WebDAV/CalDAV/CardDAV protocol layer
github.com/emersion/go-ical iCalendar parsing/serialisation
github.com/emersion/go-vcard vCard parsing/serialisation
golang.org/x/crypto bcrypt
golang.org/x/net golang.org/x/net/webdav
gopkg.in/yaml.v3 YAML config parsing
modernc.org/sqlite Pure-Go SQLite driver (calendar/address book shares)
S
Description
No description provided
Readme AGPL-3.0
826 KiB
v2026.9.2
Latest
2026-09-08 20:21:01 +00:00
Languages
Go 82.1%
templ 12.8%
JavaScript 2.3%
TypeScript 2.1%
Makefile 0.4%
Other 0.3%