AZ-104: Implement and manage storage in Azure

Note: สำหรับ Blog นี้ ผมย้ายมาจาก Notion ที่เขียนไว้ตอนเดือน 9-10 ปีที่แล้วนะครับ บาง Service อย่าง Azure AD มีเปลี่ยนชื่อเป็น Microsoft Entra ID เป็นต้นครับ

Configure storage accounts

  • Storage Product - Azure Blob Storage (containers)
    - non-relational data/optimization for massive data / Access NFS protocol.
    - Azure Files
    - SMB Share File
    - Azure Queue Storage - ตัว Queue messages can be up to 64 KB / processed asynchronously Ex ดู Event เข้า Blob โยน Queue แล้วให้ Azure Function สร้าง thumbnails
    - Azure Table Storage - Structured data / NoSQL (Azure Cosmos DB: Table API)
    Ref: https://naiwaen.debuggingsoft.com/2022/05/dp-900-short-note
  • Storage account tiers:
    - Standard Gen V2 (HDD)
    - Premium(SSD) มี 3 แบบ Premium block blobs / Premium file shares / Premium page blobs
  • consider when using Azure Storage
    - durability and availability
    - LRS / ZRS / GRS
    - secure access
    - scalability
    - manageability
    - data accessibility - REST API / SDK Access storage
  • Secure storage endpoints.
    - กำหนด Firewalls and virtual networks settings กำหนด Network / Public IP ที่ต้องการ
    - SAS ไม่นับเหรอ ?
  • Configure storage accounts: Knowledge check

Configure Azure Blob Storage

Create blob containers

  • blob types: Block ( files, images, videos) / Append (Log) / Page (VM Disk VHD)
  • ความสัมพันธ์ storage account > container > blob
  • Public access level: Private (default) > blob level > container level (เข้าได้ทุก Blob under container นั้นๆ)
  • access tiers: Hot tier (แพง / access ไว) > Cool tier (moderate) > Archive tier (ถูก / access ช้า ต้อง Rehydrate)
  • lifecycle management rules = การเปลี่ยน access tiers ตาม Rule เข้าวันที่ create
    - Hot to Cool, Hot to Archive, Cool to Archive (optimize for performance and cost)
    - จนถึง Delete Blob
  • blob object replication (require blob versioning + tier hot/cool + ห้ามทำ blob snapshots
    - latency reductions เลือก Region ใกล่กับ user
    - efficiency for computing workloads
    - data distribution process 1 region แล้ว replication
    - costs benefits: storage tier + policies ตอน replication อิง policy จาก source ทำงานแบบ asynchronous
  • upload tools: AzCopy (Online), Azure Data Box Disk, Azure Import/Export
  • pricing for Blob Storage ปัจจัยที่มีผล
    - storage tier(hot/cool/archive) มีผล Performance / Data access / Transaction
    - replication data transfer costs
    - Outbound Azure region data transfer costs
  • Configure Azure Blob Storage: Interactive lab simulation
  • Configure Azure Blob Storage: Knowledge Check
  • มี Lab Summary and resources - Training | Microsoft Learn

Configure Azure Storage security

Azure Storage security strategies

  • Encryption
    - Azure Storage encryption — encrypted
    - Data in transit (HTTPS, or SMB 3.0) / Data At REST (Disk Encryption)
  • Authentication: Azure AD / Azure RBAC
  • Authorization
    - Azure AD + Azure RBAC
    - Shared Key >> Azure storage account access keys เอาไว้แปะหัว request ใน Authorization header
    - Shared access signatures - delegates access by permission + time
    - Anonymous access to containers and blobs - Public with link

Create shared access signatures SAS ต้องมากำหนดข้อมูล ดังนี้

  • required: time interval / Permission / Scope (account-level and service-level)
  • optional: IP addresses / Protocol
  • SAS ต้องมากำหนดข้อมูล ดังนี้
    • required: time interval / Permission / Scope (account-level and service-level)
    • optional: IP addresses / Protocol

Identify URI and SAS parameters จากที่ตั้งค่าไว้ตะกี้ แปลงเป็น URI ยังไง

https://myaccount.blob.core.windows.net/?restype=service&comp=properties&sv=2015-04-05&ss=bf&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=F%6GRVAZ5Cdj2Pw4tgU7IlSTkWgn7bUkkAg8P6HESXwmf%4B

//Azure Resource 
https://myaccount.blob.core.windows.net/?restype=service&comp=properties

//Storage version
&sv=2015-04-05

//Storage service B=Blob / F=File 
&ss=bf

//Start & Expiry Time
&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z

//Resource
&sr=b

//Permission
&sp=rw

//IP range (Allow IP Address)
&sip=168.1.5.60-168.1.5.70

//Allow Protocal
&spr=https

//Signature
&sig=F%6GRVAZ5Cdj2Pw4tgU7IlSTkWgn7bUkkAg8P6HESXwmf%4B

ถ้าสนใจว่าแต่ละ parameter มีค่าเป็นไปได้อะไรบ้างดูจาก Create a user delegation SAS - Azure Storage | Microsoft Learn

  • Azure Storage Encryption
    - encryption at rest / AES 256 bits การจัดการ Key 2 แบบ
    - Microsoft Manage Key ง่ายๆให้ MS - Customer Manage Key ต้องใช้ Azure Key Vault

Recommendations for managing risks

  • Always use HTTPS for creation and distribution
  • Reference stored access policies where possible - ทำ Policy ก่อนสร้าง SAS ด้วย เวลา SAS หลุด เราแต่ปรับ Policy ให้เข้มขึ้นก่อน และค่อยมาแก้ Generate ใหม่

Sample: Using Stored Access Policy with Azure Storage – TheSleepyAdmins

  • Set near-term expiry times for an unplanned SAS -กำหนดอายุให้สั้นๆ
  • Require clients automatically renew the SAS - ขอก่อนหมดอายุเสมอ
  • Plan carefully for the SAS start time - เวลาแต่ละเครื่องอาจจะไม่เท่ากับ ต้องเปิดเวลา Start / Expiry 10-15 นาที
  • Define minimum access permissions for resources
  • Understand account billing for usage, including a SAS
  • Use a short-lived SAS to reduce this threat
  • ถ้าปล่อยไว้ ให้โยนไฟล์ หรือ ดึงไฟล์บ่อยๆ อาจจะเสีย Cost โจมตีให้เสียเงิน
  • Validate data written by using a SAS - validate the data after it's written, but before it's used.
  • Don't assume a SAS is always the correct choice
  • ถ้า Access Key หลุดทุก SAS หลุดหมด
  • ทำ middle-tier service เข่น WEBAPI เพื่อมาตรวจสอบ business rule, authentication / auditing ก่อนเขียนลง storage
  • ถ้าทำ Public Read ไม่ต้องทำ SAS แจก เสีย Effort
  • Monitor your applications with Azure Storage Analytics หา spike/anomaly

สรุป

  • Protect Storage Account ใช้ Access Keys

Access keys give you full rights to everything in your storage account,

  • ปิด default network rule จาก Allow เป็นอย่างอื่น
  • Protect Storage แต่ละชนิด พวก Blob / File ใช้ SAS
  • net use - ใช้กับ SAS ไม่ได้

SAS you’re able to limit the access capabilities of its users

Lab + Knowledge Check

Configure Azure Files and Azure File Sync

  • Azure Files - file shares via SMB ใช้ได้หมด Windows Linux Mac + On-Premise ก็ได้
    • lift and shift support - เอามาแทน File Share / NAS ได้เลย
    • Replicate Azure File Sync agent Windows Servers
    • Store shared application settings
    • store diagnostic data such as logs, metrics, and crash dumps
    • Required port 445 (SMB) + Enable secure transfer (Access by REST)
    • ต่างกับแบบอื่นๆ ยังไง
  • Mount Azure Files
    • Windows: Map Network Drive / PowerShell
    • Linux Mac: shell มี Tools ช่วย
  • Create file share snapshots - ฺbackup incremental / restore ระดับไฟล์ Note: Delete snapshots ก่อนถึงลบ Azure File Share ได้ โดยมี Benefit:
    - Protect against application error and data corruption (Dev เขียนผิด App Bug ทำข้อมูลเสียหาย)
    - Protect against accidental deletions or unintended changes(ลบผิด)
    - Support backup and recovery
  • Azure File Sync
    • ทำให้ Windows Server เป็น Cache ของ Azure File Share / Client เชื่อมต่อกับ Windows Server ผ่าน SMB, NFS, FTPS นอกจากนี้ช่วย
      - lift and shift - client เชื่อมได้เหมือนเดิม
      - branch offices - back up to Azure storage
      - backup and disaster recovery - ถ้า Sync แล้ว Azure Backup On-Premise ด้วย
      - file archiving with cloud tiering หรือที่ไม่ใช้บ่อยยกไป Azure File Share แทน (ลด Cost On-Premise > จัดการที่ Cloud แทน)
    • Cloud tiering - accessed files based on policy บางอันอาจจะไม่ให้ Cache ทำเป็น Link แทน **O file attribute**
  • Identify Azure File Sync components

Deploy Azure File Sync

  • Step 1: Deploy the Storage Sync Service (Azure subscription ID / Resource Group / deployment location + name)
  • Step 2: Prepare each Windows Server to use Azure File Sync
    - กำหนด Sync Group + Server endpoint
  • Step 3: Install the Azure File Sync agent แนะนำใช้ default path
    - FileSyncSvc.exe: background Windows service- monitoring changes / sync to Azure
    - StorageSync.sys: filter + ทำ cloud tiering
    PowerShell
C:\\Program Files\\Azure\\StorageSyncAgent\\StorageSync.Management.PowerShell.Cmdlets.dll
C:\\Program Files\\Azure\\StorageSyncAgent\\StorageSync.Management.ServerCmdlets.dll
  • Step 4: Register each Windows Server with the Storage Sync Service
Set Sync [Cloud endpoint] <--> [Sync group:Server endpoint]

Knowledge Check: Configure Azure Files and Azure File Sync: Knowledge check

Configure Azure Storage with tools

Azure Storage Explorer (GUI Tools: Manage Storage Account)

  • requires: permissions Azure Resource Manager and data layer ให้ full access
  • connect by
    - Azure subscriptions / storage account / SAS
    - Azure Storage Emulator - local สำหรับพัฒนา’
  • connect to resource
    - Azure Blob Storage.
    - Azure Table Storage
    - Azure Queue Storage
    - Azure Files
    - Azure Data Lake Storage
  • Ref: Get started with Storage Explorer | Microsoft Learn

Azure Import/Export service

  • ใช้ในเคส cloud migrations / content distribution / backup operations / data recovery
  • Tool WAImportExport:
    - Pack Data และส่งให้ MS จัดการ
    - แต่ต้อง Check supported disk / ใช้ BitLocker / Windows 64-bit

AzCopy tool Feature

  • data synchronization
  • job management.
  • transfer resiliency: automatically retries ถ้า job fail - fast account to account copy - เคสนี้เหมือนเป็น Tool สั่ง Cloud Copy

Azure Storage Explorer เรียกใช้ตัว AzCopy ตอน Transfer เหมือนกัน

Reference: Copy or move data to Azure Storage by using AzCopy v10 | Microsoft Learn

Knowledge Check: Configure Azure Storage with tools: Knowledge check

Create an Azure Storage account

Storage account settings

พวก Manage Service CosmosDB / SQL ไม่ได้จัดการผ่าน Storage account

  • Subscription
  • Location
  • Performance
    - Standard (HDD) general purpose v2
    - Premium (SSD) Premium xxxx
  • Replication LRS / ZRS / GRS
  • Access tier
  • Secure transfer required
  • Virtual networks - allows inbound access requests ตาม virtual network(s)

How many storage accounts do you need?

  • data diversity บางเคสอาจจะกฏว่าบังคับเก็บประเทศนั้นๆ อาจจะทำให้เลือก Region ที่ถูกกว่าไม่ได้ + replication strategy
  • cost sensitivity storage account (ฟรี) แต่พวก Service อื่นๆ ไม่ฟรี ต้องแยก และจัดลด Cost Prod (Critical/Non-Critical) กับ Dev + Test
  • tolerance for management overhead.

Other

  • Deployment model: Resource Manage (Recommend) / Classic
  • Account kind: general purpose v2 / Premium - Page blobs / Premium - Block blobs / Premium - File shares
  • Tools: Azure Portal / Azure CLI / Azure PowerShell/ client SDKs libraries

Knowledge check - Create a storage account

Control access to Azure Storage with shared access signatures

BlobContainerClient container = new BlobContainerClient( "ConnectionString", "Container" );

//Retrieve the blob you want to create a SAS token for and create a BlobClient
foreach (BlobItem blobItem in container.GetBlobs())
{
    BlobClient blob = container.GetBlobClient(blobItem.Name);
}

//BlobSasBuilder object for the blob you use to generate the SAS token
BlobSasBuilder sas = new BlobSasBuilder
{
    BlobContainerName = blob.BlobContainerName,
    BlobName = blob.Name,
    Resource = "b",
    ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(1)
};
// Allow read access
sas.SetPermissions(BlobSasPermissions.Read);

//Authenticate a call to the ToSasQueryParameters method of the BlobSasBuilder object
StorageSharedKeyCredential storageSharedKeyCredential = new StorageSharedKeyCredential( "AccountName", "AccountKey");
sasToken = sas.ToSasQueryParameters(storageSharedKeyCredential).ToString();

Upload, download, and manage data with Azure Storage Explorer

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.