Skip to content

tdfs4ds.serve.credential_vault

tdfs4ds.serve.credential_vault

Remembered credentials of the gateway (0.3.8.2): opt-in, per login, per environment.

The two halves of a stored credential are never in the same place:

  • the server holds <entry>.bin: the user name, password and logon mechanism sealed with AES-256-GCM (additional data = environment id, host, user name, entry id), and <entry>.meta: the environment, host, user name, mechanism and last-use time (none of it secret);
  • the browser holds the 256-bit key and the entry id, in a signed, HttpOnly, SameSite=Strict cookie tdfs4ds_cred_<environment id>.

Neither half opens anything alone. A token (JWT) is never stored, and nothing here logs or writes a plaintext secret. An entry expires TDFS4DS_SERVE_REMEMBER_DAYS (30) after its last successful use. TDFS4DS_SERVE_REMEMBER_CREDENTIALS=false switches it all off.

logger module-attribute

logger = logging.getLogger('tdfs4ds.serve')

MAGIC module-attribute

MAGIC = b'TDV1'

STORABLE_MECHS module-attribute

STORABLE_MECHS = ('TD2', 'LDAP')

COOKIE_PREFIX module-attribute

COOKIE_PREFIX = 'tdfs4ds_cred_'

DEFAULT_DIR module-attribute

DEFAULT_DIR = '/data/credentials'

_ENTRY module-attribute

_ENTRY = re.compile('^[A-Za-z0-9_\\-]{16,64}$')

Vault

Server half of the remembered credentials. sign / unsign come from the login gate (auth.sign / auth.unsign): the cookie value is signed with the server's secret, so a forged or edited cookie is refused before any file is read.

dir instance-attribute

dir = directory or os.environ.get('TDFS4DS_SERVE_CREDENTIALS_DIR') or DEFAULT_DIR

__init__

__init__(directory: Optional[str] = None, sign=None, unsign=None, now=time.time)

store

store(env_id: str, host: str, logmech: str, username: str, password: str, previous_cookie: Optional[str] = None) -> Optional[str]

Seal the credentials; returns the signed cookie value. None when not storable (switch off, mechanism other than TD2/LDAP, empty fields).

peek

peek(env_id: str, host: str, cookie_value: Optional[str]) -> Optional[dict]

{'username', 'logmech'} when the cookie names a live entry of this environment (nothing decrypted); None otherwise. For the login page.

load

load(env_id: str, host: str, cookie_value: Optional[str]) -> Optional[dict]

The decrypted credentials, or None (no cookie, forged cookie, wrong key, other environment, expired, tampered file). An expired entry is deleted.

touch

touch(cookie_value: Optional[str]) -> None

A successful use moves the expiry: 30 days from now.

forget_entry

forget_entry(entry_id: str) -> None
forget_cookie(cookie_value: Optional[str]) -> bool

forget_environment

forget_environment(env_id: str) -> int

Delete every entry of an environment (the environment is forgotten).

purge_expired

purge_expired() -> int

Delete expired entries (and half entries). Called at start and daily.

purge_if_due

purge_if_due() -> int

enabled

enabled() -> bool

remember_days

remember_days() -> float

cookie_name

cookie_name(env_id: str) -> str

_b64

_b64(data: bytes) -> str

_unb64

_unb64(text: str) -> bytes

_aad

_aad(env_id, host, username, entry_id) -> bytes