Thuta Learning
ရှာဖွေရန်
AdvancedDevOpsintermediate

Security & Secrets Management

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

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

  • Security & Secrets Management ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် terraform command/HCL code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

Terraform config ထဲမှာ password ကို hardcode ရေးထားရင် git repository ထဲ commit ဖြစ်ရင် leak ဖြစ်ပါတယ် — Variable ကို `sensitive = true` mark ထားရင် Terraform က plan/apply output ထဲမှာ value ကို hide ပေးပါတယ် (state file ထဲမှာတော့ ဆက်ပေါ်နေဆဲမို့ state encryption/access control ကို ခွဲသီးသန့် စဉ်းစားရပါမယ်)။ Credential (AWS access key) ကိုတော့ config ထဲ တိုက်ရိုက်မရေးဘဲ environment variable (`AWS_ACCESS_KEY_ID`) ဒါမှမဟုတ် credential file (`~/.aws/credentials`) ကနေ provider က auto-detect ဖတ်ယူအောင် setup လုပ်ရပါတယ်။ Production မှာ Vault (HashiCorp Vault) ဒါမှမဟုတ် cloud secret manager (AWS Secrets Manager) ကနေ secret ကို dynamic ဆွဲယူတာလည်း ရှိပါတယ်.

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

Database password ကို `variable "db_password" { type = string; sensitive = true }` လို့ define လုပ်ပြီး, value ကို `.tfvars` file (git-ignored) ဒါမှမဟုတ် environment variable (`TF_VAR_db_password`) ကနေ ပေးပို့ပါတယ် — `terraform plan` output ထဲမှာ `db_password = (sensitive value)` လို့ hide ပြပေးပါလိမ့်မယ်။ AWS credential ကို config ထဲ တိုက်ရိုက်မရေးဘဲ, `aws configure` command (ဒါမှမဟုတ် CI/CD environment variable) ကနေ provider က auto-detect ဖတ်ယူပါလိမ့်မယ်.

အတူတူ ကြည့်မယ်

hcl
variable "db_password" {
  description = "Database master password"
  type        = string
  sensitive   = true
}

resource "aws_db_instance" "main" {
  # ... other config ...
  password = var.db_password
}

# Set the value via environment variable, never in the .tf file:
# TF_VAR_db_password="..." terraform apply
You should see
$ terraform plan
  ~ resource "aws_db_instance" "main" {
      ~ password = (sensitive value)
    }

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

`sensitive = true` variable တစ်ခု define လုပ်ပြီး, `TF_VAR_<name>` environment variable နည်းလမ်းနဲ့ value ပေးပို့ကာ plan output ထဲမှာ value hide ဖြစ်နေတာ confirm လုပ်ကြည့်ပါ။

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

State file (local ဖြစ်စေ remote ဖြစ်စေ) ထဲမှာ sensitive data အားလုံး plain text အနေနဲ့ ပါဝင်ပါတယ် — state file access ကို ကန့်သတ်ခြင်း (encryption at rest, IAM permission) ကို production မှာ မဖြစ်မနေ setup လုပ်ပါ။

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

  • `sensitive = true` mark ထားရုံနဲ့ state file ထဲမှာပါ hide ဖြစ်သွားမယ်လို့ ထင်ခြင်း — state file ထဲမှာတော့ plain text ဆက်ပေါ်နေဆဲပါ
  • Credential ကို `.tf` file ထဲ hardcode ရေးထားပြီး, `.gitignore` ထဲ `.tf` file ကို ထည့်ဖို့ မေ့ခြင်း (config file ကိုတော့ commit ရမှာမို့ credential ကို config ထဲ လုံးဝ မထားသင့်ပါ)

အခု ကိုယ်တိုင် စမ်းကြည့်

`sensitive = true` variable တစ်ခု define လုပ်ပြီး, `TF_VAR_<name>` environment variable နည်းလမ်းနဲ့ value ပေးပို့ကာ plan output ထဲမှာ value hide ဖြစ်နေတာ confirm လုပ်ကြည့်ပါ။

You'll know it worked when: $ terraform plan ~ resource "aws_db_instance" "main" { ~ password = (sensitive value) }

Security & Secrets Management | Thuta Learning