Cocoon is a PDS implementation in Go.
- Docker and Docker Compose installed
- A domain name pointing to your server (for automatic HTTPS)
- Ports 80 and 443 open in i.e. UFW
-
Clone the repository
git clone https://github.com/haileyok/cocoon.git cd cocoon -
Create your configuration file
cp .env.example .env
-
Edit
.envwith your settingsRequired settings:
COCOON_DID="did:web:your-domain.com" COCOON_HOSTNAME="your-domain.com" COCOON_CONTACT_EMAIL="you@example.com" COCOON_RELAYS="https://bsky.network" # Generate with: openssl rand -hex 16 COCOON_ADMIN_PASSWORD="your-secure-password" # Generate with: openssl rand -hex 32 COCOON_SESSION_SECRET="your-session-secret"
-
Start the services
# Pull pre-built image from GitHub Container Registry docker-compose pull docker-compose up -dOr build locally:
docker-compose build docker-compose up -d
For PostgreSQL deployment:
# Add POSTGRES_PASSWORD to your .env file first! docker-compose -f docker-compose.postgres.yaml up -d -
Get your invite code
On first run, an invite code is automatically created. View it with:
docker-compose logs create-invite
Or check the saved file:
cat keys/initial-invite-code.txt
IMPORTANT: Save this invite code! You'll need it to create your first account.
-
Monitor the services
docker-compose logs -f
The Docker Compose setup includes:
- init-keys: Automatically generates cryptographic keys (rotation key and JWK) on first run
- cocoon: The main PDS service running on port 8080
- create-invite: Automatically creates an initial invite code after Cocoon starts (first run only)
- caddy: Reverse proxy with automatic HTTPS via Let's Encrypt
The following directories will be created automatically:
./keys/- Cryptographic keys (generated automatically)rotation.key- PDS rotation keyjwk.key- JWK private keyinitial-invite-code.txt- Your first invite code (first run only)
./data/- SQLite database and blockstore- Docker volumes for Caddy configuration and certificates
By default, Cocoon uses SQLite which requires no additional setup. For production deployments with higher traffic, you can use PostgreSQL:
# Database type: sqlite (default) or postgres
COCOON_DB_TYPE="postgres"
# PostgreSQL connection string (required if db-type is postgres)
# Format: postgres://user:password@host:port/database?sslmode=disable
COCOON_DATABASE_URL="postgres://cocoon:password@localhost:5432/cocoon?sslmode=disable"
# Or use the standard DATABASE_URL environment variable
DATABASE_URL="postgres://cocoon:password@localhost:5432/cocoon?sslmode=disable"For SQLite (default):
COCOON_DB_TYPE="sqlite"
COCOON_DB_NAME="/data/cocoon/cocoon.db"Note: When using PostgreSQL, database backups to S3 are not handled by Cocoon. Use
pg_dumpor your database provider's backup solution instead.
COCOON_ADDR (or --addr) selects the HTTP listener. By default it is the TCP address :8080. To serve on a Unix domain socket instead, prefix the path with unix: — this replaces the TCP listener rather than adding to it, which is useful when a reverse proxy runs on the same host:
COCOON_ADDR="unix:/run/cocoon/cocoon.sock"The socket's parent directory must exist and be writable, and the reverse proxy must have permission to connect to the socket. A stale socket left behind by an unclean shutdown is replaced on startup. A socket that is still in use and an existing regular file at the path are errors.
Note: The bundled Docker Compose files set
COCOON_ADDRto:8080and proxy and health-check over TCP. To use a socket there, overrideCOCOON_ADDR, share a socket directory between the Cocoon and Caddy containers, point Caddy atunix//path/to/socket, and change the health check.
By default, handles live under the hostname (alice.your-domain.com). To use a separate domain for handles:
# Comma-separated, each starting with a dot (default: .<hostname>)
COCOON_HANDLE_DOMAINS=".example.social"Note: The bundled Caddyfiles cover the hostname and
*.<hostname>. For another handle domain, add it to the site address (*.example.social) and point a wildcard DNS record for it at the server.
Note: Handles are verified over HTTPS at
https://<handle>/.well-known/atproto-did, so each handle domain needs a wildcard DNS record pointing at the server, including the default*.<hostname>. The bundled Docker Compose files don't passCOCOON_HANDLE_DOMAINSthrough; add it to thecocoonservice'senvironmentwhen you set it.
COCOON_SMTP_USER="your-smtp-username"
COCOON_SMTP_PASS="your-smtp-password"
COCOON_SMTP_HOST="smtp.example.com"
COCOON_SMTP_PORT="587"
COCOON_SMTP_EMAIL="noreply@example.com"
COCOON_SMTP_NAME="Cocoon PDS"com.atproto.repo.uploadBlob accepts at most 300 MiB (314,572,800 bytes) per
file by default, including requests without a Content-Length header. This
matches the limit the official PDS installer configures, which leaves room for
video uploads forwarded by the video service. Set COCOON_BLOB_UPLOAD_LIMIT or --blob-upload-limit
to a positive byte count to change it; zero uses the default and negative values
are rejected. Larger uploads return BlobTooLarge. This setting does not apply
to Spaces uploads or repository imports.
Uploads spool to temporary files before persistence, so allow temporary disk space for concurrent uploads. Database-backed blob metadata and parts commit together. S3 objects are not deleted on failure: a lost upload or commit acknowledgment could otherwise cause a successful upload to be deleted. Failed S3 publication can therefore leave an unreferenced object. This is not crash-safe cleanup, a total storage quota, or a rate limit.
Cocoon supports S3-compatible storage for both database backups (SQLite only) and blob storage (images, videos, etc.):
# Enable S3 backups (SQLite databases only - hourly backups)
COCOON_S3_BACKUPS_ENABLED=true
# Enable S3 for blob storage (images, videos, etc.)
# When enabled, blobs are stored in S3 instead of the database
COCOON_S3_BLOBSTORE_ENABLED=true
# S3 configuration (works with AWS S3, MinIO, Cloudflare R2, etc.)
COCOON_S3_REGION="us-east-1"
COCOON_S3_BUCKET="your-bucket"
COCOON_S3_ENDPOINT="https://s3.amazonaws.com"
COCOON_S3_ACCESS_KEY="your-access-key"
COCOON_S3_SECRET_KEY="your-secret-key"
# Optional: CDN/public URL for blob redirects
# When set, com.atproto.sync.getBlob redirects to this URL instead of proxying
COCOON_S3_CDN_URL="https://cdn.example.com"Blob Storage Options:
COCOON_S3_BLOBSTORE_ENABLED=false(default): Blobs stored in the databaseCOCOON_S3_BLOBSTORE_ENABLED=true: Blobs stored in S3 bucket underblobs/{did}/{cid}
Blob Serving Options:
- Without
COCOON_S3_CDN_URL: Blobs are proxied through the PDS server - With
COCOON_S3_CDN_URL:getBlobreturns a 302 redirect to{CDN_URL}/blobs/{did}/{cid}
Tip: For Cloudflare R2, you can use the public bucket URL as the CDN URL. For AWS S3, you can use CloudFront or the S3 bucket URL directly if public access is enabled.
Requests forwarded to AppViews, chat services and feed generators must use public destinations. Cocoon blocks private and loopback addresses, including DNS answers and redirect targets, and refuses HTTPS-to-HTTP redirects. Service credentials are removed for the rest of a redirect chain once it changes scheme, host or port.
These requests connect directly, ignoring HTTP_PROXY, HTTPS_PROXY and NO_PROXY. Private-network AppViews are not supported. The configured PLC directory is separate and unchanged. Proxy timeouts remain 20 seconds for response headers and two minutes for the whole request.
OAuth permission-set and Spaces type lookups fetch identity documents and lexicon records directly, without environment proxies. Public fetches require HTTPS, a DNS hostname and port 443; private addresses are blocked even when returned by DNS or reached through a redirect. Identity-document redirects are not followed. Each HTTP request has a ten-second timeout and a 2 MiB response limit, with a thirty-second limit for the full lookup.
Lexicon records must be returned by com.atproto.sync.getRecord with a signed repository commit and an inclusion proof for the requested record. Cocoon checks the signature against the authority's DID signing key, verifies the record's content and NSID, and bounds proof decoding. Unsigned com.atproto.repo.getRecord responses are no longer accepted. A valid proof authenticates a published record; it does not establish that the record is the latest version.
The configured PLC directory remains trusted for direct DID-document requests, so a local PLC still works. This exception does not extend to redirects or the PDS endpoints listed in its documents. Lexicons hosted on private, HTTP, IP-literal or custom-port PDS endpoints cannot be resolved.
Cocoon uses the public PLC directory (https://plc.directory) to create, update, and resolve did:plc identities. You can point it at a different directory, such as a local PLC instance for integration testing, so that test accounts are never registered with the real directory:
COCOON_PLC_URL="http://localhost:2582"Warning: Accounts created against a non-default PLC directory only exist in that directory and will not be resolvable by the wider network. Leave this unset for production deployments.
Accounts can turn on two-factor sign-in with an authenticator app or a YubiKey from /account/2fa. To let people add a YubiKey just by touching it, get a free client ID and API key from Yubico and set:
COCOON_YUBICO_CLIENT_ID="12345"
COCOON_YUBICO_API_KEY="base64-secret-key-from-yubico"YubiKey codes are then checked with Yubico's YubiCloud service at api.yubico.com. If it can't be reached, YubiKey sign-in fails until it's back; authenticator codes and backup codes still work.
Without these settings, a YubiKey must first have a slot programmed with a secret key that the server stores (the setup page gives the ykman command).
The default image is based on Debian. You can use the Alpine-based image if you prefer.
Note
Currently, we do not have pre-built Alpine-based image on the GitHub Container Registry. You have to build them locally.
In the compose file, replace every dockerfile: Dockerfile by dockerfile: Dockerfile.alpine, e.g.
services:
cocoon:
build:
context: .
dockerfile: Dockerfile.alpineYou can also build the image locally with
docker build -f Dockerfile.alpine -t cocoon:alpine .Create an invite code:
docker exec cocoon-pds /cocoon create-invite-code --uses 1Reset a user's password:
docker exec cocoon-pds /cocoon reset-password --did "did:plc:xxx"docker-compose pull
docker-compose up -dNote
Just because something is implemented doesn't mean it is finished. Tons of these are returning bad errors, don't do validation properly, etc. I'll make a "second pass" checklist at some point to do all of that.
-
com.atproto.identity.getRecommendedDidCredentials -
com.atproto.identity.requestPlcOperationSignature -
com.atproto.identity.resolveHandle -
com.atproto.identity.signPlcOperation -
com.atproto.identity.submitPlcOperation -
com.atproto.identity.updateHandle
-
com.atproto.repo.applyWrites -
com.atproto.repo.createRecord -
com.atproto.repo.putRecord -
com.atproto.repo.deleteRecord -
com.atproto.repo.describeRepo -
com.atproto.repo.getRecord -
com.atproto.repo.importRepo(Works "okay". Use with extreme caution.) -
com.atproto.repo.listRecords -
com.atproto.repo.listMissingBlobs
-
com.atproto.server.activateAccount -
com.atproto.server.checkAccountStatus -
com.atproto.server.confirmEmail -
com.atproto.server.createAccount -
com.atproto.server.createInviteCode -
com.atproto.server.createInviteCodes -
com.atproto.server.deactivateAccount -
com.atproto.server.deleteAccount -
com.atproto.server.deleteSession -
com.atproto.server.describeServer -
com.atproto.server.getAccountInviteCodes -
com.atproto.server.getServiceAuth [ ]- not going to add app passwordscom.atproto.server.listAppPasswords-
com.atproto.server.refreshSession -
com.atproto.server.requestAccountDelete -
com.atproto.server.requestEmailConfirmation -
com.atproto.server.requestEmailUpdate -
com.atproto.server.requestPasswordReset -
com.atproto.server.reserveSigningKey -
com.atproto.server.resetPassword []- not going to add app passwordscom.atproto.server.revokeAppPassword-
com.atproto.server.updateEmail
-
com.atproto.sync.getBlob -
com.atproto.sync.getBlocks -
com.atproto.sync.getLatestCommit -
com.atproto.sync.getRecord -
com.atproto.sync.getRepoStatus -
com.atproto.sync.getRepo -
com.atproto.sync.listBlobs -
com.atproto.sync.listRepos [ ]- BGS doesn't even have this implemented lolcom.atproto.sync.notifyOfUpdate-
com.atproto.sync.requestCrawl -
com.atproto.sync.subscribeRepos
Cocoon implements the ATProto Spaces alpha. See docs/spaces.md.
-
com.atproto.space.createRecord,putRecord,deleteRecord,applyWrites,clearRecords -
com.atproto.space.getRecord,listRecords,listRepoOps,getLatestCommit,getRepo,listSpaces -
com.atproto.space.getBlob,listBlobs -
com.atproto.space.getDelegationToken,authorizeSpaceSync,notifyCredentialsRevoked -
com.atproto.space.notifyRepoUpdate,listWriters,removeWriter -
com.atproto.space.createSpace,getSpace,updateSpace,deleteSpace -
com.atproto.space.exportSpaceMeta,importSpaceMeta,importRepo -
com.atproto.memberspace.putMembers,removeMembers,listMembers
-
com.atproto.label.queryLabels -
com.atproto.moderation.createReport(Note: this should be handled by proxying, not actually implemented in the PDS) -
app.bsky.actor.getPreferences -
app.bsky.actor.putPreferences
This project is licensed under MIT license. server/static/pico.css is also licensed under MIT license, available at https://github.com/picocss/pico/.