Permission denied on Cloud9 Ubuntu VM

On Ubuntu Linux 14.04.3 LTS, on Cloud9 ( …

I added ServiceStack to a working core project on a Cloud9 Ubuntu VM, and am getting the following error:

Hosting environment: Production
Content root path: /home/ubuntu/workspace/cms
Now listening on:
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Unhandled Exception: System.UnauthorizedAccessException: Access to the path '/sys/class/net/lo/operstate' is denied. ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.IO.UnixFileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported)   at System.IO.UnixFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)   at System.IO.UnixFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding)
   at System.IO.File.ReadAllText(String path)
   at System.Net.NetworkInformation.LinuxNetworkInterface.GetOperationalStatus(String name)
   at System.Net.NetworkInformation.LinuxNetworkInterface..ctor(String name)
   at System.Net.NetworkInformation.LinuxNetworkInterface.GetOrCreate(Dictionary`2 interfaces, String name)
   at System.Net.NetworkInformation.LinuxNetworkInterface.<>c__DisplayClass5_0.<GetLinuxNetworkInterfaces>b__2(String name, LinkLayerAddressInfo* llAddr)   at Interop.Sys.EnumerateInterfaceAddresses(IPv4AddressDiscoveredCallback ipv4Found, IPv6AddressDiscoveredCallback ipv6Found, LinkLayerAddressDiscoveredCallback linkLayerFound)
   at System.Net.NetworkInformation.LinuxNetworkInterface.GetLinuxNetworkInterfaces()
   at ServiceStack.IPAddressExtensions.GetAllNetworkInterfaceIpv4Addresses()

I just created an Ubuntu VM (same OS version) on my local machine, and did not have the same problem, I was able to run the app just fine (which is basically just a few lines for an empty AppHost and adding 1 line to the Startup.cs file), so looks like it’s a Cloud 9 permission thing …

I’m wondering then if there are special permissions that are required to run ServiceStack … I’d really like to be able to run ServiceStack on Cloud9 … Thought I’d ask here first. I see the same stacktrace here, but not sure if it’s related.

This looks like the permission issue is due to a locked down Cloud9 VM.

There aren’t any special permissions required to run ServiceStack, it’s just a Web App calling published .NET Framework APIs, it doesn’t use any unsafe code and there’s no longer any Code Access Security in .NET Core to worry about. This error is just the result of calling .NET’s NetworkInterface.GetAllNetworkInterfaces() API which is what throws this Exception. We can wrap it try/catch and ignore it, but it will prevent the InternalNetworkAccess in Restricting Services from working.

Perhaps this issue needs to be bubbled up to the CoreFx team so they’re aware of it.

hmmm weird the only place this is getting called in ServiceStack is already being handled, so this shouldn’t have caused ServiceStack to stop working. Is ServiceStack failing to start completely, i.e. doesn’t respond to any HTTP Requests?

Do you have any more information on the StackTrace, i.e. where GetAllNetworkInterfaceIpv4Addresses() is being called from.

1 Like

Error seems to occur on first HTTP request that hits ServiceStack in the pipeline. I don’t get why the Exception isn’t caught internally in the catch statement inside ServiceStack (as you mention). I see that @xplicit might be trying to track this down

It’s a .NET Core serious bug, It cannot handle exception when it raised inside this method. (Also it can’t get NetworkInterfaces info, but this could be skipped if it was handle exception). I tried to find a workaround with enabling/disabling interfaces, changing permissions, etc, but nothing helps. Currently I see only one way to avoid this situation while it won’t fixed in .NET Core: when OS is linux try to read content of the file File.ReadAllText("/sys/devices/virtual/net/lo/operstate"); if it throws exception then do not call GetAllNetworkInterfaces()

1 Like

Yeah ok looks like it’s a serious issue that needs to address in the CoreFx libraries, we’ll have to wait to see how MS addresses it before hard coding a solution in the code-base. In the meantime I’ve added a flag you can disable to prevent accessing the problematic NetworkInformation APIs:

IPAddressExtensions.AccessNetworkInterface = false;

There seems to be some movements on the issue, so I’ll wait till they reach a conclusion before pushing out another .NET Core release.


@mjc This should be resolved in the next release of .NET Core, in the meantime you can use IPAddressExtensions.AccessNetworkInterface = false; which is now available on NuGet if you do a nuget restore

1 Like

Awesome, that flag will work nicely for now! and I did confirm that I can now run the ServiceStack API on a Cloud9 Ubuntu VM, sweet !! I’ve been waiting for this day :smile:

I’ll keep following that issue in the corefx repo too, pretty interesting.

@mjc Awesome glad to hear it Matt! We’re very interested in your progress with .NET Core, please let us know if you run into any more issues or if you’ve got something public you can show us - we love to see more examples of ServiceStack running on .NET Core :slight_smile: