Database Security Basics
Assets, Threats और Trust Boundaries से शुरू करें
Database security confidentiality, integrity और availability protect करती है। पहले inventory बनाएँ:
| Asset | Threat | Evidence |
|---|---|---|
| Student/parent data | Disclosure | Access matrix/audit |
| Fees/marks | Unauthorized change | Authorization/change control |
| Service | Ransomware/overload | Monitoring/recovery |
| Secrets/keys | Code/backup theft | Vault/rotation logs |
Browser→app→DB, admin workstation→management network→DB और DB→backup boundaries map करें। Classification, owner, purpose, retention, RPO/RTO और incident contact लिखें।
Network Exposure घटाएँ और TLS Verify करें
- MySQL private network में रखें; public Internet पर 3306 न खोलें।
- Firewall में केवल approved app/admin sources।
- Admin के लिए bastion/VPN/private endpoint।
- Production/test/dev networks और credentials अलग।
[mysqld]
bind_address=10.20.30.10
require_secure_transport=ON
mysql --login-path=school_app \
--ssl-mode=VERIFY_IDENTITY \
--ssl-ca=/approved/ca.pemREQUIRED unencrypted fallback रोकता है; VERIFY_CA CA और VERIFY_IDENTITY hostname भी check करता है। Trusted certificates और renewal test करें। REQUIRE SSL/X509 network controls को complement करते हैं।
Dedicated Identities और Protected Secrets
CREATE USER 'school_runtime'@'10.20.30.%'
IDENTIFIED BY RANDOM PASSWORD REQUIRE SSL
COMMENT 'Production school web runtime';
GRANT SELECT,INSERT,UPDATE ON school_app.attendance
TO 'school_runtime'@'10.20.30.%';
SHOW GRANTS FOR 'school_runtime'@'10.20.30.%';App root, developer या migration identity use न करे। Secret vault/environment injection में हो—Git, JS, public folder, screenshot/chat में नहीं। Narrow host, roles, minimum scope, rotation और safe deprovisioning रखें। FILE/GRANT OPTION/admin privileges avoid करें। Break-glass admin monitor करें। user lifecycle पढ़ें।
Injection रोकें और Authorization Enforce करें
Business input validate और हर data value bind करें। Identifiers के लिए allowlist रखें।
$pdo=new PDO($dsn,$dbUser,$dbPassword,[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
]);
$stmt=$pdo->prepare(
'SELECT student_id,student_name FROM students
WHERE class_id=:class_id AND student_id=:id'
);
$stmt->execute([
':class_id'=>$authorizedClassId,
':id'=>$validatedStudentId,
]);Query authorized class boundary रखती है। केवल student_id check करने पर cross-class/tenant leak हो सकता है। SQL errors/secrets user को न दिखाएँ; multi-step rules में transactions, limits और safe debug policy रखें। Injection, broken access, mass assignment और races test करें। prepared statements पढ़ें।
Sensitive Data Lifecycle Protect करें
- Minimum data collect, classify और retention तय करें।
- Verified TLS और supported at-rest encryption।
- Keys DB से बाहर और recovery tested।
- Backups/exports encrypt और links expire।
- Development में masked/synthetic data।
- Logs से secrets/sensitive fields redact।
- Expired data और copies securely delete।
Web-user passwords adaptive password API से hash करें:
$hash=password_hash($password,PASSWORD_ARGON2ID);
if(password_verify($candidate,$hash)) {
// Secure session और authorization
}Argon2id unavailable हो तो PASSWORD_DEFAULT और rehash plan रखें। Plain SHA-256 password function नहीं; encryption reversible है।
MySQL Server Harden और Patch करें
[mysqld]
require_secure_transport=ON
local_infile=OFF
secure_file_priv=/var/lib/mysql-files- Supported MySQL/OS और timely patches।
- Non-root OS service और restrictive permissions।
- No anonymous/test/empty admin accounts।
skip-grant-tablesactive न छोड़ें।- LOCAL/file import controlled workflow तक disabled।
- Approved plugins/components only।
- Production और nonproduction separate।
- Reviewed config और drift detection।
Hosting change process से config apply/test करें। Directory secure_file_priv operations restrict करता है; NULL disable करता है। Web app को FILE न दें।
Access, Changes और Failures Monitor करें
- Authentication success/failure और locks।
- Account, role, GRANT/REVOKE/config changes।
- Privilege escalation/new definers।
- Backup failures, restore tests, binlog continuity।
- Abnormal queries, errors, connections, export volume।
- Host, firewall, vault/control-plane events।
Deployed edition/service के audit facilities use करें। General query log sensitive values और overhead ला सकता है, इसलिए default continuous audit नहीं। Logs protect, time sync, retain और actionable alert करें।
SHOW GRANTS FOR 'school_runtime'@'10.20.30.%';
SELECT USER(),CURRENT_USER(),CURRENT_ROLE();
SHOW VARIABLES LIKE 'require_secure_transport';
SHOW VARIABLES LIKE 'local_infile';Recovery और Incident Response भी Security है
- Prepare: owners, contacts, forensics और clean recovery।
- Detect: identities, data, timeline validate।
- Contain: evidence preserve; account lock/network isolate।
- Eradicate: root cause patch; secrets/keys rotate।
- Recover: known-good restore और validation।
- Learn: timeline, impact, controls और retest।
Encrypted, restricted, immutable/offsite backup और RPO/RTO के भीतर isolated restore proof रखें। Replica अकेला backup नहीं।
backup guide use करें।
Official संदर्भ
Encryption, access control और server security official MySQL 8.4 manual से verified हैं। Edition/managed service पर features validate करें।