Table of Contents

Class SecretsEnvironmentInstaller

Namespace
FishMMO.Installer
Assembly
FishMMO-Installer.dll

The one place FishMMO's secrets and environment variables are configured.

public static class SecretsEnvironmentInstaller
Inheritance
SecretsEnvironmentInstaller
Inherited Members

Remarks

One screen, one writer, one copy. Every FISHMMO_* variable the servers actually read lands in a single file — /etc/fishmmo/db-secrets.env on Linux, %ProgramData%\FishMMO\db-secrets.env on Windows — which every systemd unit loads with EnvironmentFile=-/etc/fishmmo/db-secrets.env. Splitting that file between several wizards is how it used to lose data: each one rewrote the whole file and emitted only the keys it knew about, so configuring the database silently deleted the mail credentials. There is now exactly one editor, it loads every key before it writes any, and a full rewrite is therefore safe.

The file is the only thing this screen reads. It never seeds itself from the process environment. A shell that still exports an old FISHMMO_DB_PASSWORD from some earlier session would otherwise show that stale value as "current", and saving would copy it back over the real one — which is how a secrets file and an exported snippet ended up holding two different passwords written half a minute apart. What the environment does get is a comparison: DescribeEnvironmentMismatches(IReadOnlyDictionary<string, string>, Func<string, string?>?) names every variable whose value in this shell differs from the file's, without printing either one.

That warning matters because the runtime precedence is the opposite. DatabaseSecrets resolves the environment first and the file second, so a process started by hand from a polluted shell uses the shell's value no matter what this screen writes. That order is deliberate — an operator must be able to override a deployment for one run — so the fix is to say so plainly, not to reorder the runtime.

Keys it does not know are still preserved. An operator will have added something — a proxy variable, a feature flag, a note to themselves. Unrecognised assignments, comments, blank lines and anything this parser cannot make sense of are carried through verbatim.

There is no export. This screen used to be able to write the same values out again as a fish/PowerShell/CMD snippet or a stray .env. Every one of those was a second copy of a live credential, and the fish one landed in conf.d, where every new shell sourced it and re-exported the database password into itself and into every process it launched. The services never needed it: systemd hands them the secrets file. Only the creation is gone — FishMMO.Installer.SecretsEnvironmentInstaller.ExportedSnippetPaths() still lists those paths so the uninstall can offer to delete the copies an earlier version already made.

What is deliberately not here:

  • FISHMMO_PG_SUPERUSER_PASSWORD — prompted per run by design. Persisting the PostgreSQL superuser password to disk is a worse trade than persisting the application user's, because it is the credential that can drop the cluster.
  • FISHMMO_SIGNING_KEY_KEK_BASE64 and FISHMMO_CLIENT_GATE_SECRET — owned by SecurityKeyInstaller, which provisions them into the deployment_secrets table. Writing them here as well would give the deployment two sources of truth for the same key, and the wrong one would win silently.
  • FISHMMO_CONNECTION_STRING / ConnectionStrings__NpgsqlConnection — an alternative spelling of the FISHMMO_DB_* set below. Offering both invites a deployment where the two disagree.
  • Tooling-only variables (FISHMMO_UNITY_EXE, FISHMMO_INSTALL_ROOT, FISHMMO_TRADE_RENDER_DIR, FISHMMO_ALLOW_COREDUMPS, FISHMMO_PG_LISTEN_ADDRESSES) — they steer a developer's machine, not a server.

Mail is the one setting with a second destination. The Control Panel is the process that drains the outbound email queue and sends (the LoginServer still creates accounts and enqueues, but its own Smtp:DrainQueue is off), and it resolves each SMTP setting from the environment first and its configuration second. The non-secret values are therefore mirrored into FishMMO-Setup/<environment>/appsettings.ControlPanel.json so a deployment that does not use the secrets file still works — but the password is written to the secrets file only. That JSON ships in the repository, and a live sending credential must never be committed.

Methods

ComposeSecretsFile(string?, IReadOnlyDictionary<string, string>)

Produces the full text of the secrets file: every known key set to the value given, and everything else in the existing file left exactly as it was.

public static string ComposeSecretsFile(string? existingContent, IReadOnlyDictionary<string, string> values)

Parameters

existingContent string

Current file content, or null when there is no file yet.

values IReadOnlyDictionary<string, string>

The known keys and their values. A key absent from this map (or present with an empty value) is removed from the file; the servers treat an empty variable as unset anyway, and an empty assignment is noise.

Returns

string

Remarks

Known keys are rewritten where they already stand, so the comment above a key stays with it. Keys that are not in the file yet are appended. Duplicate assignments to a key being written are collapsed to one: both systemd and DatabaseSecrets take the last assignment, so a leftover duplicate further down would quietly beat the new value.

Values are written raw, never quoted. DatabaseSecrets takes everything after the first = literally — it does not strip quotes — so quoting here would deliver the quote characters to the server as part of the password. Quotes an operator wrote by hand around a key we are not writing survive untouched, because those lines are preserved rather than re-emitted.

Public only so it can be tested directly; it is the one function here whose failure would destroy an operator's credentials.

Configure()

Runs the interactive editor until the operator goes back.

public static Task Configure()

Returns

Task

Remarks

Four guided steps rather than seventeen numbered settings and five letter actions. The flat list showed every variable at once and made the operator assemble a database connection out of six separate menu entries; each step now prompts its fields in the order they belong together, with the current value as the default so Enter keeps it.

B goes back, not 0: a lone zero in a column of letters reads as the letter O, and was asked about as one. 0 and Escape are still accepted, silently.

DescribeDatabase(IReadOnlyDictionary<string, string>)

The database connection in one line. Never includes the password.

public static string DescribeDatabase(IReadOnlyDictionary<string, string> values)

Parameters

values IReadOnlyDictionary<string, string>

Returns

string

DescribeEnvironmentMismatches(IReadOnlyDictionary<string, string>, Func<string, string?>?)

Names every variable whose value in the launching shell differs from the file's.

public static IReadOnlyList<string> DescribeEnvironmentMismatches(IReadOnlyDictionary<string, string> fileValues, Func<string, string?>? readEnvironment = null)

Parameters

fileValues IReadOnlyDictionary<string, string>

What the secrets file holds — the values this screen edits.

readEnvironment Func<string, string>

How to read a variable; defaults to this process's environment. Injectable so the comparison can be tested without touching the real environment, and so the screen can ask ReadInherited(string) instead of the live process.

Returns

IReadOnlyList<string>

Remarks

This is the diagnostic the screen could not previously give. An operator whose shell still exported an old password had no way to see that the shell and the file disagreed, and the disagreement is what decides which password a hand-started server actually uses: DatabaseSecrets takes the environment first and the file second.

Neither value is returned, formatted or logged — only the key name and the fact that the two differ. An empty variable is not a disagreement, because the runtime treats an empty variable as unset and falls through to the file; the shell's value is compared trimmed, because trimming is what the runtime does to it before use, so trailing whitespace is not reported as a difference that would not exist in practice.

DescribeMailSummary(IReadOnlyDictionary<string, string>)

Mail in one line for the menu; the mail step shows the full sentence.

public static string DescribeMailSummary(IReadOnlyDictionary<string, string> values)

Parameters

values IReadOnlyDictionary<string, string>

Returns

string

DescribeOtherSecrets(IReadOnlyDictionary<string, string>)

Whether each standalone secret exists — never anything about its value.

public static string DescribeOtherSecrets(IReadOnlyDictionary<string, string> values)

Parameters

values IReadOnlyDictionary<string, string>

Returns

string

DescribeService(IReadOnlyDictionary<string, string>)

Environment, and the log level when one is pinned.

public static string DescribeService(IReadOnlyDictionary<string, string> values)

Parameters

values IReadOnlyDictionary<string, string>

Returns

string

GroupMenuLines(IReadOnlyDictionary<string, string>)

The four menu rows, built from the file's values.

public static IReadOnlyList<string> GroupMenuLines(IReadOnlyDictionary<string, string> values)

Parameters

values IReadOnlyDictionary<string, string>

Returns

IReadOnlyList<string>

Remarks

Public so the rows can be asserted without a terminal.

HasUnsavedChanges(IReadOnlyDictionary<string, string>, IReadOnlyDictionary<string, string>)

Whether the screen holds edits that are not on disk.

public static bool HasUnsavedChanges(IReadOnlyDictionary<string, string> saved, IReadOnlyDictionary<string, string> current)

Parameters

saved IReadOnlyDictionary<string, string>
current IReadOnlyDictionary<string, string>

Returns

bool

Remarks

Compared on non-empty values only, because that is what a save round-trips: an empty value means "unset", ComposeSecretsFile(string?, IReadOnlyDictionary<string, string>) emits no line for it, and reloading the file would not produce the key at all. Without that, a file containing a bare KEY= would report unsaved changes for ever.

ParseKeyValues(string?)

Reads the secrets file into key/value pairs the way the servers read it, minus any quotes a human wrapped a value in.

public static Dictionary<string, string> ParseKeyValues(string? content)

Parameters

content string

Returns

Dictionary<string, string>

Remarks

Used to load the screen, never to decide what to write — what is written comes from ComposeSecretsFile(string?, IReadOnlyDictionary<string, string>), which works from the original lines. Public for the same reason as that one.