全部產品
Search
文件中心

MaxCompute:資料動態脫敏

更新時間:Jun 19, 2024

當您期望某些使用者只可以查看MaxCompute專案中隱藏關鍵資訊的敏感性資料時,您可以開啟MaxCompute動態脫敏功能,在資料訪問或展示時即時隱藏或替換敏感性資料,以防止敏感性資料泄露。本文為您介紹如何開啟MaxCompute動態脫敏功能,並提供參考樣本。

背景資訊

MaxCompute本身不具備動態脫敏的能力,依賴DataWorks資料保護傘服務的資料脫敏功能。您需先開通DataWorks的資料保護傘服務,才可為目標MaxCompute專案開啟動態脫敏功能。

為MaxCompute專案開啟動態脫敏功能後,您可基於DataWorks的資料識別規則,設定項目的脫敏規則(對哪些敏感性資料進行脫敏)。當您從除DataWorks入口外的MaxCompute cmd、log view查詢敏感性資料時,在展示層按照配置的脫敏規則進行脫敏。該功能可以有效保護諸如手機號、社會安全號碼、銀行卡號、車牌號、IP地址等敏感資訊。動態脫敏功能僅會對查詢結果進行脫敏,不會影響底層儲存的資料。

推薦您使用DataWorks預設的資料識別規則,如果需要自訂資料識別規則,請參見配置資料識別規則

使用限制

  • 僅DataWorks專業版及以上版本,才可使用此功能。DataWorks基礎版暫時無法使用此功能,如您的DataWorks為基礎版,請升級DataWorks為合適版本。詳情請參見DataWorks各版本詳解

  • 僅華北2(北京)、華東2(上海)、華東1(杭州)、西南1(成都)、華南1(深圳)、華北2(北京政務雲)、華東2(上海金融雲)、中國(香港)、新加坡、德國(法蘭克福)、馬來西亞(吉隆坡)、美國(矽谷)地區支援使用MaxCompute底層脫敏。

  • MaxCompute底層脫敏的生效範圍為會話層級,即在進行會話查詢時需增加相關脫敏服務調用語句,脫敏配置才會生效。

  • MaxCompute底層脫敏不支援對MaxCompute資料表的主鍵欄位進行脫敏。

  • MaxCompute底層脫敏僅支援對String類型欄位進行脫敏。

  • 只有MaxCompute專案中已經存在資料並且資料已建立24小時(h)的情況下,才能使用此功能。

準備工作

  1. 準備待脫敏的MaxCompute專案和資料。具體操作,請參見建立MaxCompute專案匯入資料

  2. 訪問資料保護傘服務並開通。具體操作,請參見進入資料保護傘

    服務聲明頁面,勾選我已閱讀並接受以上協議條款,單擊立刻開通

    image.png

  3. 申請網路白名單。

    阿里雲主帳號填寫表單申請MaxCompute專案訪問外部網路,開通後才可調用脫敏服務。

    如果目標IP或網域名稱不存在安全限制,審核通過後即可訪問目標IP或網域名稱,審核周期為3個工作日之內。

    申請內容格式如下:

    專案名稱(待脫敏的專案名稱) : data_shield_hz
    日誌地址 :
    問題描述 : 對Project開啟網域名稱白名單,使UDF啟動並執行時候可以訪問某些網域名稱。
    地區:杭州
    要訪問的網域名稱: dsg-cn-hangzhou.data.aliyun.com,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com
    連接埠:80,443

    不同地區申請的網域名稱不同,請填寫以下列表中地區對應的網域名稱。

    上海:dsg-cn-shanghai.data.aliyun.com,dsg-oss-dic-ori.oss-cn-shanghai.aliyuncs.com
    杭州:dsg-cn-hangzhou.data.aliyun.com,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com
    北京:dsg-cn-beijing.data.aliyun.com,dsg-oss-dic-ori.oss-cn-beijing.aliyuncs.com   
    成都:dsg-cn-chengdu.data.aliyun.com,dsg-oss-dic-ori-cd.oss-cn-chengdu.aliyuncs.com
    深圳售賣區: dsg-cn-shenzhen.data.aliyun.com,dsg-oss-dic-ori-sz.oss-cn-shenzhen.aliyuncs.com
    華北政務云: dsg-cn-north-2-gov-1.data.aliyun.com,dsg-oss-dic-ori-north-2-gov-1.oss-cn-north-2-gov-1-internal.aliyuncs.com
    上海金融云:dsg-cn-shanghai-finance-1.data.aliyun.com,dsg-oss-dic-ori-sh-fin-1.oss-cn-shanghai.aliyuncs.com
    香港 :dsg-cn-hongkong.data.aliyun.com,dsg-oss-hongkong.oss-cn-hongkong.aliyuncs.com
    新加坡: dsg-ap-southeast-1.data.aliyun.com,dsg-oss-ap-southeast-1.oss-ap-southeast-1.aliyuncs.com
    美西: dsg-us-west-1.data.aliyun.com,dsg-oss-us-west-1.oss-us-west-1.aliyuncs.com
    馬來西亞:dsg-ap-southeast-3.data.aliyun.com,dsg-oss-ap-malaysia.oss-ap-southeast-3.aliyuncs.com
    法蘭克福: dsg-eu-central-1.data.aliyun.com,dsg-oss-eu-central-1.oss-eu-central-1-internal.aliyuncs.com

開啟資料脫敏功能

  1. 選擇脫敏情境。

    1. 登入DataWorks控制台,進入資料保護傘頁面。具體操作,請參見進入資料保護傘

    2. 在左側導覽列,選擇規則配置 > 資料脫敏管理,進入資料脫敏管理

    3. 脫敏情境下拉式清單選擇MaxCompute引擎層脫敏

      說明

      如果需要在DataWorks介面上展示脫敏效果,需要開啟資料開發/資料地圖展示脫敏

      建立資料脫敏情境更多內容請參見建立資料脫敏情境

  2. 建立資料脫敏規則

  3. 可選:若脫敏規則指定的資料不需要對某些使用者進行脫敏展示,您可配置脫敏規則白名單。

    1. 資料脫敏管理介面,單擊白名單組態管理

    2. 白名單組態管理頁簽,單擊右上方的新增白名單

    3. 新增白名單對話方塊中,選擇規則使用者組生效時間

      說明

      設定白名單生效時間後,若不在白名單脫敏時間的區間內,使用者在查詢該敏感資訊時將會繼續脫敏。

查詢SQL確認脫敏結果

DataWorks資料開發介面

  1. 關閉頁面查詢內容脫敏開關,詳情請參見安全設定與其他

    關閉專案

  2. 執行查詢SQL。

    在您執行具體查詢SQL前,請先在當前會話中通過set命令調用脫敏服務,不同地區調用底層脫敏服務命令如下所示。

    說明

    MaxCompute底層資料脫敏僅支援會話層級使用。

    上海
    set odps.output.field.formatter={"name":"aegis:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-shanghai.data.aliyun.com:80,dsg-cn-shanghai.data.aliyun.com:443,dsg-oss-dic-ori.oss-cn-shanghai.aliyuncs.com:80,dsg-cn-shanghai.data.aliyun.com:443;
    杭州
    set odps.output.field.formatter={"name":"aegis_hz:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-hangzhou.data.aliyun.com:80,dsg-cn-hangzhou.data.aliyun.com:443,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:80,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:443;
    北京
    set odps.output.field.formatter={"name":"aegis_bj:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-beijing.data.aliyun.com:80,dsg-cn-beijing.data.aliyun.com:443,dsg-oss-dic-ori.oss-cn-beijing.aliyuncs.com:80,dsg-oss-dic-ori.oss-cn-beijing.aliyuncs.com:443;
    成都
    set odps.output.field.formatter={"name":"aegis_cd:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-chengdu.data.aliyun.com:80,dsg-cn-chengdu.data.aliyun.com:443,dsg-oss-dic-ori-cd.oss-cn-chengdu.aliyuncs.com:80,dsg-oss-dic-ori-cd.oss-cn-chengdu.aliyuncs.com:443;
    香港
    set odps.output.field.formatter={"name":"aegis_hk:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-hongkong.data.aliyun.com:80,dsg-cn-hongkong.data.aliyun.com:443,dsg-oss-hongkong.oss-cn-hongkong.aliyuncs.com:80,dsg-oss-hongkong.oss-cn-hongkong.aliyuncs.com:443;

    主要參數解釋如下。

    命令

    含義

    odps.output.field.formatter

    表示要調用ODPS的脫敏函數(此脫敏函數要求脫敏欄位為String類型)。

    • aegis_hz:<SchemaName>:masking_v2:表示函數名稱(name)。

      其中SchemaName是根據MaxCompute專案是否配置Schema三層模型,若已配置則需要配置對應的SchemaName。關於Schema的介紹詳情,請參見Schema操作

    • ["alias","index"]:表示參數資訊(預設參數)。

    odps.isolation.session.enable

    表示當前調用是會話層級。會話結束後,脫敏功能便會失效。

    odps.internet.access.list

    表示運行執行函數時訪問相關網域名稱,用於查詢資料保護傘的脫敏資訊。

    以杭州地區SchemaName為default為例,完整實現MaxCompute底層資料脫敏指令碼如下所示。

    set odps.output.field.formatter={"name":"aegis_hz:default:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    set odps.internet.access.list=dsg-cn-hangzhou.data.aliyun.com:80,dsg-cn-hangzhou.data.aliyun.com:443,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:80,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:443;
    select * from table;
  3. 在資料開發介面查看脫敏結果。

    image.png

odpscmd介面查詢結果

  1. 配置訪問網域名稱。

    在您執行具體查詢SQL前,請先在odpscmd服務的Config設定檔中配置訪問網域名稱。

    不同地區的網域名稱配置,具體如下。

    上海
    set odps.internet.access.list=dsg-cn-shanghai.data.aliyun.com:80,dsg-cn-shanghai.data.aliyun.com:443,dsg-oss-dic-ori.oss-cn-shanghai.aliyuncs.com:80,dsg-cn-shanghai.data.aliyun.com:443;
    杭州
    set odps.internet.access.list=dsg-cn-hangzhou.data.aliyun.com:80,dsg-cn-hangzhou.data.aliyun.com:443,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:80,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:443;
    北京
    set odps.internet.access.list=dsg-cn-beijing.data.aliyun.com:80,dsg-cn-beijing.data.aliyun.com:443,dsg-oss-dic-ori.oss-cn-beijing.aliyuncs.com:80,dsg-oss-dic-ori.oss-cn-beijing.aliyuncs.com:443;
    成都
    set odps.internet.access.list=dsg-cn-chengdu.data.aliyun.com:80,dsg-cn-chengdu.data.aliyun.com:443,dsg-oss-dic-ori-cd.oss-cn-chengdu.aliyuncs.com:80,dsg-oss-dic-ori-cd.oss-cn-chengdu.aliyuncs.com:443;
    香港
    set odps.internet.access.list=dsg-cn-hongkong.data.aliyun.com:80,dsg-cn-hongkong.data.aliyun.com:443,dsg-oss-hongkong.oss-cn-hongkong.aliyuncs.com:80,dsg-oss-hongkong.oss-cn-hongkong.aliyuncs.com:443;

    主要參數解釋如下。

    命令

    含義

    odps.internet.access.list

    表示運行執行函數時訪問相關網域名稱,用於查詢資料保護傘的脫敏資訊。

    以杭州地區SchemaName為default為例,設定檔代碼如下:

    project_name=data_shield_hz
    # app access id and key are optional for individual users
    # app_access_id=<app_accessid>
    # app_access_key=<app_accesskey>
    access_id=客戶aid
    access_key=客戶ak
    # this endpoint is for office environment
    end_point=http://service.odps.aliyun.com/api
    # this url is for odpscmd update
    update_url=http://odps.alibaba-inc.com/official_downloads
    # download sql results by instance tunnel
    use_instance_tunnel=true
    # the max records when download sql results by instance tunnel
    instance_tunnel_max_record=10000
    set odps.internet.access.list=dsg-cn-hangzhou.data.aliyun.com:80,dsg-cn-hangzhou.data.aliyun.com:443,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:80,dsg-oss-dic-ori-hz.oss-cn-hangzhou.aliyuncs.com:443;
  2. 執行查詢SQL。

    在您執行具體查詢SQL前,請先在當前會話中通過set命令調用脫敏服務,不同地區調用底層脫敏服務命令如下所示。

    說明

    MaxCompute底層資料脫敏僅支援會話層級使用。

    上海
    set odps.output.field.formatter={"name":"aegis:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    杭州
    set odps.output.field.formatter={"name":"aegis_hz:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    北京
    set odps.output.field.formatter={"name":"aegis_bj:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    成都
    set odps.output.field.formatter={"name":"aegis_cd:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    香港
    set odps.output.field.formatter={"name":"aegis_hk:<SchemaName>:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;

    主要參數解釋如下。

    命令

    含義

    odps.output.field.formatter

    表示要調用ODPS的脫敏函數(此脫敏函數要求脫敏欄位為string類型)。

    • aegis_hz:<SchemaName>masking_v2:表示函數名稱(name)。

      其中SchemaName是根據MaxCompute專案是否配置Schema三層模型,若已配置則需要配置對應的SchemaName。關於Schema的介紹詳情,請參見Schema操作

    • ["alias","index"]:表示參數資訊(預設參數)。

    odps.isolation.session.enable

    表示當前調用是會話層級。會話結束後,脫敏功能便會失效。

    以杭州地區為例,完整實現MaxCompute底層資料脫敏指令碼如下所示。

    set odps.output.field.formatter={"name":"aegis_hz:default:masking_v2","param":["alias","index"]};
    set odps.isolation.session.enable=true;
    select * from table;
  3. 查看脫敏結果。

    image.png

取消使用底層脫敏

執行如下SQL語句,取消使用的底層脫敏。

set odps.output.field.formatter=;
select * from table;

或在DataWorks中配置脫敏情境時,資料範圍不要選擇目標MaxCompute專案,詳情請參見配置脫敏情境