【问题标题】:What is the best way to secure spring cloud config?保护 Spring Cloud 配置的最佳方法是什么?
【发布时间】:2019-05-11 03:57:05
【问题描述】:

我有一个运行 spring 总线的 spring 云配置服务器。我想让对该服务器的调用安全:

  1. 当客户要求配置时。
  2. 调用 /monitor 时 - 由 webhook 使用。

这样做的最佳做法是什么?基本的?加密? 有人可以提供一个工作示例吗?

谢谢!

【问题讨论】:

    标签: spring spring-cloud spring-cloud-config spring-cloud-bus


    【解决方案1】:

    此外,您可以使用Spring Cloud Vault 控制对配置中机密的访问。

    此解决方案比加密您的应用程序和配置服务器之间的所有通信更简单,但也许这不是您想要的。

    我希望它有所帮助。

    【讨论】:

    【解决方案2】:

    您可以通过添加加密和解密属性来保护它

    您需要提供 jks 以安全地加密和解密它们

    Spring 云配置服务器支持对称和非对称密钥

    要配置对称密钥,您需要将encrypt.key 设置为秘密字符串(或使用ENCRYPT_KEY 环境变量将其排除在纯文本配置文件之外)。

    对于非对称你需要在 bootsrap.yml 中提供这样的属性:

    server:
      port: 8888
    spring:
      cloud:
        config:
          server:
            git:
              uri: your git url or your local repository on file system 
              username: username for git or bitbucket if needed
              password: password
              clone-on-start: true this property will clone all repo localy on starttup
              force-pull: true
      application:
         name: config-server
    encrypt:
      key-store:
        location: jks location
        password: letmein
        alias: mytestkey
        secret: changeme
    

    要生成 jks 你需要执行这个命令

    keytool -genkeypair -alias mytestkey -keyalg RSA \
      -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" \
      -keypass changeme -keystore server.jks -storepass letmein
    

    其实java默认对某些key长度参数是有限制的。 默认为 128 位。

    要使用更多的密钥长度,您只需替换现有的local_policy.jar 和US_export_policy.jar 中的<java-home>/lib/security

    这里是下载链接:

    https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

    您还可以通过这些端点加密和解密您的属性:

    curl config_server_host:port/encrypt-d your data to be encrypted
    
    curl config_server_host:port/decrypt -d your data to be decrypted // this will automatically use this endpoint to decrypt values
    //Both are http post requests
    

    要使用配置服务器加密,您需要在配置中为您的应用程序提供这样的前缀,该前缀将从配置服务器获取配置:

    '{cipher}your_encrypted_data'
    

    【讨论】:

      猜你喜欢
      • 2020-09-26
      • 2021-04-10
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2015-07-28
      • 2014-07-05
      • 1970-01-01
      相关资源
      最近更新 更多