TExcelTAD

CIA, AAA and Access Control

A small company shares one admin password for its reporting server. One day a report is changed and nobody can say who did it, whether they were allowed to, or when. Nothing was "hacked" in the film sense, yet three things failed at once: the server could not tell people apart, it could not limit what each person could do, and it kept no record. Those three are the AAA of security, and they are how systems protect the CIA properties in practice.

CIA in one paragraph

You met the CIA triad in the on-ramp course: confidentiality (only the right people can read it), integrity (it is correct and unmodified, and changes are authorised) and availability (it works when it is needed). In this track every attack lesson names the property it hits and every control names the property it protects. Two more properties appear often: authenticity (the data or party is what it claims to be) and non-repudiation (someone cannot plausibly deny an action, which needs signatures or trustworthy logs).

AAA: the three questions every request answers

Step Question Typical mechanisms Fails as
Authentication (authn) Who are you? passwords + MFA, passkeys, certificates, API tokens shared accounts, stolen credentials
Authorisation (authz) What may you do? roles, attributes, ACLs, policies over-broad permissions, missing checks
Accounting (auditing) What did you do, and when? audit logs, session records no logs, logs that can be edited by the actor

The order matters. Authorisation without authentication is meaningless (anyone can claim to be the admin), and accounting without authentication records only "someone". Identification (stating a user name) is sometimes listed as a separate first step: it is the claim, authentication is the proof.

A request through all three steps

The program below is a toy API. It stores only the SHA-256 of each API token (tokens are long random strings, so a plain fast hash is acceptable for them; passwords are different, see password storage), compares hashes with hmac.compare_digest so the comparison takes the same time whether the first byte or the last one differs, checks the user's roles against the action, and writes one audit line per request, allowed or not.

python · try it yourself
import hashlib, hmac

# Authentication data: we store only SHA-256 of each API token (tokens are long, unguessable strings).
TOKENS = {
    "alice": hashlib.sha256(b"tok-alice-7f3a9c").hexdigest(),
    "bob":   hashlib.sha256(b"tok-bob-51d0e2").hexdigest(),
}
ROLES = {"alice": {"editor"}, "bob": {"viewer"}}
PERMISSIONS = {                      # role -> set of (action, resource type)
    "viewer": {("read", "report")},
    "editor": {("read", "report"), ("write", "report")},
}
audit_log = []

def authenticate(user, token):
    stored = TOKENS.get(user)
    given = hashlib.sha256(token.encode()).hexdigest()
    return stored is not None and hmac.compare_digest(stored, given)

def authorize(user, action, resource):
    return any((action, resource) in PERMISSIONS[r] for r in ROLES.get(user, ()))

def request(t, user, token, action, resource):
    if not authenticate(user, token):
        decision = "DENY (authn)"
    elif not authorize(user, action, resource):
        decision = "DENY (authz)"
    else:
        decision = "ALLOW"
    audit_log.append(f"{t} user={user} action={action} resource={resource} -> {decision}")   # accounting

request("10:00:01", "alice", "tok-alice-7f3a9c", "write", "report")
request("10:00:02", "bob",   "tok-bob-51d0e2",   "read",  "report")
request("10:00:03", "bob",   "tok-bob-51d0e2",   "write", "report")
request("10:00:04", "bob",   "guess-123",        "read",  "report")
request("10:00:05", "carol", "tok-carol",        "read",  "report")
print("\n".join(audit_log))
denied = [line for line in audit_log if "DENY" in line]
print(f"{len(denied)} of {len(audit_log)} requests denied")
10:00:01 user=alice action=write resource=report -> ALLOW
10:00:02 user=bob action=read resource=report -> ALLOW
10:00:03 user=bob action=write resource=report -> DENY (authz)
10:00:04 user=bob action=read resource=report -> DENY (authn)
10:00:05 user=carol action=read resource=report -> DENY (authn)
3 of 5 requests denied

The tokens are written in the code only so the output is stable; a real service generates them with secrets.token_urlsafe(32) and never logs them. Notice what the log does and does not contain: the user, action, resource, time and decision, but no token. An audit log that records secrets becomes a target itself.

Access-control models

Authorisation needs a rule for who may do what. Four models cover nearly every system you will meet; the on-ramp has RBAC and ABAC in code.

Model Who decides Rule looks like Where you meet it
DAC (discretionary) the owner of the object "owner may grant read to group" Linux file modes, Windows ACLs, shared documents
MAC (mandatory) a central policy, not the owner labels: a secret process cannot write to an unclassified file SELinux, AppArmor, military systems
RBAC (role-based) administrators assign roles "editors may write reports" most business apps, Kubernetes RBAC, cloud IAM roles
ABAC (attribute-based) a policy over attributes "allow if department = finance and time is in office hours" cloud IAM conditions, XACML, zero-trust gateways

DAC is what you see on your own Linux account. This session runs in your sandbox as the unprivileged user learner: the owner creates a file and decides who else may read it.

bash · try it yourself
id
echo "q3 figures" > report.txt
chmod 640 report.txt
stat -c '%A %U %G %n' report.txt
chmod o+r report.txt
stat -c '%A %U %G %n' report.txt
uid=1000(learner) gid=1000(learner) groups=1000(learner)
-rw-r----- learner learner report.txt
-rw-r--r-- learner learner report.txt

The second chmod is the weakness of DAC in one line: the owner can share data with everyone, and nothing in the model stops it. MAC exists for data where the organisation, not the owner, must decide. Linux permissions are taught in Linux Users, Groups, Permissions, sudo and SUID.

Least privilege

The principle of least privilege: every account, process and service gets the permissions its task needs and no more, for no longer than needed. It limits the damage of every attack in this track: a stolen token for a read-only role cannot delete anything. Its companions are separation of duties (the person who requests a payment is not the one who approves it) and need to know.

How missing AAA is detected

  • Authentication: many DENY (authn) lines for one account (guessing) or for many accounts from one source (spraying), logins at unusual times or from new places. You build these detectors in Brute Force and Password Spraying.
  • Authorisation: DENY (authz) lines show someone probing beyond their role; the dangerous case is the opposite, an ALLOW that should not exist, which logs alone don't reveal. It is found by access reviews: comparing what each account may do with what it does.
  • Accounting: audit for the logs themselves. Is every sensitive action logged? Can the actor delete their own entries? Are clocks synchronised so events can be ordered?

An access review in miniature, comparing permissions granted with permissions used over 90 days of (synthetic) logs:

python · try it yourself
# Permissions granted per account vs. permissions actually used in 90 days of audit logs.
granted = {
    "svc-backup": {"read:db", "write:db", "read:files", "delete:files"},
    "svc-report": {"read:db", "write:db"},
    "dana":       {"read:files", "write:files", "admin:users"},
}
used = {
    "svc-backup": {"read:db", "read:files"},
    "svc-report": {"read:db"},
    "dana":       {"read:files", "write:files"},
}
for account in granted:
    unused = sorted(granted[account] - used.get(account, set()))
    share = len(unused) / len(granted[account])
    print(f"{account:<11} granted {len(granted[account])}  unused {len(unused)} ({share:.0%})  remove: {', '.join(unused)}")
svc-backup  granted 4  unused 2 (50%)  remove: delete:files, write:db
svc-report  granted 2  unused 1 (50%)  remove: write:db
dana        granted 3  unused 1 (33%)  remove: admin:users

How it is fixed

  • One account per person and per service; no shared logins. MFA for people, short-lived credentials for services.
  • Roles built from tasks, reviewed on a schedule (quarterly is common) and when people change jobs; unused permissions removed, as in the review above. A backup account needs to read the database, not write it.
  • Deny by default: a request that matches no rule is refused, as carol was.
  • Audit logs written to a place the actor cannot change (a separate log server or append-only storage), with synchronised clocks and no secrets inside.

Pitfalls

  • Confusing authn and authz. "The user is logged in" is not "the user may do this". Many web bugs are a missing authorisation check on an authenticated request (IDOR).
  • Checking in the client only. A hidden button is not access control; the server must check every request.
  • Logging too little or too much. No log means no investigation; a log with passwords or tokens is a breach waiting to happen.
  • Roles that only grow. Permissions added for one project are rarely removed. Without reviews, least privilege decays.

Practice

  1. A hospital lets a nurse read records only for patients on her ward during her shift. Which access-control model is that?
  2. In the first example, which line of the log would you alert on first, and why?
  3. A developer's laptop is stolen with a valid API token for svc-report. Using the review above, what could the thief do before and after the clean-up?
Answers
  1. ABAC: the decision uses attributes of the user (ward, shift), the resource (patient's ward) and the environment (time). RBAC alone ("nurses may read records") is too coarse.
  2. The DENY (authn) for bob with a wrong token: a known account with a bad secret is how guessing looks. One line is not an attack, but it is the line to count. The unknown user carol matters too: requests for accounts that don't exist suggest someone is trying names.
  3. Before: read and write the database. After removing write:db: read only. The theft is still a confidentiality incident (revoke the token at once), but the integrity damage is gone.

Test yourself

A user logs in successfully but is refused when trying to delete another user's account. Which AAA step refused the request?

  1. Authentication
  2. Authorisation
  3. Accounting
  4. Identification

Why does the toy API compare token hashes with hmac.compare_digest instead of ==?

  1. It is faster
  2. It takes the same time wherever the strings differ, so timing does not leak how much of a guess was right
  3. It hashes the token again
  4. == cannot compare hex strings

Who decides access under DAC?

  1. A central security policy with labels
  2. The owner of the object
  3. An attribute policy engine
  4. Nobody: everything is allowed

The access review found that svc-backup never used delete:files in 90 days. What does least privilege suggest?

  1. Keep it in case it is needed
  2. Remove it, and grant it again only if a task needs it
  3. Give it to every service so they match
  4. Delete the account