%3CLINGO-SUB%20id%3D%22lingo-sub-1491930%22%20slang%3D%22en-US%22%3EGrant%20user%20permissions%20for%20ad-hoc%20analytic%20using%20OPENROWSET%20in%20SQL%20endpoint%20of%20Synapse%20Workspace%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1491930%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Synapse%20Analytics%20Workspace%20enables%20you%20to%20read%20the%20files%20from%20Azure%20Data%20Lake%20storage%20using%20OPENROWSET(BULK%20%3CFILE%20url%3D%22%22%3E).%20In%20this%20article%20you%20will%20see%20how%20to%20grant%20minimal%20permission%20to%20the%20users%20who%20need%20to%20analyze%20files%20with%20OPENROWSET(BULK)%20function.%3C%2FFILE%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20you%20try%20Azure%20Synapse%20workspace%2C%20you%20usually%20start%20with%20full%20permissions%20(for%20example%20as%20database%20owner).%20Once%20you%20need%20to%20let%20other%20users%20access%20the%20files%20on%20Data%20Lake%2C%20you%20probably%20think%20that%20is%20the%20minimal%20permission%20that%20you%20need%20to%20assign%20to%20user%20to%20let%20them%20just%20do%20ad-hoc%20analysis%20without%20any%20other%20permissions.%3C%2FP%3E%0A%3CP%3EIn%20this%20post%20you%20will%20learn%20how%20to%20configure%20minimal%20permission%20to%20needed%20to%20analyze%20the%20files%20on%20Azure%20storage.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1322228647%22%20id%3D%22toc-hId--1322228647%22%3ECreating%20server%20principals%3C%2FH2%3E%0A%3CP%3ESQL%20endpoint%20in%20Synapse%20workspace%20uses%20standard%20T-SQL%20syntax%20to%20create%20principals%20who%20can%20access%20your%20data.%20The%20following%20statement%20creates%20a%20new%20login%20with%20username%20testprincipal%20and%20password%20VeryStrongAndSecurePassword1234!!!%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Ecreate%26nbsp%3Blogin%26nbsp%3Btestprincipal%0Awith%26nbsp%3Bpassword%26nbsp%3B%3D%26nbsp%3B'VeryStrongAndSecurePassword1234!!!'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20this%20T-SQL%20statement%20you%20can%20create%20new%20principals%20that%20are%20assigned%20to%20the%20public%20role.%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20see%20what%20we%20can%20do%20with%20this%20principal.%20If%20we%20login%20using%20this%20username%2Fpassword%20we%20can%20try%20to%20run%20the%20following%20queries%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Eselect%26nbsp%3Bname%26nbsp%3Bfrom%26nbsp%3B%26nbsp%3Bsys.databases%0A--%26nbsp%3Bsuccess%26nbsp%3B%0A%0Ause%26nbsp%3BSampleDB%0A--Msg%26nbsp%3B916%2C%26nbsp%3BLevel%26nbsp%3B14%2C%26nbsp%3BState%26nbsp%3B2%2C%26nbsp%3BLine%26nbsp%3B1%0A--The%26nbsp%3Bserver%26nbsp%3Bprincipal%26nbsp%3B%22testprincipal%22%26nbsp%3Bis%26nbsp%3Bnot%26nbsp%3Bable%26nbsp%3Bto%26nbsp%3Baccess%26nbsp%3Bthe%26nbsp%3Bdatabase%26nbsp%3B%22SampleDB%22%26nbsp%3Bunder%26nbsp%3Bthe%26nbsp%3Bcurrent%26nbsp%3Bsecurity%26nbsp%3Bcontext.%0A%0Aselect%26nbsp%3Btop%26nbsp%3B10%26nbsp%3B%26nbsp%3B*%0Afrom%26nbsp%3Bopenrowset(bulk%26nbsp%3B'https%3A%2F%2Fpandemicdatalake.blob.core.windows.net%2Fpublic%2Fcurated%2Fcovid-19%2Fecdc_cases%2Flatest%2Fecdc_cases.parquet'%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bformat%3D'parquet')%26nbsp%3Bas%26nbsp%3Ba%0A--%26nbsp%3BSuccess%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20default%2C%20a%20new%20user%20can%20see%20all%20databases%2C%20execute%20OPENROWSET%20to%20query%20files%20on%20Azure%20Data%20Lake%20storage%2C%20but%20cannot%20access%20other%20databases%20or%20create%20objects.%20This%20can%20be%20verified%20using%20the%20following%20function%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JovanPop_0-1593173983885.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201295i7713592ADC81BFD3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JovanPop_0-1593173983885.png%22%20alt%3D%22JovanPop_0-1593173983885.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENew%20login%26nbsp%3B%20is%20in%20the%20public%20role%20and%20has%20the%20permissions%20to%20view%20any%20database%20and%20to%20run%20ad-hoc%20query%20using%20OPENROWSET%2C%20but%20no%20other%20permissions.%3C%2FP%3E%0A%3CP%3EThis%20version%20of%20OPENROWSET%20enables%20principals%20to%20public%20access%20storage%20or%20in%20case%20of%20Azure%20AD%20principal%20to%20access%20files%20on%20the%20storage%20where%20storage%20admin%20granted%20Storage%20Blob%20Data%20Reader%20RBAC%20role%20to%20Azure%20AD%20user%20who%20access.%20If%20you%20need%20more%20fine%20grained%20impersonation%20mechanism%2C%20you%20should%20create%20data%20sources%20and%20protect%20them%20with%20credentials%20in%20databases.%20The%20following%20section%20will%20describe%20how%20to%20enable%20principal%20access%20objects%20in%20databases.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1165284186%22%20id%3D%22toc-hId-1165284186%22%3EHow%20to%20access%20protected%20storage%20using%20credential%3C%2FH2%3E%0A%3CP%3EIf%20you%20need%20to%20allow%20the%20principals%20to%20access%20some%20non-public%20DataLake%20storage%2C%20or%20storage%20that%20cannot%20be%20accessed%20using%20Azure%20AD%20passthrough%2C%20you%20can%20create%20server-level%20credentials%20that%20matches%20storage%20URL%20used%20in%20OPENROWSET%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20CREDENTIAL%20%5Bhttps%3A%2F%2Fpandemicdatalake.blob.core.windows.net%5D%0AWITH%20%20%20%20IDENTITY%3D'SHARED%20ACCESS%20SIGNATURE'%2C%0A%20%20%20%20%20%20%20%20SECRET%20%3D%20'sv%3D2018-03-28%26amp%3Bss%3Dbfqt%26amp%3Bsrt%3Dsco%26amp%3Bsp%3Drwdlacup%26amp%3Bse%3D2019-04-18T20%3A42%3A12Z%26amp%3Bst%3D2019-04-18T12%3A42%3A12Z%26amp%3Bspr%3Dhttps%26amp%3Bsig%3DlQHczNvrk1KoYLCpFdSsMANd0ef9BrIPBNJ3VYEIq78%253D'%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20case%2C%20SQL%20principal%20need%20to%20have%20GRANT%20REFERENCES%20permission%20for%20this%20credential%20in%20order%20to%20use%20it%26nbsp%3B%20to%20access%20storage%20using%20Shared%20access%20signature%20defined%20in%20the%20credential%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Egrant%26nbsp%3Breferences%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bon%26nbsp%3Bcredential%3A%3A%5Bhttps%3A%2F%2Fpandemicdatalake.blob.core.windows.net%5D%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bto%26nbsp%3Btestprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFind%20more%20information%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Fsql%2Fdevelop-storage-files-storage-access-control%3Ftabs%3Dshared-access-signature%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESynapse%20analytics%20documentation.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--642170277%22%20id%3D%22toc-hId--642170277%22%3EConfiguring%20database%20permissions%3C%2FH2%3E%0A%3CP%3ELet%E2%80%99s%20enable%20user%20to%20access%20database.%20In%20the%20context%20of%20some%20database%20such%20as%20SampleDB%20execute%20the%20following%20statement%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Ecreate%26nbsp%3Buser%26nbsp%3Btestprincipal%26nbsp%3Bfor%26nbsp%3Blogin%26nbsp%3Btestprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20statement%20created%20a%20database%20user%20that%20will%20access%20current%20database%20using%20the%20login%20defined%20in%20the%20previous%20script.%20This%20principal%20can%20now%20connect%20to%20SampleDB%20database%20(NOTE%3A%20use%20this%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FSynapse%2Fblob%2Fmaster%2FSQL%2FSamples%2FLdwSample%2FSampleDB.sql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%20data-linktype%3D%22external%22%3Esetup%20script%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20initialize%20the%20objects%20in%20this%20database)%20%2C%20can%20still%20use%20OPENROWSET%20with%20absolute%20URL%20to%20read%20files%20from%20storage%2C%20and%20it%20can%20also%20use%20OPENROWSET%20that%20references%20some%20public%20data%20source%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%26nbsp%3BTOP%26nbsp%3B10%26nbsp%3B*%0AFROM%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BOPENROWSET(%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BBULK%26nbsp%3B'puYear%3D*%2FpuMonth%3D*%2F*.parquet'%2C%0A--%26nbsp%3BYellowTaxi%26nbsp%3Bis%26nbsp%3Ba%20data%26nbsp%3Bsource%26nbsp%3Bthat%20references%20a%26nbsp%3Bpublic%26nbsp%3Blocation%26nbsp%3B(without%26nbsp%3Bcredential)%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BDATA_SOURCE%26nbsp%3B%3D%26nbsp%3B'YellowTaxi'%2C%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BFORMAT%3D'PARQUET'%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B)%26nbsp%3BAS%26nbsp%3Bnyc%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20case%2C%20data%20source%20doesn%E2%80%99t%20have%20credential%20and%20references%20public%20location%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20EXTERNAL%20DATA%20SOURCE%20YellowTaxi%0AWITH%20(%20LOCATION%20%3D%20'https%3A%2F%2Fazureopendatastorage.blob.core.windows.net%2Fnyctlc%2Fyellow%2F')%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20this%20principal%20cannot%20read%20some%20files%20using%20a%20pre-defined%20data%20source%20that%20is%20protected%20with%20credential%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20EXTERNAL%20DATA%20SOURCE%20SqlOnDemandDemo%20WITH%20(%0A%20%20%20%20LOCATION%20%3D%20'https%3A%2F%2Fsqlondemandstorage.blob.core.windows.net'%2C%0A%20%20%20%20CREDENTIAL%20%3D%20sqlondemand%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20some%20principals%20try%20to%20read%20the%20files%20from%20this%20storage%2C%20they%20will%20get%20the%20following%20error%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JovanPop_1-1593173983896.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201296iDAA555D13179168A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JovanPop_1-1593173983896.png%22%20alt%3D%22JovanPop_1-1593173983896.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20issue%20here%20is%20that%20data%20source%20uses%20credential%20to%20access%20storage%2C%20and%20the%20current%20user%20cannot%20reference%20this%20credential.%3C%2FP%3E%0A%3CP%3EIn%20order%20to%20access%20the%20files%20via%20credential-protected%20data%20source%2C%20the%20principal%20needs%20to%20have%20%3CSTRONG%3Ereferences%20permission%3C%2FSTRONG%3E%20on%20the%20underlying%20database%20scoped%20credential%20(in%20this%20case%20%3CSTRONG%3Esqlondemand%3C%2FSTRONG%3E%20credential)%20that%20is%20used%20in%20data%20source%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Egrant%26nbsp%3Breferences%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bon%26nbsp%3Bdatabase%26nbsp%3Bscoped%26nbsp%3Bcredential%3A%3Asqlondemand%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bto%26nbsp%3Btestprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20the%20user%20who%20uses%20OPENROWSET%20with%20data%20source%20still%20need%20to%20have%20ADMINISTER%20BULK%20OPERATIONS%20permission.%20If%20you%20deny%20this%20permission%2C%20the%20principal%20cannot%20use%20OPENROWSET%20anymore%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20execute%20from%20master%20database%20context%3A%0Adeny%26nbsp%3BADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%26nbsp%3Bto%26nbsp%3Btestprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20following%20section%20you%20will%20see%20how%20to%20use%20this%20role%20to%20enable%20principals%20to%20do%20ad-hoc%20analysis.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1845342556%22%20id%3D%22toc-hId-1845342556%22%3EAd-hoc%20analyst%20role%3C%2FH2%3E%0A%3CP%3EIn%20Synapse%20SQL%20endpoint%20you%20have%20special%20permissions%20that%20enable%20principals%20to%20read%20files%20from%20storage%20using%20OPENROWSET%3A%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EADMINISTER%20BULK%20OPERATIONS%20that%20enables%20principal%20to%20execute%20OPENROWSET%20from%20any%20database.%3C%2FLI%3E%0A%3CLI%3EADMINISTER%20DATABASE%20BULK%20OPERATIONS%26nbsp%3Bthat%20enables%20principal%20to%20execute%20OPENROWSET%20from%20the%20database(s)%20where%20he%20has%20this%20permission.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EADMINISTER%20BULK%20OPERATIONS%20permission%20is%20automatically%20assigned%20to%20public%20role%2C%20so%20any%20new%20principal%20will%20be%20able%20to%20run%20OPENROWSET%20from%20any%20database%20on%20the%20endpoint.%3C%2FP%3E%0A%3CP%3EIn%20the%20previous%20example%20with%20revoking%26nbsp%3BADMINISTER%20BULK%20OPERATIONS%20you%20might%20notice%20that%20I%20used%20DENY%20and%20not%20REVOKE.%20You%20need%20to%20explicitly%20DENY%20permissions%20and%20you%20cannot%20just%20REVOKE%20this%20permission%20like%20in%20this%20example%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Erevoke%26nbsp%3BADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%26nbsp%3Bto%26nbsp%3Btestprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20try%20to%20revoke%20this%20permission%2C%20testprincipal%20will%20still%20be%20able%20to%20execute%20OPENROWSET%20(you%20can%20confirm%20this%20using%20%3CSTRONG%3Efn_my_permissions(NULL%2C%26nbsp%3B'SERVER')%3C%2FSTRONG%3E%20function)%3C%2FP%3E%0A%3CP%3EThis%20might%20confuse%20you%2C%20but%20the%20reason%20is%20that%20ADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%26nbsp%3Bis%20not%20initially%20granted%20to%20testprincipal.%20testprincipal%20belongs%20to%20the%20%3CSTRONG%3Epublic%3C%2FSTRONG%3E%20role%2C%20and%20in%20synapse%20SQL%20endpoint%2C%20public%20role%20has%20ADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%20permission%20by%20default.%20If%20you%20want%20to%20revoke%20this%20permission%2C%20you%20would%20need%20to%20revoke%20it%20from%20the%20public%20role%20using%20this%20statement%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Erevoke%26nbsp%3BADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%26nbsp%3Bto%26nbsp%3Bpublic%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20will%20have%20just%20the%20users%20who%20will%20analyze%20files%20in%20ad-hoc%20manner%2C%20you%20can%20leave%20this%20permission%20to%20public%20role.%20Otherwise%20it%20might%20be%20good%20to%20revoke%20it%20and%20create%20separate%20data%20analyst%20role%20that%20will%20have%20this%20permission.%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20have%20more%20granular%20control%2C%20you%20can%20create%20database%20users%20in%20databases%20and%20explicitly%20define%26nbsp%3BADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%20only%20in%20some%20databases.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Egrant%20ADMINISTER%20DATABASE%20BULK%20OPERATIONS%20to%20testprincipal%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20fine%20grained%20permission%20will%20enable%20you%20to%20ensure%20that%20principal%20will%20ad-hoc%20analysis%20of%20external%20storage%20only%20through%20the%20databases%20that%20you%20defined.%20This%20might%20be%20very%20important%20if%20you%20start%20creating%20external%20tables%20on%20storage%20and%20you%20don't%20want%20to%20have%20a%20user%20without%20permission%20to%20read%20data%20from%20external%20table%20to%20bypass%20this%20restriction%20using%20global%26nbsp%3BADMINISTER%26nbsp%3BBULK%26nbsp%3BOPERATIONS%20permission.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFind%20more%20information%20about%20the%20security%20model%20in%20Synapse%20SQL%20in%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fsynapse-analytics%2Fsql%2Fdevelop-storage-files-storage-access-control%3Ftabs%3Duser-identity%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edocumentation%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1491930%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20configure%20minimal%20permissions%20required%20for%20the%20users%20that%20will%20analyze%20DataLake%20using%20Serverless%20endpoint%20in%20Synapse%20Analytics%20workspace.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1491930%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESynapse%20Administration%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20Security%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20SQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Azure Synapse Analytics Workspace enables you to read the files from Azure Data Lake storage using OPENROWSET(BULK <file url>). In this article you will see how to grant minimal permission to the users who need to analyze files with OPENROWSET(BULK) function.

 

When you try Azure Synapse workspace, you usually start with full permissions (for example as database owner). Once you need to let other users access the files on Data Lake, you probably think that is the minimal permission that you need to assign to user to let them just do ad-hoc analysis without any other permissions.

In this post you will learn how to configure minimal permission to needed to analyze the files on Azure storage.

 

Creating server principals

SQL endpoint in Synapse workspace uses standard T-SQL syntax to create principals who can access your data. The following statement creates a new login with username testprincipal and password VeryStrongAndSecurePassword1234!!!:

 

create login testprincipal
with password = 'VeryStrongAndSecurePassword1234!!!';

 

Using this T-SQL statement you can create new principals that are assigned to the public role.

Let’s see what we can do with this principal. If we login using this username/password we can try to run the following queries:

 

select name from  sys.databases
-- success 

use SampleDB
--Msg 916, Level 14, State 2, Line 1
--The server principal "testprincipal" is not able to access the database "SampleDB" under the current security context.

select top 10  *
from openrowset(bulk 'https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/latest/ecdc_cases.parquet',
                format='parquet') as a
-- Success

 

By default, a new user can see all databases, execute OPENROWSET to query files on Azure Data Lake storage, but cannot access other databases or create objects. This can be verified using the following function:

JovanPop_0-1593173983885.png

New login  is in the public role and has the permissions to view any database and to run ad-hoc query using OPENROWSET, but no other permissions.

This version of OPENROWSET enables principals to public access storage or in case of Azure AD principal to access files on the storage where storage admin granted Storage Blob Data Reader RBAC role to Azure AD user who access. If you need more fine grained impersonation mechanism, you should create data sources and protect them with credentials in databases. The following section will describe how to enable principal access objects in databases.

 

How to access protected storage using credential

If you need to allow the principals to access some non-public DataLake storage, or storage that cannot be accessed using Azure AD passthrough, you can create server-level credentials that matches storage URL used in OPENROWSET:

 

 

CREATE CREDENTIAL [https://pandemicdatalake.blob.core.windows.net]
WITH    IDENTITY='SHARED ACCESS SIGNATURE',
        SECRET = 'sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-04-18T20:42:12Z&st=2019-04-18T12:42:12Z&spr=https&sig=lQHczNvrk1KoYLCpFdSsMANd0ef9BrIPBNJ3VYEIq78%3D';

 

In this case, SQL principal need to have GRANT REFERENCES permission for this credential in order to use it  to access storage using Shared access signature defined in the credential:

 

grant references 
    on credential::[https://pandemicdatalake.blob.core.windows.net]
    to testprincipal;

 

Find more information in Synapse analytics documentation.

 

Configuring database permissions

Let’s enable user to access database. In the context of some database such as SampleDB execute the following statement:

 

create user testprincipal for login testprincipal;

 

This statement created a database user that will access current database using the login defined in the previous script. This principal can now connect to SampleDB database (NOTE: use this setup script to initialize the objects in this database) , can still use OPENROWSET with absolute URL to read files from storage, and it can also use OPENROWSET that references some public data source:

 

SELECT TOP 10 *
FROM
    OPENROWSET(
        BULK 'puYear=*/puMonth=*/*.parquet',
-- YellowTaxi is a data source that references a public location (without credential)
        DATA_SOURCE = 'YellowTaxi', 
        FORMAT='PARQUET'
    ) AS nyc

 

In this case, data source doesn’t have credential and references public location:

 

CREATE EXTERNAL DATA SOURCE YellowTaxi
WITH ( LOCATION = 'https://azureopendatastorage.blob.core.windows.net/nyctlc/yellow/')

 

However, this principal cannot read some files using a pre-defined data source that is protected with credential:

 

CREATE EXTERNAL DATA SOURCE SqlOnDemandDemo WITH (
    LOCATION = 'https://sqlondemandstorage.blob.core.windows.net',
    CREDENTIAL = sqlondemand
);

 

If some principals try to read the files from this storage, they will get the following error:

JovanPop_1-1593173983896.png

The issue here is that data source uses credential to access storage, and the current user cannot reference this credential.

In order to access the files via credential-protected data source, the principal needs to have references permission on the underlying database scoped credential (in this case sqlondemand credential) that is used in data source:

 

grant references 
    on database scoped credential::sqlondemand
    to testprincipal;

 

Note that the user who uses OPENROWSET with data source still need to have ADMINISTER BULK OPERATIONS permission. If you deny this permission, the principal cannot use OPENROWSET anymore:

 

-- execute from master database context:
deny ADMINISTER BULK OPERATIONS to testprincipal;

 

In the following section you will see how to use this role to enable principals to do ad-hoc analysis.

 

Ad-hoc analyst role

In Synapse SQL endpoint you have special permissions that enable principals to read files from storage using OPENROWSET: 

  • ADMINISTER BULK OPERATIONS that enables principal to execute OPENROWSET from any database.
  • ADMINISTER DATABASE BULK OPERATIONS that enables principal to execute OPENROWSET from the database(s) where he has this permission.

 

ADMINISTER BULK OPERATIONS permission is automatically assigned to public role, so any new principal will be able to run OPENROWSET from any database on the endpoint.

In the previous example with revoking ADMINISTER BULK OPERATIONS you might notice that I used DENY and not REVOKE. You need to explicitly DENY permissions and you cannot just REVOKE this permission like in this example:

 

revoke ADMINISTER BULK OPERATIONS to testprincipal;

 

If you try to revoke this permission, testprincipal will still be able to execute OPENROWSET (you can confirm this using fn_my_permissions(NULL, 'SERVER') function)

This might confuse you, but the reason is that ADMINISTER BULK OPERATIONS is not initially granted to testprincipal. testprincipal belongs to the public role, and in synapse SQL endpoint, public role has ADMINISTER BULK OPERATIONS permission by default. If you want to revoke this permission, you would need to revoke it from the public role using this statement:

 

revoke ADMINISTER BULK OPERATIONS to public;

 

If you will have just the users who will analyze files in ad-hoc manner, you can leave this permission to public role. Otherwise it might be good to revoke it and create separate data analyst role that will have this permission.

If you want to have more granular control, you can create database users in databases and explicitly define ADMINISTER BULK OPERATIONS only in some databases. 

 

grant ADMINISTER DATABASE BULK OPERATIONS to testprincipal;

 

This fine grained permission will enable you to ensure that principal will ad-hoc analysis of external storage only through the databases that you defined. This might be very important if you start creating external tables on storage and you don't want to have a user without permission to read data from external table to bypass this restriction using global ADMINISTER BULK OPERATIONS permission.

 

Find more information about the security model in Synapse SQL in documentation.