如何从Spring Boot应用程序中隧道PCF服务

帕提班

我有一个部署在关键的Cloud Foundry上的spring boot应用程序我正在尝试从我的Spring Boot应用程序隧道(cf ssh)到pcf中的该应用程序,但是无法找到任何api或客户端库来实现它。

隧道PCF的实际cli命令: cf ssh -N -T -L 10001:localhost:10001 ms名称

欢迎任何建议。

丹尼尔·米库萨(Daniel Mikusa)

如果您试图编写与cf ssh命令具有相同功能的Java代码,那应该是可能的。它是标准的SSH,但是具有短暂的凭据,因此,该技巧将生成可从您的应用程序使用的凭据。

这是使用标准SSH / SCP / SFTP客户端的示例,请注意,这ssh.bosh-lite.com将是您的SSH域,您可以从cf curl /v2/info以下位置看到

$ ssh -p 2222 cf:$(cf app app-name --guid)/[email protected]
$ scp -P 2222 -oUser=cf:$(cf app app-name --guid)/0 my-local-file.json ssh.bosh-lite.com:my-remote-file.json
$ sftp -P 2222 cf:$(cf app app-name --guid)/[email protected]

https://github.com/cloudfoundry/diego-ssh#cloud-foundry-via-cloud-controller-and-uaa


也就是说,您应该能够使用任何标准的SSH Java库执行类似的操作。

如上所述,诀窍在于获取凭据。用户名将采用格式cf:application-guid/app-instance-number,这很容易,但是密码需要使用cf ssh-code或对UAA API的类似调用来生成

例如: curl -vv -H 'Accept: application/json' -H "Authorization: $(cf oauth-token)" "https://uaa.run.pivotal.io/oauth/authorize?client_id=ssh-proxy&response_type=code"

本示例用于curl发送请求并cf oauth-token为登录用户获取有效的Oauth2承载令牌。您可以通过多种方式获得有效的承载令牌,包括直接调用API或使用cf-java-client。对于需要执行SSH操作的用户,它只需要是一个有效的令牌(即,正在运行的用户cf ssh)。

希望有帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Spring Boot应用程序中通过SSH隧道连接到远程MySQL

Spring Boot应用程序即服务

如何在 Spring Boot 应用程序中从 Api 网关(Zuul)调用外部服务(非 MSA)

如何从Spring Boot应用程序为React应用程序提供服务?

如何在Spring Boot应用程序中配置PageableHandlerMethodArgumentResolver

如何在intellij中运行spring boot应用程序?

如何避免Spring Boot应用程序中的冗余流量?

如何在Spring Boot应用程序中覆盖DefaultListableBeanFactory?

访问 PCF Spring Boot 应用程序上的 VCAP 属性

在Spring Boot应用程序中组织服务,服务实现和存储库的最佳实践

如何dockerize Spring Boot应用程序?

Spring Boot应用程序中的会话

Spring Boot应用程序中的NonUniqueResultException

使用Junit5在Spring Boot应用程序中测试服务层时如何避免数据库连接

Spring Boot:如何在Spring Boot应用程序中显示系统目录中的图像?

如何防止Spring Boot守护程序/服务器应用程序立即关闭/关闭?

从Spring Boot应用程序的服务层中的请求获取标头

为什么Spring Boot应用程序不断从config服务中获取配置?

在Linux的嵌入式Tomcat服务器中运行Spring Boot应用程序

Spring Boot多模块应用程序中的JUnit 4 Test无法自动装配服务

在微服务开发中为Spring Boot应用程序返回对象列表时出错

在Spring Boot应用程序之间Jaeger中未显示服务依赖性

dockerfile中的命令以运行部署在jboss服务器上的spring boot应用程序

基于 Spring Boot 微服务的应用程序中的全文搜索功能

单元测试Spring Boot应用程序服务层

在服务器上运行 spring boot 应用程序

Spring Boot应用程序即服务+ VM选项

在 Spring Boot 应用程序中使用 Soap 服务

我的Spring Boot Vaadin应用程序如何服务动态生成的HTML文件