多条内容批量审查

介绍如何调用接口在WebService应用通道中进行多条内容批量审查。

批量审查

介绍调用WebService应用通道,通过
POST
发送一个json文本对内容进行批量审查。需要将HTTP header中的 Content-type 设置为 "application/json"。

本文以批量审查Swift内容为例。

请求方式

POST

请求地址

/skg/v1/dlp/channel/webserviceapp/<WebService应用ID>/bulk_async

请求参数

参数名称 类型/是否必须 描述
callback_url String(必选) 异步模式回调的url,所有对象检查完成后一并回调。
verbose Bool(必选) 是否返回incident_info。
objects List(必选) 检查对象的列表,具体参数参考以下表格。
以下表格详细介绍了objects列表的具体参数。
参数名 类型 说明
user String(必选) 生成事件的用户名 - 支持域用户,格式为域名\用户名。
filename String(可选) 文件名 - 可做根据文件名设置的策略匹配
customAttribute String(可选) 支持用户自定义的参数名。
queryID String(必选) 与此请求关联的事件查询ID,保持唯一。若请求无事件生成则无法查询到事件详情。
注: queryid的值对应于第三方云服务中的流量UUID。
redaction Dict(可选) 脱敏后内容的处理。
  • response:将脱敏后的内容返回至当前路径。以下为代码示例:
    "redaction": {
    "sendBackType": "response",
    }
  • httpUpload:将脱敏后的内容发送至指定URL。以下为代码示例:
    "redaction": {
    "sendBackType": "httpUpload",
    "url": "http://172.22.148.115/upload",
    }
  • S3:将脱敏后的内容上传至云存储。以下为适用于S3的代码示例:
    "redaction": {
        "sendBackType": "s3",
        "s3Bucket": "skyguardts",
        "accessKey": "skyguardts",
        "secretKey": "skyguardts",
        "endpointUrl": "http://172.22.148.117:9000",
        },

    此步骤同样适用于SwiftCOSOSS云端服务。具体相关配置参数,请参考章节异步模式下审查云服务存储内容的objectinfo参数

md5 String(可选) 文件MD5值,用于记录和缓存加速。支持MD5和文档一同送检,也支持仅送检MD5。
"md5":"09e066b382d4225de3c0594aa89b5fi"
operation int(可选) 操作ID。创建WebService应用时定义,在API流量日志的Webservice操作字段中将会显示操作ID对应的操作名称。默认有以下四种,用户也可以自定义:
  • 1 - 读取
  • 2 - 写入
  • 3 - 添加
  • 4 - 删除
callback_url String(可选) call back的监听地址
verbose String(必选) 是否返回事件信息。
uploadtype String(必选) 只限于异步。支持AWS S3、阿里云OSS、腾讯云COS、Swift等云存储,以及本地文件和下载URL。
  • swift
  • oss
  • cos
  • s3
  • file
  • http
X-Auth-User String(必选) swift的认证用户名。
X-Auth-Key String(必选) swift的认证Key。
X-Auth-Token String(必选) swift的认证token。
objectUrl String(必选) swift的认证文件的地址。

请求示例

以下示例为调用接口,对WebService通道中的文件进行批量上传,以供内容安全审查。

{
  "callback_url": "http://172.22.113.49:5000/post.php",
  "verbose" : True, //是否返回incident_info
  "objects": [
    {
      "user": "abc\enduser1",
      "filename": "confidential.doc",
      "queryID": "cd2fd109-c4d4-489f-9b27-53752f7827d6",
      "uploadtype": "swift",
      "objectInfo" : {
          "authUrl" : "http://swift.example.com/auth/v1.0",
          "X-Auth-User" : "testuser",
          "X-Auth-Key" : "2121212",
          "X-Auth-Token" : "AUTH_tkbdac2a3474ee4d6396133c99cfd962c",
          "objectUrl" : "https://swift-server/confidential.doc"
      }
    },
    {
      "user": "abc\enduser2",
      "filename": "test.doc",
      "queryID": "47992d42-04b7-4860-b186-b8c11f8b2253",
      "uploadtype": "swift",
      "objectInfo" : {
          "authUrl" : "http://swift.example.com/auth/v1.0",
          "X-Auth-User" : "testuser",
          "X-Auth-Key" : "2121212",
          "X-Auth-Token" : "AUTH_tkbdac2a3474ee4d6396133c99cfd962c",
          "objectUrl" : "https://swift-server/confidential.doc"
      }
    }
  ]
}
 

Python请求示例 - 批量送检

以下示例为使用Python代码调用接口,对WebService通道中的文件进行批量上传,以供内容安全审查。

import json
import requests
 
auth_headers = {
    "Authorization": "<Authorization>",
    "x-skg-timestamp": "<timestamp>",
}
ucwi_endpoint = "<ENDPOINT>"
url = ucwi_endpoint + "/skg/v1/dlp/channel/webserviceapp/78217a43-542d-47e2-97a5-4435bf11521d/bulk_async"
data = {
    "callback_url": CALLBACK_URL,
    "verbose": False,
    "objects": [
        {  
            "user": "cloudtest\\clouduser",
            "filename": "file1",
            "queryID": "<queryID1>",
            "uploadtype": "swift",
            "objectInfo": {
                "authUrl": "http://172.22.117.120:8080/auth/v1.0",
                "X-Auth-User": "admin:admin",
                "X-Auth-Key": "admin",
                # "X-Auth-Token": "<X-Auth-Token>",
                "objectUrl": "http://<ip_address>:8080/v1/AUTH_admin/container1/DLP.docx",
            }  
        }, 
        {  
            "user": "cloudtest\\clouduser",
            "filename": "file1",
            "queryID": "<queryID2>",
            "uploadtype": "swift",
            "objectInfo": {
                "authUrl": "http://172.22.117.120:8080/auth/v1.0",
                "X-Auth-User": "admin:admin",
                "X-Auth-Key": "admin",
                # "X-Auth-Token": "<X-Auth-Token>",
                "objectUrl": "http://<ip_address>:8080/v1/AUTH_admin/container1/skyguard.txt",
            }, 
        },
        {  
            "user": "cloudtest\\clouduser",
            "filename": "file1",
            "queryID": "<queryID3>",
            "uploadtype": "s3",
            "objectInfo": {
                "s3Region": "cn-north-1",
                "accessKey": "<AWS_AK>",
                "secretKey": "<AWS_SK>",
                "endpointUrl": "https://s3.cn-north-1.amazonaws.com.cn",
                "s3Bucket": "falseuser-test1",
                "s3Key": "Desert.jpg",
            }, 
        } 
    ]
}
r = requests.post(url, headers=auth_headers, json=data)
print(r.json())

Java请求示例 - 批量送检

以下示例为使用Java代码调用接口,批量上传WebService通道中的多个文件,以供内容安全审查。

import java.util.HashMap;
import java.util.Iterator;
import java.io.File;
import java.io.FileInputStream;
 
import javax.net.ssl.SSLContext;
import java.security.cert.X509Certificate;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
 
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
 
public class TestCloudBulkAsync {
 
 
    public static String inspectCloudBulk() {
        String host = "<UCWI_HOST>";
        String port = "<UCWI_PORT>";
        String apiPath = "/skg/v1/dlp/channel/webserviceapp/78217a43-542d-47e2-97a5-4435bf11521d/bulk_async";
        String url = "https://" + host + ":" + port + apiPath;
 
        JSONObject bodyJson = new JSONObject();
        JSONArray metadataArray = new JSONArray();
 
        bodyJson.put("callback_url", "<CALLBACK_URL>");
        bodyJson.put("verbose", true);
 
        JSONObject metadataJson1 = new JSONObject();
        JSONObject objectInfo1 = new JSONObject();
 
        String queryId1 = UUID.randomUUID().toString();
        metadataJson1.put("queryID", queryId1);
        metadataJson1.put("user", "cloudtest\\clouduser");
        metadataJson1.put("filename", "file1");
        metadataJson1.put("uploadtype", "swift");
 
        objectInfo1.put("authUrl", "http://172.22.117.120:8080/auth/v1.0");
        objectInfo1.put("X-Auth-User", "admin:admin");
        objectInfo1.put("X-Auth-Key", "admin");
        objectInfo1.put("objectUrl", "http://172.22.117.120:8080/v1/AUTH_admin/container1/DLP.docx");
 
        metadataJson1.put("objectInfo", objectInfo1);
        metadataArray.add(metadataJson1);
 
        JSONObject metadataJson2 = new JSONObject();
        JSONObject objectInfo2 = new JSONObject();
 
        String queryId2 = UUID.randomUUID().toString();
        metadataJson2.put("queryID", queryId2);
        metadataJson2.put("user", "cloudtest\\clouduser");
        metadataJson2.put("filename", "file2");
        metadataJson2.put("uploadtype", "swift");
 
        objectInfo2.put("authUrl", "http://<ip_address>:8080/auth/v1.0");
        objectInfo2.put("X-Auth-User", "admin:admin");
        objectInfo2.put("X-Auth-Key", "admin");
        objectInfo2.put("objectUrl", "http://<ip_address>:8080/v1/AUTH_admin/container1/skyguard.txt");
 
        metadataJson2.put("objectInfo", objectInfo2);
        metadataArray.add(metadataJson2);
 
        JSONObject metadataJson3 = new JSONObject();
        JSONObject objectInfo3 = new JSONObject();
 
        String queryId3 = UUID.randomUUID().toString();
        metadataJson3.put("queryID", queryId3);
        metadataJson3.put("user", "cloudtest\\clouduser");
        metadataJson3.put("filename", "file3");
        metadataJson3.put("uploadtype", "s3");
 
        objectInfo3.put("s3Region", "cn-north-1");
        objectInfo3.put("accessKey", "<AWS_AK>");
        objectInfo3.put("secretKey", "<AWS_SK>");
        objectInfo3.put("endpointUrl", "<S3_ENDPOINT>");
        objectInfo3.put("s3Bucket", "<S3_BUCKET>");
        objectInfo3.put("s3Key", "<S3_KEY>");
 
        metadataJson3.put("objectInfo", objectInfo3);
        metadataArray.add(metadataJson3);
 
        bodyJson.put("objects", metadataArray);
 
        HttpPost post = new HttpPost(url);
 
 
        post.addHeader("Authorization", "<Authorization>");
        post.addHeader("x-skg-timestamp", "<timestamp>");
        post.setHeader("Content-type", "application/json");
 
        CloseableHttpClient client = HttpClients.createDefault();
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] chain, String authType) {
                    return true;
                }
            }).build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
            client = HttpClients.custom().setSSLSocketFactory(sslsf).build();
        }
        catch (Exception e){
            e.printStackTrace();
        }
 
        String bodyString = bodyJson.toJSONString();
        StringEntity requestEntity = new StringEntity(bodyString,"utf-8");
        post.setEntity(requestEntity);
        String result = "";
        try {
            CloseableHttpResponse resp = client.execute(post);
            HttpEntity entity = resp.getEntity();
            result = EntityUtils.toString(entity, "UTF-8");
        }
        catch (Exception e){
            e.printStackTrace();
        }
 
        return result;
    }
 
    public static void main(String []args) {
        String result = inspectCloudBulk();
        System.out.println(result);
    }
}

返回参数

批量审查请求返回结果中包含以下参数:
名称 描述
result 请求是否成功,成功为0,失败为1
actionCode 请求成功时,用户可选择对符合请求条件的内容进行默认操作,默认操作包括1-允许数据传输和2-阻断数据传输
errorCode 请求失败时返回的错误代码
message 请求失败时返回的错误消息
Incident_info 策略匹配的事件信息。若匹配策略,发现违规内容,系统还将返回策略匹配信息。参考返回示例获取详细信息。

返回示例

若匹配策略,发现违规内容,系统还将返回策略匹配信息。

以下示例及其备注信息详细介绍了返回结果中的各参数及其含义。

{
  "cd2fd109-c4d4-489f-9b27-53752f7827d": {
    "localDetectedTime": "2019-07-29T16:17:43.079368+0800",  //检测时间
    "incident_info":          //事件信息
{
      "matchedPolicies": [    //匹配策略
        {
          "numberOfMatches": 1,    //匹配策略的事件数量
          "name": "abc\enduser1",  //违规用户的域名和用户名
          "actionSettingName": "阻断",  //对违规事件执行的动作
          "matchedRules": [  //匹配的策略规则
            {
              "name": "company",  //规则名称
              "matchedConditions": [   //匹配的条件
                {
                  "type": 5,   //条件匹配类型, 包括: 1:正则, 2:字典, 3:外部脚本, 4:文件类型组, 5:关键字, 6:脚本, 7:文件指纹, 8:机器学习, 9:终端位置, 10:文件名称, 11:附件数量, 12:数据库指纹, 13:文件大小, 14:二进制, 15:压缩文件深度, 16:加密文件, 17:格式不匹配文件, 18:内置模板
                  "matchedElements": [  //匹配的元素
                    {
                      "matchedContents": [  //匹配的内容
                        {
                          "detectedValues": [   //检测到的内容
                            {
                              "text": "company"  //关键字
                            }
                          ],
                          "isFileSuffixMatch": true,   //文件后缀名是否一致
                          "isArchiveFile": false,    //是否为压缩文件
                          "isEncryptFile": false,    //是否为加密文件
                          "encodeType": "UnknownEncoding",   //文件编码类型, 具体请参阅国际标准编码类型及其解释
                          "numberOfMatches": 1,    //匹配数
                          "locationPath": "confidential.doc",      //文件全路径
                          "id": "0-0",      //文件ID
                          "contentSize": 22     //内容大小
                        }
                      ],
                      "numberOfMatches": 1,
                      "isTruncated": false
                    }
                  ],
                  "isTraditionalMatching": false       //是否开启繁体匹配
                }
              ]
            }
          ],
          "priority": 31,        //优先级
          "groupName": "默认策略组",     //策略组名称
          "severity": 3          //敏感级别 1 - 高, 2 - 中, 3 - 低, 4 - 信息
        }
      ]
    },
    "result": 0,
    "actionCode": 2
  },
  "47992d42-04b7-4860-b186-b8c11f8b2253": {
    "localDetectedTime": "2019-07-29T07:52:26.423684",
    "incident_info": {},
    "result": 0,
    "actionCode": 1
  }
}