Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# On a server never keep these values: choose your own password and tokens (`openssl rand -hex 32`).

# Log in with these while there is no admin to set up the first one (email and own password); ignored after.
ADMIN_EMAIL=admin
ADMIN_PASSWORD=admin-password
ADMIN_EMAIL=exceptic
ADMIN_PASSWORD=exceptic
# Sign in with Google: an OAuth client with the redirect URI <PUBLIC_URL>/auth/google/callback (needs PUBLIC_URL).
# GOOGLE_CLIENT_ID=
# GOOGLE_CLIENT_SECRET=
Expand All @@ -17,6 +17,11 @@ API_TOKEN=local-development-token-0123456789
# TRUSTED_PROXIES=127.0.0.1 # reverse proxies, comma-separated, whose X-Forwarded-For/-Proto are believed
# LOG_LEVEL=debug

# make dev only (needs systemd): run the server within a container's limits, as --cpus/--memory do.
# The server sizes its memory and its queue by them. Unset: no limits.
# DEV_CPUS=1
# DEV_MEMORY=512M

# Email notifications (Mailtrap's sandbox for testing).
# SMTP_HOST=sandbox.smtp.mailtrap.io
# SMTP_PORT=2525
Expand Down
6 changes: 3 additions & 3 deletions CLAUDE.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ Your apps send errors and logs with the official Sentry SDKs: just give the SDK
<!-- docker-run -->
```sh
docker run -d --name exceptic -p 8000:8000 -v exceptic-data:/data --memory 512m --stop-timeout 30 \
-e ADMIN_PASSWORD='<at least 12 characters>' \
devforth/exceptic:latest
```

Open http://localhost:8000 and log in as `admin` with that password, then set up the first admin with your email and a password of your own. On the **Projects** page add a project and copy its DSN.
Open http://localhost:8000 and log in as `exceptic` with the password `exceptic`, then set up the first admin with your email and a password of your own. On the **Projects** page add a project and copy its DSN.
<!-- /docker-run -->

For a server use [compose.yml](compose.yml) behind HTTPS: [Deployment](docs/deployment.md).
Expand Down
2 changes: 1 addition & 1 deletion cmd/exceptic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func resetPassword(args []string) error {
case err != nil:
return err
case len(admins) == 0:
return errors.New("no admin yet: set ADMIN_PASSWORD, start the server and log in with ADMIN_EMAIL and it to set one up")
return errors.New("no admin yet: start the server and log in with ADMIN_EMAIL and ADMIN_PASSWORD to set one up")
case len(admins) > 1:
return fmt.Errorf("%d admins: name the one, exceptic reset-password <email>", len(admins))
}
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Projects are added on the Projects page (or by a coding agent with `create_proje

| Variable | Default | |
|---|---|---|
| `ADMIN_EMAIL` | `admin` | Login for setting up the first admin: an email, up to 254 characters. |
| `ADMIN_PASSWORD` | | 12 to 256 characters. While there is no admin, log in with `ADMIN_EMAIL` and this password to create the first admin with your own email and password. After that both are ignored. |
| `ADMIN_EMAIL` | `exceptic` | Login for setting up the first admin: an email, up to 254 characters. |
| `ADMIN_PASSWORD` | `exceptic` | Any password up to 256 characters. While there is no admin, log in with `ADMIN_EMAIL` and this password to create the first admin with your own email and password. After that both are ignored. On a server others can reach, set your own: until the first admin exists, whoever logs in with these sets it up. |
| `SESSION_LIFETIME` | `1d` | How long a login lasts. |
| `GOOGLE_CLIENT_ID` | | With `GOOGLE_CLIENT_SECRET` and `PUBLIC_URL`: [Sign in with Google](deployment.md#sign-in-with-google). |
| `GOOGLE_CLIENT_SECRET` | | The secret of that Google client. |
Expand Down
15 changes: 8 additions & 7 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Image tags: `latest` (newest release), `X.Y` (newest patch of a minor version),
<!-- minimal-env -->
```sh
PUBLIC_URL=https://errors.example.com
ADMIN_PASSWORD=<at least 12 characters>
ADMIN_PASSWORD=<your password>
SECRET_KEY=<openssl rand -hex 32> # encrypts chat tokens; generated into /data when not set
```
<!-- /minimal-env -->

With an `https://` `PUBLIC_URL` the login works only over HTTPS: set up the proxy first ([HTTPS and a reverse proxy](#https-and-a-reverse-proxy)). To try it on plain http, use `PUBLIC_URL=http://<server>:8000` and publish `"8000:8000"`.

3. Run `docker compose up -d`, open `https://errors.example.com` and log in as `admin`. The password is `ADMIN_PASSWORD`. A form opens where you create the first admin with your email and your own password.
3. Run `docker compose up -d`, open `https://errors.example.com` and log in as `exceptic`. The password is `ADMIN_PASSWORD`. A form opens where you create the first admin with your email and your own password.
4. On the **Projects** page add a project and give its DSN to your app: [Connecting apps](sdk.md).

The container runs as an unprivileged user (uid 65534). A bind-mounted data folder must be writable by it: `sudo chown 65534:65534 ./data`. A named volume, as in the example, needs nothing.
Expand Down Expand Up @@ -90,13 +90,14 @@ server {

Give the container 512 MB: `compose.yml` sets `mem_limit: 512m`, with `docker run` add `--memory 512m`. The server sizes its memory and its queue by that limit, and needs no more; without a limit it keeps to a smaller default whatever the machine has ([`GOMEMLIMIT`](configuration.md#server), [Ingest](configuration.md#ingest)).

How much the server can take at most, by CPU, in a 512 MB container: the most errors it stored while 10 processes of the official Node.js SDK sent them without pause. Each error was about 16 KB (a stack trace, 10 breadcrumbs, user, tags). Normal use is far below this.
How much the server can store at most, by CPU, in a 512 MB container: the most errors a minute it kept storing for 10 minutes without falling behind. Each error was about 16 KB (a stack trace with source, 10 breadcrumbs, user, tags, request). This is close to the worst case: 3 in 4 errors were new. Repeated errors cost less: an issue stores up to 10 of its errors a minute and only counts the rest.

| CPU | 2 | 4 |
| CPU | 1 | 2 |
|---|---|---|
| Errors a minute, all projects together | 35,600 | 54,100 |
| Data a minute | 555 MB | 845 MB |
| A full database, the cleanup deleting meanwhile | 19,900 errors, 310 MB | 31,500 errors, 490 MB |
| Errors a minute, all projects together | 20,000 | 40,000 |
| Data a minute | 315 MB | 630 MB |

Memory does not change these numbers: with 1 CPU, 256 MB stored as much as 512 MB. It matters once the database is full and the cleanup compacts it: writes wait meanwhile and envelopes are held in memory, so a smaller container refuses sooner ([Ingest](configuration.md#ingest)).

Logs sent along take their share: with 5 logs per error, about a quarter fewer errors.

Expand Down
5 changes: 2 additions & 3 deletions docs/dockerhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ Source and full documentation: https://github.com/devforth/exceptic
<!-- docker-run: copied from README.md by make api-types -->
```sh
docker run -d --name exceptic -p 8000:8000 -v exceptic-data:/data --memory 512m --stop-timeout 30 \
-e ADMIN_PASSWORD='<at least 12 characters>' \
devforth/exceptic:latest
```

Open http://localhost:8000 and log in as `admin` with that password, then set up the first admin with your email and a password of your own. On the **Projects** page add a project and copy its DSN.
Open http://localhost:8000 and log in as `exceptic` with the password `exceptic`, then set up the first admin with your email and a password of your own. On the **Projects** page add a project and copy its DSN.
<!-- /docker-run -->

For a server use Docker Compose behind HTTPS: [compose.yml](https://github.com/devforth/exceptic/blob/main/compose.yml) with an `.env` next to it:

<!-- minimal-env: copied from docs/deployment.md by make api-types -->
```sh
PUBLIC_URL=https://errors.example.com
ADMIN_PASSWORD=<at least 12 characters>
ADMIN_PASSWORD=<your password>
SECRET_KEY=<openssl rand -hex 32> # encrypts chat tokens; generated into /data when not set
```
<!-- /minimal-env -->
Expand Down
10 changes: 4 additions & 6 deletions docs/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestDocsValues(t *testing.T) {
value{Phrase: "| `GOMEMLIMIT` | {}% of the", Value: config.ContainerMemoryPercent},
value{Phrase: "memory limit, else `{}MiB` |", Value: config.DefaultMemoryLimit >> 20},
value{Phrase: "| `ADMIN_EMAIL` | `{}` |", Value: config.DefaultAdminEmail},
value{Phrase: "| `ADMIN_PASSWORD` | | {} to ", Value: config.MinPasswordLength},
value{Phrase: " to {} characters. While there is no admin", Value: config.MaxPasswordLength},
value{Phrase: "| `ADMIN_PASSWORD` | `{}` |", Value: config.DefaultAdminPassword},
value{Phrase: "| Any password up to {} characters.", Value: config.MaxPasswordLength},
value{Phrase: "| `SESSION_LIFETIME` | `{}` |", Value: days(config.DefaultSessionLifetime)},
value{Phrase: "REST API](api.md), at least {} characters", Value: config.MinAPITokenLength},
value{Phrase: "| `RATE_LIMIT_EVENTS_PER_MINUTE` | `{}` |", Value: config.DefaultRateLimitEventsPerMinute},
Expand Down Expand Up @@ -122,7 +122,6 @@ func TestDocsValues(t *testing.T) {
value{Phrase: "files of {} MB (`json-file`)", Value: logSize},
value{Phrase: "`--log-opt max-size={}m ", Value: logSize},
value{Phrase: "--log-opt max-file={}`", Value: logFiles},
value{Phrase: "ADMIN_PASSWORD=<at least {} characters>", Value: config.MinPasswordLength},
value{Phrase: "open `https://errors.example.com` and log in as `{}`.", Value: config.DefaultAdminEmail},
value{Phrase: "request bodies up to {} MB", Value: ingest.MaxBodyBytes >> 20},
value{Phrase: "max_size {}MB", Value: ingest.MaxBodyBytes >> 20},
Expand All @@ -147,13 +146,12 @@ func TestDocsValues(t *testing.T) {
)

fixtures.DocValues(t, "README.md",
value{Phrase: "ADMIN_PASSWORD='<at least {} characters>'", Value: config.MinPasswordLength},
value{Phrase: "log in as `{}` with that password", Value: config.DefaultAdminEmail},
value{Phrase: "log in as `{}` with the password", Value: config.DefaultAdminEmail},
value{Phrase: "with the password `{}`, then", Value: config.DefaultAdminPassword},
value{Phrase: "--stop-timeout {} \\", Value: grace},
value{Phrase: "--memory {}m --stop-timeout", Value: memory},
)
fixtures.DocValues(t, "skills/exceptic/SKILL.md",
value{Phrase: "`ADMIN_PASSWORD` ({}+ characters)", Value: config.MinPasswordLength},
value{Phrase: "Tell the user to log in as `{}`", Value: config.DefaultAdminEmail},
value{Phrase: "sends only `{}`, so", Value: notifyLevels},
)
Expand Down
18 changes: 1 addition & 17 deletions internal/api/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestUILoginRedirectStaysOnSite(t *testing.T) {
var state api.LoginState

if err := json.Unmarshal(server.browser().call(http.MethodGet, "login_state?next=/logs", nil).Body.Bytes(), &state); err != nil ||
state.Redirect != "" || state.Disabled != "" || state.AppName != server.app.Services.AppName {
state.Redirect != "" || state.AppName != server.app.Services.AppName {
t.Errorf("login_state without a session: %+v", state)
}
}
Expand Down Expand Up @@ -539,22 +539,6 @@ func TestUISecureCookiesFromPublicURL(t *testing.T) {
}
}

// Without an admin nobody can log in; the login page says why.
func TestUIDisabledWithoutPassword(t *testing.T) {
server := startLoginServer(t, storetest.Open(t), "admin", "")
client := server.browser()

var state api.LoginState

if err := json.Unmarshal(client.call(http.MethodGet, "login_state", nil).Body.Bytes(), &state); err != nil || !strings.Contains(state.Disabled, "ADMIN_PASSWORD") {
t.Fatalf("login_state: %+v %v", state, err)
}

if response := client.login("admin", ""); response.Code != http.StatusServiceUnavailable || !strings.Contains(response.Body.String(), "ADMIN_PASSWORD") {
t.Fatalf("login: %d %s", response.Code, response.Body)
}
}

// Sessions survive restarts, and a restart with any ADMIN_EMAIL and
// ADMIN_PASSWORD creates no user once an admin exists.
func TestUISessionsSurviveRestart(t *testing.T) {
Expand Down
18 changes: 1 addition & 17 deletions internal/api/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ type LoginStateInput struct {
// LoginState is what the login page shows; Redirect (a local path) when the
// browser is logged in already.
type LoginState struct {
AppName string `json:"app_name"`
// Disabled says why nobody can log in (no ADMIN_PASSWORD); empty otherwise.
Disabled string `json:"disabled,omitempty"`
AppName string `json:"app_name"`
Redirect string `json:"redirect,omitempty"`
// Google: the page offers to sign in with Google.
Google bool `json:"google,omitempty"`
Expand Down Expand Up @@ -92,9 +90,6 @@ type PersonalToken struct {
// wrongLogin is the answer to a wrong password and to an unknown email alike.
const wrongLogin = "Wrong email or password."

// loginDisabled is why nobody can log in to a server without an admin.
const loginDisabled = "The web UI is disabled: set ADMIN_PASSWORD to enable it."

// LoginRequests are the handlers of the login's plain requests (login_state,
// login, setup_admin, logout, change_password) for NewUI. Every password check goes
// through auth, so the login's limits apply to each.
Expand All @@ -107,10 +102,6 @@ func LoginRequests(logger *slog.Logger, auth *session.Auth, appName string) map[
"login_state": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
state := LoginState{AppName: appName, Google: auth.GoogleEnabled()}

if auth.Disabled(r.Context()) {
state.Disabled = loginDisabled
}

// Logged in already: straight on.
if _, ok := auth.SessionUser(r); ok {
state.Redirect = server.SafeNext(r.URL.Query().Get("next"))
Expand All @@ -126,13 +117,6 @@ func LoginRequests(logger *slog.Logger, auth *session.Auth, appName string) map[
return
}

// Not a refusal of this user: the server has none yet.
if auth.Disabled(r.Context()) {
server.JSONError(w, http.StatusServiceUnavailable, loginDisabled)

return
}

result, err := auth.Login(w, r, input.Email, input.Password)

switch {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestSetupAdmin(t *testing.T) {

var state api.LoginState

if err := json.Unmarshal(client.call(http.MethodGet, "login_state", nil).Body.Bytes(), &state); err != nil || state.Disabled != "" {
if err := json.Unmarshal(client.call(http.MethodGet, "login_state", nil).Body.Bytes(), &state); err != nil || state.AppName == "" {
t.Fatalf("login_state: %+v %v", state, err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func New(ctx context.Context, options Options) (*App, error) {
})

// Nothing creates users at start: the first admin is set up on the login page.
if err := all.Users.LogSetup(ctx, settings.AdminPassword); err != nil {
if err := all.Users.LogSetup(ctx); err != nil {
_ = notifier.Close(ctx)

return nil, err
Expand Down
16 changes: 9 additions & 7 deletions internal/platform/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ func validAdminEmail(value string) bool {
return isEmail || (len(value) <= MaxEmail && adminLoginRe.MatchString(value))
}

// ValidPasswordLength is the length rule of every password, ADMIN_PASSWORD
// included, in characters.
// ValidPasswordLength is the length rule of every user's password, in characters.
func ValidPasswordLength(password string) bool {
length := utf8.RuneCountInString(password)

Expand Down Expand Up @@ -179,8 +178,7 @@ type Config struct {
TrustedProxies Proxies
// AdminEmail and AdminPassword, typed on the login page while there is
// no admin, open the form that sets up the first one; later they are not
// used. AdminEmail is the login as typed, an email or not. An empty
// password keeps the UI closed until then.
// used. AdminEmail is the login as typed, an email or not.
AdminEmail string
AdminPassword string
// SessionLifetime (SESSION_LIFETIME) is how long a UI login lasts; it
Expand Down Expand Up @@ -208,7 +206,9 @@ const (
SDKLogBatch = 100
DefaultMemoryLimit = 200 << 20 // GOMEMLIMIT outside a container with a memory limit

DefaultAdminEmail = "admin"
// The login that opens the first admin's setup, unless ADMIN_EMAIL and ADMIN_PASSWORD are set.
DefaultAdminEmail = "exceptic"
DefaultAdminPassword = "exceptic"

DefaultSessionLifetime = 24 * time.Hour

Expand Down Expand Up @@ -254,6 +254,7 @@ func loadFrom(getenv func(string) string) (*Config, error) {
RateLimitEventsPerMinute: DefaultRateLimitEventsPerMinute,
RateLimitLogsPerMinute: DefaultRateLimitLogsPerMinute,
AdminEmail: DefaultAdminEmail,
AdminPassword: DefaultAdminPassword,
SessionLifetime: DefaultSessionLifetime,
}

Expand Down Expand Up @@ -324,8 +325,9 @@ func loadFrom(getenv func(string) string) (*Config, error) {
}

if value := getenv("ADMIN_PASSWORD"); value != "" {
if !ValidPasswordLength(value) {
return nil, fmt.Errorf("ADMIN_PASSWORD: must be %d to %d characters", MinPasswordLength, MaxPasswordLength)
// Any length: it only opens the first admin's setup, whose own password follows the rules.
if utf8.RuneCountInString(value) > MaxPasswordLength {
return nil, fmt.Errorf("ADMIN_PASSWORD: at most %d characters", MaxPasswordLength)
}

config.AdminPassword = value
Expand Down
14 changes: 11 additions & 3 deletions internal/platform/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestLoadDefaults(t *testing.T) {

if config.Port != DefaultPort || config.DataDir != DefaultDataDir || config.LogLevel != DefaultLogLevel || config.APIToken != "" || config.AllowedIPs != nil ||
config.RateLimitEventsPerMinute != 10000 || config.RateLimitLogsPerMinute != 10000 ||
config.AdminEmail != DefaultAdminEmail || config.AdminPassword != "" || config.SessionLifetime != 24*time.Hour {
config.AdminEmail != DefaultAdminEmail || config.AdminPassword != DefaultAdminPassword || config.SessionLifetime != 24*time.Hour {
t.Fatalf("unexpected defaults: %+v", config)
}
}
Expand Down Expand Up @@ -133,8 +133,7 @@ func TestLoadErrors(t *testing.T) {
{"negative events rate limit", "RATE_LIMIT_EVENTS_PER_MINUTE", "-1", "RATE_LIMIT_EVENTS_PER_MINUTE"},
{"bad logs rate limit", "RATE_LIMIT_LOGS_PER_MINUTE", "10k", "RATE_LIMIT_LOGS_PER_MINUTE"},
{"short api token", "API_TOKEN", "secret", "at least"},
{"short admin password", "ADMIN_PASSWORD", "short-pass", "12 to 256"},
{"long admin password", "ADMIN_PASSWORD", strings.Repeat("p", MaxPasswordLength+1), "12 to 256"},
{"long admin password", "ADMIN_PASSWORD", strings.Repeat("p", MaxPasswordLength+1), "at most 256"},
{"admin email with a space", "ADMIN_EMAIL", "john doe", "ADMIN_EMAIL"},
{"long admin email", "ADMIN_EMAIL", strings.Repeat("a", MaxEmail+1), "ADMIN_EMAIL"},
{"former admin variable with a space", "ADMIN_USERNAME", "john doe", "ADMIN_USERNAME"},
Expand Down Expand Up @@ -254,3 +253,12 @@ func TestAdminEmail(t *testing.T) {
})
}
}

// ADMIN_PASSWORD only opens the first admin's setup, so a short one is accepted.
func TestShortAdminPassword(t *testing.T) {
config, err := loadFrom(env(map[string]string{"ADMIN_EMAIL": "exceptic", "ADMIN_PASSWORD": "exceptic"}))

if err != nil || config.AdminPassword != "exceptic" {
t.Fatalf("config %+v, err %v", config, err)
}
}
4 changes: 1 addition & 3 deletions internal/services/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ func NewUsers(logger *slog.Logger, database store.Store) *Users {
}

// LogSetup says at start, while there is no admin, how to set one up.
func (users *Users) LogSetup(ctx context.Context, adminPassword string) error {
func (users *Users) LogSetup(ctx context.Context) error {
admins, err := users.store.Admins(ctx)

switch {
case err != nil:
return err
case len(admins) > 0:
case adminPassword == "":
users.logger.Warn("no admin yet: set ADMIN_PASSWORD (and ADMIN_EMAIL), the UI is closed until then")
default:
users.logger.Info("no admin yet: log in with ADMIN_EMAIL and ADMIN_PASSWORD to set one up")
}
Expand Down
8 changes: 0 additions & 8 deletions internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,6 @@ func (auth *Auth) waitForCheck(ctx context.Context, knownDevice bool) (done func
}
}

// Disabled: there is no admin yet and no ADMIN_PASSWORD to set one up
// with, so nobody can log in.
func (auth *Auth) Disabled(ctx context.Context) bool {
open, err := auth.open(ctx)

return err == nil && !open && auth.adminPassword == ""
}

// open reports whether an admin exists.
func (auth *Auth) open(ctx context.Context) (bool, error) {
if auth.opened.Load() {
Expand Down
Loading
Loading