-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
influxdb设置鉴权后,通过influx-proxy写入数据异常,查询数据正常 #76
Comments
当然是backend尚未支持用户名密码。 |
@shell909090 那目前这个添加鉴权后,如何处理写入时的问题呢? |
最低限度是修改代码。在backend中加入鉴权信息,在消息头中写入鉴权。 |
@shell909090 对GO语言不熟,能指导下怎么修改吗? |
你好!需要您的帮助 烦请指导一下。
…------------------ 原始邮件 ------------------
发件人: "Shell.Xu"<notifications@github.com>;
发送时间: 2019年6月17日(星期一) 中午11:12
收件人: "shell909090/influx-proxy"<influx-proxy@noreply.github.com>;
抄送: "李峰"<646584614@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [shell909090/influx-proxy] influxdb设置鉴权后,通过influx-proxy写入数据异常,查询数据正常 (#76)
最低限度是修改代码。在backend中加入鉴权信息,在消息头中写入鉴权。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
首先,修改 https://github.com/shell909090/influx-proxy/blob/master/backend/config.go 文件,在BackendConfig结构中,增加Username和Password。 |
1.influxdb实例可能有好几个不同用户
2.如果只配置到config.go中,那么就相当于用户和密码就写死了,每次新增用户或者修改密码。还得需要重启proxy
能不能以参数的形式传入到config.go中去,在转发给后端inflxudb。这样更灵活。这样能实现吗?
…------------------ 原始邮件 ------------------
发件人: "Shell.Xu"<notifications@github.com>;
发送时间: 2019年6月26日(星期三) 下午4:51
收件人: "shell909090/influx-proxy"<influx-proxy@noreply.github.com>;
抄送: "李峰"<646584614@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [shell909090/influx-proxy] influxdb设置鉴权后,通过influx-proxy写入数据异常,查询数据正常 (#76)
首先,修改https://github.com/shell909090/influx-proxy/blob/master/backend/config.go文件,在BackendConfig结构中,增加Username和Password。
其次,修改https://github.com/shell909090/influx-proxy/blob/master/backend/http.go#L192,在里面加入鉴权头。
具体鉴权方法请参考https://docs.influxdata.com/influxdb/v1.7/administration/authentication_and_authorization/。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
这个是可能的。但是这和我们原始的设计就出现偏差了。我们的原始设计里,多个backend只负责数据存储,因此鉴权是在proxy层完成的。这层鉴权有设计,但是始终没有实现完成。而你的预想模式里,用户名密码会被穿透到后面的backend去。这会导致一些问题,例如如何在多个backend中同步新建用户/修改密码。或者是用户密码在多个backend中不一致导致写入时对时错。 |
是这样吗?
1. config.py
'local': {
'url': 'http://localhost:8086',
'db': 'test',
'zone':'local',
'Username':'admin'
'Password':'admin123'
'interval': 1000,
'timeout': 10000,
'timeoutquery':600000,
'maxrowlimit':10000,
'checkinterval':1000,
'rewriteinterval':10000,
},
2. /backends/config.go
type BackendConfig struct {
URL string
DB string
Zone string
Username string
Password string
Interval int
Timeout int
TimeoutQuery int
MaxRowLimit int
CheckInterval int
RewriteInterval int
WriteOnly int
}
3. /backend/http.go
func NewHttpBackend(cfg *BackendConfig) (hb *HttpBackend) {
hb = &HttpBackend{
client: &http.Client{
Timeout: time.Millisecond * time.Duration(cfg.Timeout),
},
// TODO: query timeout? use req.Cancel
// client_query: &http.Client{
// Timeout: time.Millisecond * time.Duration(cfg.TimeoutQuery),
// },
Interval: cfg.CheckInterval,
URL: cfg.URL,
DB: cfg.DB,
Zone: cfg.Zone,
Username cfg.Username,
Password cfg.Password,
Active: true,
running: true,
WriteOnly: cfg.WriteOnly,
}
go hb.CheckActive()
return
}
4. /backend/http.go
func (hb *HttpBackend) WriteStream(stream io.Reader, compressed bool) (err error) {
q := url.Values{}
q.Set("db", hb.DB)
q.Set("u",hb.Username)
q.Set("p",hb.Password)
req, err := http.NewRequest("POST", hb.URL+"/write?"+q.Encode(), stream)
if compressed {
req.Header.Add("Content-Encoding", "gzip")
}
我这样修改对吗? 有不对的烦请指导一下!! 非常感谢
…------------------ 原始邮件 ------------------
发件人: "Shell.Xu"<notifications@github.com>;
发送时间: 2019年6月26日(星期三) 下午4:51
收件人: "shell909090/influx-proxy"<influx-proxy@noreply.github.com>;
抄送: "李峰"<646584614@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [shell909090/influx-proxy] influxdb设置鉴权后,通过influx-proxy写入数据异常,查询数据正常 (#76)
首先,修改https://github.com/shell909090/influx-proxy/blob/master/backend/config.go文件,在BackendConfig结构中,增加Username和Password。
其次,修改https://github.com/shell909090/influx-proxy/blob/master/backend/http.go#L192,在里面加入鉴权头。
具体鉴权方法请参考https://docs.influxdata.com/influxdb/v1.7/administration/authentication_and_authorization/。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
这个不是PR,所以没有diff,看起来不是很清晰。粗看的话,应该就是这个样子。 |
按理说它这个权鉴流程应该是:config.py配置文件将参数传递到redis。然后backend的config.go将redis的参数获取到,通过http.go将权鉴头信息添加到WriteStream函数中。最后将完整的write的http信息,传递给单实例influxdb。实现数据写入的吧???
如果有什么不对还请指正出来。因为现在按照我的这个想法 改完之后 并没有达到预期的效果。
命令如下:
curl -i -XPOST 'http://192.168.22.129:6666/write?db=test&u=e3base&p=e3base123' --data-binary 'cpu_load_short3,host=server01,region=us-west value=0.01 1434255562000040571'
日志中提示如下:
2019/07/08 06:44:24.335885 http.go:231: status: 401
2019/07/08 06:44:24.335910 backends.go:180: unknown error Unknown Error, maybe overloaded.
2019/07/08 06:44:24.335931 backends.go:182: write http error: Unknown Error
2019/07/08 06:44:33.814447 http.go:214: write status code: 401
2019/07/08 06:44:33.815117 http.go:221: error response: {"error":"unable to parse authentication credentials"}
还请指导??
config.py配置如下:
BACKENDS = {
'local': {
'url': 'http://192.168.22.129:25001',
'db': 'test',
'zone':'local',
'u':'e3base',
'p':'e3base123',
'interval': 1000,
'timeout': 10000,
'timeoutquery':600000,
'maxrowlimit':10000,
'checkinterval':1000,
'rewriteinterval':10000,
},
…------------------ 原始邮件 ------------------
发件人: "Shell.Xu"<notifications@github.com>;
发送时间: 2019年7月7日(星期天) 凌晨0:15
收件人: "shell909090/influx-proxy"<influx-proxy@noreply.github.com>;
抄送: "李峰"<646584614@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [shell909090/influx-proxy] influxdb设置鉴权后,通过influx-proxy写入数据异常,查询数据正常 (#76)
这个不是PR,所以没有diff,看起来不是很清晰。粗看的话,应该就是这个样子。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
在http请求前,先把请求内容dump出来看看? |
curl -i -XPOST 'http://localhost:6666/write?db=test&u=aaa&p=123' --data-binary 'cpu_load_short32,host=server01,region=us-west value=0.09 1434255562000040578'
报错如下:
2019/05/08 14:21:58.469542 http.go:225: status: 401
2019/05/08 14:21:58.469610 backends.go:243: unknown error Unknown Error, maybe overloaded.
2019/05/08 14:21:58.800641 file.go:112: read error: unexpected EOF
2019/05/08 14:22:00.012223 http.go:208: write status code: 401
2019/05/08 14:22:00.012443 http.go:215: error response: {"error":"unable to parse authentication credentials"}
是什么原因呢?
The text was updated successfully, but these errors were encountered: