Security and data governance
引入
6:35
数据库
数据库是关于某个领域的一组真实陈述。这门课介绍如何建模、查询、保护和治理数据。前三个单元介绍如何建模和组织数据:关系设计、SQL 和规范化。接下来的两个单元介绍如何利用索引和事务,让数据访问快速且安全。最后一个单元介绍数据治理。这里的每条查询都已在文档记录的示例模式上执行过。
英文讲解 · 可切换中英文字幕
本课内容
| English | 释义 | 拼音 |
|---|---|---|
| Authentication/ɔːˌθentɪˈkeɪʃn/ | 身份认证 | shēn fèn rèn zhèng |
| authorisation/ˌɔːθəraɪˈzeɪʃn/ | 授权 | shòu quán |
| principle of least privilege/ˈprɪnsɪpl ɒv liːst ˈprɪvɪlɪdʒ/ | 最小权限原则 | zuì xiǎo quán xiàn yuán zé |
| SQL injection/ˌes kjuː ˈel ɪnˈdʒekʃn/ | SQL注入 | SQL zhù rù |
| Data governance/ˈdeɪtə ˈɡʌvənəns/ | 数据治理 | shù jù zhì lǐ |
| quasi-identifiers/ˈkweɪzaɪ aɪˈdentɪfaɪəz/ | 准标识符 | zhǔn biāo shí fú |
| k-anonymous/keɪ əˈnɒnəməs/ | k匿名 | k nì míng |
| Pseudonymisation/ˌsuːdəʊˌnɪmaɪˈzeɪʃn/ | 假名化 | jiǎ míng huà |
| l-diversity/el daɪˈvɜːsɪti/ | l多样性 | l duō yàng xìng |
| keyed hash | 密钥哈希 | mì yào hā xī |
| parameterised statement | 参数化语句 | cān shù huà yǔ jù |
身份与权限
- 认证证明你是谁;授权证明你可以做什么。最小权限原则塑造了这两者:账户仅获得使任务运行所需的最窄范围授权。


Authorisation decides —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Authentication proves identity; authorisation bounds the rights.
注入,已终止
- 通过粘贴用户文本构建的查询——
"... WHERE name = '" + input + "'"——与输入' OR '1'='1匹配所有行:在示例架构中,所有8学生均被选中。 - 参数化语句将查询和值通过独立通道发送:攻击者的文本只能作为值处理,因此该攻击类别彻底终结,而不仅限于单个示例。
Input ' OR '1'='1 in a pasted query matches —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The tautology makes the WHERE always true - on the sample, all 8 students.
权限适配与循环治理
- 教学授权:
GRANT SELECT ON Student TO reader; GRANT SELECT, INSERT ON Enrollment TO clerk;——办事员无法删除选课记录,被盗会话受限于授予的权限。应在角色变更时撤销权限,而非审计日。 - 数据治理对数据进行分类(公开、内部、敏感),指定所有者,设定保留期限,并审计访问权限:敏感成绩列在静止状态下加密,其访问记录被日志化,过期授权每季度撤销。切勿以所有者身份连接应用程序——否则每个漏洞都会以完全权限运行。
Parameterised statements end SQL injection because —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Separate channels: attacker text can only ever be a value.
这是一张新卡片,翻译完成前会显示英文。
Removing names is not anonymity
- Deleting names leaves quasi-identifiers 准标识符: postcode, birth date and sex together identify most people. A release is k-anonymous k匿名 if every combination of quasi-identifiers appears at least $k$ times; group sizes $5, 3, 7, 4$ make it $3$-anonymous.
- Pseudonymisation 假名化 replaces names with codes, but the data is still personal, because the key can link back.
- Privacy by design adds minimisation (collect only what the purpose needs), limits on how long data is kept, and coarser values, such as age bands instead of birth dates.
A release has quasi-identifier groups of sizes 6, 4, 9, 2 and 5. What is the largest k for which it is k-anonymous?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
k is the smallest group size: 2.
Removing the name column is enough to make a table anonymous.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Postcode, birth date and sex together can still identify most people.
这是一张新卡片,翻译完成前会显示英文。
k-anonymous but still leaking
- A group of 3 records with the same quasi-identifiers is 3-anonymous. If all three have the same diagnosis, anyone who knows a person is in that group learns the diagnosis.
- l-diversity l多样性 asks for at least $l$ different sensitive values in every group. Group size measures hiding in a crowd; diversity measures whether the crowd shares the secret.
A 3-anonymous group in which all three share one diagnosis protects the diagnosis.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Anyone placing a person in the group learns it; l-diversity is needed.
这是一张新卡片,翻译完成前会显示英文。
Worked example: make a release 2-anonymous
- Four rows share no quasi-identifiers 准标识符, so each person is unique. Generalise until every combination appears at least twice.
| Before: postcode, birth date | After: postcode, age band |
|---|---|
| 315010, 2004-03-12 | 3150**, 20–24 |
| 315016, 2003-11-30 | 3150**, 20–24 |
| 315201, 1998-07-04 | 3152**, 25–29 |
| 315208, 1999-01-19 | 3152**, 25–29 |
- Now each group holds 2 rows: 2-anonymous. Then check the diagnoses: if both rows in a group share one, the group still leaks it (l-diversity).
Hashing every 8-digit ID at $10^9$ hashes a second: time (seconds)?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
$10^8/10^9 = 0.1$ s.
The safest replacement for student IDs in a shared research file is:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Small ID spaces make plain hashes reversible by brute force.
这是一张新卡片,翻译完成前会显示英文。
Worked example: a hash is not a pseudonym
- Replacing 8-digit student IDs with their SHA-256 hashes looks anonymous. But there are only $10^8$ possible IDs, and hashing them all at $10^9$ a second takes $\mathbf{0.1}$ s.
- A table of all the hashes reverses every one. Use a random code with the key kept separately, or a keyed hash 密钥哈希 whose secret key never leaves the data owner.
这是一张新卡片,翻译完成前会显示英文。
Marks that slip away
- Escaping instead of parameterising. Escaping fixes one character; a parameterised statement 参数化语句 ends the whole type of attack.
- Deleting names and calling it anonymous. Postcode, birth date and sex together still identify most people.
- Calling pseudonymised data non-personal. Whoever holds the key can link the codes back, so it is still personal data.
这是一张新卡片,翻译完成前会显示英文。
Recap
| Step | Answers | Checked with |
|---|---|---|
| Authentication | who are you? | password, key, second factor |
| Authorisation | what may you do? | roles and grants |
-
Least privilege: grant only what the job needs.
-
Parameterised statements 参数化语句 end SQL injection as a type of attack.
-
Grant narrowly, remove rights when roles change, classify and audit sensitive data.
出了什么问题?只有网站团队能看到这些信息。