DEV Community

Cover image for จัดการ Azure Key Vaults ด้วย HashiCorp Vault KMS
terngr
terngr

Posted on

1

จัดการ Azure Key Vaults ด้วย HashiCorp Vault KMS

Image description

Azure Cloud Services มีบริการจัดเก็บและบริหารความลับเรียกว่า Azure Key vault โดยช่วยจัดเก็บ และเรียกใช้งาน Objects 3 ประเภท Keys, Secrets และ Certificates

  • Keys เช่น Key-pairs
  • Secrets เช่นรหัสผ่าน
  • Certificates หรือ Certificate Authority(CA) โดยสามารถกำหนด Subjects, validation periods ได้

Objects ทั้ง 3 แบบใน Key vault
Image description

เราสามารถสร้าง Objects ทั้ง 3 นี้ขึ้นมาใหม่โดยใช้ Azure Portal หรือ Import เข้ามาก็ได้

การจัดการความลับเหล่านี้ โดยปกติแล้วจะถูกจัดการผ่าน Azure Portal, เช่นต้องการสร้าง Keys ใหม่ก็จะ Create ผ่าน Portal เมื่อใช้งานเสร็จต้องการลบ ก็สามารถทำได้ผ่าน Portal ซึ่งการบริหารจัดการเหล่านี้ HashiCorp Vault - Secrets as a service สามารถเข้ามาช่วยดูแลและยังครอบคลุม Secrets Lifecycle Management

Prerequisites

  • Azure Key vaults Premium(with HSM Supported)
  • HashiCorp Vault Enterprise

ส่วนที่ 1

เราจะทำการสร้าง Key Vaults และสร้าง Key-pairs ไว้ใช้งาน โดยทำผ่าน Azure Portal

ให้ Log in ไปยัง Azure Portal, เลือก Directory ที่ต้องการใช้งาน

ค้นหาคำว่า Key vaults และเข้าไปยัง Key vaults

Image description

กด + Create

ใส่รายละเอียดสำหรับสร้าง Key vaults

Image description

  • Subscription: เลือก Subscription ที่ต้องการ
  • Resource group: เลือก Resource group สำหรับ Key vaults, หากยังไม่มีสามารถกดสร้างใหม่ได้
  • Key vault name: ชื่อ Key vault ที่ต้องการ เช่น "sukkarin-keyvault-3"
  • Region: เลือกเป็น Southeast Asia
  • Pricing tier: สามารถเลือกได้ทั้ง Standard และ Premium(HSM supported) ในกรณีนี้เราจะใช้งานร่วมกับ HashiCorp Vault โดยมีการใช้ HSM ด้วย ให้เลือก Premium

กด Review + Create

กด Create

รอจน Deploy สำเร็จ

Image description

Deploy สำเร็จแล้ว, เลือก Go to resource

Image description

ใต้แถบ Objects กดเลือก Keys
เลือก +Import/Generate เพื่อทำการสร้าง key-pairs

Image description

Name: ใช้ชื่อที่ต้องการ เช่น "my-keypair-1"
Key type: RSA-HSM
RSA key size: 2048

กด Create

Image description

จะเห็นได้ว่ามีการสร้าง my-keypair-1 สำเร็จ
กดที่ Key-pairs ที่เพิ่งสร้าง
เลือก Current version
จะพบว่าเราสามารถ Download Public Key ไปใช้งานได้

Image description

เมื่อไม่มีการใช้งาน Key-pairs นี้แล้ว สามารถลบออกได้โดยเข้าไปที่ Key vaults, my-keypair-1

Image description

เลือก Delete
กด Delete อีกครั้งเพื่อยืนยัน

Image description

จะมี Popup แสดงว่าลบคีย์สำเร็จ
จะไม่เห็น my-keypair-1 แล้ว
Image description

ส่วนที่สอง เราจะให้ HashiCorp Vault เป็นคนบริหารจัดการคีย์ โดยจะทำการสร้าง Key ขึ้นมาก่อน, จากนั้น Import Key ไปที่ Azure Key Vaults

Prerequisites มี Vault ติดตั้งไว้แล้วพร้อมใช้งาน
Install Vault

เปิดการใช้งาน Key management บน Vault

sukkarin@vault:~$ vault secrets enable keymgmt
Success! Enabled the keymgmt secrets engine at: keymgmt/
Enter fullscreen mode Exit fullscreen mode

ให้ Vault ทำการสร้าง Key ใช้ชื่อว่า "example-key" กำหนดให้ใช้ Algorithm RSA-2048

sukkarin@vault:~$ vault write -f keymgmt/key/example-key type="rsa-2048"
Success! Data written to: keymgmt/key/example-key
Enter fullscreen mode Exit fullscreen mode

Setup Azure Provider โดยระบุชื่อ Key vault, client_id, client_secret และ tenant_id
cliend_id และ client_secret จะต้องมีสิทธิ์ในการ Import key สามารถเพิ่มสิทธิ์ได้ที่หน้า Access Policy ของ Key Vaults ที่ต้องการเพิ่ม

sukkarin@vault:~$ vault write keymgmt/kms/example-key \
    provider="azurekeyvault" \
    key_collection="sukkarin-keyvault-3" \
    credentials=client_id="<client-id>" \
    credentials=client_secret="<client-secret>" \
    credentials=tenant_id="<tenant-id>"
Success! Data written to: keymgmt/kms/example-key
Enter fullscreen mode Exit fullscreen mode

Import Key ชื่อ example-key เข้าไปที่ Azure Key vault ชื่อ sukkarin-keyvault-3

sukkarin@vault:~$ vault write keymgmt/kms/sukkarin-keyvault-3/key/example-key \
    purpose="sign,verify" \
    protection="hsm"
Success! Data written to: keymgmt/kms/sukkarin-keyvault-3/key/example-key
Enter fullscreen mode Exit fullscreen mode

เปิดดูที่ Azure portal ไปที่ Key vault, เลือก sukkarin-keyvault-3, เลือก Keys จะพบคีย์ example-key-1680172858 ถูก Import เข้ามาเรียบร้อยแล้ว

Image description

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay