簡體   English   中英

從 Azure Data Lake Storage(第 2 代)檢索審核日志

[英]Audit Logs Retrieval from Azure Data Lake Storage (Gen 2)

我正在嘗試從 Azure Data Lake Storage(第 2 代)中檢索審核日志

到目前為止,我已經嘗試在 Gen 2 中使用AZCOPY、REST API (目前不受支持)來檢索(連接)審計日志並尋找用於檢索日志的替代解決方案

當使用AZCOPY連接時,它只使用基於 API 的調用,當我嘗試檢索日志時,我收到錯誤,即分層命名空間帳戶不支持 API 調用。 添加圖像以供參考。 AZCOPY 錯誤的快照

是否有針對此用例的解決方法或我可以嘗試檢索日志的任何其他方法?

更新:

我可以使用 read api 從 ADLS GEN2 獲取文件內容。 我可以為您提供一個由 py​​thon 代碼編寫的示例(您可以根據我的代碼更改為任何其他語言)。 從下面的代碼中,可以直接獲取文件內容,也可以獲取可以在postman中使用的Authorization

Python 3.7 代碼如下:

import requests
import datetime
import hmac
import hashlib
import base64

storage_account_name = 'xxx'
storage_account_key = 'xxx'
api_version = '2018-11-09'
request_time = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
#the file path on adls gen2
FILE_SYSTEM_NAME='dd1/myfile.txt'

string_params = {
    'verb': 'GET',
    'Content-Encoding': '',
    'Content-Language': '',
    'Content-Length': '',
    'Content-MD5': '',
    'Content-Type': '',
    'Date': '',
    'If-Modified-Since': '',
    'If-Match': '',
    'If-None-Match': '',
    'If-Unmodified-Since': '',
    'Range': '',
    'CanonicalizedHeaders': 'x-ms-date:' + request_time + '\nx-ms-version:' + api_version,
    'CanonicalizedResource': '/' + storage_account_name+'/'+FILE_SYSTEM_NAME
    }

string_to_sign = (string_params['verb'] + '\n' 
                  + string_params['Content-Encoding'] + '\n'
                  + string_params['Content-Language'] + '\n'
                  + string_params['Content-Length'] + '\n'
                  + string_params['Content-MD5'] + '\n' 
                  + string_params['Content-Type'] + '\n' 
                  + string_params['Date'] + '\n' 
                  + string_params['If-Modified-Since'] + '\n'
                  + string_params['If-Match'] + '\n'
                  + string_params['If-None-Match'] + '\n'
                  + string_params['If-Unmodified-Since'] + '\n'
                  + string_params['Range'] + '\n'
                  + string_params['CanonicalizedHeaders']+'\n'
                  + string_params['CanonicalizedResource'])

signed_string = base64.b64encode(hmac.new(base64.b64decode(storage_account_key), msg=string_to_sign.encode('utf-8'), digestmod=hashlib.sha256).digest()).decode()

#print out the datetime
print(request_time)
#print out the Authorization
print('SharedKey ' + storage_account_name + ':' + signed_string)

headers = {
    'x-ms-date' : request_time,
    'x-ms-version' : api_version,
    'Authorization' : ('SharedKey ' + storage_account_name + ':' + signed_string)
}
url = ('https://' + storage_account_name + '.dfs.core.windows.net/'+FILE_SYSTEM_NAME)
#print out the url
print(url)
r = requests.get(url, headers = headers)

#print out the file content
print(r.text)

運行代碼后,獲取文件內容:

在此處輸入圖片說明

您還可以在郵遞員中使用上面代碼中生成的值,例如授權/日期:

在此處輸入圖片說明


您可能知道 SDK 尚未准備好用於 azure 數據湖第 2 代,因此截至目前,解決方案是使用ADLS Gen2 Read api

檢索文件內容后,您可以保存它。

您可以自行完成身份驗證工作。 如果您對如何使用 ADLS Gen 2 api 進行閱讀有任何疑問,請隨時告訴我。

當您在 ADLS Gen2 中注冊多協議訪問時,ADLS Gen2 $logs現在可用。 可以在http://aka.ms/mpaadls找到描述多協議訪問的博客。 您可以在此處注冊訪問權限。

目前不支持在 Azure 門戶中啟用日志。 以下是如何使用 PowerShell 啟用日志的示例。

$storageAccount = Get-AzStorageAccount -ResourceGroupName <resourceGroup> -Name <storageAccountName>

Set-AzStorageServiceLoggingProperty -Context $storageAccount.Context -ServiceType Blob -LoggingOperations read,write,delete -RetentionDays <days>. 

要使用日志,您現在可以使用 AzCopy 和 SDK。 暫時無法在 Azure 存儲資源管理器中查看$logs

隨着 2019 年 11 月(版本 1.11.1)發布 Azure 存儲資源管理器,現在可以查看隱藏的容器,例如 $logs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM