简体   繁体   English

将Cloud Foundry连接到MongoDB Atlas的推荐方法

[英]Recommended way to connect cloud foundry to mongodb atlas

I've got a spring boot app which is connected to mongodb atlas. 我有一个连接到mongodb地图集的spring boot应用程序。 Everything is working locally. 一切都在本地工作。

I now want to publish this to pivotal cloud foundry. 我现在想将其发布到关键的云铸造厂。

Secure connection between PCF and atlas PCF和地图集之间的安全连接

In mongodb atlas I need to open up the firewall an allow certain ip numbers. 在mongodb地图集中,我需要打开防火墙并允许某些IP地址。 How should I configure mongodb atlas to connect to pcf in the most secure way? 我应该如何配置mongodb atlas以最安全的方式连接到pcf?

Autoconfigure getting in the way 自动配置妨碍

cloud foundry is overriding my connection urls to point to localhost:27017 instead of my atlas cluster. cloud Foundry覆盖了我的连接URL,使其指向localhost:27017而不是我的地图集集群。 What is the recommended way to connect to mongodb atlas? 建议使用什么方式连接到mongodb地图集?

In mongodb atlas I need to open up the firewall an allow certain ip numbers. 在mongodb地图集中,我需要打开防火墙并允许某些IP地址。 How should I configure mongodb atlas to connect to pcf in the most secure way? 我应该如何配置mongodb atlas以最安全的方式连接到pcf?

White listing IP addresses for applications that run on CF is not particularly effective. 对于在CF上运行的应用程序,白名单IP地址并不是特别有效。 The reason it's not effective is that you don't know the IP address from which you'll be connecting, because it depends on where Diego decides to run your application. 之所以无效,是因为您不知道要连接的IP地址,因为它取决于Diego决定运行应用程序的位置。 In other words, it depends on the cell where your application is told to run. 换句话说,它取决于告诉您的应用程序运行的单元格。 To compound matters, that will change when you restart / restage your application. 更复杂的是,当您重新启动/重新启动应用程序时,情况将会改变。

Because the IP can vary, what you end up needing to do is white list all of your Cells. 由于IP可能会有所不同,因此最终要做的是将所有Cell都列入白名单。 The problem with this and why it's not effective is that you've ended up white listing every app running on the platform. 这样做的问题以及为什么它无效,是因为您最终将平台上运行的每个应用程序白名单化。

What you can do to improve the security a bit is to make use of application security groups. 您可以采取一些措施来提高安全性,那就是利用应用程序安全组。 ASG's can be used to limit outgoing traffic. ASG可用于限制传出流量。 You can also control them at the space level. 您还可以在空间级别上控制它们。 That means you can configure your default running security group to not allow access to your MongoDb server, but you can allow access for individual spaces by binding an ASG to only those spaces with apps that need to talk to your MongoDb servers. 这意味着您可以将默认的运行安全组配置为不允许访问MongoDb服务器,但是可以通过将ASG仅绑定到需要与MongoDb服务器通信的应用程序的那些空间来允许对单个空间的访问。

The downside of this approach is that it requires you to be a platform administrator, which means it will only work if you own your CF installation (not going to work for public providers). 这种方法的缺点是它要求您成为平台管理员,这意味着它只有在拥有CF安装后才可以使用(不适用于公共提供商)。

More on ASG's here: https://docs.cloudfoundry.org/adminguide/app-sec-groups.html 有关ASG的更多信息,请访问: https//docs.cloudfoundry.org/adminguide/app-sec-groups.html

For public providers, you can use a proxy. 对于公共提供程序,您可以使用代理。 To make this work, you need to have your application configured to talk through a proxy when it attempts to access your Mongodb servers. 为了使此工作有效,您需要将您的应用程序配置为在尝试访问Mongodb服务器时通过代理进行对话。 You control the proxies, which have fixed IPs, so you can white list the proxies to allow access to just your app. 您可以控制具有固定IP的代理,因此可以将代理列入白名单,以仅允许访问您的应用。 If you don't want to run your own proxy servers, there are public proxy providers that you can use. 如果您不想运行自己的代理服务器,则可以使用一些公共代理提供程序。

cloud foundry is overriding my connection urls to point to localhost:27017 instead of my atlas cluster. cloud Foundry覆盖了我的连接URL,使其指向localhost:27017而不是我的地图集集群。 What is the recommended way to connect to mongodb atlas? 建议使用什么方式连接到mongodb地图集?

It's possible to disable auto configuration. 可以禁用自动配置。 One way is described in the docs here. 这里的文档中描述了一种方法。 If you include the Spring Cloud Connectors dependencies and use them manually, then the auto configuration will not run. 如果您包括Spring Cloud Connectors依赖项并手动使用它们,则自动配置将不会运行。

https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html#manual https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html#manual

The other option is to tell the Java build pack not to install the auto configuration. 另一个选择是告诉Java构建包不要安装自动配置。 You can do that by setting the following environment variable for your application, either with cf set-env or via a manifest.yml file. 您可以通过使用cf set-env或manifest.yml文件为应用程序设置以下环境变量来实现。

Ex: JBP_CONFIG_SPRING_AUTO_RECONFIGURATION='[enabled: false]' 例如: JBP_CONFIG_SPRING_AUTO_RECONFIGURATION='[enabled: false]'

Be careful if you do this as it will disable everything provided by the auto reconfiguration, which includes setting the "cloud" profile for your app. 如果这样做,请小心,因为它将禁用自动重新配置提供的所有功能,其中包括为您的应用设置“云”配置文件。 If you use this option to disable auto reconfiguration, you'll probably also want to set SPRING_PROFILES_ACTIVE='cloud' to manually enable the cloud profile. 如果使用此选项禁用自动重新配置,则可能还需要设置SPRING_PROFILES_ACTIVE='cloud'来手动启用云配置文件。

I suppose your other option is to simply embrace the auto configuration. 我想您的另一个选择是简单地接受自动配置。 It's a little confusing / magical at first, but I've found this article to explain it very well. 刚开始时有点令人困惑/不可思议,但是我发现这篇文章可以很好地解释它。

https://spring.io/blog/2015/04/27/binding-to-data-services-with-spring-boot-in-cloud-foundry https://spring.io/blog/2015/04/27/binding-to-data-services-with-spring-boot-in-cloud-foundry

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM