Bug 51609 - Linux/mac: System.Security.SecurityException: Couldn't impersonate token.
Summary: Linux/mac: System.Security.SecurityException: Couldn't impersonate token.
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 57130 ()
Depends on:
Blocks:
 
Reported: 2017-01-18 15:39 UTC by 3dcreator.pl
Modified: 2017-09-13 13:36 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 51609 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description 3dcreator.pl 2017-01-18 15:39:11 UTC
Hi there,
I'm trying to get Microsoft.Reporting to run in Docker container based on official mono image. When I try to generate a report using LocalReport class, I get a stacktrace as visible below. It goes through this class: https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Principal/WindowsImpersonationContext.cs what I believe is causing the problem, in particular constructor code:
		internal WindowsImpersonationContext (IntPtr token)
		{
			// we get a copy to control it's lifetime
			_token = DuplicateToken (token);
			if (!SetCurrentToken (token)) {
				throw new SecurityException ("Couldn't impersonate token.");
			}
			undo = false;
        }

It seems like the SetCurrentToken(token) returns false. Why can that be? In container there is only one user, namely root. I've checked that this does not work under Linux and Mac, but on mono on Windows it works like a charm.

I've googled half of the internet for solution, but no luck.




Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.Reporting.DefinitionInvalidException: The definition of the report '' is invalid. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: An unexpected error occurred in Report Processing. ---> System.TypeInitializationException: The type initializer for 'Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion' threw an exception. ---> System.Security.SecurityException: Couldn't impersonate token.\n  at System.Security.Principal.WindowsImpersonationContext..ctor (System.IntPtr token) [0x0001d] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Principal/WindowsImpersonationContext.cs:48 \n  at System.Security.Principal.WindowsIdentity.Impersonate (System.IntPtr userToken) [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Principal/WindowsIdentity.cs:183 \n  at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext+<>c__DisplayClass1.<Run>b__0 (System.Object state) [0x00002] in <44a2919bb540434ba8201154b2c66315>:0 \n  at System.Security.SecurityContext.Run (System.Security.SecurityContext securityContext, System.Threading.ContextCallback callback, System.Object state) [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/ReferenceSources/SecurityContext.cs:78 \n  at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.Run (Microsoft.ReportingServices.Diagnostics.ContextBody callback) [0x00012] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion..cctor () [0x00023] in <44a2919bb540434ba8201154b2c66315>:0 \n   --- End of inner exception stack trace ---\n  at Microsoft.ReportingServices.ReportIntermediateFormat.Report..ctor (System.Int32 id, System.Int32 idForReportItems) [0x00028] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.ReadReport (Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection) [0x0000c] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.Phase1 (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] definition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection, System.String& description, System.String& language, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection& dataSources, System.Boolean& hasExternalImages, System.Boolean& hasHyperlinks) [0x0015f] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportPublishing.ReportPublishing.CreateIntermediateFormat (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] definition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, Microsoft.ReportingServices.ReportProcessing.PublishingErrorContext errorContext, System.AppDomain compilationTempAppDomain, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection, System.String& description, System.String& language, Microsoft.ReportingServices.ReportProcessing.ParameterInfoCollection& parameters, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection& dataSources, Microsoft.ReportingServices.ReportProcessing.UserLocationFlags& userReferenceLocation, System.Collections.ArrayList& dataSetsName, System.Boolean& hasExternalImages, System.Boolean& hasHyperlinks) [0x00040] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CompileOdpReport (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] reportDefinition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, Microsoft.ReportingServices.ReportProcessing.PublishingErrorContext errorContext, System.AppDomain compilationTempAppDomain, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection, System.String& reportDescription, System.String& reportLanguage, Microsoft.ReportingServices.ReportProcessing.ParameterInfoCollection& parameters, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection& dataSources, Microsoft.ReportingServices.ReportProcessing.UserLocationFlags& userReferenceLocation, System.Collections.ArrayList& dataSetsName, System.Boolean& hasExternalImages, System.Boolean& hasHyperlinks) [0x00006] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] reportDefinition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkFactory, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, System.AppDomain compilationTempAppDomain, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.ReportProcessing.ReportProcessingFlags processingFlags, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection) [0x0004b] in <44a2919bb540434ba8201154b2c66315>:0 \n   --- End of inner exception stack trace ---\n  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] reportDefinition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkFactory, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, Microsoft.ReportingServices.DataExtensions.DataSourceInfoCollection originalDataSources, System.AppDomain compilationTempAppDomain, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.ReportProcessing.ReportProcessingFlags processingFlags, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection) [0x00189] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext reportContext, System.Byte[] reportDefinition, Microsoft.ReportingServices.ReportProcessing.IChunkFactory createChunkFactory, Microsoft.ReportingServices.ReportProcessing.ReportProcessing+CheckSharedDataSource checkDataSourceCallback, System.AppDomain compilationTempAppDomain, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.ReportProcessing.ReportProcessingFlags processingFlags, Microsoft.ReportingServices.Diagnostics.IDataProtection dataProtection) [0x00000] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.ReportCompiler.CompileReport (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext context, System.Byte[] reportDefinition, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.Library.ControlSnapshot& snapshot) [0x0002e] in <44a2919bb540434ba8201154b2c66315>:0 \n   --- End of inner exception stack trace ---\n  at Microsoft.Reporting.ReportCompiler.CompileReport (Microsoft.ReportingServices.Diagnostics.ICatalogItemContext context, System.Byte[] reportDefinition, System.Boolean generateExpressionHostWithRefusedPermissions, Microsoft.ReportingServices.Library.ControlSnapshot& snapshot) [0x00052] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.PreviewStore+StoredReport.EnsureCompiled (Microsoft.ReportingServices.Diagnostics.CatalogItemContextBase itemContext) [0x00016] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.PreviewStore.GetCompiledReport (Microsoft.ReportingServices.Diagnostics.CatalogItemContextBase context, System.Boolean rebuild, System.Byte[]& reportDefinition, Microsoft.ReportingServices.Library.ControlSnapshot& snapshot) [0x000ae] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.PreviewStore.GetCompiledReport (Microsoft.ReportingServices.Diagnostics.CatalogItemContextBase context, System.Boolean rebuild, Microsoft.ReportingServices.Library.ControlSnapshot& snapshot) [0x00000] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.LocalService.GetCompiledReport (Microsoft.ReportingServices.Diagnostics.CatalogItemContextBase itemContext, System.Boolean rebuild, Microsoft.ReportingServices.Library.ControlSnapshot& snapshot) [0x00000] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.LocalService.CompileReport (Microsoft.ReportingServices.Diagnostics.CatalogItemContextBase itemContext, System.Boolean rebuild) [0x00000] in <44a2919bb540434ba8201154b2c66315>:0 \n  at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession () [0x00020] in <1fd7ff494d42451fb1061687654b7e13>:0 \n   --- End of inner exception stack trace ---\n  at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession () [0x00038] in <1fd7ff494d42451fb1061687654b7e13>:0 \n  at Microsoft.Reporting.WebForms.LocalReport.InternalRender (System.String format, System.Boolean allowInternalRenderers, System.String deviceInfo, Microsoft.Reporting.WebForms.PageCountMode pageCountMode, Microsoft.ReportingServices.Interfaces.CreateAndRegisterStream createStreamCallback, Microsoft.Reporting.WebForms.Warning[]& warnings) [0x00031] in <1fd7ff494d42451fb1061687654b7e13>:0 \n  at Microsoft.Reporting.WebForms.LocalReport.InternalRender (System.String format, System.Boolean allowInternalRenderers, System.String deviceInfo, Microsoft.Reporting.WebForms.PageCountMode pageCountMode, System.String& mimeType, System.String& encoding, System.String& fileNameExtension, System.String[]& streams, Microsoft.Reporting.WebForms.Warning[]& warnings) [0x00013] in <1fd7ff494d42451fb1061687654b7e13>:0 \n  at Microsoft.Reporting.WebForms.LocalReport.Render (System.String format, System.String deviceInfo, Microsoft.Reporting.WebForms.PageCountMode pageCountMode, System.String& mimeType, System.String& encoding, System.String& fileNameExtension, System.String[]& streams, Microsoft.Reporting.WebForms.Warning[]& warnings) [0x00000] in <1fd7ff494d42451fb1061687654b7e13>:0 \n  at Microsoft.Reporting.WebForms.Report.Render (System.String format, System.String deviceInfo, System.String& mimeType, System.String& encoding, System.String& fileNameExtension, System.String[]& streams, Microsoft.Reporting.WebForms.Warning[]& warnings) [0x00000] in <1fd7ff494d42451fb1061687654b7e13>:0 \n  at Reporting.Generator.ReportOperator.CreateReport (Reporting.Generator.Model.ReportCreationInfo creationInfo) [0x0008d] in .....
Comment 1 Marek Safar 2017-09-13 13:36:10 UTC
*** Bug 57130 has been marked as a duplicate of this bug. ***