الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 7الاسم في الدورة: Objective 4h: sensitive data and secrets management with Vault

Handle sensitive data and secrets

Infrastructure code touches passwords, keys and tokens. Terraform can hide them in its output, but they may still be in the state. This chapter shows the safe patterns: sensitive values, secrets from Vault or Key Vault, protected state, and scanning the code.

  • 5 الدروس
  • 3 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

المهارات في هذا الفصل

  • البيانات الحساسة والأسرار مع Vault

7.1

Mark values as sensitive

sensitive = true hides a value in plan and apply output. It does not encrypt it in the state.

secrets.tf
variable "db_admin_password" {
  type      = string
  sensitive = true
}
 
output "connection_string" {
  value     = "postgres://admin:${var.db_admin_password}@${azurerm_postgresql_flexible_server.db.fqdn}/shop"
  sensitive = true
}
terraform plan
  + administrator_password = (sensitive value)
terraform output -raw connection_string

الأوامر في هذا الدرس

7.2

Keep secrets out of code

A secret must never be in a .tf or committed .tfvars file.

Good placeHow
Environment variableexport TF_VAR_db_admin_password=… (CI secret store)
HashiCorp Vaultvault_kv_secret_v2 data source, or dynamic secrets
Azure Key Vaultazurerm_key_vault_secret data source
Generated by Terraformrandom_password → write it into Key Vault
HCP TerraformSensitive workspace variables
keyvault.tf
resource "random_password" "db" {
  length  = 24
  special = true
}
 
resource "azurerm_key_vault_secret" "db" {
  name         = "db-admin-password"
  value        = random_password.db.result
  key_vault_id = azurerm_key_vault.main.id
}

الأوامر في هذا الدرس

7.3

Read secrets from Vault

Vault stores secrets centrally, with access policies and audit logs. Terraform reads them with the Vault provider; dynamic secrets are created on demand and expire.

vault.tf
provider "vault" {
  address = "https://vault.example.com:8200"
}
 
data "vault_kv_secret_v2" "db" {
  mount = "secret"
  name  = "shop/db"
}
 
resource "azurerm_postgresql_flexible_server" "db" {
  # ...
  administrator_password = data.vault_kv_secret_v2.db.data["password"]
}

في العمل

Newer Terraform versions add ephemeral values and resources: secrets that are used during the run but never written to plan or state. Use them where your providers support them.

7.4

Protect the state

Because state can hold secrets, treat the state file like a password store.

  • Use a remote backend with encryption at rest and access control (Azure Storage with RBAC, HCP Terraform).
  • Turn on versioning / soft delete for the state container.
  • Give write access to the state only to the pipeline identity.
  • Never commit *.tfstate to Git: add it to .gitignore.
.gitignore
.terraform/
*.tfstate
*.tfstate.*
*.tfvars
!example.tfvars
crash.log

7.5

Scan the code for security problems

Static scanners find insecure settings (public storage, open NSGs, no encryption) before apply.

trivy config .
checkov -d .
tflint --init && tflint
ToolChecks
Trivy (config)Misconfigurations in Terraform, Kubernetes, Dockerfiles
CheckovHundreds of cloud security policies
TFLintProvider-specific errors and best practices

تذكّر

Put the scan in the pipeline before plan. A failed scan stops the pull request.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل