首页 文章

保护spring cloud配置的最佳方法是什么?

提问于
浏览
0

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

  • 当客户端要求配置时 .

  • 调用/ monitor时 - 由webhook使用 .

这样做的最佳做法是什么?基本?加密?有人能提供一个有效的例子吗?

谢谢!

2 回答

  • 1

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

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

    我希望它有所帮助 .

  • 0

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

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

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

    要配置对称密钥,需要将 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默认情况下对某些密钥长度参数有限制 . 默认为128位 .

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

    这是下载链接:

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

    此外,您还可以通过此类 endpoints 加密和解密您的媒体资源:

    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'
    

相关问题