Rana Maninder Singh
Lesson 3 of 12Cybersecurity for Data, AI & Analytics

Data Classification, Privacy & Protection Controls

Lesson opener

In one line: Label data by how much harm its exposure or alteration would cause, attach concrete handling rules to each label, and implement those rules with encryption, masking, tokenization, loss-prevention checks and retention so that protection follows the data into lakes, dashboards and AI systems.

Why it matters: A classification policy on a slide protects nothing. Protection happens when a column containing personal information is masked for a dashboard role, when an export to an external tool is blocked, when an index never ingests restricted text, and when old extracts are deleted on time. Engineers and analysts turn policy words into controls that run every day.

Before this lesson: Identity, Access & Least Privilege controlled who may reach data. Managers' classification and privacy awareness is covered in Privacy, Security & Compliance; this lesson goes further into engineering controls and does not repeat the governance introduction.

Northline Consumer Goods (illustrative) is building a customer insights dashboard and a support assistant. The source tables contain names, emails, mobile numbers, order totals and free-text support notes, and the notes sometimes contain phone numbers a customer typed in. The privacy lead asks the engineers: "Which fields are personal, which controls apply to each, who can see the raw values, and when is the data deleted?"

What you will be able to do

Deliverable: a classification and protection plan: dataset or column inventory, label, handling rules, protection controls, retention, owner, validation tests and escalation path.

Prerequisites

PrerequisiteWhy it matters
Cybersecurity Foundations for Data, AI & AnalyticsAssets, owners and CIA ratings that feed classification.
Identity, Access & Least PrivilegeAccess roles that classification rules refer to.
Privacy, Security & ComplianceGovernance-level classification and privacy awareness.
Master Data DomainsWhere customer and supplier master data originate.
Security, Guardrails & GovernanceData handling for AI assistants.
Cloud FundamentalsVocabulary for storage services and managed keys.

Plain English

Classification labels. A small set of labels, typically four, keeps the scheme usable. A common pattern (the names and counts are your organisation's decision):

LabelMeaningTypical examples
PublicApproved for anyonePublished price list, annual report
InternalFor staff; low harm if leakedOrg charts, aggregated sales by region
ConfidentialHarm if exposed; need-to-knowCustomer-level orders, supplier contracts, personal data
RestrictedSerious harm; tightly limitedPayroll, health data, credentials, bank details

A label is only useful if it drives rules. For each label write down: who may access it, whether it can leave the company, which tools and model endpoints may process it, how it is stored and protected, whether it may appear in logs, tickets or prompts, and how long it is kept.

Personal information (PI) versus non-PI. PI identifies or can reasonably be linked to a person: names, emails, phone numbers, account identifiers, device identifiers and sometimes combinations of ordinary fields (postcode, birth date and job title can identify someone). Order totals by region are not PI; order lines linked to a customer id are. What counts as personal or sensitive, and what the duties are, is jurisdiction-specific and decided by the legal and data protection functions. As engineers you find the PI, label it and apply controls.

Be especially alert to free text. Support notes, survey comments and chat logs hold PI in unpredictable places, and when such text is loaded into a lake, shown on a dashboard or embedded for an AI index, the PI travels with it.

Encryption at rest and in transit.

Masking, tokenization, pseudonymization, aggregation. Different techniques for different needs:

TechniqueWhat it doesGood forLimits
MaskingHides part of a value (a***@example.com)Showing records to support staff or dashboardsOriginal still exists; mask can leak if too light
TokenizationReplaces a value with a consistent token; the mapping or key is held in a restricted systemJoining datasets without exposing the valueToken vault becomes a high-value target
PseudonymizationReplaces direct identifiers with codes while the link back is kept separatelyAnalytics on behaviourStill personal data in many jurisdictions; re-identification is possible with extra information
AggregationReports totals or averages with minimum group sizesDashboardsSmall groups can reveal individuals
Dropping the fieldNot collecting or loading itEverything where the field is not neededNone; it is the strongest control

Prefer data minimisation: do not bring a field into the lake or index if the use case does not need it.

DLP patterns. Data loss prevention means detecting and blocking unintended movement of sensitive data. Patterns that work at engineering level: scan files and tables for PI patterns before they are published; block exports of confidential datasets to personal storage or unapproved tools; check text for PI before it is sent to an external AI service or stored in an index; restrict who can download or share from the BI workspace; and alert on unusually large exports. Pattern matching is imperfect, so treat detections as a safety net on top of classification and access control, not a replacement.

Retention and deletion. How long should each dataset be kept, and how is it deleted from every copy (lake, warehouse, backups, extracts, indexes, notebooks)? The purpose, business need and legal or contractual retention rules differ by dataset and jurisdiction. The data owner and the legal function decide the period; engineers make deletion possible and prove it. A dataset with no retention rule is a question to raise, not a default to "keep forever".

Teacher walkthrough

Build the plan for the customer insights dashboard and support assistant.

  1. Business owner. The Head of Customer Operations owns the customer data; the privacy lead owns the labels and retention rules; the platform lead owns implementation.
  2. Approved users. Insights analysts see masked or aggregated customer fields; the support team sees customer detail through the support tool only; the privacy lead and a small restricted group can request raw values under approval.
  3. Data and systems in scope. The customer table, order history, support notes, the lake zones that hold them, the dashboard, the support assistant's index and any exports.
  4. Permissions. Raw PI lives only in the restricted zone, readable by named service identities and an approval-based group. The curated zone holds tokens in place of direct identifiers. The dashboard role reads curated and aggregated data only.
  5. Validation. Scan every column sample for PI patterns; confirm free-text columns are either excluded, scrubbed or classified as confidential; test that a dashboard user cannot see raw values; test that an export from the confidential zone to an unapproved destination is blocked; confirm encryption settings and TLS enforcement in configuration; confirm a retention job removes data past its period.
  6. Escalation. PI found in a place labelled non-PI, or in a log or prompt, goes to the privacy lead and the security on-call. Confirmed exposure follows the organisation's incident process; notification obligations are decided by the data protection lead under the applicable jurisdiction.
  7. Monitoring evidence. Access logs on the restricted zone, DLP detections, export logs, retention job reports and quarterly sampling of dashboards and indexes for PI.
  8. Fallback and containment. If PI is found where it should not be, restrict the location, take the dashboard or index offline if necessary, purge or rebuild after scrubbing and record what was exposed and to whom.
  9. Stop condition. Raw PI in a dashboard dataset, an AI index or a log stops publication until it is scrubbed and the owner confirms. Missing retention for a restricted dataset blocks onboarding of that dataset.
  10. Review. Labels and rules are reviewed annually and when a new data source or use case appears.

Worked example

The script classifies columns from synthetic samples by detecting email and phone patterns, assigns a handling plan, demonstrates masking and tokenization, and checks datasets against retention rules. The tokenization uses a keyed hash (HMAC) with a demo key EXAMPLE-NOT-A-REAL-TOKEN; a real key would live in a key management service and a keyed hash is one form of pseudonymization, not a guarantee of anonymity. The pattern checks are deliberately simple and will miss some formats. The retention periods are illustrative proposals. It uses only the Python standard library.

import hashlib
import hmac
import re

DEMO_KEY = b"EXAMPLE-NOT-A-REAL-TOKEN"  # demo only; real keys live in a key vault
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
PHONE = re.compile(r"\b\d{10}\b")

SAMPLE = {
    "customer_email": ["asha.verma@example.com", "li.wen@example.org"],
    "mobile": ["9876543210", "9123456780"],
    "order_total": ["1250.00", "89.90"],
    "region": ["North", "South"],
    "support_note": ["Call back on 9876543210 please", "Delivered late"],
}
PLAN = {
    "personal": {"class": "confidential", "control": "tokenize or mask outside the restricted zone"},
    "non_personal": {"class": "internal", "control": "standard role access"},
}


def detect(values):
    found = set()
    for v in values:
        if EMAIL.search(v):
            found.add("email")
        if PHONE.search(v):
            found.add("phone")
    return found


def mask_email(value):
    local, domain = value.split("@")
    return local[0] + "***@" + domain


def tokenize(value):
    return "tok_" + hmac.new(DEMO_KEY, value.encode(), hashlib.sha256).hexdigest()[:12]


for column, values in SAMPLE.items():
    kinds = detect(values)
    kind = "personal" if kinds else "non_personal"
    print(f"{column:15s} {kind:13s} {sorted(kinds)} -> {PLAN[kind]['class']}: {PLAN[kind]['control']}")

print(mask_email("asha.verma@example.com"))
print(tokenize("9876543210") == tokenize("9876543210"))
print(tokenize("9876543210") == tokenize("9123456780"))

RETENTION_DAYS = {"web_logs": 90, "customer_extract": 365}
HOLDINGS = [("web_logs", 120), ("customer_extract", 200), ("scratch_export", 400)]
for name, age in HOLDINGS:
    limit = RETENTION_DAYS.get(name)
    if limit is None:
        print(name, "NO RETENTION RULE: ask the data owner")
    else:
        print(name, "DELETE-OR-REVIEW" if age > limit else "within retention")

Expected result: customer_email and mobile are detected as personal and routed to confidential handling; order_total and region stay internal; and support_note is also detected as personal because one sample contains a phone number, which is the free-text lesson in one line. The mask prints a***@example.com. Tokenizing the same value twice gives the same token (True), so joins still work, while different values give different tokens (False for equality). In retention, web_logs at 120 days exceeds its 90-day period and needs deletion or an owner-approved exception, customer_extract is within retention, and scratch_export has no rule at all, which is exactly the ownership question to escalate.

A second workplace case

The Northline HR team wants an AI assistant that summarises employee survey comments. Comments are free text and may name individuals or include health details. The protection plan classifies the raw comments as restricted, strips names and direct identifiers before indexing, reports themes only for groups above a minimum size so a small team cannot be singled out, keeps raw comments in the restricted zone with a short retention period set by HR and legal, and routes prompts through an approved model endpoint with no logging of raw text. The same labels and techniques apply, but the choice of aggregation with minimum group sizes matters more than masking here, because the risk is singling out a person rather than leaking a field.

Failure example

Symptom: An analyst notices that the "customer insights" dashboard tooltip shows full email addresses when hovering over the top-spender chart.

Diagnosis: The dashboard dataset was built from the raw customer table because it was the easiest join. The email column was hidden from the table view but remained in the model and surfaced in the tooltip. Nobody scanned the dataset for PI, and the dashboard role could read the underlying table.

Correction: Remove the email column from the dashboard dataset, rebuild it from the curated zone where emails are tokenized, restrict the dashboard role to curated data, and review other reports using the same dataset. Check access logs to see who loaded the report; report the exposure through the incident process and let the privacy lead decide whether any notification is required in the applicable jurisdiction.

Validation: Open the rebuilt dashboard as the dashboard role and as an administrator, check every visual, tooltip, export and underlying data view for PI, and run the column scan against the new dataset.

Prevention: Make a PI scan part of every dashboard publish step, build dashboards only from curated sources, hide-by-removal rather than hide-by-formatting, and keep a list of datasets that must never be used as dashboard sources.

Guided practice

Scenario: A Northline support assistant will index support tickets containing customer name, email, order id and free-text comments. Produce the classification and protection plan.

Hints:

  1. Which fields do you really need in the index?
  2. Which columns are personal, and which technique suits each?
  3. Where could PI hide in free text?
  4. What is the retention question, and who answers it?
  5. What stops the plan?

Complete solution:

Independent practice

Create a classification and protection plan for a data and AI use case that handles personal information, such as a customer churn model, a loyalty dashboard or an HR helpdesk assistant.

Acceptance criteria

Common mistakes

  1. Publishing labels without handling rules, so the label changes nothing.
  2. Treating hidden columns as protected when the data is still in the model, tooltip or export.
  3. Ignoring free-text fields, which often hold the most surprising PI.
  4. Believing encryption at rest means any user may be given access safely.
  5. Using masking when tokenization or removal is needed, or the reverse.
  6. Calling pseudonymized data "anonymous" and relaxing the controls.
  7. Showing aggregates for tiny groups that identify individuals.
  8. Loading whole tables into lakes or AI indexes "in case they are useful".
  9. Keeping data forever because nobody owns the retention decision.
  10. Relying on DLP pattern matching alone to catch PI.

Quick check

  1. Why is a classification label without handling rules ineffective?
  2. Why is a support-notes column a classification risk even when other columns are clean?
  3. What is the difference between masking and tokenization in how they are used?
  4. Does encryption at rest stop an authorised but over-privileged user seeing the data?
  5. Who decides how long customer data is retained, and what must engineering provide?

Answers:

  1. Because people and systems act on rules, not names. Without rules for access, sharing, tools, logging and retention, the label does not change any behaviour.
  2. Free text can contain emails, phone numbers, names or sensitive details typed by customers, and these travel into dashboards, logs and AI indexes unless scanned or scrubbed.
  3. Masking hides part of a value for display; the real value remains stored. Tokenization replaces the value with a consistent token so datasets can be joined, with the mapping or key held in a restricted system.
  4. No. Encryption protects against stolen media or storage files; authorised users see decrypted data, so access control and least privilege are still needed.
  5. The data owner with the privacy and legal functions decides, according to purpose and jurisdiction; engineering must make deletion possible across all copies and prove it ran.

Quiz alignment

The quiz (QUIZ_CYBER3) covers labels and handling rules, PI and non-PI including free text, encryption in transit and at rest with key management, masking, tokenization and pseudonymization, aggregation limits, DLP patterns and retention, using the customer dashboard, support assistant and HR survey cases.

Lesson summary

Classification is useful only when labels drive concrete rules. Find PI in structured and free-text fields, minimise what enters lakes, dashboards and AI indexes, and choose the right technique: drop, mask, tokenize, pseudonymize or aggregate with minimum group sizes. Use TLS and encryption at rest with separate key control, but never mistake encryption for authorisation. Add DLP checks at exports, shares and prompts, accept their limits, and raise retention questions for every copy with a named owner. Leave jurisdiction-specific duties to the legal and data protection functions, and validate with synthetic data.

Bridge to the next lesson

Data is protected by labels and controls, but it also moves across networks and between services. The next lesson, Network Security for Cloud, Data & AI, covers trust boundaries, private connectivity, segmentation, egress control and safe exposure of warehouses, vector databases and BI gateways.

Sources

Northline Consumer Goods, its datasets, labels and retention periods are illustrative. Definitions of personal and sensitive data, retention periods, anonymization standards and notification duties are jurisdiction-specific and are decided by the organisation's legal and data protection functions. Every credential-like string in this lesson is a harmless fake.