Skip to content

[BUG] DLS accepts now / date math in role definition but rejects at query time #6470

Description

@sutadaka

Describe the bug

DLS accepts a role definition containing date math expressions (e.g., now-30d/d) without any validation error (HTTP 201). The issue only surfaces at query time when a user mapped to that role attempts a search, resulting in:

'now' is not allowed in DLS queries

The role appears correctly configured but fails at query time. Either date math should be supported in DLS filters (preferred), or the Security plugin should validate and reject at role creation time.

Related component

Other

To Reproduce

  1. Create a DLS role with a date math filter:

PUT _plugins/_security/api/roles/time_restricted
{
"cluster_permissions": [],
"index_permissions": [
{
"index_patterns": ["test-index-*"],
"dls": "{"range": {"@timestamp": {"gte": "now-30d/d"}}}",
"allowed_actions": ["read"]
}
]
}

Response: 201 Created — no validation error.

  1. Map a user to the role:

PUT _plugins/_security/api/rolesmapping/time_restricted
{
"users": ["restricted_user"]
}

  1. Query as the restricted user:

GET test-index-*/_search
{
"query": { "match_all": {} }
}

  1. Error returned:
    {
    "error": {
    "root_cause": [{"type": "parse_exception", "reason": "could not read the current timestamp"}],
    "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "'now' is not allowed in DLS queries"
    }
    },
    "status": 400
    }

Expected behavior

Either:

  1. (Preferred) Support date math expressions (now, now-30d/d, etc.) in DLS queries, resolving them at query time. This is a common access control pattern — restricting users to a rolling time window of data.
  2. (Minimum fix) Validate the DLS query string at role creation time and reject expressions containing now with a clear error, rather than silently accepting them and failing later at query time.

Additional Details

Plugins
Security plugin (Fine-Grained Access Control / DLS)

Screenshots

Image

Host/Environment (please complete the following information):

  • Amazon OpenSearch Service (managed)
  • Version: 2.13

Additional context
Use case: Multiple users query the same index. Some users should only see data from the last N days (rolling window), while admins retain full access. DLS with a time-range filter is the natural solution, but the lack of date math support forces workarounds like scheduled Lambda functions to rotate hardcoded epoch timestamps in the role definition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagedIssues labeled as 'Triaged' have been reviewed and are deemed actionable.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions