Hashicorp Vault

HashiCorp Vault เป็นเครื่องมือจัดการความปลอดภัยและการเข้าถึงข้อมูลสำคัญในระบบไอที มันถูกออกแบบมาเพื่อจัดเก็บ จัดการ และควบคุมการเข้าถึงข้อมูลลับต่าง ๆ เช่น รหัสผ่าน คีย์ API และข้อมูลที่เป็นความลับอื่น ๆ โดยมีคุณสมบัติที่สำคัญดังนี้

  1. การจัดเก็บข้อมูลลับ (Secrets Management): Vault ช่วยในการจัดเก็บข้อมูลลับต่าง ๆ ในที่เดียว และควบคุมการเข้าถึงอย่างเข้มงวด ผู้ใช้งานสามารถกำหนดสิทธิ์การเข้าถึงได้ตามบทบาทหรือการกำหนดนโยบายเฉพาะ

  2. Dynamic Secrets: Vault สามารถสร้างข้อมูลลับแบบชั่วคราวสำหรับการเข้าถึงระบบภายนอก เช่น ฐานข้อมูลหรือบริการอื่น ๆ ซึ่งข้อมูลลับเหล่านี้จะถูกสร้างใหม่ในทุกครั้งที่มีการร้องขอ และจะหมดอายุเมื่อใช้งานเสร็จสิ้น

  3. Encryption as a Service: Vault ให้บริการการเข้ารหัสข้อมูลผ่าน API เพื่อใช้ในการเข้ารหัสและถอดรหัสข้อมูลต่าง ๆ โดยที่แอปพลิเคชันหรือระบบต่าง ๆ ไม่จำเป็นต้องมีการจัดการคีย์เข้ารหัสเอง

  4. การควบคุมการเข้าถึงที่ปลอดภัย (Access Control): Vault มีระบบการควบคุมสิทธิ์การเข้าถึงที่ละเอียด ผู้ใช้งานจะสามารถเข้าถึงเฉพาะข้อมูลที่จำเป็นตามที่ได้รับอนุญาต ซึ่งลดความเสี่ยงจากการเปิดเผยข้อมูลที่ไม่จำเป็น

  5. Audit Logging: Vault มีการบันทึกการใช้งานเพื่อให้สามารถตรวจสอบการเข้าถึงและใช้งานข้อมูลลับต่าง ๆ ทำให้มีความโปร่งใสและสามารถติดตามการดำเนินการย้อนหลังได้

Consul คืออะไร

Consul เป็นเครื่องมือที่ให้บริการ service discovery และ distributed key-value store ที่ใช้สำหรับเก็บข้อมูลเช่น การกำหนดค่าและข้อมูลสภาวะการทำงานของระบบแบบกระจายตัว (distributed systems) โดย Consul มีคุณสมบัติหลัก ๆ ดังนี้

  1. High Availability: สามารถทำงานในโหมดกระจายตัวที่มีหลายโหนด (nodes) เพื่อเพิ่มความทนทานต่อการล้มเหลว

  2. Replication: Consul จะทำการ replicates ข้อมูลระหว่างโหนดหลายโหนด เพื่อความทนทานต่อการสูญเสียข้อมูล

  3. Service Discovery: มีคุณสมบัติการค้นหาบริการและการติดตามสุขภาพ (health checking) ของบริการในระบบ

การใช้ Consul เป็น backend สำหรับ HashiCorp Vault เป็นการตั้งค่าที่ช่วยให้ Vault สามารถจัดเก็บข้อมูลที่สำคัญและมีความทนทานในการทำงาน โดย Consul ทำหน้าที่เป็น Storage Backend ที่สามารถจัดเก็บข้อมูลต่าง ๆ ที่ Vault ต้องการเก็บ เช่น Secret, Tokens, และข้อมูลการกำหนดค่าอื่น ๆ การตั้งค่า Consul เป็น backend มีประโยชน์ในด้านการจัดเก็บที่ปลอดภัยและการกระจายโหลดสำหรับการใช้งาน Vault ใน production environment

การติดตั้ง Hashicorp Vault

ติดตั้ง Consul

จากตัวอย่างนี้ จะติดตั้ง consul บน Kubernetes cluster ผ่าน Helm Chart ของ Hashicorp

Architecture

ตาม recommend ของ Hashicorp กำหนดว่า consul server ควรมีอย่างน้อย 5 node และกระจายกันอยู่ใน 3 AZ แต่โดยส่วนมากสำหรับ small production site ใช้ 3 node ก็เพียงพอ เช่นกัน

consul for production

Hardware Requirement

Size
CPU
Memory
Disk Capacity
Disk IO
Disk Throughput

Small

2-4 core

8-16 GB

100+ GB

3000+ IOPS

75+ MB/s

Large

8-16 core

32-64 GB

200+ GB

7500+ IOPS

250+ MB/s

Network Latency Requirement

round trip time (RTT) ในการสื่อสารกันระหว่าง agent ต้องไม่เกิน ดังนี้

  • RTT ของทุก traffic โดยเฉลี่ย ต้องไม่เกิน 50ms

  • RTT ที่ percentile 99 ต้องไม่เกิน 100ms

Firewall rule

Name
Port / Protocol
Source
Destination
Description

RPC

8300 / TCP

All agents (client & server)

Server agents

Used by servers to handle incoming requests from other agents.

Serf LAN

8301 / TCP & UDP

All agents (client & server)

All agents (client & server)

Used to handle gossip in the LAN. Required by all agents.

Serf WAN

8302 / TCP & UDP

Server agents

Server agents

Used by server agents to gossip over the WAN to other server agents. Only used in multi-cluster environments.

HTTP/HTTPS

8500 & 8501 TCP

Localhost of client or server agent

Localhost of client or server agent

Used by clients to talk to the HTTP API. HTTPS is disabled by default.

DNS

8600 TCP & UDP

Localhost of client or server agent

Localhost of client or server agent

Used to resolve DNS queries.

gRPC (Optional)

8502 TCP

Envoy proxy

Client agent or server agent that manages the sidecar proxies service registration

Used to expose the xDS API to Envoy proxies. Disabled by default.

Sidecar Proxy (Optional)

21000 - 21255 TCP

All agents (client & server)

Client agent or server agent that manages the sidecar proxies service registration

Port range used for automatically assigned sidecar service registrations.

ตัวอย่าง value file

สร้างไฟล์ consul.values.yaml

ติดตั้งด้วยคำสั่งดังนี้


ติดตั้ง Vault

เตรียม YAML file ชื่อ vault.values.yaml ดังนี้

ติดตั้งด้วยคำสั่งดังนี้

หลังจากติดตั้งเสร็จ ตรวจสอบสถานะ vault

จะขึ้นผลลัพธ์ว่าถูก seal ไว้อยู่

ใช้ command ดังนี้เพื่อ generate root key ใช้ในการ bootstrap cluster ครั้งแรกเท่านั้น

circle-exclamation

ทำการ unseal vault server

จะได้ผลลัพธ์ดังนี้

ทำ port-forward เพื่อทดสอบใช้งาน Vault

เข้า web browser ผ่าน http://localhost:8200arrow-up-right

ทดสอบ login ผ่าน UI ด้วย token ของ root

circle-info

root token ได้มาจากตอน bootstrap cluster ด้วยคำสั่ง vault operator init

ดังนั้นสามารถหาได้จากคำสั่ง

Last updated