Skip to content
Muhammet Şafak
tr

Book I of III The Unreliable Systems Trilogy

The Production Database Access Guide

Identities, credentials, just-in-time access, mediated execution and audit

A practical guide to deciding who and what can reach a production database, how, for how long, and with what record left behind.

  • 329 pages
  • 1st edition
  • Free

The book's thesis

Not

a credential-distribution problem

But

an authorization, execution and accountability problem

  • 01

    Authorization

    Decide who may do what to which data, where and for how long — decided per request.

  • 02

    Execution

    Inspect each statement before it runs and bound its effect (transaction, row guard, timeout) before it commits.

  • 03

    Accountability

    Keep evidence of who asked, who approved and what actually ran.

About the book

On a Thursday evening, a one-row fix changed a batch of invoices, and the log named only a shared admin role. The scene takes place at Ledgerly, a fictional invoicing and payments company, and no step in it was unreasonable: the password was shared to get the first service running, the client auto-committed by default, and the role could change every table because that was easier than deciding which tables each service needed.

From that scene the book draws one claim: production database access is not a credential-distribution problem but an authorization, execution and accountability problem. The credential in the story was legitimate and did exactly what it was issued to do; what was missing was everything around it. Across five parts and sixteen chapters, the book follows Ledgerly from a shared admin password to an access model that was designed on purpose.

Every control asks something of the people who build and operate it, so each chapter states the cost, the common mistakes and when not to use the control. The book is written from the defender’s side: it does not teach attack techniques, does not interpret compliance regimes and is not a database administration book.

Contents

  1. 01 Preface Sets out the book's thesis that production database access is an authorization, execution and accountability problem, not a credential-distribution problem. Also covers who the book is for, the defender's perspective and the pseudocode notation.
  2. 02 The Door Nobody Designed Argues that a shared admin account is not a decision anyone made, but something that accumulates. Access is a design of five parts, and good access has five properties that pull against each other: least privilege, short life, observability, reversibility and low friction.
  3. 03 A Threat Model for Production Data Builds a short threat model of actors, paths, threat classes, impacts and controls so that a team can compare doors. Errors, misuse and compromise need different controls, and blast radius is described along seven dimensions.
  4. 04 Identities, Roles and Least Privilege Keeps identity, login and role apart and starts every role from no privileges. Covers column-level grants, an owner role without a login, a role per workload and a JIT write ceiling that is never granted to a login.
  5. 05 Credentials and Secrets Reduces the number of copies of each credential and gives every remaining read a name. Covers rotation with two logins per service, dynamic credentials with a built-in end and workload identity in place of a stored password.
  6. 06 Connections as Policy Treats a connection as a limited resource and a point of policy. Covers per-role connection budgets, a reserve for the people who repair the system, the pooler as a place for central refusal and session context under transaction-mode pooling.
  7. 07 Reads, Replicas and Data Copies Asks first whether a read decides something or follows a write, and why reporting and human reads never fall back to the primary. Explains that "read-only" is three mechanisms and that a replica is governed by the same roles as the primary.
  8. 08 Paths In: Bastions, Proxies and Access Gateways Separates network reach from database access. A bastion makes the path singular but leaves the login shared; an access gateway authenticates a person, creates a session login that carries that identity and removes it when the session ends.
  9. 09 Just-in-Time and Break-Glass Access Replaces standing access with access for a task and a time. Covers JIT write requests bound to a reviewed fix, revocation derived from the same record that drove the grant, four-eyes approval and break-glass as a self-declared, alerted and reviewed session.
  10. 10 Mediated Execution: Query Analysis and Dangerous Operations Explains execution as how a statement reaches the data, which grants do not answer. Mediated execution puts a component between the statement and the data, with one loop for every statement and a matrix that gives each statement class a deny, gate or allow.
  11. 11 Ad-hoc Queries and Data Fixes Makes a read-only session the default for investigation and treats writing as its own act with request, review, time limit and record. The safe order is count, snapshot, transaction, row-count guard, postcondition, commit.
  12. 12 Schema Changes and Migration Access Covers DDL run as a migrator role from the pipeline, a short-lived credential for the owner's power and review of the pipeline's own access. Includes short lock waits, online tools and expand and contract.
  13. 13 Sensitive Data: Classification, Masking and Minimization Classifies every column, defaulting unclassified columns to Confidential, and puts minimization before masking. Compares dynamic masking for human readers with static masking for the analytics copy, and keeps Restricted columns out of JIT requests.
  14. 14 Backups, Exports and Other Side Doors Explains that a side door carries the data without the controls of the system it came from. Covers backup access, separate principals for taking, restoring and deleting backups, restored copies and vendor exports controlled by a grant.
  15. 15 Auditing and Accountability Defines the audit log as the record of who did what to which data, kept where the actor cannot change it. Covers statement records, tamper evidence, checks for holes and silent producers, and keeping the record from becoming a copy of the data.
  16. 16 Access During Incidents States that urgency changes the speed of a control, never the identity that acts, the statement that runs or the record that is left. Covers an ordered containment, the difference between revocation and rotation and deriving the blast radius from the audit record.
  17. 17 An Access Checklist and Closing Thoughts Gathers the book into an access checklist and a maturity model whose stages end with an exit test someone can rerun. Offers a choice among access patterns per task, and treats every "no" as a finding with an owner and a date.
  18. 18 Appendix: Glossary, Pattern Quick Reference, Dangerous-Operations Matrix, Compliance Crosswalk, Access Review Template, Post-Incident Review Template Reference material: a glossary, a pattern quick reference, a dangerous-operations matrix, a compliance crosswalk of engineering artifacts, an access review template and a post-incident review template.

Sample chapter: Just-in-Time and Break-Glass Access

An excerpt from one chapter; the full text is in the downloadable edition.

Break-glass access

Break-glass is emergency access with a defined logging set and mandatory review. The name comes from the glass-fronted fire switch: reachable by anyone who needs it, and breaking it is visible to everyone.

In the book’s model it is the role human_breakglass, and it is the only human role that reads Restricted columns. It reads every table and writes INSERT and UPDATE on every table except the two append-only ones; on bank_accounts and payment_tokens it writes UPDATE only, and only on non-Restricted columns. It never writes ledger_entries or audit_events, because no human role does. It is not a route for routine fixes, and it is not a data fix path: a data fix is planned, reviewed and bounded (Chapter 10), and break-glass is none of those things by design.

A break-glass request is self-declared. It has no approver. The person in the session says an emergency exists, gives a reason, and the gateway marks the request approved and grants the role to the same session login until expires_at. The same revoke job and the same session timer take it back.

The approver is the whole control for JIT, so an emergency role without one may seem odd. Break-glass exists for the cases where the approver pool has not answered, and an approval step would reproduce that failure. The control moves from before the access to around it: an alert at declaration, the logging set below, a short fixed window, and a review that follows without exception.

function declareBreakGlass(session, reason):
    // a hijacked token alone must not be enough to declare
    requireFreshMultiFactor(session.principal)
    // one live request per session: a break-glass declaration supersedes it
    supersedeLiveRequest(session.login)
    // the window is the gateway's fixed maximum; there is no argument for it
    window = breakGlassMaxWindow
    request = newRequest(kind: "breakglass", requester: session.principal,
                         requester_login: session.login, approver: null,
                         reason: reason, expires_at: now() + window)
    markApproved(request.id)
    try:
        auditLogAppend({ actor: session.principal, action: "breakglass",
                         subject: session.login, request: request.id,
                         expires_at: request.expires_at })
    on AuditLogUnavailable:
        markRefused(request.id)
        raise GrantRefused
    setSessionEnd(session.login, request.expires_at)
    grant(human_breakglass, to: session.login)
    // paged after the grant: a paging outage must not block an emergency;
    // the review queue below is the net for a page that never arrived
    queueReview(request.id, reviewer: "not-the-requester")
    notify("security", "break-glass declared: " + request.id)
    notify("platform", "break-glass declared: " + request.id)

Three decisions in that block need a comment.

The window is fixed by the gateway, at two hours in Ledgerly’s illustration. No longer window is available on request, because “I need it a little longer” turns an exception into a habit. If the emergency outlasts the window, the person declares again and the second declaration alerts again; that is the intended friction.

The audit-log check is the same as for JIT. If the log is down, the declaration is refused. I accept that cost, because a break-glass session with no record is the one thing a review cannot reconstruct, and the review is what makes the role tolerable. What on-call does when the normal path and the log are both down belongs to Chapter 15.

The alert is a notification to the security contacts and the platform team that someone has opened the broadest access Ledgerly has, not a request for permission. In a healthy system it is rare enough to be read; if it fires weekly it will stop being read, and break-glass is being used for something that deserves a designed path.

Glossary

The key terms used in the book, with short definitions.

least privilege
Granting only what a task needs, for as long as it needs it, with the cost of doing so counted.
standing access
Access that exists continuously whether or not it is being used.
just-in-time (JIT) access
Access granted for a specific task and a limited time.
break-glass
Emergency access with heavy logging and mandatory review. The role is `human_breakglass`, and the request is self-declared.
mediated execution
A mode in which the principal never holds a connection: it submits a statement, the gateway or a runner analyzes it, and the runner executes it.
access gateway
An identity-aware intermediary that authenticates a human, issues a short-lived credential and records the session. Not a bastion, and not a database proxy.
bastion
A hardened host that is the single network path to a protected system. It forwards traffic and does not understand the database protocol.
short-lived credential
A credential that expires on its own within a short, defined time.
blast radius
How much can be affected if one principal, credential or action goes wrong. Always stated about a specific thing.
statement-bound approval
An approval attached to the exact statement set that will run, identified by `approved_hash`, rather than only to a time window or a privilege set.
audit log
The record of who did what to which data, kept where the actor cannot change it. The `audit_events` table is the application's business record, not the audit log.
side door
A data copy or export path that bypasses the access controls of the primary.

Frequently asked

8 questions

  • Who is this book for?

    Backend and platform engineers who build services that talk to a production database, SRE and DBA roles who operate it, tech leads who decide how access should work, and engineers who have newly become responsible for security. No security background is required.

  • Do I need to know a particular database engine?

    No. Familiarity with an engine helps with the examples but is not required. The book is engine-independent and uses pseudocode, an engine-neutral SQL-like notation and Mermaid diagrams.

  • Is it a compliance handbook?

    No. Regimes such as GDPR, KVKK, PCI DSS, SOC 2 and HIPAA come up only to explain what auditors and customers tend to ask. The book does not interpret any regime, cite its articles or say what is required of you; it aims to give your legal and compliance colleagues an architecture they can reason about.

  • What do I need to know before reading it?

    No security background is required. The preface asks you to be comfortable with relational databases (tables, roles and grants, transactions, replicas), with services that connect to a database over a network (connection pools and timeouts), and with on-call work: being paged, repairing something under pressure and writing down afterward what happened.

  • Is the book free?

    Yes. The license line reads "© 2026 Muhammet Şafak — free to download and read". PDF and EPUB files are offered in the download panel on this page. This edition is 329 pages.

  • Which languages and formats is it available in?

    Seven languages: English, Turkish, Spanish, Simplified Chinese, Portuguese, German and French. Each is offered as a PDF and an EPUB.

  • Does the book contain code examples I can run?

    No example is written in a real programming language, and nothing in the book is meant to be pasted into a terminal. Procedures are pseudocode; roles, grants and tables use a SQL-like notation that belongs to no particular engine. There is no configuration syntax for a specific proxy, vault or cloud product, and diagrams use Mermaid.

  • Is this a standalone book or part of a series, and in what order should I read the series?

    It is the first of three books in The Unreliable Systems Trilogy: I Access (this book), II Events (Designing Reliable Event-Driven Systems) and III Agents (Engineering Reliable AI Agents). The preface asks for general engineering knowledge, not for another book, so you can also start with whichever of the three matches your current problem.

Blog posts that touch on this book's subject.

Search the site

Start typing to search posts, projects and pages.

Esc to close Powered by Pagefind