web API 里的简单认证 basic auth
在调用curl命令请求ranger的时候, 命令行里需要写入账号密码 curl -u username:password, 不知道这是不是通用的一种技术规范. 咨询了chatgpt, 发现其实就是标准的 basic auth 简单加密.
curl -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" -v -i -s -X GET http://172.16.48.143:6080/service/xusers/secure/users/1
背后的原理很简单, 使用base64对username:password进行转义, 按照标准格式放在header里对服务端进行请求即可: Authorization: Basic 123YWRtaW46YWRtaW4=
安全性: 由于base64没有加密, 密码相当于明文在http请求里传输. 不过站点如果设置为https, 虽然对客户端和服务端仍然是明文, 但网络嗅探无法得到具体的header了.
在curl里直接设置为 base64 计算后的header, ranger服务端也能接受承认.
curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic YWRtaW46YWRtaW4=" -v -i -s -X GET http://172.16.48.143:6080/service/xusers/secure/users/1
错误的账号密码, ranger会拒绝
curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic 123YWRtaW46YWRtaW4=" -X GET http://172.16.48.143:6080/service/xusers/secure/users/1
{"statusCode":401,"msgDesc":"Authentication Failed"}
chatgpt 咨询
