项目作者: vecosy

项目描述 :
Centralized Configuration System written in Golang - Spring cloud compatible
高级语言: Go
项目地址: git://github.com/vecosy/vecosy.git
创建时间: 2019-10-18T16:36:50Z
项目社区:https://github.com/vecosy/vecosy

开源协议:Apache License 2.0

下载


Centralized Configuration System

Build Status
codecov
Build Status
Go Report Card
Gitter chat

GitHub
FOSSA Status

What is Vecosy

Vecosy is a configuration service exposed through REST/GRPC.

Is Spring Cloud Conf compatible and also provide a Golang client.

The Golang client (or any other GRPC client) has the ability to detect the configuration changes maintaining a connection
to the server via a GRPC stream.

A configuration is identified by three elements: application name, application version and the environment.

Vecosy uses a GIT repository as configuration store with a naming convention to identify the correct application branch (appName/appVersion),

The system will find the closest (<=) version *very useful when a new release doesn’t need any configuration changes

The security is guaranteed by a JWS token for each application branch and via a TLS connection.

Each application branch can use three different structures/merging strategies: smartConfig, spring, raw (see Configuration repo for more details)

Logical schema


Schema

Why VeCoSy (Versioned Configuration System)

  • Easy to use
  • Secure
    • JWS token for each application
    • TLS
  • Three different merging strategies
    • Smart
    • Spring
    • Raw
  • Compatible

QuickStart (demo)

The demo uses the config-sample repository

Run the server

```shell script
$ docker pull vecosy/vecosy:demo
$ docker run —rm -p 8080:8080 -p 8081:8081 vecosy/vecosy:demo

  1. ### Generate the JWS token
  2. Use the [app1/1.0.0 branch](https://github.com/vecosy/config-sample/tree/app1/1.0.0) to run
  3. ```shell script
  4. $ echo "app1" | jose-util sign --key priv.key --alg RS256

the code below has already a valid token for the vecosy:demo

Golang Client

Example repo

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/viper"
  5. "github.com/vecosy/vecosy/v2/pkg/vecosy"
  6. )
  7. func main() {
  8. jwsToken := "eyJhbGciOiJSUzI1NiJ9.YXBwMQo.A98GFL-P3vtehn0r5GCO_a0OYb5h6trxg3a8WE9hOPDzJ40yOEGtZxyUM6_3Exk65c52-nzWEEc5P-QtgGrgJFOOZlKneKoa1bYBlWRONoysuq95UtSY0doEOMWGvI9AqB685OzmVPuW2UlHg_HlQuuTO6Re1uKc5gr1qZPlyyWEsfoVYTFbfidLoBKWPOuZTxpd8uRx0Rv3LrrmFEcGPHaMNQ2WiXAEJG6OaMTBtwKiynEFH3DU5Rx2WP9M98bH-emC_w7Zq1xKaCOsj2t09F00KohcGC49zSPgPVpp_TwF1qt6_0d0Mnh_Eqi_NHpobVvO85ZOLS05AyW9LQyA5A"
  9. vecosyCl, err := vecosy.NewClientBuilder("localhost:8081", "app1", "1.0.0", "dev").WithJWSToken(jwsToken).Build(nil)
  10. panicOnError(err)
  11. err = vecosyCl.WatchChanges()
  12. panicOnError(err)
  13. fmt.Printf("db.user:%s\n", viper.GetString("db.user"))
  14. }
  15. func panicOnError(err error) {
  16. if err != nil {
  17. panic(err)
  18. }
  19. }

Spring Client

Take a look to spring-boot-example

Endpoints

Remember to add the Authorization header with the token generated before Bearer [token]
(except if the server has been started with --insecure option)

SmartConfig Strategies

from app1/1.0.0

Spring-could Strategies

for spring-app1/v1.0.0

Raw file

for app1/1.0.0

for spring-app1/1.0.0

Installation

Prepare the configuration

Create a folder for the server configuration $HOME/myVecosyConf.

Create a $HOME/myVecosyConf/vecosy.ymlwith your configuration (see Server Configuration chapter)

Run

```shell script
$> docker -d —name myVecosyInstance -v $HOME/myVecosyConf:/config -p 8080:8080 -p 8081:8081 vecosy/vecosy:latest

  1. # Server Configuration
  2. *some configuration options can be passed via command line run `vecosy-server --help` for the options*
  3. ## TLS
  4. ```yaml
  5. server:
  6. tls:
  7. enabled: true
  8. certificateFile: ./myCert.crt
  9. keyFile: ./myCert.key
  10. rest:
  11. address: ":8443"
  12. grpc:
  13. address: ":8081"
  14. ...

GIT authentication

No authentication

  1. ...
  2. repo:
  3. remote:
  4. url: https://github.com/vecosy/config-sample.git
  5. pullEvery: 30s
  6. local:
  7. path: /tmp/vecosyData

plain authentication

  1. ...
  2. repo:
  3. remote:
  4. url: https://github.com/vecosy/config-sample.git
  5. pullEvery: 30s
  6. auth:
  7. type: plain
  8. username: gitRepoUsername
  9. password: gitRepoPassword
  10. local:
  11. path: /tmp/vecosyData

http (basic) authentication

  1. ...
  2. repo:
  3. remote:
  4. url: https://github.com/vecosy/config-sample.git
  5. pullEvery: 30s
  6. auth:
  7. type: http
  8. username: gitRepoUsername
  9. password: gitRepoPassword
  10. local:
  11. path: /tmp/vecosyData

public key authentication

  1. ...
  2. repo:
  3. remote:
  4. url: github.com:vecosy/config-sample.git
  5. pullEvery: 30s
  6. auth:
  7. type: pubKey
  8. username: git
  9. keyFile: ./myPubKeyFile
  10. keyFilePassword: myPubKeyPassword
  11. local:
  12. path: /tmp/vecosyData

Full Example

  1. server:
  2. tls:
  3. enabled: true
  4. certificateFile: ./myCert.crt
  5. keyFile: ./myCert.key
  6. rest:
  7. address: ":8443"
  8. grpc:
  9. address: ":8081"
  10. repo:
  11. remote:
  12. url: github.com:vecosy/config-sample.git
  13. pullEvery: 30s
  14. auth:
  15. type: pubKey
  16. username: git
  17. keyFile: ./myPubKeyFile
  18. keyFilePassword: myPubKeyPassword
  19. local:
  20. path: /tmp/vecosyData

Configuration Repo" class="reference-link">Configuration Repo

Branching convention

The app configuration is stored in a git repository, vecosy use a branch name convention to manage different configuration on the same repository appName/version
(i.e app1/1.0.0).

Versions

When a configuration request is processed, the system will find the related branch on the git repo appname/appVersion if the specific version is not present, the nearest (<=) version will be used.

Merging strategies

Vecosy supports two different merging systems, each one use a different naming convention to merge configuration files.

SmartConfig

smart config

The config.yml in the root folder is the common configuration that will be merged by the specific environment (for dev env: dev/config.yml).

Example

https://github.com/vecosy/config-sample/tree/app1/1.0.0

Spring style

spring config

It uses the spring-cloud naming convention.

The application.yml will be overriden by [appname].yml file that will be overriden by [appname]-[profile].yml

Example

https://github.com/vecosy/config-sample/tree/spring-app1/1.0.0

Security

The security is based on a JWS token.

Every application branch has to contains a pub.key file with the public key of the specific application.

Example

1. Generate the application keys

```shell script
$ openssl genrsa -out priv.key 2048
$ openssl rsa -in priv.key -outform PEM -pubout -out pub.key

  1. The `pub.key` has to be added on the application branch on the git repo at the root level.
  2. The `priv.key` will be necessary generating the JWS token for each application that will need the configuration
  3. and should be saved in an external safe place like [vault](https://www.vaultproject.io/)
  4. ### 2. generate a jws token
  5. #### install jose-util
  6. ```shell script
  7. $ go get -u github.com/square/go-jose/jose-util
  8. $ go install github.com/square/go-jose/jose-util

generate jws token

```shell script

the jws payload is not important

$ echo “myAppName” | jose-util sign —key priv.key —alg RS256

  1. the generated token can be used as *Bearer* Authorization header, in the `token` variable in the GRPC metadata header or as spring cloud configuration [token](https://github.com/vecosy/spring-boot-example/blob/master/src/main/resources/bootstrap.yml)
  2. ### 3. Configure your application to use the JWS token
  3. #### vecosy-client (golang)
  4. passing on the `vecosy.NewClientBuilder(...).WithJWSToken(jwsToken)` parameter
  5. #### Spring-cloud application (java)
  6. by Spring cloud configuration [token](https://github.com/vecosy/spring-boot-example/blob/master/src/main/resources/bootstrap.yml)
  7. ## Disable the security
  8. the `--insecure` command line option will disable the security system.
  9. # Client (Golang)
  10. Vecosy client use [viper](https://github.com/spf13/viper) as configuration system.
  11. ## Specific viper configuration
  12. ```go
  13. cfg := viper.New()
  14. vecosyCl,err := vecosy.NewClientBuilder("my-vecosy-server:8080","myApp", "myAppVersion", "integration").
  15. WithJWStoken(jwsToken).
  16. Build(cfg)
  17. // now you can use cfg to get the your app configuration
  18. cfg.getString("my.app.config")

Default viper configuration

  1. vecosyCl,err := vecosy.NewClientBuilder("my-vecosy-server:8080","myApp", "myAppVersion", "integration").
  2. WithJWStoken(jwsToken).
  3. Build(nil)
  4. viper.getString("my.app.config")

Insecure connection

The server has to be started with --insecure option

  1. vecosyCl,err := vecosy.NewClientBuilder("my-vecosy-server:8080","myApp", "myAppVersion", "integration").
  2. Insecure().
  3. Build(nil)
  4. viper.getString("my.app.config")

TLS connection

  1. vecosyCl,err:= vecosy.NewClientBuilder("my-vecosy-server:8080","myApp", "myAppVersion", "integration").
  2. WithTLS("./myTrust.crt").
  3. WithJWSToken(jwsToken).
  4. Build(nil)
  5. viper.getString("my.app.config")

Watch changes

  1. vecosyCl,err:= vecosy.NewClientBuilder("my-vecosy-server:8080","myApp", "myAppVersion", "integration").
  2. WithJWStoken(jwsToken).
  3. Build(nil)
  4. vecosyCl.WatchChanges()

This will maintain a GRPC connection with the server that will inform the client on every configuration changes on the git repo.

It’s also possible to add handlers to react to the changes

  1. vecosyCl.AddOnChangeHandler(func(prevConfiguration map[string]interface{}) {
  2. fmt.Printf("something has changed from %+v to %+v",prevConfiguration, viper.AllSettings())
  3. })

More info

have a look to the integration test for more details

Future features/improvements

  • web interface
  • metrics
  • different config repo type (etcd, redis,…)
  • improving spring compatibility (watch changes doesn’t work right now)

    Work in progress

    Kubernetes helm chart https://github.com/vecosy/helm

License

FOSSA Status