【问题标题】:Audit Logs Retrieval from Azure Data Lake Storage (Gen 2)从 Azure Data Lake Storage(第 2 代)中检索审核日志
【发布时间】:2019-06-11 12:12:21
【问题描述】:

我正在尝试从 Azure Data Lake Storage(第 2 代)检索审核日志..

到目前为止,我已尝试在 Gen 2 中使用 AZCOPY、REST API(目前不支持)来检索(连接)审核日志并寻找用于检索日志的替代解决方案

当使用 AZCOPY 连接时,它只使用基于 API 的调用,当我尝试检索日志时,我得到了分层命名空间帐户不支持 API 调用的错误。添加图片以供参考。 Snapshot of AZCOPY error

是否有针对此用例的解决方法或我可以尝试检索日志的任何其他方法?

【问题讨论】:

    标签: azure


    【解决方案1】:

    更新:

    我可以使用 read api 从 ADLS GEN2 获取文件内容。我可以为您提供一个由 py​​thon 代码编写的示例(您可以根据我的代码更改为任何其他语言)。从下面的代码中可以直接获取文件内容,或者获取Authorization可以在postman中使用。

    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 data Lake gen 2 做好准备,所以到目前为止,解决方案是使用 ADLS Gen2 Read api

    获取文件内容后,即可保存。

    并且您可以自己进行身份验证工作。如果您对如何使用 ADLS Gen 2 api 进行阅读有任何问题,请随时告诉我。

    【讨论】:

    • 我们尝试使用 READ API for ADLS(第 2 代)读取数据,并在尝试从 Postman API 工具中访问 URL 后遇到与上述相同的错误。从 ADLS(第 2 代)检索审计日志的任何其他建议或替代方法都会有所帮助
    【解决方案2】:

    ADLS Gen2 $logs 现在在您注册 ADLS Gen2 中的多协议访问时可用。可以在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

    【讨论】:

      【解决方案3】:

      随着 2019 年 11 月(版本 1.11.1)发布的 Azure 存储资源管理器,现在可以查看隐藏的容器,例如 $logs

      【讨论】:

        猜你喜欢
        • 2020-11-22
        • 2019-09-10
        • 2019-05-16
        • 2019-10-02
        • 2020-01-24
        • 2023-03-20
        • 1970-01-01
        • 2020-01-13
        • 2020-06-20
        相关资源
        最近更新 更多