# Staff auth and Discord

Protect staff accounts with per-login 2FA and forward moderation events to Discord.

Both modules start disabled because they need secrets. Secrets are read from environment variables on the server process, never from YAML, so they don't end up in backups or screenshots of your config.

## Staff Auth

Staff Auth adds a second check every time a protected staff member logs in. Until they verify, GlacierStaff commands, menus and any external admin commands you list are blocked.

### 1. Create the encryption key

Generate 32 secure random bytes, Base64-encode them, and set the result as `GLACIERSTAFF_STAFFAUTH_KEY`:

```bash
openssl rand -base64 32
```

> [!CAUTION]
> **Back up the key and `staffauth/credentials.properties` together.** One without the other can't be used to restore enrolments.

### 2. Choose who's protected

Assign `glacierstaff.staff.staffauth.required` to the roles that need 2FA. It isn't part of `glacierstaff.admin`, so you have to grant it deliberately.

### 3. Enrol with an authenticator app

After confirming the staff member's identity, run at the console:

```text
glacierstaffauth enroll <minecraft-uuid>
```

They then run `/staffauth setup` and confirm the code on their private keypad. On later logins, `/staffauth verify` opens the keypad.

### 4. Optional: approve logins through Discord

1. Turn on `general.discord.enabled` in `modules/staffauth.yml`.
2. Set `GLACIERSTAFF_DISCORD_BOT_TOKEN`.
3. After confirming account ownership, link the accounts at the console:

```text
glacierstaffauth link <minecraft-uuid> <discord-user-id>
```

Staff run `/staffauth discord` and reply to the bot's DM with the one-time approval text. The bot must be able to DM the linked account.

### 5. Protect other plugins' commands

List command roots and aliases under `general.protected-command-roots`. The defaults already cover the risky vanilla and permission commands:

```yaml
general:
  protected-command-roots:
    - "op"
    - "deop"
    - "stop"
    - "lp"
    - "luckperms"
    - "ban"
    - "tempban"
```

Add the roots and aliases of any other moderation or admin plugin you run.

### Managing sessions

| Where | Command | Does |
| --- | --- | --- |
| In-game | `/staffauth` | Opens the auth menu |
| In-game | `/staffauth logout` | Ends your current session |
| Console | `glacierstaffauth status <uuid>` | Shows enrolment |
| Console | `glacierstaffauth revoke <uuid>` | Locks an active session |
| Console | `glacierstaffauth reset <uuid>` | Clears lost factors before re-enrolment |

On a network, configure Staff Auth on every server that exposes staff actions.

## Discord webhooks

1. Create a webhook in your Discord channel and set its URL as `GLACIERSTAFF_DISCORD_WEBHOOK_URL`. The variable name can be changed with `general.webhook.url-environment`.
2. Enable the `discord` module.
3. Choose events in `modules/discord.yml`:

```yaml
general:
  include-player-identifiers: true
events:
  report-submitted: true
  report-resolved: true
  freeze-changed: true
  punishment: true
  staff-mode: true
  alt-flagged: true
  note-added: true
```

Set `include-player-identifiers: false` to redact player names and UUIDs from every message.

### Checking delivery

```text
/staffdiscord status
/staffdiscord test
```

`status` shows the configuration, queue counts and the last delivery result. The console can always run `test`; in-game staff also need `glacierstaff.staff.discord.test`.
