MSBA-343 · Lesson 2 of 12 · 19 min
Extensible data security
▶ Video coming soon A video version of this lesson is on the way.
Role-based security decides which forms, actions and services a user can reach. It does not decide which rows they see once they get there. A customer service agent who can open the pump warranty list sees every warranty the legal entity holds. For most of Cobalt Ridge that was exactly right. For one group it was not, and the second clinic began with the request that had come out of Thandeka's security review.
The Mining business unit had hired two field service coordinators who would work from the Calgary warehouse with mining customers only. Piotr wanted them to see warranties for mining pumps, plan repairs and print certificates, but not browse the municipal water customers' installed base, which included sensitive details about city water systems. The coordinators would hold the customer service role like everyone else on the service desk. The row filter had to come from somewhere else, and in finance and operations apps that somewhere is extensible data security, usually shortened to XDS.
What an XDS policy does
An XDS policy is a security policy that filters data. It is a metadata object, built in Visual Studio and stored in the model under Security, Policies. At run time, when a user to whom the policy applies queries a table that the policy constrains, the system adds the policy's condition to the WHERE or ON clause of the statement. The filter is applied to select, update, delete and insert operations alike, so a user cannot change or create a row they would not be allowed to see.
Every policy has four parts. The primary table is the table whose rows decide access, such as CustTable. The policy query is a query on the primary table with a range that defines the allowed rows, such as customers in a given customer group. The constrained tables are the tables whose data is filtered; each must be related to the primary table through an explicit relation, which is how the system knows how to join them. The context decides to whom the policy applies.
Contexts
The context is what makes a policy apply to some users and not others. There are two kinds. A role context ties the policy to roles. With the RoleName context type, the policy applies to users who hold the named role. With the RoleProperty context type, the policy has a context string, and it applies to users whose assigned roles carry a matching context string; this lets one policy cover several roles. An application context ties the policy to a string that code sets at run time with the XDS::SetContext API, so the policy applies only while code has declared that context.
Desmond chose a role context for the coordinators. He created a small role, CR Mining service coordinator, which held no privileges at all. Its only purpose was to carry the policy. The coordinators kept the customer service role for their access to forms and received the new role in addition. That separation meant the filter could be removed by removing one role, and it meant nobody had to duplicate the customer service role to attach a policy to it.
| Context type | Policy applies when | Typical use |
|---|---|---|
| RoleName | The user holds the role named on the policy | One clearly defined group, such as mining coordinators |
| RoleProperty | A context string on the user's roles matches the policy's context string | One policy shared by several roles |
| Application context | Code has set a matching context string with XDS::SetContext | Filtering only during a specific process |
Building the warranty policy
Prudence built the policy step by step. First the query. She created CRXDSMiningCustomers, a query with CustTable as its only data source and a range on the customer group field with the value MINING. In XDS the query's range is what defines the allowed rows, so it had to be simple and selective. She resisted the temptation to join other tables into the policy query, because every join in the policy query is added to every query on every constrained table.
Next the policy itself. She added a security policy named CRMiningWarrantyPolicy, set the primary table to CustTable and the query to CRXDSMiningCustomers, set the context type to RoleName and the role name to the new coordinator role, and set the policy to enabled. Then she added constrained tables. CRPumpWarrantyTable was the obvious one, and it already had a relation to CustTable through its CustAccount field from the first clinic series. She also added CustTrans, the customer transactions table, after Piotr confirmed that the coordinators would see customer balances on the service form, and she checked that a relation to CustTable existed for it.
Security policy: CRMiningWarrantyPolicy
PrimaryTable: CustTable
Query: CRXDSMiningCustomers (CustTable, range CustGroup = MINING)
ContextType: RoleName
RoleName: CRMiningServiceCoordinator
Enabled: Yes
Constrained tables:
CRPumpWarrantyTable via relation CustTable (CustAccount)
CustTrans via relation CustTable (AccountNum)A relation can only be used for a constrained table if it leads from the constrained table to the primary table in a way the system can join on. When a relation is missing, the right answer is usually to add one to the custom table, or to add a constrained table through an intermediate table that does have relations. Prudence found that a third table she had considered, a service note table from a planned future feature, did not yet have a customer field at all. She left it out and added a note to the design document, so that whoever built the feature would know the policy needed it.
Several policies at once
A user can be subject to more than one XDS policy. When several policies constrain the same table for the same user, the user sees the intersection of what the policies allow, not the union. Each row must satisfy every applicable policy. This catches out designers who think of policies as grants. Desmond made Prudence say it aloud: an XDS policy only ever removes rows.
The rule has a practical consequence. If Piotr later asked for a policy that limited coordinators to customers in western provinces or states, and the coordinators also held the mining policy, they would see only mining customers in the west. That might be right. If the intention was mining customers anywhere plus western customers of any kind, XDS could not express it with two policies; it would need a single policy whose query expressed the combined rule, or a different design entirely.
Performance
Because the policy query is added to every statement on every constrained table for every user the policy applies to, a poorly designed policy can slow the whole application for those users. Microsoft's guidance is to keep policy queries simple, to make sure the fields in the range and in the relations are indexed, and to avoid constraining large transaction tables unless there is a real need. The warranty table was small and already indexed on CustAccount. CustTrans was large, but it had an index starting with the account number, so the added join used it.
Prudence ran the trace tools from lesson 3 on the coordinator's service form before and after enabling the policy. The extra join added a few milliseconds per query. Desmond asked her to keep the trace in the sign-off pack anyway. A policy that is cheap today can become expensive when someone adds a constrained table later, and a baseline makes the change visible.
Where XDS does not belong
XDS is a sharp tool, and Microsoft documents places not to use it. The most important for Cobalt Ridge was financial dimensions. XDS is not supported for financial dimension data, and applying policies to the tables behind dimension values, such as customers, vendors or operating units used as backing entities, can make dimension values appear blank or missing for the affected users and can damage data. Thandeka had once asked whether XDS could hide the Mining business unit's results from municipal managers. The answer was no: financial reporting security is handled through reporting tools and their own access controls, not through row filters on dimension tables.
The second place is legal entity separation. A user who should only work in CRUS does not need a policy at all. Role assignments can be limited to specific organizations, and the system's company context already separates data that is stored per company. XDS is for filters within a company that the organization model cannot express, such as customer group, region or business line.
The third is anything the user should be able to override. A policy is absolute for the users it covers. If a coordinator occasionally needs to see a municipal customer, the design is wrong; the right answer might be a separate role or a manual escalation. The fourth is the inspection certificate feature from MSBA-341. Thandeka had decided against XDS there, because every buyer needed to see every certificate on the purchase lines they worked with, and role-based security already limited who could maintain them.
Testing and troubleshooting
Testing a policy means testing it as the people it applies to and the people it does not. Prudence used three test users: a coordinator with both roles, a service agent with only the customer service role, and an administrator. The coordinator saw only mining warranties on the list, on the lookup from a sales order and in the customer transactions on the service form; an attempt to create a warranty for a municipal customer failed with a message that the record could not be found, because the insert was filtered too. The service agent saw everything, as before.
Troubleshooting runs the other way. When a user reports missing data and an XDS policy might be the cause, Microsoft documents a quick diagnostic: temporarily assign the user the XDSDataAccessPolicyBypassRole role. Users who hold that role bypass all XDS policies, so if the data appears, a policy is filtering it. Desmond added a caution. The bypass role is powerful, so it must be removed immediately after the test, and assigning it should be logged like any other privileged change. In production he wanted it held by nobody permanently.
| Test | Coordinator | Service agent | Expected reason |
|---|---|---|---|
| Warranty list shows municipal pumps | No | Yes | Policy filters CRPumpWarrantyTable for the coordinator role |
| Create warranty for municipal customer | Fails | Succeeds | Insert is filtered by the policy |
| Customer transactions on service form | Mining only | All | CustTrans is a constrained table |
| Same tests with bypass role added | All rows | All rows | XDSDataAccessPolicyBypassRole ignores policies |
Policies and code
Code runs in the user's security context, so X++ queries are filtered by policies just as form queries are. That is usually what is wanted, but it can surprise a developer. A batch job that summarises warranties by customer group will give different totals depending on who runs it, because the policy filters the rows the batch job reads under that user's identity. Desmond's convention was that summary and integration jobs run under a dedicated service account that holds no policy roles, and that the job's description says so. Code that needs a narrower view during one process can use an application context set with XDS::SetContext, but Desmond had not yet found a need for it at Cobalt Ridge and preferred to keep policies tied to roles, where Thandeka could see them in reviews.
Policies are also part of the model, so they follow the same release discipline as privileges. A policy change goes through a pull request, the reviewer checks the query and constrained tables, and the release notes say which roles it affects. Enabling or disabling a policy in production is a change to what users can see, and Thandeka wanted it on the change log with an owner and a reason.
Worked problem
Filtering warranties for mining coordinators
Two new coordinators must see only mining customers' pump warranties and customer transactions, while everyone else on the service desk keeps seeing all customers. How should Desmond and Prudence implement this?
Show solution
- Confirm that the restriction is a row filter within the same legal entities, not a legal entity boundary or a financial dimension.
- Create a query on CustTable with a range on customer group MINING.
- Create a role, CR Mining service coordinator, with no privileges, to carry the policy.
- Create the policy with primary table CustTable, the query, a RoleName context for the new role, and constrained tables CRPumpWarrantyTable and CustTrans through their relations.
- Check that the relation fields are indexed and trace the service form before and after enabling the policy.
- Test as a coordinator, a service agent and an administrator, and use the bypass role only for a short diagnostic.
Answer: A RoleName policy on CustTable, carried by a privilege-free role, filters both constrained tables for the coordinators only, and the tests show that inserts as well as reads are filtered.
Common mistakes
MistakeTreating an XDS policy as something that grants extra rows.
InsteadPolicies only remove rows, and several policies give the intersection.
MistakeUsing XDS to restrict financial dimension values.
InsteadXDS is not supported for financial dimensions; use reporting security instead.
MistakeWriting complex joins into the policy query.
InsteadKeep the policy query simple and indexed, because it is added to every constrained query.
MistakeLeaving the bypass role assigned after troubleshooting.
InsteadAssign it briefly, log the change and remove it.
Summary and key terms
- XDS policies filter rows by adding the policy query to statements on constrained tables.
- A policy has a primary table, a policy query, constrained tables linked by relations, and a context.
- Role contexts apply policies to users by role name or role property; application contexts apply when code sets them.
- Several policies give the intersection of their rows, and policy queries must be simple and indexed.
- XDS is not for financial dimensions or legal entity separation; the bypass role helps diagnose missing data.
- Extensible data security (XDS)
- A framework for filtering table rows for some users through security policies.
- Primary table
- The table whose rows, selected by the policy query, decide which related rows are allowed.
- Constrained table
- A table whose rows are filtered by a policy through a relation to the primary table.
- Policy context
- The setting that decides to whom or when a policy applies.
- XDSDataAccessPolicyBypassRole
- A role whose holders bypass all XDS policies, used for diagnosis.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Which operations does an XDS policy filter?
Show answer
Select, update, delete and insert operations on constrained tables.
Why did Desmond create a role with no privileges?
Show answer
To carry the policy, so the filter could be added or removed without changing the customer service role.
What does it mean if data appears after the bypass role is assigned?
Show answer
An XDS policy was filtering it.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.