2017-02-10 51 views
3

我一直在擺弄春季雲配置,但有一個使用情況配置屬性分爲兩種類型:如何在Git和Vault複合環境存儲庫中使用Spring Cloud Config?

  1. 非祕密值,開發人員應該能夠查看和維護(如JDBC網址等)

  2. 祕密值,這應被視爲只有通過具有特殊訪問指定的人(如密碼)

所以我的支持「很感興趣保持「,目前在快照版本中可用。似乎我可以將Git用於開發人員管理的屬性,保管庫用於保密屬性,並對其進行配置,以便Vault在發生衝突時總是優先於Git。

但是,我發現Vault不僅總是優先...它被用作獨有的後端。根本沒有返回來自Git的屬性。

application.yml看起來是這樣的:

spring: 
    profiles: 
    active: git, vault 
    cloud: 
    config: 
     server: 
     vault: 
      order: 1 
     git: 
      uri: https://github.com/spring-cloud-samples/config-repo 
      basedir: target/config 
      order: 2 

我已經寫了財產到保險櫃是這樣的:

vault write secret/foo foo=vault 

我打電話來像這樣我的配置服務器:

curl -X "GET" "http://127.0.0.1:8888/foo/default" -H "X-Config-Token: a9384085-f048-7c99-ebd7-e607840bc24e" 

但是,JSON響應負載只包含Vault屬性。從Git的沒有:

{ 
    "name": "foo", 
    "profiles": [ 
     "default" 
    ], 
    "label": null, 
    "version": null, 
    "state": null, 
    "propertySources": [ 
     { 
      "name": "vault:foo", 
      "source": { 
       "foo": "vault" 
      } 
     } 
    ] 
} 

,如果我在application.yml扭轉order設置,給Git的優先級高於庫沒關係。只要Vault配置文件處於活動狀態,它將作爲獨佔後端。

但是,如果我停用Vault配置文件,那麼同樣的捲曲操作不從Git的後臺返回結果:

{ 
    "name": "foo", 
    "profiles": [ 
     "default" 
    ], 
    "label": "master", 
    "version": "30f5f4a144dba41e23575ebe46369222b7cbc90d", 
    "state": null, 
    "propertySources": [ 
     { 
      "name": "https://github.com/spring-cloud-samples/config-repo/foo.properties", 
      "source": { 
       "democonfigclient.message": "hello spring io", 
       "foo": "from foo props" 
      } 
     }, 
     { 
      "name": "https://github.com/spring-cloud-samples/config-repo/application.yml", 
      "source": { 
       "info.description": "Spring Cloud Samples", 
       "info.url": "https://github.com/spring-cloud-samples", 
       "eureka.client.serviceUrl.defaultZone": "http://localhost:8761/eureka/", 
       "foo": "from-default" 
      } 
     } 
    ] 
} 

有什麼我可能會錯過?爲什麼Git屬性和Vault屬性不能......好,「合成」在一起的一些原因?

文檔中的唯一示例顯示了Git和Subversion一起使用,並且有一個提示警告您所有回購應包含相同的標籤(例如master)。我想知道是否這是問題,因爲標籤總是爲Vault提供null

+0

您好Steve感謝這份報告。我會在下個禮拜看看。 –

+0

您使用的是什麼版本的Spring Cloud?我只是試過這個,得到了這個,它爲我工作。 –

+0

1.2.3(快照)。我只是在https://github.com/spring-cloud-samples/configserver –

回答

2

我相信你的依賴關係肯定有問題。我還建立了一個使用git和vault的spring雲配置服務器,它工作得很好。 我認爲強制使用1.3.0-BUILD.SNAPSHOT是不夠的。 Spring雲配置1.3.0-BUILD.SNAPSHOT取決於spring-vault-core。您可能會錯過這種依賴關係。這可能會導致您在其中一條評論中提到的創建失敗bean。 這裏是a link與git和Vault的示例項目。隨時檢查一下。

+0

非常感謝@ ryan-baxter和你自己。我現在有所需的配置[服務器](https://github.com/steve-perkins/spring-config-server)和[客戶端](https://github.com/steve-perkins/spring-config-sample -app)啓動並運行。 –

相關問題