{"id":107675,"date":"2023-01-05T07:00:00","date_gmt":"2023-01-05T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=107675"},"modified":"2023-01-04T18:35:24","modified_gmt":"2023-01-05T02:35:24","slug":"20230105-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230105-00\/?p=107675","title":{"rendered":"How can I force a user to have a specific SID prefix, so that they go into a particular group?"},"content":{"rendered":"<p>A customer wanted to create a user with a specific SID prefix:<\/p>\n<blockquote class=\"q\">\n<p>We know that you can&#8217;t create a user with a specific SID, but can we at least create it with a specific SID prefix?<\/p>\n<p>We na\u00efvely tried this:<\/p>\n<pre>net user \/add Fred\r\nnet localgroup \"Cryptographic Operators\" Fred \/add\r\n<\/pre>\n<p>Since the Cryptographic Operators group SID is S-1-5-32-569, we expected that the newly-created user &#8220;Fred&#8221; would have a SID of the form S-1-5-32-569-(random)-1000, but it doesn&#8217;t.<\/p>\n<p>How do we create a user with a specific SID prefix? We want Fred to be a member of the &#8220;Cryptographic Operators&#8221; group, so we need the user SID to be under the &#8220;Cryptographic Operators&#8221; SID.<\/p>\n<\/blockquote>\n<p>Okay, that&#8217;s not how SID prefixes work.<\/p>\n<p>Group membership is not controlled by SID prefixes. It is not the case that all members of the &#8220;Cryptographic Operators&#8221; group have a SID prefix of S-1-5-32-569, nor is it the case that you must have that prefix in order to be a member of the &#8220;Cryptographic Operators&#8221; group.<\/p>\n<p>In fact, S-1-5-32-569 is not a legal SID prefix at all, since it is not a so-called <i>domain identifier<\/i>, which is the fancy name for &#8220;a thing that can produce new SIDs via suffixing.&#8221;<\/p>\n<p>If you think about it, it makes sense that group membership is not controlled by SID prefixes. After all, a user can belong to multiple groups: You are probably a member of the local Administrators group (S-1-5-32-544), the Remote Desktop Users group (S-1-5-32-555), the Users group (S-1-5-32-545), the Authenticated Users group (S-1-5-11), and a whole bunch of others. But you have only one SID, so it can&#8217;t have all of those groups as a prefix.<\/p>\n<p>Group membership is determined by entries in the user&#8217;s token, and those entries are placed there at token creation based on the group memberships. When the system later wants to check if a user is in a group, it does so by looking in the token to see if there is an entry for that group in the token. It doesn&#8217;t do it by doing a prefix check on the user SID.<\/p>\n<p>You have your gym membership card in your wallet, but that doesn&#8217;t mean that you were born at the gym. Your national identity number was issued by Stockholm, but that doesn&#8217;t prevent you from being a registered resident of G\u00f6teborg.<\/p>\n<p>The way to create a user in a group is to do exactly what the customer did: Create the user (which will assign them a SID), and then add the user to the groups you want them to be members of (which will add them in the group membership database).<\/p>\n<p>The numeric properties of the SID are not important. As long as each entity gets a unique SID, that&#8217;s the important thing. The prefixing technique is just a way to make sure that separate SID-creating entities can create unique SIDs without colliding with each other: If you give each SID-creating entity a unique prefix to stamp onto its created SIDs, then you can be sure that their SIDs won&#8217;t collide.<\/p>\n<p><b>Bonus chatter<\/b>: Although the numeric properties are not important from a security standpoint, you can use knowledge of the SID-assignment algorithm to infer information about the circumstances of the SID&#8217;s creation, in the same way that looking at a person&#8217;s national identity number tells you where they were born.\u00b9 For example, by looking at the SID, you can determine which SID-creating entity issued it, and from the RID you can infer <a href=\"https:\/\/social.technet.microsoft.com\/wiki\/contents\/articles\/20590.management-of-sids-in-active-directory.aspx\"> which domain controller was used<\/a>.<\/p>\n<p>\u00b9 In 1990, Sweden stopped encoding geographic information in the national identity number, so that trick works only for older people.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The prefix doesn&#8217;t define group membership.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-107675","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>The prefix doesn&#8217;t define group membership.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=107675"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107675\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=107675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=107675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=107675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}