Skip to content

Create Sensitive Field Masking Rule



POST /api/v1/data_mask_rule/add

Overview

Create regex masking rules for sensitive fields that are applied by role in the current workspace.

Prerequisites and Usage Steps

This write endpoint requires the dataRightsManage.workspaceConfigManage management permission.

Use the API Key of the target workspace. This group configures standalone sensitive rules at the query return stage; it does not rewrite raw stored data, create fields, or serve as a permanent deletion/anonymization API.

After selecting the data category, actual field, regex, and required roles, create the rule. Names are not checked for uniqueness. On success, the new rule object is returned; after a timeout or HTTP 500, query the list first and do not repeatedly create rules with the same name.

A write is committed first, and then the rule cache for the corresponding data category is deleted (for modifications, both the old and new categories are cleared). Cache failure may occur after the commit. Then test with the actual read identity. A successful save in the rule list does not mean the rule has been verified as effective on all query surfaces and caches.

Effectiveness also depends on the target query chain, data category, and actual role set; role configuration is not data query authorization itself. When the same account/Key has multiple roles with query permission for that category, if one of those roles has no applicable sensitive rule, this group of rules may not be applied as a whole. Do not bind only one role and assume masking is enforced for all readers; verify with the actual roles/Key in Query Data and on the target display surface. Current regex replacement handles only string values; numbers, objects, arrays, booleans, and null are not automatically converted to strings for masking. The matched string portion in standard queries is replaced with ***, while other text is retained. Regex validation on save uses the regex library, while the query execution path uses standard re; it is recommended to use only syntax compatible with Python standard re.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or enter: Obtain an OpenAPI Key with this operation permission from API Key Management in the target workspace.

Body Request Parameters

Parameter Type Required Description
roleUUIDs[*] string A role UUID. Before writing, the server checks whether it is in the workspace's available role set.
Example: role_example
How to obtain or enter: Enter the UUID from the role list for each item; do not use role names.
name string Y Required and non-empty, up to 128 characters. Duplicate names are currently allowed, and no idempotency guarantee by name is provided.
Allowed null: False
Maximum length: 128
Allowed empty string: False
Example: 验证码脱敏
How to obtain or enter: Enter the rule purpose. First query existing configurations from the list to avoid duplicate creation after a timeout.
type string Y Required. The historical declaration allows null, but clients must select an actually supported category and must not treat null as all categories; null cannot form a reliably effective rule, and modifications may also violate non-null storage constraints.
Allowed null: True
Allowed values: ['lineage', 'logging', 'metric', 'object', 'custom_object', 'keyevent', 'tracing', 'rum', 'security', 'network', 'profiling', 'billing']
Example: logging
How to obtain or enter: Select lineage/logging/metric/object/custom_object/keyevent/tracing/rum/security/network/profiling/billing according to the actual data category being queried.
field string Y A comma-separated list of field names; a standalone * item means all fields. Field-name prefix wildcards such as message* are not supported. When all fields are needed, it is recommended to pass * by itself.
Allowed null: False
Maximum length: 128
Allowed empty string: False
Example: message
How to obtain or enter: Obtain the original field name by querying the corresponding data fields; do not enter an alias.
reExpr string Y Required and non-empty, up to 5000 characters. For example, it converts 验证码=123456 to 验证码=***; custom replacement parameters are not supported. Some regex extended syntax can be saved but fails when executed with standard re, so availability cannot be determined solely by a successful save.
Allowed null: False
Maximum length: 5000
Allowed empty string: False
Example: (?<=验证码=)[0-9]{6}
How to obtain or enter: Enter an expression compatible with standard Python re and use JSON escaping; you can first test it with controlled samples in Masking Test.
roleUUIDs array Y Required array. The current check excludes deleted roles; disabled but undeleted roles may pass. [] means no explicitly matched role, not all roles. Do not treat * as a validation-free wildcard role for this public API; if the normal role table does not contain that UUID, a 404 will be returned.
Allowed null: False
Example: ["role_example"]
How to obtain or enter: Obtain the UUID of an available, undeleted role in the current workspace from Role List; for system roles, use the actual identifier from the list.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/data_mask_rule/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"验证码脱敏","type":"logging","field":"message","reExpr":"(?<=验证码=)[0-9]{6}","roleUUIDs":["role_example"]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content.id integer Record ID; not used for addressing.
content.uuid string wdmk_ rule UUID, used for details, modifications, and batch actions.
content.workspaceUUID string Workspace to which the rule belongs.
content.name string Rule name; the current endpoint does not check for duplicate names.
content.type string Data category, which determines the applicable namespace.
content.field string Raw field configuration, comma-separated; consumers do not automatically trim leading and trailing spaces from each item.
content.reExpr string Saved regex, without custom replacement text.
content.roleUUIDs array<string> Applicable role UUIDs; [] does not mean all roles.
content.roleUUIDs[*] string A role UUID, which may be a system role identifier or a custom role_ UUID.
content.status integer 0 enabled, 2 disabled, 3 deleted; list/details exclude 3 and retain 2.
content.creator string Creator identity, which may be a Key UUID.
content.updator string Updater identity; an empty string if not yet updated.
content.createAt integer Creation time in Unix seconds.
content.updateAt integer Update time in Unix seconds; may be -1 if not updated.
content.deleteAt integer Deletion time in Unix seconds; -1 if not deleted.
content.declaration object or null Workspace common declaration attached to a non-empty business object; when not configured, it may be null or an empty object; an empty object is not added. The exact position in pagination is subject to the structure on this page.
{
  "code": 200,
  "content": {
    "id": 10,
    "uuid": "wdmk_example",
    "workspaceUUID": "wksp_example",
    "name": "验证码脱敏",
    "type": "logging",
    "field": "message",
    "reExpr": "(?<=验证码=)[0-9]{6}",
    "roleUUIDs": [
      "role_example"
    ],
    "status": 0,
    "creator": "wsak_example",
    "updator": "",
    "createAt": 1785427200,
    "updateAt": -1,
    "deleteAt": -1,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Response

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed A request field is missing, or a field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Invalid request JSON syntax Request JSON format error Fix the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The top level of the request JSON is not an object Part of the JSON file has a format error Submit an object as shown in the example.
404 ft.NotFoundRole Any roleUUIDs member is not in the available, undeleted role set of the current workspace The specified role was not found or has been deleted Obtain the UUID again from the role list; do not use names, roles from another workspace, or *.
400 ft.ErrorRegularExpression Regex pre-check failed during save The regular expression is invalid Change it to a valid expression compatible with standard re, and verify JSON backslash escaping.
500 ft.InternalServerError Storage or response failure; a cache clearing failure after a write commit may also result in 500 Internal error For write requests, first read back via list/details before deciding whether to retry; keep the traceId and contact the administrator.

Feedback

Is this page helpful?