【问题标题】:Aspnetcode run with non-root user in linuxAspnetcode 在 linux 中以非 root 用户运行
【发布时间】:2017-08-11 21:59:53
【问题描述】:

我正在尝试使用非 root 用户在 docker 映像(从 microsoft/aspnetcore 继承)中运行一个非常简单的 hello world aspnetcore 应用程序,但出现此错误:

暴击:Microsoft.AspNetCore.Server.Kestrel[0] 无法启动 Kestrel。 System.AggregateException:发生一个或多个错误。 (错误 -13 EACCES 权限被拒绝)---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: 错误 -13 EACCES 权限被拒绝 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 状态码)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle 句柄,SockAddr & addr,Int32 标志)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress 地址)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket() 在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.b__8_0(对象 状态) --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.d__12.MoveNext() --- 内部异常堆栈跟踪结束 --- 在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) 在 System.Threading.Tasks.Task.Wait(Int32 毫秒超时, CancellationToken 取消令牌)在 Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(服务器地址 地址)在 Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 应用) --->(内部异常 #0)Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: 错误 -13 EACCES 权限被拒绝 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 状态码)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle 句柄,SockAddr & addr,Int32 标志)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress 地址)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket() 在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.b__8_0(对象 状态) --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.d__12.MoveNext()

似乎没有root权限就无法运行aspnetcore,并且在某些安全策略非常受限的场景中,root用户是不允许运行docker镜像的主进程的。

有没有办法以非root用户在linux中运行aspnetcore应用程序?

Sudo 选项无效,因为相同的安全策略。

谢谢,

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

    最后的问题是我试图使用端口 80 来绑定我的应用程序。如果你使用更高的端口,即5000。权限没有问题。

    【讨论】:

    • 这就是 Linux 的工作方式。对于所有端口
    • 附带说明,您永远不应该在端口 80 上运行 ASP.NET Core,因为这是大多数 Web 服务器用作默认端口的端口。该问题表明您可以尝试将 ASP.NET Core 应用程序直接公开到 Internet。 不要那样做 Kestrel(现在)不应该充当面向 Internet 的服务器,并且始终在反向代理(apache、nginx、iis)后面运行,唯一的例外是 WebListener,它是获准用于 IFS,但仅限 Windows
    • 您好,您可以分享您如何创建非 root 用户的 docker 文件。我无法在没有 root 用户的情况下运行容器,尽管非 root 用户仍然以 root 身份运行
    猜你喜欢
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 2017-07-08
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    相关资源
    最近更新 更多