Docker setup #2

merged
opened by baileytownsend.dev targeting main from feature/DockerSetup
+4
.dockerignore
···
+
target
+
/target
+
**/.idea
+
.idea
+1 -4
src/oauth_provider.rs
···
"Invalid identifier or password",
),
AuthResult::TwoFactorRequired(masked_email) => {
-
// Email sending step can be handled here if needed in the future.
-
-
// {"error":"second_authentication_factor_required","error_description":"emailOtp authentication factor required (hint: 2***0@p***m)","type":"emailOtp","hint":"2***0@p***m"}
let body_str = match serde_json::to_string(&serde_json::json!({
"error": "second_authentication_factor_required",
"error_description": format!("emailOtp authentication factor required (hint: {})", masked_email),
···
},
Err(err) => {
log::error!(
-
"Error during pre-auth check. This happens on the create_session endpoint when trying to decide if the user has access:\n {err}"
+
"Error during pre-auth check. This happens on the oauth signin endpoint when trying to decide if the user has access:\n {err}"
);
oauth_json_error_response(
StatusCode::BAD_REQUEST,
+5 -1
Cargo.toml
···
hex = "0.4"
jwt-compact = { version = "0.8.0", features = ["es256k"] }
scrypt = "0.11"
-
lettre = { version = "0.11.18", features = ["tokio1", "pool", "tokio1-native-tls"] }
+
#lettre = { version = "0.11.18", default-features = false, features = ["pool", "tokio1-rustls", "smtp-transport", "hostname", "builder"] }
+
#lettre = { version = "0.11", default-features = false, features = ["builder", "webpki-roots", "rustls", "aws-lc-rs", "smtp-transport", "tokio1", "tokio1-rustls"] }
+
aws-lc-rs = "1.13.0"
+
lettre = { version = "0.11", default-features = false, features = ["builder", "webpki-roots", "rustls", "aws-lc-rs", "smtp-transport", "tokio1", "tokio1-rustls"] }
+
rustls = { version = "0.23", default-features = false, features = ["tls12", "std", "logging", "aws_lc_rs"] }
handlebars = { version = "6.3.2", features = ["rust-embed"] }
rust-embed = "8.7.2"
axum-template = { version = "3.0.0", features = ["handlebars"] }
+79 -15
README.md
···
# Setup
-
We are getting close! Testing now
-
-
Nothing here yet! If you are brave enough to try before full release, let me know and I'll help you set it up.
-
But I want to run it locally on my own PDS first to test run it a bit.
-
-
Example Caddyfile (mostly so I don't lose it for now. Will have a better one in the future)
+
PDS Gatekeeper has 2 parts to its setup, docker compose file and a reverse proxy (Caddy in this case). I will be
+
assuming you setup the PDS following the directions
+
found [here](https://atproto.com/guides/self-hosting), but if yours is different, or you have questions, feel free to
+
let
+
me know, and we can figure it out.
+
+
## Docker compose
+
+
The pds gatekeeper container can be found on docker hub under the name `fatfingers23/pds_gatekeeper`. The container does
+
need access to the `/pds` root folder to access the same db's as your PDS. The part you need to add would look a bit
+
like below. You can find a full example of what I use for my pds at [./examples/compose.yml](./examples/compose.yml).
+
This is usually found at `/pds/compose.yaml`on your PDS>
+
+
```yml
+
gatekeeper:
+
container_name: gatekeeper
+
image: fatfingers23/pds_gatekeeper:arm-latest
+
network_mode: host
+
restart: unless-stopped
+
#This gives the container to the access to the PDS folder. Source is the location on your server of that directory
+
volumes:
+
- type: bind
+
source: /pds
+
target: /pds
+
depends_on:
+
- pds
+
```
+
+
## Caddy setup
+
+
For the reverse proxy I use caddy. This part is what overwrites the endpoints and proxies them to PDS gatekeeper to add
+
in extra functionality. The main part is below, for a full example see [./examples/Caddyfile](./examples/Caddyfile).
+
This is usually found at `/pds/caddy/etc/caddy/Caddyfile` on your PDS.
```caddyfile
-
http://localhost {
-
@gatekeeper {
-
path /xrpc/com.atproto.server.getSession
-
path /xrpc/com.atproto.server.updateEmail
-
path /xrpc/com.atproto.server.createSession
-
path /@atproto/oauth-provider/~api/sign-in
+
path /xrpc/com.atproto.server.getSession
+
path /xrpc/com.atproto.server.updateEmail
+
path /xrpc/com.atproto.server.createSession
+
path /@atproto/oauth-provider/~api/sign-in
}
handle @gatekeeper {
-
reverse_proxy http://localhost:8080
+
reverse_proxy http://localhost:8080
}
-
reverse_proxy /* http://localhost:3000
+
reverse_proxy http://localhost:3000
+
```
+
+
If you use a cloudflare tunnel then your caddyfile would look a bit more like below with your tunnel proxying to
+
`localhost:8081` (or w/e port you want).
+
+
```caddyfile
+
http://*.localhost:8082, http://localhost:8082 {
+
@gatekeeper {
+
path /xrpc/com.atproto.server.getSession
+
path /xrpc/com.atproto.server.updateEmail
+
path /xrpc/com.atproto.server.createSession
+
path /@atproto/oauth-provider/~api/sign-in
+
}
+
+
handle @gatekeeper {
+
reverse_proxy http://localhost:8080
+
}
+
+
reverse_proxy http://localhost:3000
}
-
```
+
```
+
+
# Environment variables and bonuses
+
+
Every environment variable can be set in the `pds.env` and shared between PDS and gatekeeper and the PDS, with the
+
exception of `PDS_ENV_LOCATION`. This can be set to load the pds.env, by default it checks `/pds/pds.env` and is
+
recommended to mount the `/pds` folder on the server to `/pds` in the pds gatekeeper container.
+
+
`PDS_DATA_DIRECTORY` - Root directory of the PDS. Same as the one found in `pds.env` this is how pds gatekeeper knows
+
knows the rest of the environment variables.
+
+
`GATEKEEPER_EMAIL_TEMPLATES_DIRECTORY` - The folder for templates of the emails PDS gatekeeper sends. You can find them
+
in [./email_templates](./email_templates). You are free to edit them as you please and set this variable to a location
+
in the pds gateekeper container and it will use them in place of the default ones. Just make sure ot keep the names the
+
same.
+
+
`PDS_BASE_URL` - Base url of the PDS. You most likely want `https://localhost:3000` which is also the default
+
+
`GATEKEEPER_HOST` - Host for pds gatekeeper. Defaults to `127.0.0.1`
+
+
`GATEKEEPER_PORT` - Port for pds gatekeeper. Defaults to `8080`
+29
examples/Caddyfile
···
+
{
+
email youremail@myemail.com
+
on_demand_tls {
+
ask http://localhost:3000/tls-check
+
}
+
}
+
+
*.yourpds.com, yourpds.com {
+
tls {
+
on_demand
+
}
+
# You'll most likely just want from here to....
+
@gatekeeper {
+
path /xrpc/com.atproto.server.getSession
+
path /xrpc/com.atproto.server.updateEmail
+
path /xrpc/com.atproto.server.createSession
+
path /@atproto/oauth-provider/~api/sign-in
+
}
+
+
handle @gatekeeper {
+
#This is the address for PDS gatekeeper, default is 8080
+
reverse_proxy http://localhost:8080
+
}
+
+
reverse_proxy http://localhost:3000
+
#..here. Copy and paste this replacing the reverse_proxy http://localhost:3000 line
+
}
+
+
+51
examples/compose.yml
···
+
version: '3.9'
+
services:
+
caddy:
+
container_name: caddy
+
image: caddy:2
+
network_mode: host
+
depends_on:
+
- pds
+
restart: unless-stopped
+
volumes:
+
- type: bind
+
source: /pds/caddy/data
+
target: /data
+
- type: bind
+
source: /pds/caddy/etc/caddy
+
target: /etc/caddy
+
pds:
+
container_name: pds
+
image: ghcr.io/bluesky-social/pds:0.4
+
network_mode: host
+
restart: unless-stopped
+
volumes:
+
- type: bind
+
source: /pds
+
target: /pds
+
env_file:
+
- /pds/pds.env
+
watchtower:
+
container_name: watchtower
+
image: containrrr/watchtower:latest
+
network_mode: host
+
volumes:
+
- type: bind
+
source: /var/run/docker.sock
+
target: /var/run/docker.sock
+
restart: unless-stopped
+
environment:
+
WATCHTOWER_CLEANUP: true
+
WATCHTOWER_SCHEDULE: "@midnight"
+
gatekeeper:
+
container_name: gatekeeper
+
image: fatfingers23/pds_gatekeeper:arm-latest
+
network_mode: host
+
restart: unless-stopped
+
#This gives the container to the access to the PDS folder. Source is the location on your server of that directory
+
volumes:
+
- type: bind
+
source: /pds
+
target: /pds
+
depends_on:
+
- pds