Thuta Learning
How Databases Work
ExercisesData & Databasesbeginner

လေ့ကျင့်ခန်း — ဒေတာဘေ့စ် လုံခြုံရေး Audit တစ်ခု

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • လေ့ကျင့်ခန်း — ဒေတာဘေ့စ် လုံခြုံရေး Audit တစ်ခု concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram/table ကို ဖတ်ပြီး data model/schema/architecture ဘယ်လို ပုံသဏ္ဌာန်ရှိသလဲ ခြေရာခံနိုင်ရန်
  • ကိုယ့် project အတွက် database concept/system ကို ဘယ်လို အသုံးချသင့်သလဲ ရှင်းပြနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Security audit ဆိုတာ security topic တွေကို တစ်ခုချင်းစီ သင်ယူတာနဲ့ မတူပါဘူး။ ယခင်သင်ခန်းစာတွေမှာ authentication၊ least privilege၊ network access၊ TLS၊ secrets management နဲ့ SQL injection ကို သီးခြား concept တွေအနေနဲ့ မိတ်ဆက်ခဲ့ပါတယ်။

အစစ်အမှန် audit တစ်ခုဆိုတာ run နေတဲ့ system တစ်ခုလုံးကို ကြည့်ပြီး layer တိုင်းမှာ ဒီ concept တွေကို တကယ် အကောင်အထည်ဖော်ထားလားလို့ မေးခွန်းထုတ်တာပါ — concept တစ်ခုချင်းစီကို တစ်ပိုင်းတစ်စ မှန်အောင်လုပ်ထားပေမယ့် system တစ်ခုလုံးအနေနဲ့ အန္တရာယ်ရှိနေနိုင်လို့ပါ။

ဒီ exercise က သေးငယ်ပြီး လက်တွေ့ကျတဲ့၊ ရည်ရွယ်ချက်ရှိရှိ ချို့ယွင်းအောင်ပြုလုပ်ထားတဲ့ setup တစ်ခုကို ပေးထားပါတယ် — အောက်က characteristic ခြောက်ခုစလုံးက setup ထဲမှာ ရှိနေပါတယ်။

  • database operation အားလုံးအတွက် (read-only reporting အပါအဝင်) shared admin account တစ်ခုတည်းကို အသုံးပြုနေသည်။
  • connection string နဲ့ password ကို source control ထဲ commit လုပ်ထားသော config file ထဲတွင် hardcode လုပ်ထားသည်။
  • database server ကို public internet မှ တိုက်ရိုက် ချိတ်ဆက်နိုင်ပြီး၊ connection ကို ကန့်သတ်မည့် firewall rule လုံးဝမရှိပါ။
  • connection သည် TLS ကို ဘယ်တော့မှ negotiate မလုပ်သဖြင့် traffic များကို encrypt မလုပ်ဘဲ ပို့ဆောင်နေသည်။
  • backup များကို ညတိုင်း run နေသော်လည်း test-restore တစ်ကြိမ်မှ မလုပ်ဖူးသေးပါ။
  • query အချို့သည် user input ကို query string ထဲသို့ တိုက်ရိုက် concatenate လုပ်ထားသည်။

Framework-neutral failure များ

ဒါတွေက authentication၊ least privilege၊ network exposure၊ encryption နဲ့ operational readiness တို့ရဲ့ framework-neutral failure တွေဖြစ်ပြီး၊ product-specific configuration ပြဿနာများ မဟုတ်ပါ။

သင့်ရဲ့တာဝန်ကတော့ တကယ့် auditor တစ်ယောက် လုပ်မယ့်နည်းလမ်းအတိုင်း layer တစ်ခုချင်းစီကို ဘာမှားနိုင်လဲ၊ ဘာလို့ အရေးကြီးလဲ လို့ မေးခွန်းထုတ်ပြီး၊ နောက်ပိုင်း practical section ထဲက worked answer key နဲ့ ပြန်စစ်ဖို့ပါပဲ။

text
FLAWED DATABASE SETUP (AUDIT TARGET)
------------------------------------
FLAWED DATABASE SETUP (AUDIT TARGET)
-----
[ Web App ]
     |
     | connects with ONE shared "admin" account
     | (same account for writes AND read-only reports)
     v
[ Config file -- committed to git repo ]
     | connection string + password in PLAIN TEXT
     v
[ Database Server ]
     | NO TLS -- traffic sent unencrypted
     | reachable from 0.0.0.0/0 -- NO FIREWALL RULE
     v
[ Public Internet ] <-- anyone can attempt to connect

[ Nightly Backup Job ]
     | backups are created on schedule
     | NEVER test-restored -- unknown if usable
     v
[ ??? ] -- recovery path is unverified

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

ဒီ exercise ထဲက setup ကို တကယ် audit လုပ်ရင် layer တစ်ခုချင်းစီအလိုက် ဘယ်လိုလုပ်ဆောင်မလဲဆိုတာ ဒီမှာ ပြထားပါတယ် — production ကို မထိခိုက်ခင် careful engineer တစ်ယောက် လုပ်မယ့်နည်းလမ်းအတိုင်းပါ။

Identity

operation အားလုံးအတွက် shared admin account တစ်ခုတည်းသုံးတာက least-privilege failure ပါ။ ပုံမှန် read/write path၊ read-only reporting path၊ human operator တစ်ခုစီအတွက် credential သီးသန့် ခွဲပေးသင့်ပါတယ်။

Secrets handling

source control ထဲ commit လုပ်ထားတဲ့ password တစ်ခုဟာ commit လုပ်လိုက်တဲ့ခဏတည်းမှာပဲ ချို့ယွင်းသွားပါပြီ။ credential ကို environment variable (သို့) secrets manager ထဲ ရွှေ့ပြီး ချက်ချင်း rotate လုပ်ရန်လိုပါတယ်။

Network exposure

public internet တစ်ခုလုံးကနေ ချိတ်ဆက်နိုင်တဲ့ database တစ်ခုမှာ real perimeter မရှိပါ။ application server များကနေသာ connect ခွင့်ပေးတဲ့ firewall rule ချမှတ်ပါ။

Encryption in transit

TLS မပါဘဲ credential နဲ့ data တွေက network ပေါ်ကနေ ဖတ်နိုင်တဲ့ ပုံစံနဲ့ ဖြတ်သန်းနေပါတယ်။ TLS ကို enable လုပ်ခြင်းက ဒီအပေါက်ကို ပိတ်ပေးပါတယ်။

Backups

ဘယ်သူမှ restore မလုပ်ဖူးသေးတဲ့ backup တစ်ခုဟာ plan မဟုတ်ဘဲ မျှော်လင့်ချက်သာ ဖြစ်ပါတယ်။ ပုံမှန် test restore ကို schedule လုပ်ပြီး data အသုံးဝင်မှုကို အတည်ပြုပါ။

အတူတူ စမ်းရေးကြည့်မယ်

javascript
function auditDatabaseSetup(setup) {
  const issues = [];

  if (setup.usesSharedAdminAccount) {
    issues.push(
      "Shared admin/superuser account used for all access -- violates " +
      "least privilege; app writes, read-only reporting, and human " +
      "operators should each use separate, narrowly scoped credentials."
    );
  }
  if (setup.credentialsHardcoded) {
    issues.push(
      "Credentials hardcoded in a committed config file -- move to " +
      "environment variables or a secrets manager, and rotate the " +
      "exposed credentials immediately."
    );
  }
  if (setup.publiclyExposed) {
    issues.push(
      "Database reachable directly from the public internet -- " +
      "restrict network access with a firewall/security-group rule " +
      "that allows only the app servers."
    );
  }
  if (!setup.usesTLS) {
    issues.push(
      "Connections are not encrypted with TLS -- credentials and " +
      "data can be read by anyone observing the network traffic."
    );
  }
  if (!setup.backupsRestoreTested) {
    issues.push(
      "Backups exist but have never been test-restored -- an " +
      "unverified backup is not a confirmed recovery path."
    );
  }
  if (!setup.usesParameterizedQueries) {
    issues.push(
      "User input is concatenated directly into queries -- " +
      "vulnerable to SQL injection; use parameterized queries " +
      "or prepared statements instead."
    );
  }

  return issues;
}

const flawedSetup = {
  usesSharedAdminAccount: true,
  credentialsHardcoded: true,
  publiclyExposed: true,
  usesTLS: false,
  backupsRestoreTested: false,
  usesParameterizedQueries: false,
};

const hardenedSetup = {
  usesSharedAdminAccount: false,
  credentialsHardcoded: false,
  publiclyExposed: false,
  usesTLS: true,
  backupsRestoreTested: true,
  usesParameterizedQueries: true,
};

console.log("Flawed setup issues found:", auditDatabaseSetup(flawedSetup).length);
console.log("Hardened setup issues found:", auditDatabaseSetup(hardenedSetup).length);
You should see
Flawed setup ကို run လိုက်ရင် `Flawed setup issues found: 6` ဟု log ထုတ်ပြီး၊ ဆိုထားတဲ့ ပြဿနာခြောက်ခုစလုံး (shared admin, hardcoded credentials, public exposure, no TLS, untested backups, non-parameterized queries) ကို string array အဖြစ် ပြန်ပေးပါတယ်။ hardenedSetup ကို run လိုက်ရင်တော့ `Hardened setup issues found: 0` ဟု log ထုတ်ပြီး empty array ပြန်ပေးပါတယ်။

၅ မိနစ် စမ်းကြည့်

အသင်းအလေးစားတစ်ခုရဲ့ production database ကို ဒီလိုစီစဉ်ထားပါတယ် — application က operation အားလုံးအတွက် (read-only reporting dashboard အပါအဝင်) shared admin/superuser account တစ်ခုတည်းကို အသုံးပြု connect လုပ်သည်။ connection string (password အပါအဝင်) ကို application code နဲ့ git repository တူတူထဲမှာရှိတဲ့ config file တစ်ခုထဲ hardcode လုပ်ထားသည်။ database server သည် internet ပေါ်က IP address မည်သည့်နေရာမှမဆို connection လက်ခံနိုင်ပြီး၊ ဘယ်သူချိတ်ဆက်နိုင်သလဲ ကန့်သတ်မည့် firewall (သို့) security-group rule လုံးဝမရှိပါ။ connection သည် TLS ကို မသုံးပါ။ ညတိုင်း backup ကို configure ထားပြီး လများစွာ run နေခဲ့ပေမယ့် ဘယ်သူမှ restore လုပ်ကြည့်ဖူးခြင်း မရှိပါ။ နောက်ဆုံးအနေနဲ့ codebase ရဲ့ ရှေးဟောင်းအပိုင်းအချို့က form input ကို SQL string ထဲ တိုက်ရိုက် concatenate လုပ်ပြီး query တည်ဆောက်ထားသည်။ ဒီ description ကို ကိုယ်တိုင်လေ့လာပြီး တွေ့ရှိသမျှ security ပြဿနာအားလုံးကို list ဆွဲပါ၊ တစ်ခုချင်းစီအတွက် ဘယ်လို တိကျစွာ ပြင်ဆင်မလဲဆိုတာ ဖော်ပြပါ။ practical section ထဲက worked answer key ကို မဖတ်မီ ကိုယ်ပိုင် list ကို ပြီးအောင်လုပ်ကြည့်ပါ။

သတိလေးတစ်ချက်

ဒါကို ပြဿနာတစ်ခုတည်းလို့ မှတ်ပြီး TLS ကဲ့သို့ အထင်ရှားဆုံးအချက်ကိုပဲ ပြင်ပြီး shared admin account နဲ့ public exposure ကို လျစ်လျူရှုမိတာ။

actual risk နဲ့ မကိုက်ညီတဲ့ fix ကို အဆိုပြုမိတာ — ဥပမာ admin password ကိုပဲ ပြောင်းလိုက်ပြီး least-privilege accounts များအဖြစ် ခွဲမပေးဘဲ ထားခဲ့တာမျိုး။

OWASP Database Security Cheat SheetHow Databases Work

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • ဒါကို ပြဿနာတစ်ခုတည်းလို့ မှတ်ပြီး TLS ကဲ့သို့ အထင်ရှားဆုံးအချက်ကိုပဲ ပြင်ပြီး shared admin account နဲ့ public exposure ကို လျစ်လျူရှုမိတာ။
  • actual risk နဲ့ မကိုက်ညီတဲ့ fix ကို အဆိုပြုမိတာ — ဥပမာ admin password ကိုပဲ ပြောင်းလိုက်ပြီး least-privilege accounts များအဖြစ် ခွဲမပေးဘဲ ထားခဲ့တာမျိုး။
  • ဒီ course က database concept/landscape ကို framework-neutral level မှာသာ သင်ပေးပါတယ် — SQL syntax, PostgreSQL, MongoDB, Redis ကို နက်နက်ရှိုင်းရှိုင်း လေ့လာချင်ရင် SQL, PostgreSQL, MongoDB, Redis tutorial တွေဆီ ဆက်သွားပါ။

လေ့ကျင့်ခန်း

အသင်းအလေးစားတစ်ခုရဲ့ production database ကို ဒီလိုစီစဉ်ထားပါတယ် — application က operation အားလုံးအတွက် (read-only reporting dashboard အပါအဝင်) shared admin/superuser account တစ်ခုတည်းကို အသုံးပြု connect လုပ်သည်။ connection string (password အပါအဝင်) ကို application code နဲ့ git repository တူတူထဲမှာရှိတဲ့ config file တစ်ခုထဲ hardcode လုပ်ထားသည်။ database server သည် internet ပေါ်က IP address မည်သည့်နေရာမှမဆို connection လက်ခံနိုင်ပြီး၊ ဘယ်သူချိတ်ဆက်နိုင်သလဲ ကန့်သတ်မည့် firewall (သို့) security-group rule လုံးဝမရှိပါ။ connection သည် TLS ကို မသုံးပါ။ ညတိုင်း backup ကို configure ထားပြီး လများစွာ run နေခဲ့ပေမယ့် ဘယ်သူမှ restore လုပ်ကြည့်ဖူးခြင်း မရှိပါ။ နောက်ဆုံးအနေနဲ့ codebase ရဲ့ ရှေးဟောင်းအပိုင်းအချို့က form input ကို SQL string ထဲ တိုက်ရိုက် concatenate လုပ်ပြီး query တည်ဆောက်ထားသည်။ ဒီ description ကို ကိုယ်တိုင်လေ့လာပြီး တွေ့ရှိသမျှ security ပြဿနာအားလုံးကို list ဆွဲပါ၊ တစ်ခုချင်းစီအတွက် ဘယ်လို တိကျစွာ ပြင်ဆင်မလဲဆိုတာ ဖော်ပြပါ။ practical section ထဲက worked answer key ကို မဖတ်မီ ကိုယ်ပိုင် list ကို ပြီးအောင်လုပ်ကြည့်ပါ။

You'll know it worked when: Flawed setup ကို run လိုက်ရင် `Flawed setup issues found: 6` ဟု log ထုတ်ပြီး၊ ဆိုထားတဲ့ ပြဿနာခြောက်ခုစလုံး (shared admin, hardcoded credentials, public exposure, no TLS, untested backups, non-parameterized queries) ကို string array အဖြစ် ပြန်ပေးပါတယ်။ hardenedSetup ကို run လိုက်ရင်တော့ `Hardened setup issues found: 0` ဟု log ထုတ်ပြီး empty array ပြန်ပေးပါတယ်။

လေ့ကျင့်ခန်း — ဒေတာဘေ့စ် လုံခြုံရေး Audit တစ်ခု | Thuta Learning