# Bluesky-PDS

Bluesky is an ambitious federated social network initially supported by Twitter, but is an independent public benefit corporation as of 2022 ([Wikipedia](<https://en.wikipedia.org/wiki/Bluesky>))

The network is federated with the ATProtocol, which allows all participating users to communicate through a series of relays, whether their account is "on" the primary bsky.social server, or on their own, independently-managed data server instance.

A Personal Data Server (PDS) is a small server which is the "home" for one or more accounts, and serves to manage all their data storage, "distributing" the data separately from the other components of the network (*relaying, scraping, etc*), and giving users control of the presentation and storage of their data.

[Get a 7-day trial of ElfHosted Bluesky-PDS! 🪄](<https://store.elfhosted.com/product/bluesky-pds/>)

## How do I access Bluesky-PDS?

Bluesky-PDS is available:

- From your dashboard: [https://your-username.elfhosted.com](<https://your-username.elfhosted.com>)
- Directly: [https://your-username-bluesky-pds.elfhosted.com](<https://your-username-bluesky-pds.elfhosted.com>)

> [!NOTE]
>
> **Signed-in users see their own URLs**
>
> The addresses above show the general pattern. [Sign in](<https://docs-internal.elfhosted.com/app/bluesky-pds/>) and these become your personal, clickable links.

> [!WARNING]
>
> **Here be geeks**
>
> The Bluesky PDS stack in ElfHosted is experimental - we built it because we like playing with it. Users should be aware that this is a hosted implementation of the reference design, and while ElfHosted provides the **infrastructure** hosting, we can't provide support for your **use** of PDS outside ensuring that it's running, reachable, backed-up, and secure!

## How to setup PDS

PDS is configured using environment variables. In ElfHosted's configuration, environment variables are created using [ElfBot](<https://docs-internal.elfhosted.com/app/elfbot/>).

### Secure your instance

There are 3 values you need to set to properly secure your instance. Placeholders are configured to allow the app to start without error, but you should replace these and reset all data before continuing.

Values to be configured are:

- `PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX`: Generate a suitable value with openssl
- `PDS_JWT_SECRET`: use a strong password
- `PDS_ADMIN_PASSWORD`: use a strong password

The values can be applied using ElfBot, as follows:

Quick-paste into BlueSky PDS's environment variables using ElfBot

```
PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX=bb1ed941a5a004f007441bd5bb297002f4e533fadba48e429f8350249315cf0c
PDS_JWT_SECRET=changemeelfie
PDS_ADMIN_PASSWORD=changemeelfie
```

After setting all 3 values, remove any existing databases / config, by doing a reset on BlueSky PDS, using ElfBot

### Setup email

Your PDS instance will need to be able to send emails in order to validate accounts (*unless you do some dirty log-file scraping*), so before creating an account, ensure that you've setup email per [the documentation](<https://github.com/bluesky-social/pds?tab=readme-ov-file#setting-up-smtp>)

> [!NOTE]
>
> **Port 25 and 465 are blocked**
>
> Our datacenter blocks egress access on ports `25` and `465`, so ensure that your email configuration uses alternate ports. In the MailGun example below, port `587` works!

The following example sets:

- SMTP username: `bsky@mg.example.com` (*URL-encode @ signs if your username includes it*)
- SMTP password: `password`
- SMTP protocol: `smtp` (*not smtps, since we're using port 587*)
- SMTP host: `smtp.mailgun.org`
- SMTP port: `587`
- SMTP from address: `bsky@mg.example.com` (*same in this case but yours may be different*)

Quick-paste into BlueSky PDS's environment variables using ElfBot

```
PDS_EMAIL_SMTP_URL=smtp://bsky%40mg.example.com:password@smtp.mailgun.org:587
PDS_EMAIL_FROM_ADDRESS=bsky@mg.example.com
```

Paste each elfbot command in, one-at-a-time. PDS will restart after each entry.

### Create account

The `pdsadmin` tool is included in the PDS CLI, linked to your ElfHosted dashboard.

From the CLI, run `pdsadmin account create` to create your first account, and note the resulting identity, password, and DID.

Example account creation

```
> pdsadmin account create
Enter an email address (e.g. alice@youruser-bluesky-pds.elfhosted.com): alice@youruser-bluesky-pds.elfhosted.com
Enter a handle (e.g. alice.youruser-bluesky-pds.elfhosted.com): alice.youruser-bluesky-pds.elfhosted.com

Account created successfully!
-----------------------------
Handle   : alice.youruser-bluesky-pds.elfhosted.com
DID      : did:plc:ru2ohvq7uu3l5bhh5yx3mkvy
Password : <redacted>
-----------------------------
Save this password, it will not be displayed again.

elfie@youruser-blueskypds-664564cd86-hmkq6 ~>
```

### Change identifier

Your DID is your unique identifier on the Bluesky network, but you'll want to setup your "handle", which is easier to remember, looks better, and can be changed without changing your DID.

Your handle can be any supported hostname, separate from your PDS server URL.

You'll need your own domain name for this part - your [identity needs to be a valid hostname](<https://atproto.com/specs/handle>), and you need to "prove" this by either a DNS TXT entry, or a .well-known HTTP path.

The only supported method within the ElfHosted infrastruture is a DNS entry, so for every identity your PDS hosts, you need to create a TXT record `_atproto.<your identifier>`, with a value of `did=<your did>`. For example:

```
_atproto.batman.batcave.org: did=did:plc:z72i7hdynmk6r22z27h6tvur
```

Confirm the TXT record is created successfully using `dig txt +short <DNS recrod>`, as illustrated below:

```
dig txt +short _atproto.batman.batcave.org                                  
"did=did:plc:ru2ohvq7uu3l5bhh5yx3mkvy"
~ ❯
```

Once the DNS entry is added, either wait for the bluesky infrastruture to recognize the update, or try to force it using `pdsadmin request-crawl bsky.network` in the CLI.

### Setup object storage

> [!NOTE]
>
> **Why use object storage?**
>
> You may want to migrate your PDS off of ElfHosted in the future. Although you **could** simply store all your media content within your ElfHosted `/config` storage, this can (1) run out of space, and (2) be slow and time-consuming to relocate if you migrate. If you configure PDS for object storage however, then all the media is **already** on object storage under your control, and doesn't need to be migrated alongside your databases / account data.

PDS can use either local storage or S3 storage, but it won't do both, so in order to use object storage, you need to disable local storage, by setting `PDS_BLOBSTORE_DISK_LOCATION` to null, using `PDS_BLOBSTORE_DISK_LOCATION=`

Then apply the following with your own object storage config, to transition to object storage:

Quick-paste into BlueSky PDS's environment variables using ElfBot

```
PDS_BLOBSTORE_DISK_LOCATION=''
PDS_BLOBSTORE_S3_BUCKET=bucket_name
PDS_BLOBSTORE_S3_REGION=us-east-1
PDS_BLOBSTORE_S3_ENDPOINT=https://s3.us-east-1.amazonaws.com
PDS_BLOBSTORE_S3_FORCE_PATH_STYLE=true
PDS_BLOBSTORE_S3_ACCESS_KEY_ID=secret
PDS_BLOBSTORE_S3_SECRET_ACCESS_KEY=secret
```

### Logs

PDS is configured by default with `LOGS_ENABLED=true`, so in order to see what it's doing, simply using Kubernetes Dashboard to watch the logs of your bluesky-pds pod.

### Updates

In ElfHosted's environment, PDS updates are automatically grabbed every time a [new PDS release is published](<https://github.com/bluesky-social/atproto/releases?q=pds&amp;expanded=true>), and are rolled out during our daily "elf-glowup" maintenance window.

No manual updating is required.

### Backup / migrate

Your PDS data is stored in `config/bluesky-pds`, and can be backed up either by copying the contents of the folder manually, or with **Backup** in the **...** menu on its card in [ElfBot](<https://docs-internal.elfhosted.com/app/elfbot/>).

## How do I get support for Bluesky-PDS?

1. For general use of Bluesky-PDS, refer to the [official site](<https://github.com/bluesky-social/pds>) or to one of the links in the resources section below.
2. For specific support re your ElfHosted configuration / account, see the [ElfHosted support options](</get-help/>)!

## Bluesky-PDS resources

- [Bluesky-PDS (*official site*)](<https://github.com/bluesky-social/pds>)
- [Bluesky-PDS GitHub](<https://github.com/bluesky-social/pds>)
- [Bluesky-PDS AT Protocol PDS Admins Discord](<https://discord.gg/e7hpHxRfBP>)
