What is the point of MongoDB drivers if they can not be safely used to connect a mobile app directly to a database for production?

huangapple go评论81阅读模式
英文:

What is the point of MongoDB drivers if they can not be safely used to connect a mobile app directly to a database for production?

问题

为什么直接连接移动应用程序到MongoDB数据库不安全?我一直在研究使用dotnet MAUI创建应用程序,并使用MongoDB作为数据库。我在网上的几个帖子中看到,出于安全原因,将应用程序直接连接到数据库是一个非常糟糕的想法。它们几乎都建议创建一个带有REST API的服务器来进行接口交互。这在某种程度上对我有道理,但那么MongoDB驱动程序是用来做什么的呢?它们的整个目的不就是将应用程序直接连接到数据库吗?

它们只适用于内部应用程序,不涉及这种安全问题吗?我是不是漏掉了什么,或者为了这种类型的应用程序创建足够安全的架构的唯一方法是创建一个REST API以进行接口交互,作为连接到数据库的中间人?

我正在开发一个测试的MAUI应用程序,构建到Windows上一切正常。但一旦部署到我的Android模拟器(Pixel 5)上,MongoClient构造函数就会抛出错误,这促使我进行研究,直到我找到了前述的有关安全问题的信息。

(编辑)
我突然想到,dotnet绝对可以用于创建使用asp.net的REST API,这样使用驱动程序就会安全。我会保留这个问题,以防还有其他回答。

英文:

Why is it not secure to connect a mobile app to a MongoDB database directly? I've been looking into creating an application with dotnet MAUI and using MongoDB as the database. I've seen in several threads online that it's a very bad idea to connect the app directly to the database for security reasons. They almost all recommend creating a server with a rest api to interface with. This sort of makes sense to me, but then what are the MongoDB drivers for? Isn't the entire point of them to connect the application directly to the database?

Are they only meant to be used for internal applications where this type of security isn't an issue? Am I missing something here or is the only way to create an adequately secure architecture for this sort of application to create a rest api to interface with which serves as a middleman to connect to the database?

I was working on a test MAUI app and everything worked fine building to windows. Once I deployed to my android (Pixel 5) emulator, the MongoClient constructor threw an error which got me researching until I found the aforementioned information about security issues.

(Edit)
It just occurred to me that dotnet can absolutely be used to create a rest-api using asp.net, in which case it would be secure to use the drivers. I'm going to leave the question up in case there is another response.

答案1

得分: 1

一般情况下,您可能不希望直接连接您的移动应用程序到您的数据库。

MongoDB连接可以使用各种身份验证机制进行安全保护。如果使用MongoDB Atlas,默认情况下,所有连接也将通过TLS/SSL进一步进行安全保护。

几乎所有建议创建一个带有REST API的服务器来进行接口交互。这对我来说有点合理,但那么MongoDB驱动程序是用来做什么的呢?难道它们的整个目的不是直接将应用程序连接到数据库吗?

在构建REST API时,您将使用MongoDB驱动程序来建立和验证与集群的连接,通过CRUD API和其他方便的方法与数据进行交互。提供这种建议的原因(首先构建REST API)可能是为了将这些交互的状态管理移到一个中间层(托管REST API的服务器)。

最后,您将会遇到严重的可扩展性问题。MongoDB不是一个“互联网规模”的数据库,它设计用于处理数百个连接,您可以将它推到几千个,但随后它将崩溃。如果每个客户端直接连接到数据库,您将很快用尽这些连接,您的应用程序将停止工作。

如果您正在管理自己的集群,请参阅"调整MongoDB和Linux以允许数万个连接"以获取有关服务器端连接调整的详细信息。MongoDB Atlas(托管服务)记录了每个集群层的连接限制,以便您可以计划根据连接需求进行扩展。

英文:

In general you likely wouldn't want to connect your mobile application directly to your database.

> I've been looking into creating an application with dotnet MAUI and using MongoDB as the database. I've seen in several threads online that it's a very bad idea to connect the app directly to the database for security reasons.

MongoDB connections can be secured using various authentication mechanisms. If using MongoDB Atlas, all connections (by default) will also be further secured via TLS/SSL

> They almost all recommend creating a server with a rest api to interface with. This sort of makes sense to me, but then what are the MongoDB drivers for? Isn't the entire point of them to connect the application directly to the database?

When building your REST API you'd use the MongoDB Drivers to establish and authenticate a connection to your cluster, interact with your data via the CRUD APIs and other convenience methods. The reason this guidance may be provided (build a REST API first) is to move the state management of those interactions to an intermediary layer (the server where you're hosting your REST API)

> Finally, you will have seriously scalability problems. MongoDB is not an "internet-scale" database, it is designed to handle hundreds of connections, you can push it to a few thousand, but then it will fall down. If each of your clients connects directly to the database, you will exhaust this fairly quickly and your app will stop working.

If you're managing your own cluster see "Tuning MongoDB & Linux to allow for tens of thousands connections" for details on server side connection tuning. MongoDB Atlas (the managed service) documents the Connection Limits per Cluster Tier so that you can plan to scale up as your connection needs change.

答案2

得分: 0

除了Wernfried提到的用户配置问题之外,您还要担心其他人可能会从您的应用程序中提取您的凭据,并能够直接使用类似Studio3T的工具浏览MongoDB。然后,他们将尝试对您的数据库进行一些最糟糕的事情,将其用于存储和分享其他应用程序的内容,用于挖掘BitCoin,并且通常会胡作非为。

最后,您将面临严重的可伸缩性问题。MongoDB不是一个“互联网规模”的数据库,它设计用于处理数百个连接,您可以将其推向几千个,但然后它将崩溃。如果您的每个客户都直接连接到数据库,那么您将很快耗尽连接资源,您的应用程序将停止工作。

英文:

In addition to the user provisioning problem that Wernfried mentions, you have the concern that other people can and will scrape your credentials out of your app and be able to browse that MongoDB directly using something like Studio3T. They will then attempt to do some of the worst things imaginable to your database, using it to store and share content for other apps, use it to mine BitCoin, and generally run amok.

Finally, you will have seriously scalability problems. MongoDB is not an "internet-scale" database, it is designed to handle hundreds of connections, you can push it to a few thousand, but then it will fall down. If each of your clients connects directly to the database, you will exhaust this fairly quickly and your app will stop working.

huangapple
  • 本文由 发表于 2023年6月1日 13:25:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定