Skip to content

Azure.EventHubs emulator crashes on startup on Linux due to permission issues #5326

@radical

Description

@radical

This can be seen when running playground/AspireEventHub/EventHubs.AppHost, and the dashboard shows the eventhubns having crashed with:

Unhandled exception. System.UnauthorizedAccessException: Access to the path '/Eventhubs_Emulator/ConfigFiles/Config.json' is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.<Load>g__OpenRead|6_0(IFileInfo fileInfo)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Microsoft.Extensions.Hosting.HostBuilder.InitializeAppConfiguration()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at a.a.aaR.A(String[])
   at a.a.aaR.<Main>(String[])

I was able to reproduce this in a test in Aspire.Hosting.Azure.Tests with:

    {
        using var builder = TestDistributedApplicationBuilder.Create().WithTestAndResourceLogging(testOutput);
        var blob = builder.AddAzureStorage("ehstorage")
            .RunAsEmulator()
            .AddBlobs("checkpoints");
        var eventHubs = builder.AddAzureEventHubs("eh").RunAsEmulator().AddEventHub("hub");
        using var app = builder.Build();

        CancellationTokenSource cts = new();
        var t = app.RunAsync();

        var hb = Host.CreateApplicationBuilder();
        hb.AddAzureEventHubConsumerClient("eventhubns", settings =>
        {
            settings.EventHubName = "hub";
        });
        using var host = hb.Build();
        var t2 = host.RunAsync();
        
        await Task.Delay(500_000);
        await app.StopAsync();
    }

Here the file is created by aspire:

.WithAnnotation(new ContainerMountAnnotation(
Path.GetTempFileName(),
AzureEventHubsEmulatorResource.EmulatorConfigJsonPath,
ContainerMountType.BindMount,
isReadOnly: false));

var configFileMount = emulatorResource.Annotations.OfType<ContainerMountAnnotation>().Single(v => v.Target == AzureEventHubsEmulatorResource.EmulatorConfigJsonPath);
using var stream = new FileStream(configFileMount.Source!, FileMode.Create);
using var writer = new Utf8JsonWriter(stream);

cc @eerhardt @sebastienros another one of the file permissions in container when running from a Linux host.

Metadata

Metadata

Assignees

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions