Data policies in IAM
Configure role-based dynamic field masking for Kafka topics using IAM data policy statements.
Starting in Lenses 6.3, you can define data policies as statements directly within IAM roles. IAM data policy statements dynamically mask fields in Kafka topic records when users query data through Lenses.
Masking is enforced based on the IAM roles assigned to the requesting user. The underlying data stored in Kafka remains untouched.
Deprecation Notice: Legacy agent data policies (stored locally on individual agents) are deprecated in Lenses 6.3 and will be fully replaced by IAM data policies in a future release. Both models are supported in 6.3, but each agent operates on one model at a time.
Definition location
Locally on each agent, per environment
Globally on IAM roles in Lenses HQ
Scope of masking
Applies to all users in the environment, including admins
Applies only to users/groups assigned the role. (HQ root users are never masked)
Agent configuration
lenses.data.policies.legacy.enabled = true (default)
lenses.data.policies.legacy.enabled = false
Roles represent a set of permissions bound to user groups. Users and service accounts inherit the roles assigned to their groups. For a complete overview of the IAM model, see Security Architecture.
How IAM data policies work
Role Ownership: A data policy statement belongs to an IAM role. A single role can contain permission statements, data policy statements, or both. Deleting a role automatically deletes its associated data policy statements.
Inheritance: Users and service accounts inherit all statements from every role bound to their assigned groups. Lenses HQ root users bypass masking entirely.
Execution Flow: Upon each data request to an environment, Lenses HQ evaluates the user's applicable statements and passes them to the agent. The agent applies masking in-flight to the returned records. Agents do not store or cache IAM data policies locally.
Access Control Context: Data policies alter record payload visibility—they do not grant or deny topic access. To read a topic, a user still requires the
kafka:ReadTopicDatapermission. A statement applied to a topic the user cannot read has no effect.Supported Operations: Masking applies to record values returned by Lenses. If a record payload fails to decode (e.g., malformed schema), Lenses returns the raw unmasked bytes.
Before you begin
Prerequisites
Lenses HQ: Version 6.3 or later.
Lenses Agent: Version 6.3 or later on all managed environments.
Agent Maintenance Window: Brief restart window for each agent being updated.
IAM Permissions: The user managing data policies must hold the following actions on
iam:role:${Role}:
Create a role containing data policies
iam:CreateRole
Add, modify, or remove data policy statements
iam:UpdateRole
View policy statements on a role
iam:GetRoleDetails
Delete a role and its policy statements
iam:DeleteRole
Per-Agent Scope
Each environment operates its own agent instance configured via lenses.data.policies.legacy.enabled. While roles are defined globally across Lenses HQ, an IAM policy statement takes effect only in environments where the agent setting is set to false.
For example, a statement scoped to kafka:topic:*/kafka/* will begin masking data in an environment as soon as that specific agent switches to IAM mode.
What changes when an agent switches
The agent ignores local legacy policies and strictly applies IAM data policy statements.
Existing legacy policies remain stored on the agent but are inactive.
The legacy Agent Data Policy API becomes read-only. Requests to write or edit legacy policies return
409 Conflictwith:Data policies are managed by Lenses HQ; this API is read-only.Legacy data policy management screens in Lenses HQ switch to read-only mode.
User Masking Rules
Plan the migration
Lenses does not have the context to automatically convert legacy agent(s) policies into IAM data policy statements. You must manually recreate each policy as one or more statements within an IAM role, and attach the roles to the groups.
1. Identify Existing Agent Data Policies
To review active policies per environment:
Open the Studio explorer (left menu).
For each environment, navigate to Admin > Data Policies.
Alternative: Call the legacy endpoint directly:
GET /v1/environments/{environment}/proxy/api/protection/policy
2. Map Legacy Properties to IAM Schema
Fields
fields (Review field matching logic under Review Behavior Differences)
Datasets
resources (e.g., kafka:topic:prod/kafka/orders* or kafka:topic:prod/kafka/* for all topics)
Redaction
obfuscation (See mapping table below)
Name, Category, Impact
No direct key. Record metadata in the role's name and description
Obfuscation Mapping
None
none
All
all
Email
email
Initials
initials
First-1 through First-4
first_1 through first_4
Last-1 through Last-4
last_1 through last_4
Number-to-negative-one
number_negative_one
Number-to-zero
number_zero
Number-to-null
number_null
3. Review Behavior Differences
Case Sensitivity
Case-insensitive
Case-sensitive
Bare Field Names (e.g. email)
Matches field at any nesting depth
Matches top-level field only. Use *.email for any depth
Wildcard * in fields
Does not match path delimiter (.)
Matches path delimiter (.)
Conflicting Policies
Evaluates policy with the longest explicit path match
Evaluates all matching statements (Details)
None Policy
Audits field without masking
Exempts field from other overlapping masking statements
Data Sources
Kafka, Postgres, Elasticsearch
Kafka topics only
*.email on Top-Level Field
Masked on Avro; Ignored on JSON & Protobuf
Masked consistently across all data formats
Create IAM data policies
Example YAML Specification
The following role grants no permissions, but applies email, phone, and SSN masking across all Kafka topics in the prod environment for assigned users:
To mask the same fields in all environments, use kafka:topic:*/kafka/*. See Per-Agent Scope. For more roles, see Example Policies.
Create a role with data policies in HQ
In the Studio explorer, expand
IAMand selectRoles.Select
Create role.On the
Detailstab, enter the role name.In
Assign to groups, select the groups that read the affected topics.Open the
Policytab.Add a top-level
data_policieslist to the YAML, next topolicy. Use the example YAML specification as a starting point. The editor suggests a data policy statement,kafka:topicresources and obfuscation types as you type.Select
Create role.
The role appears in the Roles list. It masks data only in environments whose agent uses IAM data policies. To check its statements, open the role and select the Data Policies tab. The tab lists the Resource, Field and Obfuscation of each statement.
The Read-Only, Data Engineer and Default PII Masking templates include data policy statements. The Administrator template has none.


Add data policies to an existing role in HQ
In the Studio explorer, expand
IAM>Rolesand open the role.Select
Manage policy.Select
Edit.Add or change the entries of the
data_policieslist.Select
Save.
The Data Policies tab of the role shows the updated statements.
Manage data policies with the HQ API
Data policy statements are part of the role resource.
POST /v1/roles
Creates a role. Include statements in data_policies.
GET /v1/roles/{name}
Returns the role, including data_policies.
PATCH /v1/roles/{name}
If the request contains data_policies, replaces all statements of the role. If it omits data_policies, the statements are not changed.
POST /v1/roles/{name}/data-policies
Adds one statement to the role. Duplicates are not removed.
Example request body for POST /v1/roles/{name}/data-policies:
Switch an agent to IAM data policies
Switch one agent at a time. The agent reads lenses.data.policies.legacy.enabled once, at startup.
Create the statements and bind the roles
Create the roles with data policy statements and assign them to groups. See Create IAM data policies. Every group that reads the affected topics must have a role with the masking statements.
Verify the environment
In the Studio explorer, expand the environment and select Health. Check that the Data policies row shows IAM. The agent does not log which model is active, so use this row or the other indicators in Check which data policies an environment uses.

Roll back
Set
lenses.data.policies.legacy.enabledtotruein the agent configuration, orLENSES_DATA_POLICIES_LEGACY_ENABLED=truefor the agent Docker image.Restart the agent.
In the Studio explorer, expand the environment and select
Health. Check that theData policiesrow showsAgent-based. See Check which data policies an environment uses.
The agent applies its stored data policies again, and the agent data policy API and screens accept changes. The IAM data policy statements stay on the roles. The agent ignores them.
Check which data policies an environment uses
The agent reports to HQ which model it uses. HQ shows it in the following places.
Studio explorer > environment > Health, Data policies row
Agent-based
IAM
Environments list
Agent data policies chip
No chip
Studio explorer > environment > Admin > Data Policies
Warning banner with Open IAM roles and Learn more
Information banner: policies are managed via IAM roles and the screen is read-only
If the agent runs a version earlier than 6.3, the agent data policy screens show a banner that asks you to upgrade the agent. The Data policies row shows Agent-based.



Reference
Statement properties
A data policy statement has three required properties.
resources
list of strings
Kafka topic resource patterns, in the form kafka:topic:${Environment}/kafka/${Topic}. At least one entry.
fields
list of strings
Field path patterns. At least one entry.
HQ rejects a statement when:
obfuscationis not one of the supported values.A resource is not a
kafka:topicresource, or the topic pattern contains characters that are not valid in a Kafka topic name.A field pattern is empty, contains
/, or contains any of?[]{}()+^$|\. Use*as the only wildcard.
For the resource name format, see Lenses Resource Names. For the statement syntax reference, see Data Policy Statements.
Obfuscation types
none
No masking. Exempts the field from the user's other statements. See Multiple statements and roles.
jane@example.com
jane@example.com
all
Replaces the value with *****.
jane@example.com
*****
email
Keeps the first character of the local part and the domain. Values without @ are not changed.
jane@example.com
j*****@example.com
initials
Keeps the first character of each word.
Jane Doe
J D
first_1 to first_4
Keeps the first 1 to 4 characters.
4111111111111111 with first_4
4111*****
last_1 to last_4
Keeps the last 1 to 4 characters.
4111111111111111 with last_4
*****1111
number_negative_one
Replaces a numeric value with -1.
42
-1
number_zero
Replaces a numeric value with 0.
42
0
number_null
Replaces a numeric value with null.
42
null
Values that are not strings:
The string types (
all,email,initials,first_*,last_*) convert numbers to text before masking.A boolean value becomes
*****.A
nullvalue staysnull.The number types do not change values that are not numeric, including strings that contain digits.
Topic and field matching
Patterns use * as the only wildcard. A pattern must match the whole topic name or field path.
*matches any sequence of characters, including none. It also matches.,-and_.Matching is case-sensitive.
Emaildoes not matchemail.A field path is the list of field names from the root of the record, joined with
.. For example,customer.address.city.A leading
*.also matches no parent fields, so the pattern applies at the top level too.*.emailmatchesemail,customer.emailanda.b.email.*.customer.emailmatchescustomer.emailandorder.customer.email.*.*.emailmatchescustomer.emailbut notemail.In a resource, the environment and topic are separated by
/kafka/. Use*for the environment to match all environments.
email
email
customer.email
*.email
email, customer.email, a.b.email
emails, customer.email_address
*.customer.email
customer.email, order.customer.email
email, customer.email_address
*.*.email
customer.email, a.b.email
email
customer.email
customer.email
email, old.customer.email
customer.*
customer.email, customer.address.city
customer
*ssn*
ssn, customer.ssn_hash
SSN
To mask a field wherever it appears in the record, use the *. form, for example *.email. To mask only the top-level field, use the bare name, for example email. The leading *. rule applies to field patterns only. In a resource, * is a plain wildcard.
kafka:topic:prod/kafka/orders
Topic orders in environment prod
kafka:topic:prod/kafka/orders*
Topics in prod whose name starts with orders
kafka:topic:*/kafka/*
All topics in all environments
Multiple statements and roles
The agent combines the statements of all roles of the user:
The agent selects every statement whose resource matches the topic and whose field pattern matches the field.
If no statement matches, the value is returned unchanged.
If any matching statement uses
none, the value is returned unchanged.Otherwise, the agent applies each distinct obfuscation type once, in this order:
all,email,initials,first_1tofirst_4,last_1tolast_4,number_negative_one,number_zero,number_null. Each type is applied to the output of the previous one.
The order of roles and statements has no effect. There is no precedence between statements. A statement either matches a field or does not. For example, for the field user.email on topic orders:
email → all, user.email → email
user.email
email masking only. email matches the top-level field only.
*.email → all, user.email → email
Both
all, then email, applied in order
*.email → all, user.email → none
Both
Unmasked, because one statement uses none
For the top-level field email:
email → all, *.email → none
Both
Unmasked, because *.email also matches the top-level field and one statement uses none
To mask the top-level field but leave nested occurrences unmasked, use *.*.email for the none statement, since it does not match the top-level field. Statements of the user: email → all, *.*.email → none.
email
email
Masked with all
customer.email, a.b.email
*.*.email
Unmasked, because *.*.email does not match the top-level field
Troubleshooting
Requests fail with INVALID_ARGUMENT
If the agent cannot apply one of the caller's statements, for example because the agent does not support the obfuscation type, it rejects the request with INVALID_ARGUMENT and the message Unable to apply a data policy for this session. This prevents the agent from returning data that a statement should mask.
To keep serving requests, set the environment variable LENSES_DATAPOLICIES_STRICT_CONVERSION=false on the agent, for example in the agent Docker image. Where you control the JVM options of the agent, you can set the system property lenses.datapolicies.strict-conversion=false instead. The agent then drops the statement it cannot apply, logs a warning, and applies the remaining statements. Requests to GET /v1/environments/{environment}/kafka/topics/{topic}/records ignore this setting and are always rejected.
Data is not masked
Check the following:
The environment's
Data policiesrow showsIAM. See Check which data policies an environment uses.The user is not an HQ root user. Root users are never masked.
The user's groups have a role with a matching statement. See User Masking Rules.
The field pattern matches the full field path, with the same case. A bare field name matches top-level fields only. Use
*.nameto match the field at any depth.None of the user's roles has a
nonestatement for the field.The record can be decoded. Records that cannot be decoded are returned as raw bytes without masking.
Last updated
Was this helpful?

