Create Data Access Rule¶
POST /api/v1/data_query_rule/add
Overview¶
Create a data access rule.
Prerequisites and Usage Steps¶
First determine the data domain, roles, sources, and DQL conditions, and then create the rule with a unique name. A new rule with status=0 is immediately enabled. A successful write does not prove that the source contains data or that the final member permissions match expectations.
For creating keyevent events, use add_v2 and explicitly specify the current site's regionCode. The legacy add/modify endpoints omit regionCode and use an empty string for cross-site authorization validation, which usually returns a region error. The update v2 endpoint is also shadowed by the legacy route, so the current public update cannot reliably preserve the site of event rules/cross-site rules. Handle such changes in the console and verify what actually takes effect.
This legacy entry point does not accept regionCode. When it is not provided, an empty string is stored and interpreted by reads/queries as the current site. Avoid using it to update rules that must preserve an explicit source site.
A write replaces the configuration, commits it to the database, then clears the rule cache and records an audit entry. Cross-site validation may also read/update resource metadata. These steps are not a single atomic transaction. After a 500/timeout, first check the list/details to confirm whether the rule was saved, and avoid blindly creating it again.
Saving a rule affects the data query scope/result masking for subsequent identities that match the conditions. It does not modify, delete, or backfill raw data, nor does it add baseline query permissions to roles. Multiple roles and rules are merged according to query-side policies; you cannot infer final permissions from a single rule. Owner is exempt. The administrator and Workspace "Data Access Scope Restriction" settings change how no-matching-role cases are handled, so validate with actual queries from a representative member. After saving, the rule cache is invalidated, but this does not guarantee that all in-flight queries switch immediately.
Request Headers¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| DF-API-KEY | string | Y | The OpenAPI authentication credential for the Workspace. Example: <DF-API-KEY>How to obtain or enter: Obtain an OpenAPI Key with the required permission from API Key Management in the target Workspace. |
Body Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| indexes[*] | string | Array members should be non-empty strings; the original declaration does not enforce this per item, and incorrect types can cause a 500. Example: defaultHow to obtain or enter: A single Log Index uuid/default, or an authorized wksp_<source>:lgim_<index>. |
|
| roleUUIDs[*] | string | Use a valid role; do not use an account UUID. Example: role_exampleHow to obtain or enter: A role uuid available in this Workspace, or a standalone *. |
|
| extend.custom_key | any | Any serializable JSON value; it is not an additional effective condition. Example: productionHow to obtain or enter: Display/edit context defined by the caller, kept consistent with the actual conditions. |
|
| reExprs[*] | json | It is recommended to use only name/enable/reExpr. The original declaration does not enforce the structure of array elements, and non-objects can cause a 500. Example: {"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}How to obtain or enter: Each object defines one masking expression. |
|
| reExprs[*].name | string | Optional display name; it is not used as a match expression, and omitting it does not affect regex matching. Example: tokenHow to obtain or enter: A business-defined display name for the regex. |
|
| reExprs[*].enable | boolean | It is recommended to use an explicit Boolean; the default is treated as disabled. Disabled regexes must still be syntactically valid. Example: trueHow to obtain or enter: true when it needs to be applied, false when it is staged and not applied. |
|
| reExprs[*].reExpr | string | A non-empty regex is recommended. Currently, a missing value is checked as an empty string; do not rely on the server to complete a valid expression. Example: tkn_[0-9A-Za-z]+How to obtain or enter: The actual sensitive content pattern; when using a JSON string, backslashes must be doubled. |
|
| sources[*] | string | A single source interpreted according to the parent type; a non-empty string is recommended. Example: monitorHow to obtain or enter: Obtain the actual identifier from the corresponding data query result/source list. For the event source, do not enter the event ID or Monitor UUID. |
|
| name | string | Y | Declared as required; a non-empty unique name is recommended. An empty string may still enter the automatic naming branch; do not rely on this compatibility behavior. Maximum 64 counting units (ASCII/half-width katakana 1, other characters 2); both enabled and disabled rules of the same type participate in duplicate name checks. Allows null: False Allows empty string: False Maximum length: 64 Example: production_onlyHow to obtain or enter: Name it according to business requirements; first check existing names of the same type in the Data Access Rule List. |
| desc | string | Optional; maximum 256 using the same counting units as above. The default/empty string is cleared to empty; an update does not preserve the original value. Allows null: False Allows empty string: True Maximum length: 256 Example: Only allow viewing production environment data.How to obtain or enter: The business side fills in the rule purpose and applicable targets. |
|
| type | string | Y | Required on creation: logging/rum/tracing/metric/lineage/keyevent. The declaration allows null, but an invalid type cannot form a normal query rule, so always submit one of the strings above. Updates do not accept type and use the stored type. Allows null: True Allowed values: ['lineage', 'keyevent', 'logging', 'rum', 'tracing', 'metric'] Example: loggingHow to obtain or enter: Select according to the data domain to restrict. |
| indexes | array | For logging rules, this should be provided explicitly. It is declared optional, but log queries require a valid index scope; omitting it or using [] does not automatically change it to all. ["*"] means all available Log Indexes; * is recommended to be used alone; [] does not mean all. keyevent forces [] to be stored; other non-logging types usually use []. Do not use a regular index name instead of a UUID; authorization is not created automatically. A successful save does not prove that all remote resources are still valid. Allows null: False Example: ["default"]How to obtain or enter: Get the uuid from the Log Index List; use default for the default Log Index. For cross-Workspace, use the authorized source Workspace UUID:index UUID. |
|
| sources | array | Array of non-logging scopes; ["*"] means all available sources; omitting it or using [] does not mean all. logging forces [] to be stored. rum/lineage can be restricted by authorized Workspace UUID:source identifier; tracing/metric/keyevent use the original source string. keyevent must be a non-empty string array, does not accept wksp_: Allows null: False Example: ["*"]How to obtain or enter: For non-logging sources, enter the actual data source: for rum, use the appId from the RUM Application List; for tracing, use service; for metric, use the Measurement name; for lineage, use the actual log source; for keyevent, use the event source, such as monitor. |
|
| roleUUIDs | array | Y | Required array. ["*"] means all roles; Owner is still not subject to data access restrictions. [] matches no roles and is not equivalent to all. For the keyevent event, it must be a non-empty string array, and * can only appear alone. For other types, the roles are validated to exist within the scope, but status=0 is not guaranteed. Baseline query permissions must still be granted separately. Allows null: False Example: ["role_example"]How to obtain or enter: Get the Workspace role uuid from the Role List; you can use the Workspace Member List to verify the actual roles of members. |
| conditions | string | Enter only the filter expression, not the entire query or outer braces. Optional; the default is an empty string, and an empty string adds no additional filtering. It is recommended not to exceed 4048 characters. For keyevent, the condition is specifically limited to a Python character count ≤4048 and is parsed using E query syntax; for other types, condition semantics are not fully validated on save, and a successful save does not guarantee that future queries will succeed. This rule defines the data scope allowed for access. Allows null: False Allows empty string: True Example: `env` = 'production'How to obtain or enter: Construct the DQL filter condition from the actual tags/fields of the target data; first verify it with a query on the same source. |
|
| extend | json | Optional arbitrary JSON for display; default {}. There are no uniformly required subkeys or units, and the server does not automatically generate conditions from it. An update replaces it as a whole; do not store credentials. Allows null: False Example: {}How to obtain or enter: The client saves the display configuration as needed by its editor; use {} when not needed. |
|
| logic | string | Compatibility display field, usually and/or; optional. If omitted, an empty string is stored. The actual effective filter uses conditions directly; changing logic does not rewrite the conditions, and the merging of multiple roles/rules is not controlled by this field. Allows null: False Example: andHow to obtain or enter: Keep it consistent with the condition combination method in the client filter editor. |
|
| maskFields | string | Optional; the default empty string means field masking is not configured for this rule. Omitting it on update clears it. When fields are selected and reExprs=[], non-null values are masked as entire fields to ***. When a non-empty regex list is provided, only enabled regexes are applied; disabling all is not equivalent to whole-field masking. It is recommended to use ≤256 characters to fit the storage column. Allows null: False Allows empty string: True Example: messageHow to obtain or enter: Select from the actual field names in the query results; separate multiple fields with English commas, for example message,user_email. When * is used to select all, it must be used alone and not mixed with specific fields. |
|
| reExprs | array | Optional; default []. An update replaces it as a whole. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to mean any string; use .*. When selected fields have no regex, the entire field is masked as ***. Regexes only process matching fragments in string content and replace the matched content with ***. Save validation differs from the execution engine, so after a successful save you still need to verify with a representative query. Allows null: False Example: [{"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}]How to obtain or enter: Write a regex executable by Python re according to the sensitive value format, and verify it first with masked samples; use it together with maskFields. |
Additional Parameter Notes¶
Data notes.*
1. Role Authorization Access Notes 1. A specified role can query only data within the specified query scope. 2. If a user has multiple roles and any of the user's roles is not among the roles in this rule, this data access rule does not take effect for that user, meaning the query scope is not restricted. 3. Multiple log data access rules in a Workspace have an OR relationship.
2. Request Parameter Notes
| Parameter | type | Required | Description |
|---|---|---|---|
| name | string | Y | Name |
| desc | String | N | Description |
| type | String | Y | Type (logging, rum, tracing, metric) |
| indexes | array | Y | Required when type is logging. For index authorization from another Workspace (which must be authorized by the Workspace), use Workspace UUID:index UUID, e.g. ["wksp_111:lgim_222", "wksp_333:lgim_444"] |
| sources | array | Y | Required when type is not logging. When type is rum, it is the list of application appIds; when type is tracing, it is the list of service names; when type is metric, it is the list of Measurements |
| roleUUIDs | array | Y | List of role UUIDs |
| conditions | string | N | Filter condition for the actual data scope, e.g. "device IN ['PC'] and session_has_replay IN ['1']" |
| extend | dict | Y | Extended field that stores the structured content of conditions for frontend display, e.g. {"device": [ "PC"], "session_has_replay": [1]} |
| logic | string | N | Logic field, and/or, used to connect filter conditions |
| maskFields | string | N | Masked fields; separate multiple fields with commas |
| reExprs | array | N | Regular expressions, e.g. [{"name":"1111","enable":true,"reExpr":"tkn_[\da-z]*"},{"name":"liuyltest","enable":true,"reExpr":"test"}] |
Request Example¶
curl --request POST 'https://openapi.guance.com/api/v1/data_query_rule/add' \
-H 'DF-API-KEY: <DF-API-KEY>' \
-H 'Content-Type: application/json' \
--data-raw '{"name":"production_only","desc":"Only allow viewing production environment data.","type":"logging","indexes":["default"],"sources":[],"roleUUIDs":["role_example"],"conditions":"`env` = '"'"'production'"'"'","extend":{},"logic":"and","maskFields":"message","reExprs":[{"name":"token","enable":true,"reExpr":"tkn_[0-9A-Za-z]+"}]}'
Response¶
HTTP 200, application/json. The example below shows the main fields that can be read directly.
| Field | Type | Description |
|---|---|---|
| content.id | integer or null | Record ID; the pre-commit snapshot returned on creation may be null; use uuid for subsequent operations. |
| content.uuid | string | lqrl_ rule UUID; both modules share the entity and identifier. |
| content.workspaceUUID | string | Workspace to which this rule belongs, as distinct from the source Workspace. |
| content.status | integer | 0 enabled, 2 disabled, 3 deleted; reads in this module return only non-deleted records. |
| content.creator | string | Creator identity. |
| content.updator | string | Identity of the most recent update; may be empty initially. |
| content.createAt | integer | Creation time in Unix seconds. |
| content.updateAt | integer | Update time in Unix seconds; -1 if not updated. |
| content.deleteAt | integer | Deletion time in Unix seconds; -1 if not deleted. |
| content.name | string | Stored value: Declared as required; a non-empty unique name is recommended. An empty string may still enter the automatic naming branch; do not rely on this compatibility behavior. Maximum 64 counting units (ASCII/half-width katakana 1, other characters 2); both enabled and disabled rules of the same type participate in duplicate name checks. |
| content.desc | string | Stored value: Optional; maximum 256 using the same counting units as above. The default/empty string is cleared to empty; an update does not preserve the original value. |
| content.indexes | array | Stored value: For logging rules, this should be provided explicitly. It is declared optional, but log queries require a valid index scope; omitting it or using [] does not automatically change it to all. ["*"] means all available Log Indexes; * is recommended to be used alone; [] does not mean all. keyevent forces [] to be stored; other non-logging types usually use []. Do not use a regular index name instead of a UUID; authorization is not created automatically. A successful save does not prove that all remote resources are still valid. |
| content.indexes[] | string | Stored value: Array members should be non-empty strings; the original declaration does not enforce this per item, and incorrect types can cause a 500. |
| content.roleUUIDs | array | Stored value: Required array. ["*"] means all roles; Owner is still not subject to data access restrictions. [] matches no roles and is not equivalent to all. For the keyevent event, it must be a non-empty string array, and * can only appear alone. For other types, the roles are validated to exist within the scope, but status=0 is not guaranteed. Baseline query permissions must still be granted separately. |
| content.roleUUIDs[] | string | Stored value: Use a valid role; do not use an account UUID. |
| content.conditions | string | Stored value: Enter only the filter expression, not the entire query or outer braces. Optional; the default is an empty string, and an empty string adds no additional filtering. It is recommended not to exceed 4048 characters. For keyevent, the condition is specifically limited to a Python character count ≤4048 and is parsed using E query syntax; for other types, condition semantics are not fully validated on save, and a successful save does not guarantee that future queries will succeed. This rule defines the data scope allowed for access. |
| content.extend | json | Stored value: Optional arbitrary JSON for display; default {}. There are no uniformly required subkeys or units, and the server does not automatically generate conditions from it. An update replaces it as a whole; do not store credentials. |
| content.extend.custom_key | any | Stored value: Any serializable JSON value; it is not an additional effective condition. |
| content.logic | string | Stored value: Compatibility display field, usually and/or; optional. If omitted, an empty string is stored. The actual effective filter uses conditions directly; changing logic does not rewrite the conditions, and the merging of multiple roles/rules is not controlled by this field. |
| content.maskFields | string | Stored value: Optional; the default empty string means field masking is not configured for this rule. Omitting it on update clears it. When fields are selected and reExprs=[], non-null values are masked as entire fields to ***. When a non-empty regex list is provided, only enabled regexes are applied; disabling all is not equivalent to whole-field masking. It is recommended to use ≤256 characters to fit the storage column. |
| content.reExprs | array | Stored value: Optional; default []. An update replaces it as a whole. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to mean any string; use .*. When selected fields have no regex, the entire field is masked as ***. Regexes only process matching fragments in string content and replace the matched content with ***. Save validation differs from the execution engine, so after a successful save you still need to verify with a representative query. |
| content.reExprs[] | json | Stored value: It is recommended to use only name/enable/reExpr. The original declaration does not enforce the structure of array elements, and non-objects can cause a 500. |
| content.reExprs[].name | string | Stored value: Optional display name; it is not used as a match expression, and omitting it does not affect regex matching. |
| content.reExprs[].enable | boolean | Stored value: It is recommended to use an explicit Boolean; the default is treated as disabled. Disabled regexes must still be syntactically valid. |
| content.reExprs[].reExpr | string | Stored value: A non-empty regex is recommended. Currently, a missing value is checked as an empty string; do not rely on the server to complete a valid expression. |
| content.sources | array | Stored value: Array of non-logging scopes; ["*"] means all available sources; omitting it or using [] does not mean all. logging forces [] to be stored. rum/lineage can be restricted by authorized Workspace UUID:source identifier; tracing/metric/keyevent use the original source string. keyevent must be a non-empty string array, does not accept wksp_: |
| content.sources[] | string | Stored value: A single source interpreted according to the parent type; a non-empty string is recommended. |
| content.type | string | Stored value: Required on creation: logging/rum/tracing/metric/lineage/keyevent. The declaration allows null, but an invalid type cannot form a normal query rule, so always submit one of the strings above. Updates do not accept type and use the stored type. |
| content.regionCode | string | Stored value: v2 declares the required source site code; the Log Indexes of the same rule must belong to the same site and match this value. The legacy entry point does not accept this field. Data access rules do not replace cross-site/cross-Workspace authorization; cross-site events must have a valid authorization that includes keyevent or *. Note the actual reachability description of the duplicate route below. |
| content.declaration | object or null | Workspace common declaration attached to a non-empty business object; may be null or an empty object when not configured; an empty object is not added. The exact position in pagination is subject to the structure on this page. |
{
"code": 200,
"content": {
"id": null,
"uuid": "lqrl_example",
"workspaceUUID": "wksp_example",
"name": "production_only",
"desc": "Only allow viewing production environment data.",
"type": "logging",
"indexes": [
"default"
],
"sources": [],
"roleUUIDs": [
"role_example"
],
"conditions": "`env` = 'production'",
"extend": {},
"logic": "and",
"maskFields": "message",
"reExprs": [
{
"name": "token",
"enable": true,
"reExpr": "tkn_[0-9A-Za-z]+"
}
],
"regionCode": "",
"status": 0,
"creator": "wsak_example",
"updator": "",
"createAt": 1785427200,
"updateAt": -1,
"deleteAt": -1,
"declaration": {}
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
Error Responses¶
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 | Request field is missing, or the 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. |
| 404 | ft.NoInitOtherNodeCfg | No available source site address was found when reading or validating remote index/RUM application metadata | Other node configuration is not initialized | Have an administrator check the source site configuration, accessible address, and valid cross-Workspace authorization, then retry after fixing. |
| 400 | ft.NameRepeat | A non-deleted rule with the same name and type exists in this Workspace | Name already exists | Change the name, or verify and update the existing UUID. |
| 400 | ft.ErrorRegularExpression | Any regex is invalid, including disabled items | Invalid regular expression | Fix all reExpr values before submitting; do not use a standalone *. |
| 400 | ft.InvalidRoleUUID | The role is outside the Workspace scope, or the keyevent role array is invalid | Invalid role UUID: {} | Get a valid identifier from the Workspace role list; use the event * alone. |
| 400 | ft.InvalidLoggingIndex | The resolved regular index in the source Workspace of the current site does not exist or has been deleted | Invalid index: {} | Use a valid index UUID/default and verify authorization. |
| 400 | ft.InvalidRegionDataQueryRuleIndex | Log Indexes mix multiple sites or the site does not match, or the cross-site event has no valid authorization | {} site index information is invalid | Create rules by site, and verify the source and target from the authorization records. |
| 500 | ft.InternalServerError | Array item shape does not match, field exceeds storage length, downstream normal 5xx, database or post-commit cache failure | Internal error | Check the structure and length in this document, read the current configuration to confirm whether it has been persisted, then decide whether to retry; provide the traceId. |
| 400 | ft.InvalidSources | The keyevent source structure is invalid, or the explicitly specified current-site rum source application does not exist | Invalid resource information: {} | For events, provide a non-empty source string array and use * alone; for RUM, get the appId from a valid application. |
| 406 | ft.InvalidParameter | keyevent conditions is not a string or exceeds 4048 characters | Parameter {} is invalid |
Use a DQL condition string of compliant length. |
| 406 | ft.DqlParseError | The keyevent condition cannot be parsed | dql parser parsing failed: {} | Verify the filter condition in an event query and retain the original error and traceId. |