Create a Single Data Access Rule¶
POST /api/v1/data_query_rule/add_v2
Overview¶
Create a data access rule (for a specified site).
Before Calling and Usage Steps¶
First determine the data domain, roles, sources and DQL conditions, then create the rule with a unique name. A new rule has status=0 and 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 regionCode. The legacy add/modify omits regionCode and therefore enters cross-site authorization validation with an empty string, which typically returns a region error. Modification through v2 is in turn shadowed by the legacy route, so the current public modification cannot reliably preserve the site of event rules or cross-site rules; handle such changes from the console and verify what actually takes effect.
This standalone add_v2 path accepts regionCode; example-region in the examples must be replaced with the actual site code, and the indexes of a log rule must not span multiple sites.
A write replaces the configuration, commits to the database, then clears the rule cache and records an audit entry; cross-site validation may also read or update resource profiles. The steps are not a single atomic transaction: after a 500 or timeout, first check the list/details to confirm whether the rule was saved, to avoid blindly creating duplicates.
Saving a rule affects the scope of subsequent data queries and the result masking for identities that match the conditions; it does not modify, delete or backfill raw data, nor does it add base query permissions to roles. Multiple roles and rules are merged according to query-side policies, so the final permissions cannot be inferred from a single rule; Owner is exempt, and the "data access scope restriction" settings of administrators and the workspace change how non-matching roles are handled, so validate with actual queries from representative members. Saving invalidates the rule cache, which does not guarantee that all in-flight queries switch immediately.
Request Headers¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| DF-API-KEY | string | Y | OpenAPI authentication credential of the workspace. Example: <DF-API-KEY>How to obtain or fill in: obtain an OpenAPI Key with this operation permission from the API Key management of 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 a wrong type may cause a 500. Example: defaultHow to obtain or fill in: a single log index uuid/default, or an authorized wksp_source:lgim_index. |
|
| roleUUIDs[*] | string | Use valid roles; do not use account UUIDs. Example: role_exampleHow to obtain or fill in: a role uuid available in this workspace, or * on its own. |
|
| extend.Custom key | any | Any serializable JSON value; it is not an additional effective condition. Example: productionHow to obtain or fill in: 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 array element structure, and a non-object may cause a 500. Example: {"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}How to obtain or fill in: each object defines one masking expression. |
|
| reExprs[*].name | string | Optional display name, not used as a match expression; omitting it does not affect regex matching. Example: tokenHow to obtain or fill in: a business-defined display name for the regex. |
|
| reExprs[*].enable | boolean | An explicit boolean is recommended; if omitted, it is treated as disabled. A disabled regex must still be syntactically valid. Example: trueHow to obtain or fill in: true when it needs to be applied, false when it is staged without applying. |
|
| reExprs[*].reExpr | string | A non-empty regex is recommended. An omitted value is currently checked as an empty string, so do not rely on the server to complete a valid expression. Example: tkn_[0-9A-Za-z]+How to obtain or fill in: the real 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 fill in: obtain the real identifier from the corresponding data query result/source list; for events, do not fill in the event ID or monitor UUID for source. |
|
| name | string | Y | Declared required; a non-empty unique name is recommended. An empty string may still enter the auto-naming branch, so do not rely on this compatibility behavior. Maximum 64 counting units (ASCII/half-width katakana = 1, other characters = 2); enabled and disabled rules of the same type both participate in the duplicate name check. Allowed null: False Allowed empty string: False Maximum length: 64 Example: production_onlyHow to obtain or fill in: named by the business; first check existing names of the same type in the data access rule list. |
| desc | string | Optional; maximum 256 of the same counting units. If omitted or an empty string, it is cleared to empty; modification does not keep the original value. Allowed null: False Allowed empty string: True Maximum length: 256 Example: Only allow viewing production environment data.How to obtain or fill in: the business fills in the purpose of the rule and the applicable objects. |
|
| 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. Modification does not accept type and uses the stored type. Allowed null: True Optional values: ['lineage', 'keyevent', 'logging', 'rum', 'tracing', 'metric'] Example: loggingHow to obtain or fill in: choose according to the data domain to restrict. |
| regionCode | string | Y | Declared required by v2 as the source site code; the log indexes of the same rule must belong to the same site and be consistent with this value. The legacy entry 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. Allowed null: False Allowed empty string: False Example: example-regionHow to obtain or fill in: confirm the real regionCode from the target source site and the valid cross-workspace authorization list; the current site also uses its official code, not the literal example value. |
| indexes | array | Log rules should provide this explicitly; the declaration is optional, but log queries need a valid index scope, and omitting it ([]) does not automatically become all. ["*"] means all available log indexes; it is recommended to use * alone; [] is not all. keyevent forces the saved value to []; other non-log types usually use []. A plain index name cannot replace the UUID, and authorization is not created automatically; a successful save does not prove that all remote resources are still valid. Allowed null: False Example: ["default"]How to obtain or fill in: obtain the uuid from the log index list, and use default for the default index; for cross-workspace, use the authorized source workspace UUID:index UUID. |
|
| sources | array | Non-log scope array; ["*"] means all available sources; omitting it ([]) does not mean all. logging forces the saved value to []. rum/lineage can be limited 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_:source, and * cannot be mixed with other values. rum verifies that the application exists by query only when the current regionCode is explicitly specified; a successful save for other sources does not prove that data exists. Allowed null: False Example: ["*"]How to obtain or fill in: for non-log types, fill in the real data source: for rum, the appId from the RUM application list; for tracing, the service; for metric, the measurement name; for lineage, the actual log source; for keyevent, the event source, such as monitor. |
|
| roleUUIDs | array | Y | Required array; ["*"] means all roles, and Owner is still not subject to data access restrictions; [] matches no role and is not equal to all. Event keyevent must be a non-empty string array, and * can only appear alone; other types validate that the roles exist in the scope, without guaranteeing role status=0. Base query permissions must still be held separately. Allowed null: False Example: ["role_example"]How to obtain or fill in: obtain the workspace role uuid from the role list; use the workspace member list to verify the actual roles of members. |
| conditions | string | Fill in only the filter expression, not the whole query or outer braces. Optional, defaults to an empty string; an empty string does not add extra filtering. It is recommended not to exceed 4048 characters; keyevent specifically limits to ≤4048 Python characters and parses the E query syntax, while other types do not fully validate the semantics of conditions when saving, so success does not guarantee that future queries succeed. This rule defines the data scope that is allowed to be accessed. Allowed null: False Allowed empty string: True Example: `env` = 'production'How to obtain or fill in: construct the DQL filter condition from the real tags/fields of the target data; validate it first with a query on the same source. |
|
| extend | json | Optional arbitrary JSON for display, defaults to {}; there are no unified required sub-keys or units, the server does not generate conditions from it automatically, and modification replaces it entirely; do not store credentials. Allowed null: False Example: {}How to obtain or fill in: the client saves the display configuration required by its own editor; use {} when not needed. |
|
| logic | string | Compatibility display field, usually and/or; optional. If omitted, it is saved as an empty string; the effective filtering directly uses conditions, changing logic does not rewrite conditions, and the merging of multiple roles/rules is not controlled by this field. Allowed null: False Example: andHow to obtain or fill in: keep it consistent with the condition combination method in the client's filter editor. |
|
| maskFields | string | Optional; if omitted or an empty string, field masking is not configured for this rule. If omitted on modification, it is cleared. When fields are selected and reExprs=[], non-null values of the whole field are masked as ***; when a non-empty regex list is provided, only enabled regexes are applied, and disabling all of them is not the same as whole-field masking. It is recommended to use ≤256 characters to fit the storage column. Allowed null: False Allowed empty string: True Example: messageHow to obtain or fill in: choose from the actual field names in the query result, separated by English commas, for example message,user_email; * selects all and must be used alone, not mixed with specific fields. |
|
| reExprs | array | Optional, defaults to [], and modification replaces it entirely. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to represent any string; use .*. When the selected field has no regex, the whole field is masked as ***; a regex only processes the matched fragments of string content and replaces the matched content with ***; save-time validation differs from the execution engine, so after a successful save still validate with representative queries. Allowed null: False Example: [{"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}]How to obtain or fill in: write a regex executable by Python re according to the sensitive value format, validate it first with masked samples; use it together with maskFields. |
Supplementary Parameter Notes¶
Data notes.*
1. Role authorization access notes 1. A specified role can query only the data within the specified query scope. 2. If a user has multiple roles and one of the user's roles is not among the roles of this rule, this data access rule does not take effect for that user, that is, the query scope is not restricted. 3. The logic among multiple log data access rules in one workspace is 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 an index authorization that is not in this workspace (must be authorized through workspace authorization), use workspace UUID:index UUID, for example: ["wksp_111:lgim_222", "wksp_333:lgim_444"] |
| sources | array | Y | Required when type is not logging. When type is rum, it is a list of application appIds; when type is tracing, it is a list of service names; when type is metric, it is a list of measurements |
| roleUUIDs | array | Y | List of role UUIDs |
| conditions | string | N | Filter condition for the data scope actually used, for example: "device IN ['PC'] and session_has_replay IN ['1']" |
| extend | dict | Y | Extension field that stores the structured content of conditions, used for frontend page display, for example: {"device": [ "PC"], "session_has_replay": [1]} |
| logic | string | N | Logic field, and/or, used to join filter conditions |
| maskFields | string | N | Masked fields, multiple fields separated by commas |
| reExprs | array | N | Regular expressions, for example: [{"name":"1111","enable":true,"reExpr":"tkn_[\da-z]*"},{"name":"liuyltest","enable":true,"reExpr":"test"}] |
| regionCode | string | Y | Site code (obtainable through the workspace/website/list API) |
Request Example¶
curl --request POST 'https://openapi.guance.com/api/v1/data_query_rule/add_v2' \
-H 'DF-API-KEY: <DF-API-KEY>' \
-H 'Content-Type: application/json' \
--data-raw '{"name":"production_only","desc":"仅允许查看生产环境数据。","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":"example-region"}'
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 number; the snapshot returned at creation before commit may be null, use uuid for subsequent operations. |
| content.uuid | string | lqrl_rule UUID; both modules share the same 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 cover only non-deleted entries. |
| content.creator | string | Creating identity. |
| content.updator | string | Most recent updating identity; may be empty initially. |
| content.createAt | integer | Creation Unix seconds. |
| content.updateAt | integer | Update Unix seconds; -1 if never updated. |
| content.deleteAt | integer | Deletion Unix seconds; -1 if not deleted. |
| content.name | string | Saved value: declared required; a non-empty unique name is recommended. An empty string may still enter the auto-naming branch, so do not rely on this compatibility behavior. Maximum 64 counting units (ASCII/half-width katakana = 1, other characters = 2); enabled and disabled rules of the same type both participate in the duplicate name check. |
| content.desc | string | Saved value: optional; maximum 256 of the same counting units. If omitted or an empty string, it is cleared to empty; modification does not keep the original value. |
| content.indexes | array | Saved value: log rules should provide this explicitly; the declaration is optional, but log queries need a valid index scope, and omitting it ([]) does not automatically become all. ["*"] means all available log indexes; it is recommended to use * alone; [] is not all. keyevent forces the saved value to []; other non-log types usually use []. A plain index name cannot replace the UUID, and authorization is not created automatically; a successful save does not prove that all remote resources are still valid. |
| content.indexes[] | string | Saved value: array members should be non-empty strings; the original declaration does not enforce this per item, and a wrong type may cause a 500. |
| content.roleUUIDs | array | Saved value: required array; ["*"] means all roles, and Owner is still not subject to data access restrictions; [] matches no role and is not equal to all. Event keyevent must be a non-empty string array, and * can only appear alone; other types validate that the roles exist in the scope, without guaranteeing role status=0. Base query permissions must still be held separately. |
| content.roleUUIDs[] | string | Saved value: use valid roles; do not use account UUIDs. |
| content.conditions | string | Saved value: fill in only the filter expression, not the whole query or outer braces. Optional, defaults to an empty string; an empty string does not add extra filtering. It is recommended not to exceed 4048 characters; keyevent specifically limits to ≤4048 Python characters and parses the E query syntax, while other types do not fully validate the semantics of conditions when saving, so success does not guarantee that future queries succeed. This rule defines the data scope that is allowed to be accessed. |
| content.extend | json | Saved value: optional arbitrary JSON for display, defaults to {}; there are no unified required sub-keys or units, the server does not generate conditions from it automatically, and modification replaces it entirely; do not store credentials. |
| content.extend.Custom key | any | Saved value: any serializable JSON value; it is not an additional effective condition. |
| content.logic | string | Saved value: compatibility display field, usually and/or; optional. If omitted, it is saved as an empty string; the effective filtering directly uses conditions, changing logic does not rewrite conditions, and the merging of multiple roles/rules is not controlled by this field. |
| content.maskFields | string | Saved value: optional; if omitted or an empty string, field masking is not configured for this rule. If omitted on modification, it is cleared. When fields are selected and reExprs=[], non-null values of the whole field are masked as ***; when a non-empty regex list is provided, only enabled regexes are applied, and disabling all of them is not the same as whole-field masking. It is recommended to use ≤256 characters to fit the storage column. |
| content.reExprs | array | Saved value: optional, defaults to [], and modification replaces it entirely. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to represent any string; use .*. When the selected field has no regex, the whole field is masked as ***; a regex only processes the matched fragments of string content and replaces the matched content with ***; save-time validation differs from the execution engine, so after a successful save still validate with representative queries. |
| content.reExprs[] | json | Saved value: it is recommended to use only name/enable/reExpr; the original declaration does not enforce the array element structure, and a non-object may cause a 500. |
| content.reExprs[].name | string | Saved value: optional display name, not used as a match expression; omitting it does not affect regex matching. |
| content.reExprs[].enable | boolean | Saved value: an explicit boolean is recommended; if omitted, it is treated as disabled. A disabled regex must still be syntactically valid. |
| content.reExprs[].reExpr | string | Saved value: a non-empty regex is recommended. An omitted value is currently checked as an empty string, so do not rely on the server to complete a valid expression. |
| content.sources | array | Saved value: non-log scope array; ["*"] means all available sources; omitting it ([]) does not mean all. logging forces the saved value to []. rum/lineage can be limited 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_:source, and * cannot be mixed with other values. rum verifies that the application exists by query only when the current regionCode is explicitly specified; a successful save for other sources does not prove that data exists. |
| content.sources[] | string | Saved value: a single source interpreted according to the parent type; a non-empty string is recommended. |
| content.type | string | Saved 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. Modification does not accept type and uses the stored type. |
| content.regionCode | string | Saved value: declared required by v2 as the source site code; the log indexes of the same rule must belong to the same site and be consistent with this value. The legacy entry 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 | Common workspace declaration attached to a non-empty business object; it may be null or an empty object when not configured; an empty object adds nothing. The exact position of pagination follows the structure on this page. |
{
"code": 200,
"content": {
"id": null,
"uuid": "lqrl_example",
"workspaceUUID": "wksp_example",
"name": "production_only",
"desc": "仅允许查看生产环境数据。",
"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": "example-region",
"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 | Resolution |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | A request field is missing, or a field value violates the declared validation constraints | Parameter parsing failed | Check the parameter position, field name, type and value. |
| 400 | ft.RequestJsonFormatError | The request JSON syntax is invalid | 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 not initialized | Have an administrator check the source site configuration, accessible address and valid cross-workspace authorization, then retry. |
| 400 | ft.NameRepeat | A non-deleted rule with the same name and of the same type exists in this workspace | Name already exists | Change the name, or update the existing UUID after verification. |
| 400 | ft.ErrorRegularExpression | Any regex is invalid, including disabled items | Invalid regular expression | Fix all reExpr values and submit again; 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: {} | Take valid identifiers from the workspace role list; use event * alone. |
| 400 | ft.InvalidLoggingIndex | The resolved plain index of the current site's source workspace does not exist or has been deleted | Invalid index:{} | Use a valid index UUID/default and verify the authorization. |
| 400 | ft.InvalidRegionDataQueryRuleIndex | Log indexes mix multiple sites or do not match the site, or the cross-site event has no valid authorization | Invalid site index information for {} | Create rules per site, and verify the source and target from the authorization records. |
| 500 | ft.InternalServerError | Array item shape mismatch, field exceeding the storage length, downstream generic 5xx, database or post-commit cache failure | Internal error | Check the structure and lengths in this document and read the current configuration to confirm whether it was persisted, then decide whether to retry; provide the traceId. |
| 400 | ft.InvalidSources | The keyevent source structure is invalid, or the application of the rum source for the explicitly specified current site does not exist | Invalid resource information:{} | For events, provide a non-empty source string array and use * alone; for RUM, take the appId from a valid application. |
| 406 | ft.InvalidParameter | The keyevent conditions are not a string or exceed 4048 characters | Invalid parameter {} |
Use a DQL condition string of compliant length. |
| 406 | ft.DqlParseError | The keyevent conditions cannot be parsed | dql parser parsing failed: {} | Validate the filter condition in an event query and keep the original error and traceId. |