【问题标题】:spring-cloud-config-server alway decrypt the encrypted message?spring-cloud-config-server 总是解密加密的消息?
【发布时间】:2020-11-06 04:55:59
【问题描述】:

我正在运行一个 Spring Cloud 配置服务器。我按照用户指南成功启动它,它可以从 github config-repo/licensingservice/licensingservice.yml 加载配置。我可以使用 /decrypt 和 /encript 端点,但是当我运行时http://localhost:8888/licensingservice/default 它总是解密敏感信息 spring.datasource.password: "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91" 进入 "spring.datasource.password": "p0stgr@s" 我已经把 spring.cloud.config.server.encrypt.enabled=false 放在 bootstrap.yml 中,可以通过

看到
localhost:8888/actuator/env

github上的配置:

    example.property: "I AM IN THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform:  "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"
redis.server: "redis"
redis.port: "6379"
signing.key: "345345fsdfsf5345"

从邮递员处获取配置:

{
    "name": "licensingservice",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": "56d63a8c0c3dcb0c5c93db1f00cf71856371db8b",
    "state": null,
    "propertySources": [
        {
            "name": "https://github.com/carnellj/config-repo//licensingservice/licensingservice.yml",
            "source": {
                "example.property": "I AM IN THE DEFAULT",
                "spring.jpa.database": "POSTGRESQL",
                "spring.datasource.platform": "postgres",
                "spring.jpa.show-sql": "true",
                "spring.database.driverClassName": "org.postgresql.Driver",
                "spring.datasource.url": "jdbc:postgresql://database:5432/eagle_eye_local",
                "spring.datasource.username": "postgres",
                "spring.datasource.testWhileIdle": "true",
                "spring.datasource.validationQuery": "SELECT 1",
                "spring.jpa.properties.hibernate.dialect": "org.hibernate.dialect.PostgreSQLDialect",
                "redis.server": "redis",
                "redis.port": "6379",
                "signing.key": "345345fsdfsf5345",
                "spring.datasource.password": "p0stgr@s"
            }
        }
    ]
}

我的构建脚本:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.3.1.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    kotlin("jvm") version "1.3.72"
    kotlin("plugin.spring") version "1.3.72"
}

group = "com.matches"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

extra["springCloudVersion"] = "Hoxton.SR6"

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.springframework.cloud:spring-cloud-config-server")
    implementation("org.springframework.cloud:spring-cloud-starter-config")
    implementation("org.springframework.cloud:spring-cloud-starter-eureka")
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

配置服务器应用:

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.config.server.EnableConfigServer

@SpringBootApplication
@EnableConfigServer
class ConfigserverApplication

fun main(args: Array<String>) {
    runApplication<ConfigserverApplication>(*args)
}

我不知道为什么它总是解密密码?

【问题讨论】:

    标签: spring spring-boot encryption spring-cloud spring-cloud-config


    【解决方案1】:

    spring-cloud-config-server 总是解密加密的消息? 否

    如果我们在 ConfigServer 中像这样将encrypt 设置为false,

    ConfigClient 也可以解密。

    spring:
      cloud:
        config:
          server:
            encrypt:
              enabled: false
            git:
              uri: linkToYourURI
    

    并在 ConfigClient 中像这样使用密钥进行解密。 记得把这个放在bootstrap.yml,至于application.yml就太晚了,看这个further clarification。

    encrypt:
      key: PutYourKeyHere
    

    【讨论】:

    • 太棒了。让我意识到bootstrap.yml和application.yml的执行顺序。谢谢
    • 你得到答案了吗?
    • 是的,已经修好了。谢谢
    猜你喜欢
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 2016-09-26
    • 2018-11-07
    • 2017-01-27
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多