Chapterبەش 7 · Lectureوانە 7.1
Database Security: Threats and Countermeasuresئاسایشی بنکەدراوە: هەڕەشەکان و ڕێوشوێنەکانی بەرگری
Why data must be controlled, what a threat is and the five kinds of loss, and the computer-based countermeasures: authorization (and how it differs from authentication), access control with GRANT and REVOKE, views, backup and recovery, integrity and encryption.
بۆچی دەبێت کۆنترۆڵ بکرێت، چییە و پێنج جۆرەکەی زیان، لەگەڵ کۆمپیوتەری: (و جیاوازیی لەگەڵ )، بە GRANT و REVOKE، ، و ، و .
What you will learnچی فێر دەبیت
- Define a threat and give an example of each of the five kinds of loss.
- Name the seven computer-based countermeasures.
- Tell authentication (who are you?) from authorization (what may you do?).
- Give and take away privileges with GRANT and REVOKE, following least privilege.
- Use a view to show a user only the rows and columns they may see.
- Explain how integrity constraints and encryption protect data.
- پێناسەی بکەیت و بۆ هەر یەک لە پێنج جۆرەکەی زیان نموونەیەک بهێنیتەوە.
- حەوت کۆمپیوتەرییەکە ناو ببەیت.
- (تۆ کێیت؟) لە (چی دەتوانیت بکەیت؟) جیا بکەیتەوە.
- بە GRANT و REVOKE بدەیت و بیانسەنیتەوە، بەپێی .
- بەکاربهێنیت بۆ ئەوەی تەنها ئەو و پیشانی بدەیت کە ڕێگەی پێدراوە ببینێت.
- ڕوونی بکەیتەوە و چۆن دەپارێزن.
Why data has to be controlledبۆچی دەبێت دراوە کۆنترۆڵ بکرێت
Data is a valuable resource. Like money or buildings, it must be strictly controlled and managed. Part or all of an organisation's data may have strategic importance (customer lists, prices, plans, medical records), so it must be kept secure and confidential.
سەرچاوەیەکی بەنرخە. وەک پارە یان بینا، دەبێت بە توندی کۆنترۆڵ و بەڕێوە ببرێت. هەندێک یان هەموو دامەزراوەیەک دەکرێت گرنگییەکی ستراتیژیی هەبێت (لیستی کڕیاران، نرخەکان، پلانەکان، تۆماری نەخۆشی)، بۆیە دەبێت پارێزراو و نهێنی بمێنێتەوە.
This lesson covers database security, the types of threat and the computer-based countermeasures. RAID and other hardware controls, web security and data-protection rules come in the next lesson, RAID, web security and data protection.
ئەم وانەیە باسی ، جۆرەکانی و کۆمپیوتەری دەکات. و کۆنترۆڵەکانی تری ، وێب و یاساکانی لە وانەی دواتردان: RAID، ئاسایشی وێب و پاراستنی دراوە.
What is a threat?هەڕەشە چییە؟
Any situation or event, done on purpose or by accident, that can harm a system and therefore the organisation. Examples are theft and fraud, and the loss of , , or .
هەر دۆخ یان ڕووداوێکە، بە ئەنقەست یان بە هەڵکەوت، کە دەکرێت زیان بە سیستەمێک و لە ئەنجامدا بە دامەزراوەکە بگەیەنێت. نموونەکانی: دزی و فێڵ، لەدەستدانی ، ، یان .
Any situation or event, whether intentional or unintentional, that will adversely affect a system and so an organisation.
هەر دۆخ یان ڕووداوێک، بە ئەنقەست بێت یان نا، کە زیان بە سیستەمێک و لە ئەنجامدا بە دامەزراوەیەک دەگەیەنێت.
A hacker stealing customer records is an intentional threat. A clerk deleting the wrong table by mistake, a fire in the server room or a failed disk is not intentional, but it harms the organisation just as much. Cybersecurity sorts threats by where they come from and by what they cause: see Where threats come from and What threats cause.
کە تۆماری کڕیاران دەدزێت بە ئەنقەستە. فەرمانبەرێک کە بە هەڵە دەسڕێتەوە کە نەدەبوو بیسڕێتەوە، ئاگرێک لە ژووری ، یان دیسکێکی تێکچوو بە ئەنقەست نین، بەڵام بە هەمان ئەندازە زیان بە دامەزراوەکە دەگەیەنن. کۆرسی بەپێی سەرچاوەکەیان و بەپێی ئەوەی دەیکەن پۆلێن دەکات: بڕوانە هەڕەشەکان لە کوێوە دێن و هەڕەشەکان چی دەکەن.
What is a threat?هەڕەشە چییە؟
Five kinds of lossپێنج جۆری زیان
A threat can lead to five kinds of loss:
دەکرێت ببێتە هۆی پێنج جۆر زیان:
| Lossزیان | What it meansواتای چییە | Exampleنموونە |
|---|---|---|
| Theft and fraudدزی و فێڵ | Somebody takes the data, or uses it to steal money.کەسێک دەبات، یان بەکاری دەهێنێت بۆ دزینی پارە. | An employee copies the customer list and sells it.فەرمانبەرێک لیستی کڕیاران کۆپی دەکات و دەیفرۆشێت. |
| Loss of confidentiality (secrecy)لەدەستدانی | Company secrets become known to outsiders.نهێنییەکانی کۆمپانیا بۆ کەسانی دەرەوە ئاشکرا دەبن. | A competitor sees next year's prices and plans.کێبڕکێکارێک نرخ و پلانەکانی ساڵی داهاتوو دەبینێت. |
| Loss of privacyلەدەستدانی | Personal information about individuals is exposed. کەسیی تاکەکان ئاشکرا دەبێت. | Patients' illnesses or students' marks appear online.نەخۆشیی نەخۆشەکان یان نمرەی قوتابیان لە ئینتەرنێتدا دەردەکەون. |
| Loss of integrityلەدەستدانی | The data is changed, so it is no longer correct. دەگۆڕدرێت، بۆیە ئیتر دروست نییە. | A student changes their own marks.قوتابییەک نمرەکانی خۆی دەگۆڕێت. |
| Loss of availabilityلەدەستدانی | The data is still correct, but nobody can reach it. هێشتا دروستە، بەڵام کەس ناتوانێت پێی بگات. | Ransomware locks the server, and the hospital cannot open patient files. قفڵ دەکات و نەخۆشخانەکە ناتوانێت فایلی نەخۆشەکان بکاتەوە. |
Explains confidentiality, integrity and availability, the three things security must protect, with simple examples.
، و ڕوون دەکاتەوە، ئەو سێ شتەی دەبێت بیانپارێزێت، بە نموونەی سادە.
Whole video: three of the five losses on this screen — confidentiality, integrity and availability.
هەموو ڤیدیۆکە سێ لە پێنج جۆرەکەی زیانی سەر ئەم شاشەیە دەگرێتەوە: لەدەستدانی ، و .
Countermeasures: the seven computer-based controlsڕێوشوێنەکانی بەرگری: حەوت کۆنترۆڵە کۆمپیوتەرییەکە
A mechanism that protects a system against a . Computer-based countermeasures include , , , and , integrity rules, and .
میکانیزمێکە کە سیستەمێک لە بەرامبەر دەپارێزێت. ڕێوشوێنە کۆمپیوتەرییەکان بریتین لە ، ، ، و ، ڕێساکانی دروستی، و .
Countermeasures are mechanisms that protect the database against intentional or accidental threats.
ئەو میکانیزمانەن کە لە بە ئەنقەست یان بە ڕێکەوت دەپارێزن.
Computer-based controls cover everything from physical controls to administrative procedures. The course names seven of them:
کۆنترۆڵە کۆمپیوتەرییەکان هەموو شتێک دەگرنەوە، لە کۆنترۆڵی فیزیکییەوە تا ڕێکارە کارگێڕییەکان. کۆرسەکە حەوتیان ناو دەبات:
- Authorization: deciding what each user may do.
- Access controls: giving and taking away privileges.
- Views: showing a user only part of the data.
- Backup and recovery: keeping regular copies of the database and its log so that it can be brought back after a failure (taught in full in Backup and recovery).
- Integrity: rules that keep the data correct.
- Encryption: making the data unreadable without a key.
- RAID technology: keeping the system running when a disk fails (taught in the next lesson).
- : بڕیاردان لەسەر ئەوەی هەر چی دەتوانێت بکات.
- : دان و سەندنەوەی .
- : پیشاندانی تەنها بەشێک لە بە .
- و : هەڵگرتنی کۆپیی بەردەوامی و بۆ ئەوەی دوای تێکچوون بگەڕێنرێتەوە (بە تەواوی لە باکئەپ و گەڕاندنەوەی دراوە فێر دەبیت).
- : ڕێسا بۆ دروست هێشتنەوەی .
- : نەخوێنراوەکردنی بۆ هەر کەسێک کە کلیلەکەی نییە.
- تەکنەلۆژیای : بەردەوامکردنی کاری سیستەمەکە کاتێک دیسکێک تێکدەچێت (لە وانەی دواتر فێر دەبیت).
The next screens explain each control in turn, with the SQL commands where they exist.
شاشەکانی دواتر هەر کۆنترۆڵێک بە نۆرە ڕوون دەکەنەوە، لەگەڵ فەرمانەکانی SQL لەو شوێنانەی هەن.
Authorization: what are you allowed to do?ڕێگەپێدان: ڕێگەت پێدراوە چی بکەیت؟
Deciding what a logged-in user is allowed to see or do, for example letting only an admin delete users. It comes after .
بڕیاردانە لەسەر ئەوەی بەکارهێنەرێکی چووەژوورەوە بۆی هەیە چی ببینێت یان چی بکات، بۆ نموونە تەنها بەڕێوەبەر بتوانێت بەکارهێنەرەکان بسڕێتەوە. دوای دێت.
The granting of a right or privilege that lets a subject (a user or a program) legitimately use a system or one of its objects.
پێدانی مافێک یان کە ڕێگە بە کەسێک یان بەرنامەیەک دەدات بە شێوەیەکی ڕەوا سیستەمێک یان یەکێک لە بەشەکانی بەکاربهێنێت.
At the university gate, the guard checks your student card: that is authentication. Inside, your card opens the library and your department's lab, but not the exam office: that is authorization.
لە دەرگای زانکۆ، پاسەوانەکە کارتی خوێندکارییەکەت دەپشکنێت: ئەمە . لە ژوورەوە، کارتەکەت کتێبخانە و تاقیگەی بەشەکەت دەکاتەوە، بەڵام ژووری تاقیکردنەوەکان ناکاتەوە: ئەمە .
Where the analogy stops workingسنووری ئەم نموونەیە
The guard checks you once at the gate. A DBMS checks your privileges again on every single statement.
پاسەوانەکە یەک جار لە دەرگاکە دەتپشکنێت. لە هەموو فەرمانێکدا جارێکی تر دەپشکنێت.
Authentication checks who you are; authorization decides what you may do. A simple GitHub example shows the difference.
دەپشکنێت تۆ کێیت؛ بڕیار دەدات چی دەتوانیت بکەیت. نموونەیەکی سادەی GitHub جیاوازییەکە پیشان دەدات.
Plays 0:00-1:47: authentication answers 'who are you?', authorization answers 'what may you do?'. The example is GitHub, not a DBMS.
لە 0:00 تا 1:47 پەخش دەبێت: وەڵامی «تۆ کێیت؟» دەداتەوە و وەڵامی «چی دەتوانیت بکەیت؟» دەداتەوە. نموونەکە لە GitHub وەرگیراوە، نەک لە .
Authorization: what are you allowed to do?ڕێگەپێدان: ڕێگەت پێدراوە چی بکەیت؟
Access control and privilegesکۆنترۆڵی دەستڕاگەیشتن و مۆڵەتەکان
Deciding and enforcing who may read, add, change or delete which data. In a DBMS it works by granting and revoking .
بڕیاردان و جێبەجێکردنی ئەوەیە کە کێ بۆی هەیە کام دراوە بخوێنێتەوە، زیاد بکات، بگۆڕێت یان بسڕێتەوە. لە DBMSـدا بە پێدان و سەندنەوەی کار دەکات.
Access control is based on the granting and revoking of privileges.
لەسەر بنەمای دان و سەندنەوەی کار دەکات.
A right that lets a user create or use a database object, for example to read a table, insert into it or change it, or to run a DBMS tool. Privileges are given with GRANT and taken away with REVOKE.
مافێکە کە ڕێگە بە بەکارهێنەرێک دەدات شتێکی بنکەدراوە دروست بکات یان بەکاری بهێنێت، بۆ نموونە خشتەیەک بخوێنێتەوە، تێیدا زیاد بکات یان بیگۆڕێت، یان ئامرازێکی DBMS جێبەجێ بکات. مۆڵەت بە GRANT دەدرێت و بە REVOKE دەسەنرێتەوە.
A privilege allows a user to create or access (that is, read, write or modify) a database object, such as a table (relation), a view or an index, or to run certain DBMS utilities, such as a backup tool.
ڕێگە بە دەدات بەشێکی دروست بکات یان دەستی پێی بگات (واتە بیخوێنێتەوە، بینووسێت یان بیگۆڕێت)، وەک ، یان ، یان هەندێک ئامرازی کار پێبکات، وەک ئامرازی .
| User | Privileges |
|---|---|
| Librarianکتێبدار | SELECT, INSERT and UPDATE on loans; SELECT on booksSELECT، INSERT و UPDATE لەسەر loans؛ SELECT لەسەر books |
| Exam officeژووری تاقیکردنەوەکان | SELECT and UPDATE on marksSELECT و UPDATE لەسەر marks |
| The school website قوتابخانە | SELECT on books onlyتەنها SELECT لەسەر books |
| Database administrator | Everything, including creating users and running backupsهەموو شتێک، لەوانە دروستکردنی و گرتنی |
The DBMS can also write every refused or suspicious attempt, such as a wrong password or a command without the privilege, into a security log that the DBA reads regularly. Many refused logins in a short time can be an early sign of an attack. A fuller history of changes is shown in Keeping a history.
دەتوانێت هەموو هەوڵێکی ڕەتکراوە یان گوماناوی، وەک هەڵە یان فەرمانێک بەبێ ، لە ئاسایشدا تۆمار بکات کە بە بەردەوامی دەیخوێنێتەوە. زۆر ڕەتکراوە لە کاتێکی کورتدا دەکرێت نیشانەیەکی زووی بێت. مێژوویەکی تەواوتری گۆڕانکارییەکان لە هێشتنەوەی مێژوو پیشان دراوە.
Authorization: what are you allowed to do?ڕێگەپێدان: ڕێگەت پێدراوە چی بکەیت؟
Discretionary access control: GRANT and REVOKEکۆنترۆڵی دەستڕاگەیشتنی بەدڵخواز: GRANT و REVOKE
An method in which the owner of a database object decides which other users may use it, by granting and revoking . SQL supports it with GRANT and REVOKE.
شێوازێکی کە تێیدا خاوەنی شتێکی بنکەدراوە بڕیار دەدات کام بەکارهێنەرانی تر بۆیان هەیە بەکاری بهێنن، بە پێدان و سەندنەوەی . SQL بە GRANT و REVOKE پشتگیریی دەکات.
Most DBMSs provide discretionary access control (DAC): the owner of an object decides who else may use it, and how.
زۆربەی (DAC) دابین دەکەن: خاوەنی هەر بەشێک بڕیار دەدات کێی تر دەتوانێت بەکاری بهێنێت و چۆن.
The SQL standard supports DAC through two commands of the family. GRANT gives privileges to users, and REVOKE takes privileges away.
ستانداردی SQL بە دوو فەرمانی خێزانی پشتگیریی DAC دەکات. GRANT بە دەدات و REVOKE دەسەنێتەوە.
-- Hana works in the exam office: she may read and correct marks
CREATE USER 'hana'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT SELECT, UPDATE ON school.marks TO 'hana'@'localhost';
-- The exam period is over: from now on she may only read them
REVOKE UPDATE ON school.marks FROM 'hana'@'localhost';Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Create the account first. The password proves who Hana is (authentication).
سەرەتا دروست بکە. دەیسەلمێنێت هانا کێیە ().
- Lineدێڕی 3
Authorization: two privileges on one table,
marksin theschooldatabase. Nothing else.: دوو لەسەر یەک ،
marksلەschool. هیچی تر.- Lineدێڕی 6
REVOKEtakes one privilege back;SELECTstays.REVOKEیەک دەسەنێتەوە؛SELECTدەمێنێتەوە.
Views: show only part of the dataدیمەنەکان: تەنها بەشێک لە دراوە پیشان بدە
A virtual table made from a saved on one or more real tables. It is built again each time it is used, and it can show a user only the rows and columns they are allowed to see.
خشتەیەکی گریمانەییە کە لە هەڵگیراو لەسەر یەک یان چەند خشتەیەکی ڕاستەقینە دروست دەبێت. هەر جارێک بەکار بهێنرێت دووبارە دروست دەکرێتەوە و دەتوانێت تەنها ئەو ڕیز و ستوونانە پیشانی بەکارهێنەرێک بدات کە ڕێگەی پێدراوە ببینێت.
A view is the dynamic result of one or more relational operations on the base tables, which produces another table. It is a virtual table: it does not really exist in the database, but is produced when a user asks for it, at the moment they ask. (Relational operations are taught in Relational algebra and calculus.)
ئەنجامی گۆڕاوی یەک یان چەند کارێکی پەیوەندیدارە لەسەر ، کە تر بەرهەم دەهێنێت. مەجازییە: بە ڕاستی لە بوونی نییە، بەڵکو کاتێک داوای دەکات، لە هەمان ساتدا دروست دەکرێت. (کارە پەیوەندیدارەکان لە جەبری پەیوەندیدار فێر دەبیت.)
CREATE TABLE marks (
student_id INT PRIMARY KEY,
student_name VARCHAR(50),
class_name VARCHAR(10),
mark INT,
parent_phone VARCHAR(20)
);
INSERT INTO marks VALUES
(1, 'Aram', '7A', 88, '0750 000 0011'),
(2, 'Shilan', '7B', 93, '0770 000 0022'),
(3, 'Karwan', '7A', 76, '0751 000 0033');
CREATE VIEW class_7a_marks AS
SELECT student_name, mark
FROM marks
WHERE class_name = '7A';
SELECT * FROM class_7a_marks;Aram|88 Karwan|76
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 13-16
The view stores only this query, not a copy of the data.
SELECT student_name, markchooses the columns;WHEREchooses the rows.تەنها ئەم هەڵدەگرێت، نەک کۆپییەکی .
SELECT student_name, markهەڵدەبژێرێت؛WHEREهەڵدەبژێرێت.- Lineدێڕی 18
The view is used exactly like a table.
ڕێک وەک بەکاردێت.
In MySQL the DBA then gives the class teacher the view and nothing else: GRANT SELECT ON school.class_7a_marks TO 'soran'@'localhost';. Soran, the class teacher, can read the marks of class 7A, but he cannot see other classes or the parents' phone numbers.
لە MySQL، پاشان تەنها دەداتە مامۆستای پۆلەکە: GRANT SELECT ON school.class_7a_marks TO 'soran'@'localhost';. سۆران دەتوانێت نمرەکانی پۆلی 7A بخوێنێتەوە، بەڵام ناتوانێت پۆلەکانی تر یان ژمارە مۆبایلی دایک و باوکان ببینێت.
Creates MySQL views that show only some columns of a table; a view is a virtual table that always reflects the base table.
لە چەند دروست دەکات کە تەنها هەندێک لە پیشان دەدەن؛ گریمانەییە کە هەمیشە دۆخی ئێستای بنەڕەتی پیشان دەدات.
Whole video: CREATE VIEW in MySQL; the lesson then shows granting the view instead of the table.
هەموو ڤیدیۆکە: CREATE VIEW لە ؛ پاشان وانەکە پیشان دەدات چۆن لەسەر دەدرێت لە جیاتی .
Views: show only part of the dataدیمەنەکان: تەنها بەشێک لە دراوە پیشان بدە
A view over several tables: join, then trimدیمەنێک لەسەر چەند خشتەیەک: لێکبەستن، پاشان کورتکردنەوە
A view can also join two or three tables and then keep only the columns one user needs. The dean wants the best students with their department, but must not see their phone numbers. Three tables are joined, and three columns are kept:
دەتوانێت دوو یان سێ بە پێکەوە ببەستێت و پاشان تەنها ئەو بهێڵێتەوە کە پێویستی پێیانە. ڕاگری کۆلێژ دەیەوێت باشترین قوتابیان لەگەڵ بەشەکەیان ببینێت، بەڵام نابێت ژمارەی مۆبایلیان ببینێت. سێ بە پێکەوە دەبەسترێن و سێ دەمێننەوە:
CREATE TABLE departments (dept_id INT PRIMARY KEY, dept_name VARCHAR(50));
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(50),
phone VARCHAR(20),
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES departments (dept_id)
);
CREATE TABLE results (student_id INT PRIMARY KEY, average DECIMAL(4,1));
INSERT INTO departments VALUES (1, 'Software'), (2, 'Networks');
INSERT INTO students VALUES
(1, 'Aram', '0750 000 0011', 1),
(2, 'Shilan', '0770 000 0022', 2),
(3, 'Karwan', '0751 000 0033', 1);
INSERT INTO results VALUES (1, 91.5), (2, 93.5), (3, 76.5);
CREATE VIEW top_students AS
SELECT s.name, d.dept_name, r.average
FROM students s
JOIN departments d ON d.dept_id = s.dept_id
JOIN results r ON r.student_id = s.student_id
WHERE r.average >= 90;
SELECT * FROM top_students;Aram|Software|91.5 Shilan|Networks|93.5
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 18
SELECTkeeps three columns: no phone number and no student ID.SELECTسێ دەهێڵێتەوە: نە ژمارەی مۆبایل و نە ژمارەی قوتابی.- Lineدێڕی 19-21
Three tables joined on their keys.
سێ لەسەر بە پێکەوە دەبەسترێن.
- Lineدێڕی 22
Only students with an average of 90 or more.
تەنها ئەو قوتابیانەی تێکڕاکەیان ٩٠ یان زیاترە.
Then the DBA grants the dean this view and nothing else, exactly as on the previous screen. Joins themselves are taught in Relational algebra.
پاشان تەنها ئەم دەداتە ڕاگرەکە، ڕێک وەک شاشەی پێشوو. خودی لە جەبری پەیوەندیدار فێر دەبیت.
Views: show only part of the dataدیمەنەکان: تەنها بەشێک لە دراوە پیشان بدە
Two more ways: a private table, and totals onlyدوو ڕێگای تر: خشتەیەکی تایبەت و تەنها کۆ و تێکڕا
A separate table for sensitive columns. Keep columns such as family income or health notes in their own table, linked one-to-one to students by student_id, and grant that table only to the student-support office. Everybody else keeps using students and never meets the private columns.
جیا بۆ هەستیارەکان. وەک داهاتی خێزان یان تێبینیی تەندروستی لە تایبەت بە خۆیان هەڵبگرە کە بە student_id بە شێوەی یەک بۆ یەک بە studentsـەوە بەستراوە. ئەو تەنها بە نووسینگەی یارمەتیی قوتابیان بدە. هەموو کەسێکی تر هەر students بەکاردەهێنێت و هەرگیز تایبەتەکان نابینێت.
Totals only. Some users, such as researchers, may see counts and averages but never one person's row. Give them a view built with COUNT and GROUP BY (GROUP BY). Very small groups are still risky: if only one student in a class comes from Halabja, 'count = 1' points at her. Statistics offices therefore hide tiny counts, or round every count at random up or down to a multiple of 5.
تەنها کۆ و تێکڕا. هەندێک ، وەک توێژەران، دەتوانن ژمارە و تێکڕا ببینن، بەڵام هەرگیز یەک کەس نا. بدەرێ کە بە COUNT و GROUP BY دروست کراوە (GROUP BY). گرووپی زۆر بچووک هێشتا مەترسیدارن: ئەگەر تەنها یەک قوتابیی پۆلێک خەڵکی هەڵەبجە بێت، «ژمارە = 1» ئاماژە بەو دەکات. بۆیە نووسینگەکانی ژمارە زۆر بچووکەکان دەشارنەوە، یان هەر ژمارەیەک بە هەڕەمەکی بۆ سەرەوە یان بۆ خوارەوە دەبەنە سەر چەندجارەیەکی ٥.
Integrity: keep the data correctدروستیی دراوە: دراوە دروست ڕابگرە
Data being correct, complete and unchanged by mistakes or attacks. A database protects it with rules () that stop impossible values from being saved.
بریتییە لەوەی دراوە دروست، تەواو و بێ گۆڕانی هەڵە یان هێرش بێت. بە ڕێسا () دەیپارێزێت کە ڕێگە نادەن نرخی نەگونجاو خەزن بکرێت.
Integrity controls prevent data from becoming invalid, and so from giving misleading or incorrect results.
کۆنترۆڵەکانی ڕێگری دەکەن لەوەی نادروست ببێت و لە ئەنجامدا ئەنجامی هەڵە یان چەواشەکار بدات.
In plain words: integrity means rules that stop impossible values ever being stored, such as an age of minus five, or an order for a product that does not exist. In SQL these rules are integrity constraints: CHECK, FOREIGN KEY, NOT NULL, UNIQUE and PRIMARY KEY (see Database keys). In cybersecurity, integrity also means noticing that data was changed on the way, with a hash: see Same size is not enough.
بە وشەی سادە: واتە ئەو ڕێسایانەی هەرگیز ڕێگە نادەن بەهای مەحاڵ هەڵبگیرێت، وەک تەمەنی سالب پێنج، یان داواکردنی بەرهەمێک کە بوونی نییە. لە SQL ئەم ڕێسایانە ن: CHECK، FOREIGN KEY، NOT NULL، UNIQUE و PRIMARY KEY (بڕوانە کلیلەکانی بنکەدراوە). لە ، ئەوەش دەگرێتەوە کە بزانیت لە ڕێگادا گۆڕاوە، بە : بڕوانە هەمان قەبارە بەس نییە.
PRAGMA foreign_keys = ON;
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
age INT CHECK (age >= 0)
);
CREATE TABLE products (
product_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
product_id INT NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (customer_id),
FOREIGN KEY (product_id) REFERENCES products (product_id)
);
INSERT INTO customers VALUES (1, 'Aram', 20);
INSERT INTO products VALUES (1, 'USB cable');
INSERT INTO customers VALUES (2, 'Shilan', -5);
INSERT INTO orders VALUES (1, 1, 99);
INSERT INTO orders VALUES (2, 1, 1);
SELECT * FROM orders;Runtime error near line 20: CHECK constraint failed: age >= 0 (19) Runtime error near line 21: FOREIGN KEY constraint failed (19) 2|1|1
Only the valid order (2, 1, 1) was saved. MySQL refuses the same two rows with its own error messages.
تەنها داواکارییە دروستەکە (2، 1، 1) پاشەکەوت کرا. MySQL هەمان دوو بە پەیامی هەڵەی خۆی ڕەت دەکاتەوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
SQLite only: switch on foreign-key checks. MySQL's InnoDB checks foreign keys without this line.
تەنها بۆ SQLite: پشکنینی هەڵدەکات. InnoDBـی MySQL بەبێ ئەم دێڕە دەپشکنێت.
- Lineدێڕی 5
CHECK: an age can never be negative.CHECK: تەمەن هەرگیز ناتوانێت سالب بێت.- Lineدێڕی 16
FOREIGN KEY: an order may only name a product that exists.FOREIGN KEY: داواکارییەک تەنها دەتوانێت ناوی بەرهەمێک بهێنێت کە بوونی هەیە.- Lineدێڕی 20-21
An age of minus five, and an order for product 99, which does not exist. Both are refused.
تەمەنی سالب پێنج و داواکردنی بەرهەمی ٩٩ کە بوونی نییە. هەردووکیان ڕەت دەکرێنەوە.
Keeping a history: audit tables and triggersهێشتنەوەی مێژوو: خشتەکانی چاودێری و پیتکەکانی بنکەدراوە
Integrity rules stop impossible values, but not a wrong value that looks possible: a mark changed from 58 to 85 breaks no rule. To find out later what changed, and when, many databases keep a history table that receives the old and the new value every time a row changes. A trigger, a small program stored in the database, fills it by itself:
ڕێگری لە بەهای مەحاڵ دەکەن، بەڵام نەک لە بەهایەکی هەڵە کە ئاسایی دیارە: گۆڕینی نمرەیەک لە ٥٨ـەوە بۆ ٨٥ هیچ ڕێسایەک ناشکێنێت. بۆ ئەوەی دواتر بزانیت چی گۆڕاوە و کەی، زۆر مێژوو هەڵدەگرن کە هەر جارێک بگۆڕێت، بەها کۆن و نوێکەی تێدا دەنووسرێت. ، بەرنامەیەکی بچووک کە لە ناو هەڵگیراوە، خۆی پڕی دەکاتەوە:
CREATE TABLE marks (
student_id INT,
course VARCHAR(50),
mark INT,
PRIMARY KEY (student_id, course)
);
CREATE TABLE marks_history (
student_id INT,
course VARCHAR(50),
old_mark INT,
new_mark INT,
changed_at TEXT
);
CREATE TRIGGER keep_mark_history
AFTER UPDATE OF mark ON marks
FOR EACH ROW
BEGIN
INSERT INTO marks_history
VALUES (OLD.student_id, OLD.course, OLD.mark, NEW.mark, datetime('now'));
END;
INSERT INTO marks VALUES (7, 'Databases', 58);
UPDATE marks SET mark = 85 WHERE student_id = 7 AND course = 'Databases';
SELECT student_id, course, old_mark, new_mark FROM marks_history;7|Databases|58|85
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7-13
The history table: the old and the new mark, and when.
مێژوو: نمرە کۆن و نوێکە و کاتەکەی.
- Lineدێڕی 14-20
The trigger runs by itself after every
UPDATEofmark.OLDis the row before the change,NEWthe row after it.دوای هەر
UPDATEێکیmarkخۆی کار دەکات.OLDواتە پێش گۆڕانەکە وNEWواتە دوای گۆڕانەکە.- Lineدێڕی 23
Nobody writes into
marks_historyby hand; the trigger does it.کەس بە دەست لە
marks_historyـدا نانووسێت؛ دەینووسێت.
In MySQL the trigger is written AFTER UPDATE ON marks FOR EACH ROW with NOW(), and it can also store who made the change with USER(). SQLite has no user accounts, so there the application must record the user. A wider event log keeps logins, failed logins and changes to money or marks, each with the time, the user and the details.
لە MySQL، بە AFTER UPDATE ON marks FOR EACH ROW و NOW() دەنووسرێت و دەتوانێت بە USER() ئەوەش هەڵبگرێت کە کێ گۆڕانەکەی کردووە. SQLite هیچ نییە، بۆیە لەوێ بەرنامەکە دەبێت تۆمار بکات. فراوانتر ، سەرنەکەوتووەکان و گۆڕانکاری لە پارە یان نمرەدا هەڵدەگرێت، هەر یەکەیان لەگەڵ کات، و وردەکارییەکان.
Encryption: unreadable to outsidersشفرەکردن: نەخوێنراوە بۆ کەسانی دەرەوە
Turning readable data into a secret code that only someone with the right key can turn back. Unlike a , encryption can be reversed with the key.
گۆڕینی دراوەی خوێنراوە بۆ کۆدێکی نهێنی، بە شێوەیەک کە تەنها خاوەنی کلیلی دروست بتوانێت بیگەڕێنێتەوە بۆ دەقی ئاسایی. بە پێچەوانەی ، ئەم کارە بە کلیلەکە دەگەڕێتەوە.
The encoding of the data by a special algorithm that makes the data unreadable by any program without the decryption key.
گۆڕینی بە تایبەت، بە شێوەیەک کە هیچ بەرنامەیەک نەتوانێت بیخوێنێتەوە، مەگەر کلیلی هەبێت.
- At rest: encrypt the database files and the backups on disk, so a stolen disk or backup file is useless.
- In transit: encrypt data while it travels over the network, between the application and the database server (TLS).
- Keep the key away from the data. A key stored next to the encrypted file is like a padlock with its key hanging on it.
- : فایلەکانی و سەر دیسک شفرە بکە، بۆ ئەوەی دیسک یان فایلی دزراو بێسوود بێت.
- : شفرە بکە کاتێک بە دەڕوات، لە نێوان بەرنامەکە و (TLS).
- کلیلەکە لە دوور ڕابگرە. کلیلێک لە تەنیشت فایلە شفرەکراوەکە هەڵگیرابێت وەک قفڵێک وایە کە کلیلەکەی پێوە هەڵواسرابێت.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Why it is wrongبۆچی هەڵەیە | Do this insteadلە جیاتی ئەوە |
|---|---|---|
| Saying 'authorization' for checking a passwordوتنی بۆ پشکنینی | Checking a password is authentication.پشکنینی . | Authentication = who you are; authorization = what you may do. = تۆ کێیت؛ = چی دەتوانیت بکەیت. |
Letting every application connect as rootهێشتنی هەموو بەرنامەیەک بە root پەیوەندی بکات | One mistake or attack can then destroy every database.ئەو کاتە یەک هەڵە یان هێرش دەتوانێت هەموو لەناو ببات. | Give each user only the privileges their job needs.تەنها ئەو بە هەر بدە کە کارەکەی پێویستی پێیەتی. |
| Giving a user the whole table when they need a few columnsدانی هەموو بە کاتێک تەنها چەند پێویستە | They can read data they should never see.دەتوانێت ئەو بخوێنێتەوە کە هەرگیز نابێت بیبینێت. | Grant a view instead.لە جیاتی ئەوە بدە. |
| Checking values only in the web formپشکنینی بەهاکان تەنها لە فۆڕمی وێبدا | Other programs, or an attacker, can skip the form.بەرنامەی تر، یان هێرشبەرێک، دەتوانێت فۆڕمەکە تێپەڕێنێت. | Also put integrity constraints in the database. لە ناو دابنێ. |
| Keeping the encryption key next to the encrypted dataهەڵگرتنی لە تەنیشت شفرەکراو | A thief who copies one gets both.دزێک کە یەکێکیان کۆپی بکات هەردووکیانی دەست دەکەوێت. | Store keys separately, with their own access control.کلیلەکان بە جیا هەڵبگرە، بە تایبەت بە خۆیان. |
Exercisesڕاهێنانەکان
Which kind of loss is each event? (a) A clerk sells the list of a bank's customers. (b) A power cut stops the booking system for six hours. (c) A virus changes prices in the shop database. (d) The marks of all students are published on social media. (e) A factory's new product design reaches a competitor.
هەر ڕووداوێک کام جۆری زیانە؟ (أ) فەرمانبەرێک لیستی کڕیارانی بانکێک دەفرۆشێت. (ب) بڕانی کارەبا سیستەمی حیجزکردن بۆ شەش کاتژمێر ڕادەگرێت. (ج) ڤایرۆسێک نرخەکان لە فرۆشگاکەدا دەگۆڕێت. (د) نمرەی هەموو قوتابیان لە تۆڕە کۆمەڵایەتییەکاندا بڵاو دەکرێتەوە. (هـ) دیزاینی بەرهەمێکی نوێی کارگەیەک دەگاتە دەستی کێبڕکێکارێک.
Show answerوەڵامەکە پیشان بدە
- (a) Theft and fraud (and loss of privacy for the customers).
- (b) Loss of availability.
- (c) Loss of integrity.
- (d) Loss of privacy.
- (e) Loss of confidentiality (a company secret).
- (أ) دزی و فێڵ (و لەدەستدانی بۆ کڕیاران).
- (ب) لەدەستدانی .
- (ج) لەدەستدانی .
- (د) لەدەستدانی .
- (هـ) لەدەستدانی (نهێنییەکی کۆمپانیا).
Sort these: (a) a fingerprint opens the server room; (b) Dilan may read the books table but not change it; (c) the DBMS checks Rezan's password; (d) GRANT INSERT ON school.loans TO 'rezan'@'localhost';; (e) a code from an SMS is typed after the password.
ئەمانە پۆلێن بکە: (أ) پەنجەمۆرێک ژووری دەکاتەوە؛ (ب) دیلان دەتوانێت books بخوێنێتەوە بەڵام نایگۆڕێت؛ (ج) ڕێزان دەپشکنێت؛ (د) GRANT INSERT ON school.loans TO 'rezan'@'localhost';؛ (هـ) کۆدێکی SMS دوای دەنووسرێت.
Show answerوەڵامەکە پیشان بدە
Authentication (who are you?): (a), (c) and (e). Item (e) is a second factor: two-factor authentication. Authorization (what may you do?): (b) and (d).
(تۆ کێیت؟): (أ)، (ج) و (هـ). بڕگەی (هـ) هۆکاری دووەمە: پشتڕاستکردنەوەی دوو قۆناغی. (چی دەتوانیت بکەیت؟): (ب) و (د).
Dilan is a new clerk. Give her the right to read and add rows in school.students, but not to change or delete them. A month later she moves to another job: take away the right to add rows. (MySQL; the account 'dilan'@'localhost' already exists.)
دیلان فەرمانبەرێکی نوێیە. مافی خوێندنەوە و زیادکردنی لە school.students بدەرێ، بەڵام نەک گۆڕین یان سڕینەوەیان. مانگێک دواتر دەچێتە کارێکی تر: مافی زیادکردنی لێ بسەنەوە. (MySQL؛ 'dilan'@'localhost' پێشتر هەیە.)
Show answerوەڵامەکە پیشان بدە
GRANT SELECT, INSERT ON school.students TO 'dilan'@'localhost';
-- one month later
REVOKE INSERT ON school.students FROM 'dilan'@'localhost';A company's table employees(emp_id, name, department, salary, phone) holds salaries. Everyone in the company should see a phone list (name, department and phone) but not the salaries. Write the view.
employees(emp_id, name, department, salary, phone)ـی کۆمپانیایەک مووچەکانی تێدایە. هەموو کەسێکی کۆمپانیاکە دەبێت لیستی ژمارە تەلەفۆن ببینێت (ناو، بەش و ژمارە) بەڵام مووچەکان نا. بنووسە.
Show answerوەڵامەکە پیشان بدە
CREATE VIEW phone_list AS
SELECT name, department, phone
FROM employees;Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
salaryis simply left out. Then grantSELECTonphone_list, not onemployees.salaryتەنها لابراوە. پاشانSELECTلەسەرphone_listبدە، نەک لەسەرemployees.
Summary and reviewپوختە و پێداچوونەوە
- Data is a valuable resource; strategic data must be kept secure and confidential.
- A threat is any situation or event, intentional or not, that harms the system and the organisation. It can cause theft and fraud, or loss of confidentiality, privacy, integrity or availability.
- The seven computer-based countermeasures: authorization, access controls, views, backup and recovery, integrity, encryption and RAID.
- Authentication checks who you are; authorization decides what you may do.
- Discretionary access control uses
GRANTandREVOKE; give only the privileges a job needs (least privilege). - A view is a virtual table that shows only chosen rows and columns.
- Integrity constraints stop impossible data; encryption makes stolen data unreadable without the key.
- سەرچاوەیەکی بەنرخە؛ ستراتیژی دەبێت پارێزراو و نهێنی بمێنێتەوە.
- هەر دۆخ یان ڕووداوێکە، بە ئەنقەست یان نا، کە زیان بە سیستەم و دامەزراوەکە دەگەیەنێت. دەتوانێت ببێتە هۆی دزی و فێڵ، یان لەدەستدانی ، ، یان .
- حەوت کۆمپیوتەرییەکە: ، ، ، و ، ، و .
- دەپشکنێت تۆ کێیت؛ بڕیار دەدات چی دەتوانیت بکەیت.
-
GRANTوREVOKEبەکاردەهێنێت؛ تەنها ئەو بدە کە کارەکە پێویستی پێیەتی (). - مەجازییە کە تەنها و هەڵبژێردراوەکان پیشان دەدات.
- ڕێگری لە مەحاڵ دەکەن؛ دزراو بەبێ کلیل نەخوێنراوە دەکات.
What is a threat?هەڕەشە چییە؟
Any situation or event, intentional or not, that will harm a system and the organisation.
هەر دۆخ یان ڕووداوێک، بە ئەنقەست یان نا، کە زیان بە سیستەمێک و دامەزراوەکە دەگەیەنێت.
Which two SQL commands support discretionary access control?کام دوو فەرمانی SQL پشتگیریی کۆنترۆڵی دەستڕاگەیشتنی بەدڵخواز دەکەن؟
GRANT gives privileges; REVOKE takes them away.
GRANT دەدات؛ REVOKE دەیانسەنێتەوە.
Why is a view a security tool?بۆچی دیمەن ئامرازێکی ئاسایشە؟
It shows a user only part of the data, without giving access to the real table.
تەنها بەشێک لە پیشانی دەدات، بەبێ ئەوەی دەستڕاگەیشتن بە بدات.
What is the difference between authentication and authorization?جیاوازیی نێوان پشتڕاستکردنەوەی ناسنامە و ڕێگەپێدان چییە؟
Authentication confirms who a user is (password, key card, fingerprint). Authorization decides what that user may do (their privileges).
دڵنیا دەبێتەوە کێیە (، کارتی کلیل، پەنجەمۆر). بڕیار دەدات ئەو چی دەتوانێت بکات ().
Name the five kinds of loss a threat can cause.پێنج جۆرەکەی ئەو زیانەی هەڕەشە دەتوانێت دروستی بکات ناو ببە.
Theft and fraud; loss of confidentiality; loss of privacy; loss of integrity; loss of availability.
دزی و فێڵ؛ لەدەستدانی ؛ لەدەستدانی ؛ لەدەستدانی ؛ لەدەستدانی .
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
RAID, Web Security and Data ProtectionRAID، ئاسایشی وێب و پاراستنی دراوە
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- NIST CSRC Glossary: authentication
- NIST CSRC Glossary: authorization
- NIST CSRC Glossary: least privilege
- NIST CSRC Glossary: discretionary access control
- NIST CSRC Glossary: mandatory access control
- OWASP: SQL Injection
- MySQL 8.4 Reference Manual: Using Roles
- MySQL 8.4 Reference Manual: CREATE VIEW Statement
- MySQL 8.4 Reference Manual: CHECK Constraints
- SQLite: CREATE TRIGGER
- MySQL 8.4 Reference Manual: Information Functions (USER and CURRENT_USER)
- Microsoft Learn: Temporal tables (system-versioned)
- MariaDB Knowledge Base: System-Versioned Tables
- Statistics Canada: random rounding of published counts (General notes)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.