%3CLINGO-SUB%20id%3D%22lingo-sub-2067390%22%20slang%3D%22en-US%22%3ESecurity%3A%20The%20Principle%20of%20Least%20Privilege%20(POLP)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2067390%22%20slang%3D%22en-US%22%3E%3CP%3E%3CEM%3E(part%201%20of%20my%20series%20of%20articles%20on%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql%2Fintroduction-into-security-principles-in-the-context-of-database%2Fba-p%2F2067363%22%20target%3D%22_self%22%3Esecurity%20principles%20in%20Microsoft%20SQL%20Servers%20%26amp%3B%20Databases%3C%2FA%3E%3C%2FEM%3E%3CEM%3E)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%227%22%3EThe%20Principle%20of%20Least%20Privilege%20(POLP)%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThe%20first%20security%20principle%20that%20I%20am%20going%20to%20discuss%20is%20one%20that%20most%20System%20Administrators%20are%20familiar%20with%3A%20the%20%E2%80%9Cprinciple%20of%20least%20privilege%E2%80%9D%20(short%3A%20POLP).%20It%20demands%20that%20the%20required%20permissions%20for%20a%20task%20shall%20%3CU%3Eonly%20grant%20access%20to%20the%20needed%20information%20or%20resources%20that%20a%20task%20requires%3C%2FU%3E.%20When%20permissions%20are%20granted%2C%20we%20shall%20grant%20the%20least%20privileges%20possible.%3C%2FP%3E%0A%3CP%3EPOLP%20is%20so%20crucial%20because%20initially%20it%20is%20the%20privileges%20that%20any%20attacker%20is%20targeting.%20When%20developing%20an%20application%2C%20using%20a%20%3CEM%3Eleast-privileged%20user%20account%3C%2FEM%3E%20(LUA)%20is%20the%20first%20rule%20of%20engagement.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3ENote%3C%2FEM%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-server%2Fsecurity%2Fuser-account-control%2Fhow-user-account-control-works%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CEM%3EUser%20Account%20Control%3C%2FEM%3E%3C%2FA%3E%20(UAC)%20in%20Windows%20is%20a%20feature%20that%20Microsoft%20developed%20to%20assist%20administrators%20in%20working%20with%20least-privileges%20by%20default%20and%20elevate%20to%20higher%20permission%20only%20when%20needed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20also%20know%20that%20Microsoft%20recommends%20separating%20service%20accounts.%20This%20security%20best%20practice%20is%20generally%20referred%20to%20as%20%3CSTRONG%3E%3CEM%3Eservice%20account%20isolation%3C%2FEM%3E%3C%2FSTRONG%3E%20and%20is%20related%20to%20POLP%3A%20Using%20distinct%20service%20accounts%20prevents%20increased%20privileges%2C%20which%20happens%20easily%20when%20you%20share%20an%20account%20to%20be%20used%20for%20multiple%20purposes%20and%20as%20a%20consequence%2C%20the%20privileges%20are%20merged.%20-%20This%20would%20violate%20the%20principle%20of%20least%20privilege.%3CBR%20%2F%3EBoth%20POLP%20and%20service%20account%20isolation%20help%20reducing%20the%20attack%20surface%20(aka%20%3CSTRONG%3E%3CEM%3Eattack%20surface%20reduction%3C%2FEM%3E%3C%2FSTRONG%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E-%20Read%20more%20on%20this%20topic%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Fconnect%2Fado-net%2Fsql%2Fsql-server-security%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESQL%20Server%20security%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E%3CBR%20%2F%3Eand%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsecurity%2Fsurface-area-configuration%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESurface%20Area%20Configuration%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EService%20account%20isolation%20also%20prevents%20%3CEM%3E%3CSTRONG%3Elateral%20movement%3C%2FSTRONG%3E%3C%2FEM%3E%20between%20services%20if%20an%20attacker%20gained%20access%20to%20one%20service.%20You%20see%20how%20one%20thing%20is%20connected%20to%20another%20in%20Security%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3ENote%3C%2FEM%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3ELateral%20movement%20is%3C%2FEM%3E%3C%2FSTRONG%3E%20a%20common%20attack%20strategy%20to%20move%20from%20one%20target%20to%20the%20next%3A%20If%20the%20main%20target%20(for%20example%20the%20database%20server)%20cannot%20be%20breached%20into%20directly%2C%20attackers%20try%20to%20gain%20foothold%20in%20some%20other%20server%20in%20the%20system%20within%20the%20same%20network%20and%20then%20launch%20other%20attacks%20to%20try%20to%20get%20to%20the%20final%20goal%2C%20server%20by%20server%20or%20service%20by%20service.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--551838308%22%20id%3D%22toc-hId--551838311%22%3EPrinciple%20of%20Least%20Privilege%20in%20the%20SQL%20realm%3C%2FH2%3E%0A%3CP%3ELet%E2%80%99s%20look%20at%20some%20examples%20within%20the%20SQL%20Server%20engine%20(applying%20to%20on-prem%20as%20well%20as%20our%20Azure%20SQL-products)%3A%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-138723166%22%20id%3D%22toc-hId-138723163%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId--1668731297%22%20id%3D%22toc-hId--1668731300%22%3EExample%201%2C%20read-access%20to%20data%3C%2FH3%3E%0A%3CP%3EA%20typical%20example%20within%20SQL%20Server%20would%20be%3A%20To%20allow%20a%20User%20to%20only%20read%20data%20from%20a%20small%20set%20of%20tables%2C%20ideally%20defined%20by%20a%20schema-boundary%2C%20we%20have%20the%20SELECT-Permission%2C%20grantable%20at%20the%20schema-%20(or%20even%20table-)%20level.%20There%20is%20no%20need%20to%20grant%20SELECT%20at%20the%20whole%20database%2C%20or%20to%20grant%20anything%20other%20than%20SELECT.%3CBR%20%2F%3EIn%20the%20code-snippet%20below%20we%20see%20that%20there%20are%20many%20tables%20in%20different%20schemas%20(Application%2C%20Purchasing%2C%20Sales)%20within%20the%20database%20%3CEM%3EWideWorldImporters%3C%2FEM%3E.%20Instead%20of%20granting%20Select%20in%20the%20whole%20database%2C%20we%20chose%20to%20grant%20the%20user%20%3CEM%3EShakti%3C%2FEM%3E%20the%20permission%20at%20the%20schema%20scope.%20As%20long%20as%20this%20schema%20really%20contains%20only%20objects%20that%20Shakti%20needs%20access%20to%2C%20this%20is%20a%20best%20practice%20as%20it%20greatly%20reduces%20the%20management%20and%20reporting%20overhead%20compared%20to%20granting%20permissions%20at%20the%20object-level.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndreasWolter_0-1610818365353.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F246953i79F83D36C8F5B5E0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AndreasWolter_0-1610818365353.png%22%20alt%3D%22AndreasWolter_0-1610818365353.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3ETip%3C%2FEM%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3EAn%20alternative%20is%20to%20use%20stored%20procedures%20for%20all%20data%20access%2C%20which%20would%20allow%20even%20better%20control%20and%20completely%20hide%20the%20schema%20from%20Users.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20was%20easy%2C%20wasn%E2%80%99t%20it%3F%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-818781536%22%20id%3D%22toc-hId-818781533%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId--988672927%22%20id%3D%22toc-hId--988672930%22%3EExample%202%2C%20creating%20user%20accounts%3C%2FH3%3E%0A%3CP%3EUnfortunately%2C%20not%20everything%20is%20implemented%20to%20always%20ensure%20POLP.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20take%20another%20example%3A%3C%2FP%3E%0A%3CP%3EYou%20want%20to%20delegate%20the%20ability%20to%20create%20new%20Logins%20in%20SQL%20Server.%3CBR%20%2F%3EThe%20minimal%20permission%20available%20is%20ALTER%20ANY%20LOGIN.%20Ok%2C%20so%20now%20this%20person%20can%20create%20new%20Logins%2C%20and%20maybe%20also%20Dropping%20them%20is%20ok.%3C%2FP%3E%0A%3CP%3EBut%3A%20With%20this%20permission%20comes%20the%20ability%20to%20change%20the%20password%20of%20any%20SQL%20Login%20(%E2%80%9CALTER%20LOGIN%20%E2%80%A6%20WITH%20PASSWORD%3D'NewPassword').%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20an%20unwanted%20scenario%20as%20this%20would%20enable%20this%20person%20to%20essentially%20take%20over%20other%20accounts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3ENote%3C%2FEM%3E%3CBR%20%2F%3EThis%20would%20not%20work%20if%20the%20Account%20were%20a%20Windows%20Domain%20or%20Azure%20Active%20Directory%20account.%20This%20is%20where%20a%20separation%20of%20the%20authenticating%20system%20from%20SQL%20Server%20has%20a%20real%20advantage.%20(This%20is%20a%20great%20example%20of%20%3CEM%3ESeparation%20of%20Duties%3C%2FEM%3E%20btw.)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1498839906%22%20id%3D%22toc-hId-1498839903%22%3EExample%203%2C%20changing%20table%20structures%3C%2FH3%3E%0A%3CP%3EWhat%20about%20the%20following%3F%3CBR%20%2F%3ESay%20you%20want%20to%20allow%20a%20developer%20to%20add%20a%20set%20of%20new%20columns%20to%20the%20existing%20tables.%20(For%20example%2C%20for%20logging%20purposes%2C%20you%20need%20to%20include%20the%20timestamp%20of%20any%20new%20row.)%3C%2FP%3E%0A%3CP%3EThe%20minimal%20permission%20to%20change%20tables%2Fadd%20new%20columns%20is%20the%20ALTER-permission%20on%20each%20individual%20table%20(it%20cannot%20be%20done%20on%20schema-level).%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndreasWolter_1-1610818365360.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F246954iBFA9AA8D32E40B3D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AndreasWolter_1-1610818365360.png%22%20alt%3D%22AndreasWolter_1-1610818365360.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20my%20example%20you%20can%20see%20that%20adding%20new%20columns%20works%20fine%2C%20also%20dropping%20the%20table%20is%20not%20allowed.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndreasWolter_2-1610818365369.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F246955i2BD29899BD1660D7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AndreasWolter_2-1610818365369.png%22%20alt%3D%22AndreasWolter_2-1610818365369.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%3A%3C%2FP%3E%0A%3CP%3EInstead%20of%20adding%20new%20columns%20this%20user%20could%20also%20drop%20existing%20columns.%20This%20is%20covered%20under%20the%20same%20least%20permission%2Fprivilege%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22POLP_4_Alter_on_Table_Drop_Column.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F246957i90CD5E8B7E8E0ABE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22POLP_4_Alter_on_Table_Drop_Column.png%22%20alt%3D%22POLP_4_Alter_on_Table_Drop_Column.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOr%3A%20You%20want%20them%20to%20only%20create%20new%20tables%20but%20disallow%20to%20change%20existing%20tables.%20Since%20the%20required%20permissions%20for%20that%20are%3A%20CREATE%20TABLE%20on%20Database%20%2B%20ALTER%20on%20the%20schema%2C%20they%20could%20also%20drop%20tables.%20With%20permissions%20alone%20this%20cannot%20be%20solved.%20This%20is%20a%20common%20reason%20for%20the%20use%20of%20DDL%20Triggers%20as%20a%20preventative%20control.%20(I%20demonstrated%20an%20example%20of%20a%20DDL%20Trigger%20in%20this%20Blog-Article%3A%20%3CA%20href%3D%22http%3A%2F%2Fandreas-wolter.com%2Fen%2F202012-logging-schema-changes-ddl-trigger%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ELogging%20Schema-changes%20in%20a%20Database%20using%20DDL%20Trigger%3C%2FA%3E%2C%20which%20can%20easily%20be%20adjusted%20to%20prevent%20certain%20statements%20altogether%20by%20rolling%20them%20back.)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--308614557%22%20id%3D%22toc-hId--308614560%22%3EConclusion%3C%2FH3%3E%0A%3CP%3EThe%20more%20you%20dive%20into%20this%20subject%20and%20real-world%20implementation%2C%20the%20more%20you%20will%20realize%20that%20this%20apparently%20basic%20security%20principle%20is%20much%20tougher%20than%20you%20may%20initially%20have%20expected.%3C%2FP%3E%0A%3CP%3EThe%20permission%20system%20of%20SQL%20Server%20is%20very%20granular%2C%20vast%2C%20and%20continuously%20growing.%20(SQL%20Server%202019%20provides%20248%20permissions%20and%20Azure%20SQL%20Database%20exposes%20254%20permissions%20as%20of%20December%202020.)%3C%2FP%3E%0A%3CP%3EWhile%20some%20of%20the%20examples%20above%20are%20reasonable%2C%20we%20need%20to%20balance%20every%20decision%20for%20every%20new%20permission%20and%20look%20at%20it%20from%20multiple%20angles%20whenever%20a%20new%20functionality%20or%20command%20is%20implemented.%20For%20example%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWhich%20other%20commands%20and%20tasks%20are%20covered%20under%20the%20same%20permission%3F%3C%2FLI%3E%0A%3CLI%3EHow%20do%20they%20relate%20to%20the%20functionality%20at%20hand%3F%3C%2FLI%3E%0A%3CLI%3EIs%20the%20use%20of%20the%20new%20functionality%2Fcommand%20alone%20a%20common%20scenario%3F%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EHaving%20permissions%20on%20parts%20of%20Table-structures%2C%20like%20adding%20columns%20but%20not%20dropping%20them%2C%20would%20increase%20the%20complexity%20of%20the%20permission-system%20and%20hence%20the%20compromise%20to%20have%20just%20one%20ALTER-permission%20on%20table%20DDL%20was%20made.%3C%2FP%3E%0A%3CP%3EThat%20said%2C%20I%20know%20there%20are%20examples%20where%20the%20balance%20is%20not%20right%2C%20and%20SQL%20Server%20can%20be%20improved%2C%20like%20TRUNCATE%20TABLE%20requiring%20ALTER%20on%20the%20table%20as%20well%20and%20others.%3C%2FP%3E%0A%3CP%3EFeel%20free%20to%20let%20me%20know%20where%20you%20believe%20that%20POLP%20is%20seriously%20unbalanced%2C%20and%20more%20granularity%20is%20required%20to%20reach%20compliance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20securing%3C%2FP%3E%0A%3CP%3EAndreas%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--319117661%22%20id%3D%22toc-hId--319117664%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--2126572124%22%20id%3D%22toc-hId--2126572127%22%3EResources%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3EWikipedia%3A%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPrinciple_of_least_privilege%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPrinciple_of_least_privilege%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22http%3A%2F%2Fandreas-wolter.com%2Fen%2Fschema-design-for-sql-server-recommendations-for-schema-design-with-security-in-mind%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ESchema-design%20for%20SQL%20Server%3A%20recommendations%20for%20Schema%20design%20with%20security%20in%20mind%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Fsql-server%2Finstall%2Fsecurity-considerations-for-a-sql-server-installation%3Fview%3Dsql-server-ver15%23isolated_services%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESecurity%20Considerations%20-%20SQL%20Server%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsecurity%2Ffundamentals%2Fidentity-management-best-practices%23lower-exposure-of-privileged-accounts%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20identity%20%26amp%3B%20access%20security%20best%20practices%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdefender-for-identity%2Fuse-case-lateral-movement-path%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EUnderstand%20and%20use%20Lateral%20Movement%20Paths%20with%20Microsoft%20Defender%20for%20Identity%20%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fdetecting-threats-with-azure-security-center%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EDetecting%20threats%20with%20Azure%20Security%20Center%20%7C%20Azure%20Blog%20and%20Updates%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Fconnect%2Fado-net%2Fsql%2Fsql-server-security%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESQL%20Server%20security%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsecurity%2Fsurface-area-configuration%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESurface%20Area%20Configuration%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2067390%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20Principle%20of%20Least%20Privilege%20(POLP)%20in%20SQL%20Server%20and%20Azure%20SQL%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2067390%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20Security%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

(part 1 of my series of articles on security principles in Microsoft SQL Servers & Databases)

 

The Principle of Least Privilege (POLP)

The first security principle that I am going to discuss is one that most System Administrators are familiar with: the “principle of least privilege” (short: POLP). It demands that the required permissions for a task shall only grant access to the needed information or resources that a task requires. When permissions are granted, we shall grant the least privileges possible.

POLP is so crucial because initially it is the privileges that any attacker is targeting. When developing an application, using a least-privileged user account (LUA) is the first rule of engagement.

 

Note
User Account Control (UAC) in Windows is a feature that Microsoft developed to assist administrators in working with least-privileges by default and elevate to higher permission only when needed.

 

You may also know that Microsoft recommends separating service accounts. This security best practice is generally referred to as service account isolation and is related to POLP: Using distinct service accounts prevents increased privileges, which happens easily when you share an account to be used for multiple purposes and as a consequence, the privileges are merged. - This would violate the principle of least privilege.
Both POLP and service account isolation help reducing the attack surface (aka attack surface reduction).

 

- Read more on this topic here: SQL Server security - SQL Server | Microsoft Docs
and here: Surface Area Configuration - SQL Server | Microsoft Docs

 

Service account isolation also prevents lateral movement between services if an attacker gained access to one service. You see how one thing is connected to another in Security?

 

Note
Lateral movement is a common attack strategy to move from one target to the next: If the main target (for example the database server) cannot be breached into directly, attackers try to gain foothold in some other server in the system within the same network and then launch other attacks to try to get to the final goal, server by server or service by service.

 

Principle of Least Privilege in the SQL realm

Let’s look at some examples within the SQL Server engine (applying to on-prem as well as our Azure SQL-products):

 

Example 1, read-access to data

A typical example within SQL Server would be: To allow a User to only read data from a small set of tables, ideally defined by a schema-boundary, we have the SELECT-Permission, grantable at the schema- (or even table-) level. There is no need to grant SELECT at the whole database, or to grant anything other than SELECT.
In the code-snippet below we see that there are many tables in different schemas (Application, Purchasing, Sales) within the database WideWorldImporters. Instead of granting Select in the whole database, we chose to grant the user Shakti the permission at the schema scope. As long as this schema really contains only objects that Shakti needs access to, this is a best practice as it greatly reduces the management and reporting overhead compared to granting permissions at the object-level.

 

AndreasWolter_0-1610818365353.png

 

Tip

An alternative is to use stored procedures for all data access, which would allow even better control and completely hide the schema from Users.

 

That was easy, wasn’t it?

 

Example 2, creating user accounts

Unfortunately, not everything is implemented to always ensure POLP.

Let’s take another example:

You want to delegate the ability to create new Logins in SQL Server.
The minimal permission available is ALTER ANY LOGIN. Ok, so now this person can create new Logins, and maybe also Dropping them is ok.

But: With this permission comes the ability to change the password of any SQL Login (“ALTER LOGIN … WITH PASSWORD='NewPassword').

This can be an unwanted scenario as this would enable this person to essentially take over other accounts.

 

Note
This would not work if the Account were a Windows Domain or Azure Active Directory account. This is where a separation of the authenticating system from SQL Server has a real advantage. (This is a great example of Separation of Duties btw.)

 

Example 3, changing table structures

What about the following?
Say you want to allow a developer to add a set of new columns to the existing tables. (For example, for logging purposes, you need to include the timestamp of any new row.)

The minimal permission to change tables/add new columns is the ALTER-permission on each individual table (it cannot be done on schema-level).

AndreasWolter_1-1610818365360.png

 

In my example you can see that adding new columns works fine, also dropping the table is not allowed.

AndreasWolter_2-1610818365369.png

 

But:

Instead of adding new columns this user could also drop existing columns. This is covered under the same least permission/privilege:

POLP_4_Alter_on_Table_Drop_Column.png

 

Or: You want them to only create new tables but disallow to change existing tables. Since the required permissions for that are: CREATE TABLE on Database + ALTER on the schema, they could also drop tables. With permissions alone this cannot be solved. This is a common reason for the use of DDL Triggers as a preventative control. (I demonstrated an example of a DDL Trigger in this Blog-Article: Logging Schema-changes in a Database using DDL Trigger, which can easily be adjusted to prevent certain statements altogether by rolling them back.)

 

 

Conclusion

The more you dive into this subject and real-world implementation, the more you will realize that this apparently basic security principle is much tougher than you may initially have expected.

The permission system of SQL Server is very granular, vast, and continuously growing. (SQL Server 2019 provides 248 permissions and Azure SQL Database exposes 254 permissions as of December 2020.)

While some of the examples above are reasonable, we need to balance every decision for every new permission and look at it from multiple angles whenever a new functionality or command is implemented. For example:

 

  1. Which other commands and tasks are covered under the same permission?
  2. How do they relate to the functionality at hand?
  3. Is the use of the new functionality/command alone a common scenario?

Having permissions on parts of Table-structures, like adding columns but not dropping them, would increase the complexity of the permission-system and hence the compromise to have just one ALTER-permission on table DDL was made.

That said, I know there are examples where the balance is not right, and SQL Server can be improved, like TRUNCATE TABLE requiring ALTER on the table as well and others.

Feel free to let me know where you believe that POLP is seriously unbalanced, and more granularity is required to reach compliance.

 

Happy securing

Andreas

 

Resources