credentials
credentials
¶
Credentials-DB at-rest encryption — chooser, provisioning, migration.
Two passphrase storage modes are chosen interactively when
systemd-creds isn't available; with it, the chooser is skipped and
the credential is sealed silently. Once chosen, the mode is persisted
so the resolution chain picks it up on the next daemon start — session
mode self-describes via the tmpfs file's presence; keyring sets
credentials.use_keyring=true in config.yml.
plan_provisioning
is the shared decision core: the CLI chooser here and the TUI's modal
flow are two renderings of the same plan.
The plaintext→encrypted migration is deprecated in 0.8.0 and slated
for removal in 0.9.0. After that release fresh installs stay the
only supported entry point; operators with a stale plaintext DB must
restore from the .plaintext-backup-<stamp>.tar.gz snapshot this
phase writes before re-keying.
CREDENTIALS_COMMANDS = (CommandDef(name='credentials', help='Credentials DB management', children=(CommandDef(name='encrypt-db', help='Migrate a legacy plaintext credentials DB to SQLCipher-encrypted (deprecated in 0.8.0, removed in 0.9.0)', handler=(LazyHandler('terok_sandbox.commands.credentials:_handle_credentials_encrypt_db'))),)),)
module-attribute
¶
CREDENTIALS = CREDENTIALS_COMMANDS[0]
module-attribute
¶
__all__ = ['CREDENTIALS', 'CREDENTIALS_COMMANDS', 'ProvisioningPlan', 'TierProvisionResult', '_run_credentials_setup_phase', 'credentials_provisioned', 'plan_provisioning', 'provision_passphrase_tier']
module-attribute
¶
TierProvisionResult(passphrase, source, generated)
dataclass
¶
Outcome of provision_passphrase_tier.
generated drives the caller's follow-up duty: a minted value
must be revealed to the operator (it is their recovery key) and
acknowledged via
terok_sandbox.vault.store.recovery.acknowledge
once they confirm it is saved off-host.
ProvisioningPlan(provisioned, auto_tier, choices, keyring_available)
dataclass
¶
The decision half of first-run passphrase provisioning, frontend-free.
Every frontend renders exactly this: skip when provisioned,
provision auto_tier silently when set, otherwise put
choices to the operator. keyring_available lets a frontend
grey out the keyring choice up front instead of failing after the
pick. The CLI chooser below and the TUI's modal flow are two
renderings of one plan — the decisions themselves are made here,
once.
provision_passphrase_tier(cfg=None, *, tier, passphrase=None)
¶
Land a passphrase on tier with no terminal interaction whatsoever.
The programmatic sibling of the setup chooser, built for GUI/TUI
frontends that own the conversation themselves: no /dev/tty
announce, no ack prompt, no stdout side channel. The caller shows
the returned value in its own reveal surface and records the
operator's confirmation through
terok_sandbox.vault.store.recovery.acknowledge.
passphrase None mints a fresh
generate_passphrase
value. When the credentials DB already exists encrypted, the
supplied value must open it — a mint could never match, so None
raises NoPassphraseError
and a mismatch raises
WrongPassphraseError
before anything lands on the tier. This closes the fresh-install
trapdoor where an "unlock"-shaped prompt silently keys a brand-new
vault to an unvalidated string.
Raises ValueError for a tier outside
PROVISIONABLE_TIERS
or an explicit empty passphrase (SQLCipher reads "" as "no
encryption"), and RuntimeError when the chosen
backend (systemd-creds, OS keyring) is unreachable.
Source code in src/terok_sandbox/commands/credentials.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
credentials_provisioned(cfg=None)
¶
Return True iff setup's credentials phase has nothing left to provision.
The pre-flight probe for frontends that want to collect the tier
choice before dispatching setup non-interactively: True
when the DB is already SQLCipher-encrypted or some tier of the
resolution chain already holds a passphrase, False when a
non-TTY setup run would fail closed asking for a tier.
Not infallible: a configured-but-broken durable tier (an
unsealable systemd-creds credential, a dead passphrase_command)
propagates its fail-closed
WrongPassphraseError
— callers should surface that as a hard failure, not read it as
False.
Source code in src/terok_sandbox/commands/credentials.py
plan_provisioning(cfg=None)
¶
Probe the host and return the provisioning decisions a frontend should render.
Propagates the fail-closed WrongPassphraseError of a
configured-but-broken durable tier (see
credentials_provisioned)
— surface it as a hard failure, not as "unprovisioned".