Skip to content

Commit 5ba1228

Browse files
nhp-server and nhp-ac add remote configuration
* nhp-server and nhp-ac add remote configuration. configuration's provider is etcd * nhp-server and nhp-ac add remote configuration. configuration's provider is etcd. push modify files * correction of incorrect words in document remote_config.zh-cn.md.update remote config add sync.Mutex.etcd watcher add a quit condition to stop the loop. --------- Co-authored-by: Leon Zeng <craftleon@hotmail.com>
1 parent 05448cc commit 5ba1228

File tree

10 files changed

+931
-157
lines changed

10 files changed

+931
-157
lines changed

docs/zh-cn/remo_config.zh-cn.md

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# OpenNHP远端配置
2+
3+
## 1 OpenNHP远端配置说明
4+
5+
为方便统一管理OpenNHP配置信息,OpenNHP使用etcd作为统一远端配置中心。
6+
7+
OpenNHP三大核心组件对配置文件的支持方式:
8+
9+
| 组件 | 远端配置 | 本地配置 |
10+
| ---------- | ------------------------------- | ------------------------------- |
11+
| nhp server | <font color="green">支持</font> | <font color="green">支持</font> |
12+
| nhp ac | <font color="green">支持</font> | <font color="green">支持</font> |
13+
| nhp agent | <font color="red">不支持</font> | <font color="green">支持</font> |
14+
15+
## 2 etcd环境部署
16+
17+
### 2.1 etcd部署
18+
19+
- etcd下载地址:https://github.com/etcd-io/etcd/releases/
20+
- 下载对应服务器环境的etcd版本
21+
- etcd服务部署与启动参数安装包中的README.md文件
22+
23+
### 2.2 etcd可视化配置工具
24+
25+
- 启动etcd服务后,可以通过etcd的可视化工具来进行OpenNHP的配置信息的编辑,本文以工具etcdkeeper为例来配置etcd客户化配置环境
26+
27+
- 将etcdkeeper下载到etcd部署服务器上,下载方法:
28+
29+
```sh
30+
wget https://github.com/evildecay/etcdkeeper/releases/download/v0.7.6/etcdkeeper-v0.7.6-linux_x86_64.zip
31+
unzip etcdkeeper-v0.7.6-linux_x86_64.zip
32+
```
33+
34+
- etcdkeeper启动方法:
35+
36+
- IP设置为服务器实际IP
37+
- 端口设置为实际方法端口
38+
- 启动成功后可通过浏览器访问,访问地址如:http://192.168.32.30:8800
39+
40+
```sh
41+
cd etcdkeeper
42+
chmod +x etcdkeeper
43+
./etcdkeeper -h 192.168.32.30 -p 8800
44+
```
45+
46+
## 3 nhp server远端配置
47+
48+
### 3.1 远端配置访问配置
49+
50+
etc目录下的remote.toml为nhp server服务访问远端配置中心ETCD的配置信息
51+
52+
- Endpoints:etcd访问地址
53+
- Key:nhp server获取本服务器的key
54+
55+
```toml
56+
# NHP-Server remote config
57+
# field with (-) does not support dynamic update
58+
# If the file remote.toml exists, NHP-Server will obtain remote configuration information through the etcd client
59+
60+
# Endpoints: ETCD service access address.
61+
# Key: NHP-Server obtain the configuration information through this key.
62+
# Username: The account of the NHP-Server accessing ETCD.
63+
# Password: The password for NHP-Server to access ETCD.
64+
65+
Endpoints = ["172.16.3.53:2379"]
66+
Key = "openserver-1"
67+
```
68+
69+
70+
### 3.2 启用远端配置
71+
72+
确保配置文件./nhp-server/etc/remote.toml文件存在,并确保Endpoints和Key正确配置,在nhp server服务启动时会加载remote.toml文件并去获取文件中Key对应的配置内容。
73+
74+
75+
76+
如想继续使用本地文件的配置方式,移除remote.toml文件或将remote.toml中的Endpoints或Key的内容置为空,服务将会使用本地配置文件来启动。
77+
78+
79+
80+
### 3.3 远端配置内容
81+
82+
nhp server远端配置内容分为如下七部分:
83+
84+
- [BaseConfig]部分内容对应本地配置文件config.toml
85+
- [HttpConfig]部分内容对应本地配置文件http.toml
86+
- [[ACs]]部分内容对应本地配置文件ac.toml
87+
- [[Agents]]部分内容对应本地配置文件agent.toml
88+
- [[DBs]]部分内容对应本地配置文件db.toml
89+
- [[AuthServiceId]]部分内容对应本地配置文件resource.toml
90+
- [[SrcIps]]部分内容对应本地配置文件srcip.toml
91+
92+
远端配置信息如下:
93+
94+
```toml
95+
# NHP-Server base config
96+
# field with (-) does not support dynamic update
97+
98+
# PrivateKeyBase64 (-): server private key in base64 format.
99+
# DefaultCipherScheme: 0: gmsm, 1: curve25519.
100+
# ListenIp (-): udp listening address.
101+
# ListenPort (-): udp listening port.
102+
# Hostname (-): server domain name.
103+
# LogLevel: 0: silent, 1: error, 2: info, 3: audit, 4: debug, 5: trace.
104+
# DisableAgentValidation: whether for the server to skip the agent's public key validation.
105+
[BaseConfig]
106+
PrivateKeyBase64 = "SFhGcTlhYlU4dTJMemNsaWM5TFZ2NzZDQjJNd2VGZ2Q="
107+
DefaultCipherScheme = 0
108+
ListenIp = "" # empty for ipv4 + ipv6, "0.0.0.0" for ipv4 only
109+
ListenPort = 62206
110+
Hostname = "localhost" # the hostname of NHP-Server
111+
LogLevel = 4
112+
DisableAgentValidation = false
113+
114+
115+
# http server config
116+
117+
# EnableHttp: true: turn on http server, false: shutdown http server.
118+
# EnableTLS: whether to use TLS certificates for hosting https server.
119+
# TLSCertFile: certificate file path.
120+
# TLSKeyFile: key file path.
121+
# to update http changes, you need to restart the http server by changing "EnableHttp" to "false" and then switch it back to "true".
122+
[HttpConfig]
123+
EnableHttp = true
124+
EnableTLS = true
125+
HttpListenIp = "0.0.0.0" # empty for ipv4 + ipv6, "0.0.0.0" for ipv4 only, "127.0.0.1" for local ipv4 access only
126+
TLSCertFile = "cert/cert.pem"
127+
TLSKeyFile = "cert/cert.key"
128+
129+
# list the AC peers for the server under [[ACs]] table
130+
131+
# PubKeyBase64: public key for the AC in base64 format.
132+
# ExpireTime (epoch timestamp in seconds): peer key validation will fail when it expires.
133+
[[ACs]]
134+
PubKeyBase64 = "3wDnLkZ3ccK3Ezi3pdG003rFbX4riMIOKfvFlu4t5yKhijSdIkAx8C6mVMFxygfZ0ijt8IDAS2RdTnfZpUCbZA=="
135+
ExpireTime = 1924991999
136+
137+
# list the agent peers for the server under [[Agents]] table
138+
139+
# PubKeyBase64: public key for the agent in base64 format.
140+
# ExpireTime (epoch timestamp in seconds): peer key validation will fail when it expires.
141+
[[Agents]]
142+
PubKeyBase64 = "WnJAolo88/q0x2VdLQYdmZNtKjwG2ocBd1Ozj41AKlo="
143+
ExpireTime = 1924991999
144+
145+
# list the device peers for the server under [[Devices]] table
146+
147+
# PubKeyBase64: public key for the device in base64 format.
148+
# ExpireTime (epoch timestamp in seconds): peer key validation will fail when it expires.
149+
[[DBs]]
150+
PubKeyBase64 = "CtxNuy7lJ1mJgjqWplcwN8dZhXhSNPhECja1A0OWKa+2wtI7xuB3jPcamogGZGBBfQ4SqnoPGLA7zRQaAotoxg=="
151+
ExpireTime = 1924991999
152+
153+
154+
155+
# List resources and their sub-fields here
156+
157+
# syntax ["{AuthServiceId}"]
158+
# AuthSvcId: id of the authentication and authorization service provider.
159+
# PluginPath: path of plugin to implement auth logic.
160+
[[AuthServiceId]]
161+
AuthSvcId="default"
162+
PluginPath = "default"
163+
164+
[[AuthServiceId]]
165+
AuthSvcId="product-sdp"
166+
PluginPath = "product-sdp1"
167+
168+
169+
# list additional source addresses to be passed along with the agent address
170+
171+
# syntax [["{SrcIps}"]]
172+
# SrcIp: specify the agent source ip. Each source ip can have multiple side source ips.
173+
# Ip: specify a side source ip address to be also passed after successful knock.
174+
[[SrcIps]]
175+
SrcIp = "192.168.2.27"
176+
Ip = ["192.168.2.26","192.168.2.28"]
177+
178+
[[SrcIps]]
179+
SrcIp = "192.168.3.27"
180+
Ip = ["192.168.3.28"]
181+
```
182+
183+
184+
185+
本地文件支持动态变更的内容在远端配置环境下同样支持动态变更。
186+
187+
## 4 nhp ac远端配置
188+
189+
### 4.1 远端配置访问配置
190+
191+
参照章节3.1
192+
193+
### 4.2 启用远端配置
194+
195+
参照章节3.2
196+
197+
198+
199+
### 4.3 远端配置内容
200+
201+
nhp ac远端配置内容分为如下三部分:
202+
203+
- [BaseConfig]部分内容对应本地配置文件config.toml
204+
- [HttpConfig]部分内容对应本地配置文件http.toml
205+
- [[Servers]]部分内容对应本地配置文件server.toml
206+
207+
远端配置信息如下:
208+
209+
```toml
210+
# NHP-AC base config
211+
# field with (-) does not support dynamic update
212+
213+
# ACId (-): specify the id of this AC.
214+
# PrivateKeyBase64 (-): AC private key in base64 format.
215+
# DefaultCipherScheme: 0: gmsm, 1: curve25519.
216+
# IpPassMode:
217+
# 0: (default) immediately pass traffic with the agent source ip,
218+
# 2: process pre-access to determine actual agent source ip then pass.
219+
# FilterMode:
220+
# 0: iptables (default)
221+
# 1: ebpf xdp (requires Linux kernel >= 5.6 and XDP-capable network interface)
222+
# LogLevel: 0: silent, 1: error, 2: info, 3: audit, 4: debug, 5: trace.
223+
# AuthServiceId (-): id for authentication and authorization service provider this AC belongs to.
224+
# ResourceIds (-): resource group ids that this AC protects.
225+
[BaseConfig]
226+
ACId = "testAC-346"
227+
DefaultIp = "172.16.3.52"
228+
PrivateKeyBase64 = "N1o4c1BsSHZXQ1hsUFQyUzQ2QkJ2YlhQSGxYbDVmcU0="
229+
DefaultCipherScheme = 0
230+
IpPassMode = 0
231+
LogLevel = 4
232+
AuthServiceId = "example"
233+
ResourceIds = ["demo"]
234+
FilterMode = 0
235+
236+
# http server config
237+
238+
# EnableHttp: true: turn on http server, false: shutdown http server.
239+
# EnableTLS: whether to use TLS certificates for hosting https server.
240+
# TLSCertFile: certificate file path.
241+
# TLSKeyFile: key file path.
242+
# to update http changes, you need to restart the http server by changing "EnableHttp" to "false" and then switch it back to "true".
243+
[HttpConfig]
244+
EnableHttp = true
245+
EnableTLS = true
246+
HttpListenPort = 62206
247+
TLSCertFile = "cert/cert.pem"
248+
TLSKeyFile = "cert/cert.key"
249+
250+
251+
# list the server peers for the AC under [[Servers]] table
252+
253+
# Hostname: the domain of the server peer. If specified, it overrides the "Ip" field with its first resolved address.
254+
# Ip: specify the ip address of the server peer
255+
# Port: specify the port number of this server peer is listening
256+
# PubKeyBase64: public key of the server peer in base64 format
257+
# ExpireTime (epoch timestamp in seconds): peer key validation will fail when it expires.
258+
[[Servers]]
259+
Hostname = ""
260+
Ip = "172.16.2.15"
261+
Port = 62206
262+
PubKeyBase64 = "vfAyhQfS1Z+gE7aKSqMCw8GJlZOnw7G7OEG6dHxowtPORn9vqCPp3RqKuyBDZeVqWAMFaCjBUlfu9TpQeN1/uA=="
263+
ExpireTime = 1924991999
264+
```
265+
266+
本地文件支持动态变更的内容在远端配置环境下同样支持动态变更。

0 commit comments

Comments
 (0)