Go语言 如何解决这个警告“你信任所有代理,这是不安全的”在free5gc项目”

nvbavucw  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(368)

使命是使用WebConsole添加UE我遵循这些指南https://free5gc.org/guide/5-install-ueransim/#3-install-free5gc-webconsole,我在第4步。我在broswer上输入URL http://192.168.56.101:5000,我得到了“404页面未找到”和警告你信任所有代理,这是不安全的。
我们正在运行这个程序

package  main

import (
        "os"
        "path/filepath"
        "runtime/debug"
        "github.com/urfave/cli"
        logger_util "github.com/free5gc/util/logger"
        "github.com/free5gc/util/version"
        "github.com/free5gc/webconsole/backend/factory"
        "github.com/free5gc/webconsole/backend/logger"
        "github.com/free5gc/webconsole/backend/webui_service"
)

var WEBUI *webui_service.WebuiApp

func main() {

        defer func() {
                if p := recover(); p != nil {
                        // Print stack for panic to log. Fatalf() will let program exit.
                        logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))
                }
        }()
        app := cli.NewApp()
        app.Name = "webui"
        app.Usage = "free5GC Web Console"
        app.Action = action
        app.Flags = []cli.Flag{
                cli.StringFlag{
                        Name:  "config, c",
                        Usage: "Load configuration from `FILE`",
                },
                cli.StringSliceFlag{
                        Name:  "log, l",
                        Usage: "Output NF log to `FILE`",
                },
        }
        if err := app.Run(os.Args); err != nil {
                logger.MainLog.Errorf("WEBUI Run error: %v\n", err)
        }

}

func action(cliCtx *cli.Context) error {
        tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log"))
        if err != nil {
                return err
        }

        logger.MainLog.Infoln("WEBUI version: ", version.GetVersion())

        cfg, err := factory.ReadConfig(cliCtx.String("config"))
        if err != nil {
                return err
        }
        factory.WebuiConfig = cfg

        webui, err := webui_service.NewApp(cfg)
        if err != nil {
                return err
        }
        WEBUI = webui

        webui.Start(tlsKeyLogPath)

        return nil
}

func initLogFile(logNfPath []string) (string, error) {
        logTlsKeyPath := ""

        for _, path := range logNfPath {
                if err := logger_util.LogFileHook(logger.Log, path); err != nil {
                        return "", err
                }
                if logTlsKeyPath != "" {
                        continue
                }

                nfDir, _ := filepath.Split(path)
                tmpDir := filepath.Join(nfDir, "key")
                if err := os.MkdirAll(tmpDir, 0o775); err != nil {
                        logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)

                        return "", err
                }

                _, name := filepath.Split(factory.WebuiDefaultTLSKeyLogPath)
                logTlsKeyPath = filepath.Join(tmpDir, name)
        }

        return logTlsKeyPath, nil
}

当我运行server.go on wsl时,我得到这个警告[GIN-debug] [WARNING]你信任了所有代理,这是不安全的。我们建议您设置一个值。详情请访问https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies。我通过virtual box运行free 5gc。

go run server.go
2023-09-07T17:33:00.726845745Z [INFO][WEBUI][Main] WEBUI version:
        Not specify ldflags (which link version) during go build
        go version: go1.17.8 linux/amd64
2023-09-07T17:33:00.727778706Z [INFO][WEBUI][CFG] Read config from [./config/webuicfg.yaml]
2023-09-07T17:33:00.727938644Z [INFO][WEBUI][Main] Log enable is set to [true]
2023-09-07T17:33:00.727950271Z [INFO][WEBUI][Main] Log level is set to [info]
2023-09-07T17:33:00.727955572Z [INFO][WEBUI][Main] Report Caller is set to [false]
2023-09-07T17:33:00.728051450Z [INFO][WEBUI][Init] Server started
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /api/sample               --> github.com/free5gc/webconsole/backend/WebUI.GetSampleJSON (3 handlers)
[GIN-debug] POST   /api/login                --> github.com/free5gc/webconsole/backend/WebUI.Login (3 handlers)
[GIN-debug] POST   /api/logout               --> github.com/free5gc/webconsole/backend/WebUI.Logout (3 handlers)
[GIN-debug] GET    /api/tenant               --> github.com/free5gc/webconsole/backend/WebUI.GetTenants (3 handlers)
[GIN-debug] GET    /api/tenant/:tenantId     --> github.com/free5gc/webconsole/backend/WebUI.GetTenantByID (3 handlers)
[GIN-debug] POST   /api/tenant               --> github.com/free5gc/webconsole/backend/WebUI.PostTenant (3 handlers)
[GIN-debug] PUT    /api/tenant/:tenantId     --> github.com/free5gc/webconsole/backend/WebUI.PutTenantByID (3 handlers)
[GIN-debug] DELETE /api/tenant/:tenantId     --> github.com/free5gc/webconsole/backend/WebUI.DeleteTenantByID (3 handlers)
[GIN-debug] GET    /api/tenant/:tenantId/user --> github.com/free5gc/webconsole/backend/WebUI.GetUsers (3 handlers)
[GIN-debug] GET    /api/tenant/:tenantId/user/:userId --> github.com/free5gc/webconsole/backend/WebUI.GetUserByID (3 handlers)
[GIN-debug] POST   /api/tenant/:tenantId/user --> github.com/free5gc/webconsole/backend/WebUI.PostUserByID (3 handlers)
[GIN-debug] PUT    /api/tenant/:tenantId/user/:userId --> github.com/free5gc/webconsole/backend/WebUI.PutUserByID (3 handlers)
[GIN-debug] DELETE /api/tenant/:tenantId/user/:userId --> github.com/free5gc/webconsole/backend/WebUI.DeleteUserByID (3 handlers)
[GIN-debug] GET    /api/subscriber           --> github.com/free5gc/webconsole/backend/WebUI.GetSubscribers (3 handlers)
[GIN-debug] GET    /api/subscriber/:ueId/:servingPlmnId --> github.com/free5gc/webconsole/backend/WebUI.GetSubscriberByID (3 handlers)
[GIN-debug] POST   /api/subscriber/:ueId/:servingPlmnId --> github.com/free5gc/webconsole/backend/WebUI.PostSubscriberByID (3 handlers)
[GIN-debug] POST   /api/subscriber/:ueId/:servingPlmnId/:userNumber --> github.com/free5gc/webconsole/backend/WebUI.PostSubscriberByID (3 handlers)
[GIN-debug] PUT    /api/subscriber/:ueId/:servingPlmnId --> github.com/free5gc/webconsole/backend/WebUI.PutSubscriberByID (3 handlers)
[GIN-debug] DELETE /api/subscriber/:ueId/:servingPlmnId --> github.com/free5gc/webconsole/backend/WebUI.DeleteSubscriberByID (3 handlers)
[GIN-debug] PATCH  /api/subscriber/:ueId/:servingPlmnId --> github.com/free5gc/webconsole/backend/WebUI.PatchSubscriberByID (3 handlers)
[GIN-debug] GET    /api/registered-ue-context --> github.com/free5gc/webconsole/backend/WebUI.GetRegisteredUEContext (3 handlers)
[GIN-debug] GET    /api/registered-ue-context/:supi --> github.com/free5gc/webconsole/backend/WebUI.GetRegisteredUEContext (3 handlers)
[GIN-debug] GET    /api/ue-pdu-session-info/:smContextRef --> github.com/free5gc/webconsole/backend/WebUI.GetUEPDUSessionInfo (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :5000
rkue9o1l

rkue9o1l1#

检查方法func (engine *Engine) SetTrustedProxies(trustedProxies []string) error

  • 您可以设置一个切片的字符串与所有代理,你信任
  • 或者通过将nil传递给该函数来完全禁用它。

文件
SetTrustedProxies设置一个网络源列表(IPv4地址、IPv4 CIDR、IPv6地址或IPv6 CIDR),当(*gin.Engine).ForwardedByClientIPtrue时,可以信任包含替代客户端IP的请求报头。默认情况下启用TrustedProxies功能,并且默认情况下也信任所有代理。如果您想禁用此功能,请使用Engine.SetTrustedProxies(nil),然后Context.ClientIP()将直接返回远程地址。

相关问题