{"id":510,"date":"2021-11-30T14:51:08","date_gmt":"2021-11-30T14:51:08","guid":{"rendered":"https:\/\/fde.cat\/index.php\/2021\/11\/30\/restriction-rules\/"},"modified":"2021-11-30T14:51:08","modified_gmt":"2021-11-30T14:51:08","slug":"restriction-rules","status":"publish","type":"post","link":"https:\/\/fde.cat\/index.php\/2021\/11\/30\/restriction-rules\/","title":{"rendered":"Restriction Rules"},"content":{"rendered":"<h3>Restriction Rules: Complementing Salesforce\u2019s Record Access Control Mechanism<\/h3>\n<h3>Introduction<\/h3>\n<p>If you\u2019ve taken Salesforce Admin 201 training, you might remember learning about Sharing Settings. Sharing Settings include Sharing Models, Criteria Sharing Rules, Manual Sharing, and more. I\u2019m a software engineer on the Record Access Experience team here at Salesforce. When I took this training in 2017, it was the first time Sharing Settings truly clicked for me, even though I\u2019d been hired onto the team a month earlier. In this post, I\u2019m going to talk about Sharing, then describe a new feature called Restriction Rules and how it\u2019s implemented differently from other Sharing Settings.<\/p>\n<h3>Sharing<\/h3>\n<p>How Sharing Settings give you access to a record is described in this\u00a0image.<\/p>\n<p>How Sharing Settings give you access to\u00a0records<\/p>\n<p>If a user gets access to a record because your Org\u2019s Org-Wide-Default gives them access, Salesforce doesn\u2019t check anything else. If not, we check to find out if your Role, Owner or Criteria Sharing Rules, or Manual Shares give you access. If none of these settings grant access, we return a \u201cYou don\u2019t have access\u201d\u00a0message.<\/p>\n<h3>Under the Hood:\u00a0Sharing<\/h3>\n<p>Sharing works by materializing Share Rows in a table. For instance, if Maria owns an account, then we insert a row in an Account Sharing Table. The new row indicates that Maria can access the account because she\u2019s the\u00a0owner.<\/p>\n<p>The Accounts and Account Sharing tables with an Owner\u00a0Share<\/p>\n<p>If a Sharing Rule grants access to another user, Frank, we insert a row in the Account Sharing Table. The new row indicates that Frank has access because it was granted manually. If a Sharing Rule grants access to a group called \u201cStrategy,\u201d then the row in the Account Sharing Table points to the\u00a0group.<\/p>\n<p>The Accounts and Account Sharing tables with Owner, Manual, and Rule\u00a0Shares<\/p>\n<p>Now, if another user pulls this account up, we look at the Account Sharing Table to determine if they have direct access to it. In other words, we check if they are Maria or Frank, who have access because they are the owner or gained access via Sharing Rule. Salesforce also performs a lookup in multiple Group Maintenance Tables to determine if the user is part of the Strategy\u00a0group.<\/p>\n<p>Group Maintenance Tables help determine if the user is part of a\u00a0group.<\/p>\n<p>We have indexes and highly optimized queries on these tables, which typically gives us our lightning-fast performance at the point of accessing data. As you can see, we get a speedy response because we make a trade on the space side of the space-time trade-off. We write a whole bunch of rows in our tables to describe who sees what. While it may be fast at enforcement time, when rules are created, updated, or deleted, we end up having to rewrite a whole host of records. That process can be time-consuming. In most cases, writing these rows happens quickly. But there are times when this process increases wait times, and customers are prevented from updating object\u00a0access.<\/p>\n<h3>Restriction Rules<\/h3>\n<p>The Restriction Rules feature is the newest addition to record-level access control mechanisms at Salesforce. For a while now, Sharing Settings have needed enhancement. There are objects that should have their own sharing model, but don\u2019t. There are objects that have their own distinct access control mechanisms. And there are objects that observe Sharing Settings, but could use improvement. Restriction Rules aim to plug these gaps and position Salesforce to make future forays into uncharted territory, such as data that resides outside of Salesforce, or data that is not stored in a relational DB. If you have other ideas, let us know in the comments.<\/p>\n<h3>Setting Up a Restriction Rule<\/h3>\n<p>A Restriction Rule might look something like\u00a0this.<\/p>\n<p>The Restriction Rule\u00a0UI<\/p>\n<p>This is a sample Restriction Rule created on a task object. Check out the User Criteria and Record Criteria sections. This rule states that users in the US can only access tasks that they created. So even if the users get access to tasks that they didn\u2019t create through an existing access control mechanism, Restriction Rules act as a filter that is applied on top of that mechanism. The Restriction Rules thus deny access to those\u00a0tasks.<\/p>\n<p>Now, if we updated our Sharing triangle, it would look like\u00a0this.<\/p>\n<p>Sharing Triangle with Restriction Rules<\/p>\n<h3>Under the Hood: Restriction Rules<\/h3>\n<p>Restriction Rules invert the space-time tradeoff. Rather than store access in the Sharing Tables, we thought, why not generate an Access Control Policy that could be read at runtime to define access? This massively reduces the time it takes to create, update, or delete rules because we no longer have to materialize all these records. Furthermore, at the point of enforcement, we can reduce the number of times we make a database round trip to look at all the Sharing and Group Maintenance Tables.<\/p>\n<h3>eXtensible Access Control Markup Language\u00a0(XACML)<\/h3>\n<p>Enter XACML (and a few acronyms). Wikipedia says it\u2019s a declarative Attribute-Based Access Control (ABAC) policy language. It\u2019s a published standard specification that aims to function as an access control system. This system uses attributes associated with a user, action, or resource as inputs into the decision of whether a given user may access a given resource in a particular way. Perfect! Let\u2019s have our users create and upload these policies. Well, not so fast. XACML policies are powerful, but they can be verbose and can get complicated quickly as seen in this example from the same Wikipedia article.<\/p>\n<p>A Rule Expressed in\u00a0XACML<\/p>\n<p>Rather than make our users learn a new language altogether, we decided to make it simple to author rules either through the UI (as seen above) or the Metadata\u00a0API.<\/p>\n<h3>Architecture<\/h3>\n<p>In this image, if an admin user creates a Restriction Rule, we generate a XACML policy and store that in a XACML data store. Then, when a user accesses a record, before we go retrieve the data, we make a request to a Policy Decision Engine. This makes a decision based on what the policy says. That decision informs whether or not the user has\u00a0access.<\/p>\n<p>Architecture for Restriction Rules Creation and Enforcement<\/p>\n<p>In fact, it\u2019s not that easy. There\u2019s more happening here than meets the\u00a0eye.<\/p>\n<h3>Complicating Factors<\/h3>\n<p>To make the request to the Policy Decision Engine, we need to know which pieces of data we need to supply to it. For instance, if a Restriction Rule on a Task was created as in our example, then the Decision Engine needs to know the current user\u2019s country in order to compare it with the country named in the rule. Similarly, it needs to know the record\u2019s creator. We solve this by scanning the policy once it\u2019s created, then caching a catalog of attributes that the policy references. Then, when a user makes a request for one or more records, we look at the catalog, and supply that information to the Decision Engine along with the\u00a0request.If a user is making a query for multiple records, we cannot afford to iterate through all of them and ask the Decision Engine for a decision on each record. In such situations, we make just one call to the Decision Engine, which will then return a filter. Whilst querying for the data, we add that filter to the query, thereby eliminating records the user does not have access\u00a0to.<\/p>\n<h3>Performance Performance Performance!<\/h3>\n<p>Every time we write a new line of code, we incur a cost. When it comes to performance, the best feature is one that is never written. Of course, we wrote the feature, but worked to aggressively reduce overhead. A feature such as Restriction Rules, which could potentially be run every time a user pulls up a piece of data, must be as performant as possible. Our early iterations, much to our performance engineering team\u2019s chagrin, were quite chatty with the database. This led to increased CPU and DB usage and response\u00a0times.<\/p>\n<p>We formulated a two-pronged approach to tackle our performance issues.<\/p>\n<p>Eliminate or tune SQL queries: Some queries could be eliminated. We could infer those results from data we already had cached in memory. We rewrote some others to be more performant.Caching: We aggressively cached data that would get frequently retrieved. Initially we cached things like the catalog of attributes and the contents of the XACML policy, thereby reducing the database round trips to retrieve the policy. On further examination, it became obvious that we\u2019d get significant benefits by remembering the decision itself, as long as nothing else had changed. So we wrote a mechanism to reuse the decision.<\/p>\n<p>After these performance improvements, preliminary testing revealed that, on average, the overhead of adding Restriction Rules in terms of response times decreased by almost\u00a080%.<\/p>\n<h3>An Updated Architecture Diagram<\/h3>\n<p>Factoring in the above changes makes our architecture look like\u00a0this.<\/p>\n<p>Updated architecture diagram for Restriction Rules creation and enforcement<\/p>\n<h3>Conclusion<\/h3>\n<p>Restriction Rules are a powerful new feature that enhance our existing access control mechanisms. Furthermore, the underlying architecture that went into creating this feature also gives our engineering team a platform to create newer and more flexible access control mechanisms in the future. We invite you to try this feature out for yourself. Then, leave us some feedback!<\/p>\n<h3>Recommended Reading<\/h3>\n<p><a href=\"https:\/\/admin.salesforce.com\/blog\/2021\/learn-moar-in-winter-22-with-restriction-rules\">Learn MOAR in Winter \u201922 with Restriction Rules\u00a0\ud83d\udeab<\/a><a href=\"https:\/\/developer.salesforce.com\/blogs\/2021\/05\/control-access-to-sensitive-records-with-restriction-rules-now-in-beta\">Control Access to Sensitive Records with Restriction Rules<\/a><\/p>\n<h3>Acknowledgements<\/h3>\n<p>Thank you for reading! This project would not have been possible without the tireless efforts of the following people: Yanik Grignon, Matthew Wong, Larry Tung, Devshree Gehlot, Bhumi Damania, Priyank Bhawsar, Subhash Uppalapati, Benjamin Gee, Shyam Naren Kandala, Sunghyun Song, Virag Shah, Irina Sendyk, Arjun Sirohi, Lakshman Martha, Dan Sheehan, Dana Holloway, Alex Kaufman, Chuxi Wang, and many\u00a0others.<\/p>\n<p><a href=\"https:\/\/engineering.salesforce.com\/restriction-rules-820f2218a51b\">Restriction Rules<\/a> was originally published in <a href=\"https:\/\/engineering.salesforce.com\/\">Salesforce Engineering<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>\n<p><a href=\"https:\/\/engineering.salesforce.com\/restriction-rules-820f2218a51b?source=rss----cfe1120185d3---4\">Read More<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Restriction Rules: Complementing Salesforce\u2019s Record Access Control Mechanism Introduction If you\u2019ve taken Salesforce Admin 201 training, you might remember learning about Sharing Settings. Sharing Settings include Sharing Models, Criteria Sharing Rules, Manual Sharing, and more. I\u2019m a software engineer on the Record Access Experience team here at Salesforce. When I took this training in 2017,&hellip; <a class=\"more-link\" href=\"https:\/\/fde.cat\/index.php\/2021\/11\/30\/restriction-rules\/\">Continue reading <span class=\"screen-reader-text\">Restriction Rules<\/span><\/a><\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":229,"url":"https:\/\/fde.cat\/index.php\/2021\/02\/02\/ml-lake-building-salesforces-data-platform-for-machine-learning\/","url_meta":{"origin":510,"position":0},"title":"ML Lake: Building Salesforce\u2019s Data Platform for Machine Learning","date":"February 2, 2021","format":false,"excerpt":"Salesforce uses machine learning to improve every aspect of its product suite. With the help of Salesforce Einstein, companies are improving productivity and accelerating key decision-making. Data is a critical component of all machine learning applications and Salesforce is no exception. In this post I will share some unique challenges\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":726,"url":"https:\/\/fde.cat\/index.php\/2023\/06\/21\/tackling-cyber-threats-with-automation-inside-salesforces-cutting-edge-security-strategy\/","url_meta":{"origin":510,"position":1},"title":"Tackling Cyber Threats with Automation: Inside Salesforce\u2019s Cutting-edge Security Strategy","date":"June 21, 2023","format":false,"excerpt":"In our \u201cEngineering Energizers\u201d Q&A series, we examine the professional journeys that have shaped Salesforce Engineering leaders. In this special edition, we meet Avinash Reddy Thumma, lead threat detection engineer for Salesforce. Based in Hyderabad, India, Avinash\u2019s threat detection team specializes in protecting Salesforce\u2019s network by thwarting malicious threats. Read\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":837,"url":"https:\/\/fde.cat\/index.php\/2024\/03\/12\/from-concept-to-reality-developing-mulesofts-new-flex-gateway-api-management-solution\/","url_meta":{"origin":510,"position":2},"title":"From Concept to Reality: Developing MuleSoft\u2019s New Flex Gateway API Management Solution","date":"March 12, 2024","format":false,"excerpt":"In our \u201cEngineering Energizers\u201d Q&A series, we explore the remarkable journeys of engineering leaders who have made significant contributions in their respective fields. Today, we dive into the technical journey of Evangelina Martinez Ruiz Moreno, a Senior Director at Salesforce, who spearheaded the development of MuleSoft\u2019s new Anypoint Flex Gateway.\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":490,"url":"https:\/\/fde.cat\/index.php\/2021\/10\/19\/github-actions-security-best-practices\/","url_meta":{"origin":510,"position":3},"title":"Github Actions Security Best Practices","date":"October 19, 2021","format":false,"excerpt":"Introduction In the world of Continuous Integration and Continuous Deployment, Github Actions provide a nifty edge to quickly build end-to-end automation right into the repository. This makes integration of Actions into an organization\u2019s Github repositories pretty straightforward and convenient. Github Actions bring velocity to the Software Development Lifecycle. However, if\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":722,"url":"https:\/\/fde.cat\/index.php\/2023\/06\/06\/9-software-engineering-productivity-secrets-to-ignite-innovation-every-day\/","url_meta":{"origin":510,"position":4},"title":"9 Software Engineering Productivity Secrets to Ignite Innovation Every Day","date":"June 6, 2023","format":false,"excerpt":"During the COVID-19 pandemic, Salesforce and many other software companies asked its employees to work from home to help safeguard their safety and their families. The Salesforce Industries team \u2014 innovators of industry-specific digital solutions for global companies across verticals \u2014 remained highly productive, developing and delivering a cutting-edge emergency\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":710,"url":"https:\/\/fde.cat\/index.php\/2023\/05\/03\/the-malware-threat-landscape-nodestealer-ducktail-and-more\/","url_meta":{"origin":510,"position":5},"title":"The malware threat landscape: NodeStealer, DuckTail, and more","date":"May 3, 2023","format":false,"excerpt":"We\u2019re sharing our latest threat research and technical analysis into persistent malware campaigns targeting businesses across the internet, including threat indicators to help raise our industry\u2019s collective defenses across the internet. These malware families \u2013 including Ducktail, NodeStealer and newer malware posing as ChatGPT and other similar tools\u2013 targeted people\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":0,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"wp:attachment":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}