如何用thrift处理认证和授权?

发布于 2024-10-10 14:51:16 字数 62 浏览 5 评论 0原文

我正在开发一个使用节俭的系统。我希望检查客户身份并对操作进行 ACL。 Thrift 是否为这些提供任何支持?

I'm developing a system which uses thrift. I'd like clients identity to be checked and operations to be ACLed. Does Thrift provide any support for those?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故笙诉离歌 2024-10-17 14:51:16

不直接。执行此操作的唯一方法是使用一种身份验证方法,该方法在服务器上创建一个(临时)密钥,然后更改所有方法,以便第一个参数是该密钥,并且它们都会另外引发未经身份验证的错误。例如:

exception NotAuthorisedException {
    1: string errorMessage,
}

exception AuthTimeoutException {
    1: string errorMessage,
}

service MyAuthService {
    string authenticate( 1:string user, 2:string pass )
        throws ( 1:NotAuthorisedException e ),

    string mymethod( 1:string authstring, 2:string otherargs, ... )
        throws ( 1:AuthTimeoutException e, ... ),
}

我们使用此方法并将密钥保存到安全的 memcached 实例,密钥超时时间为 30 分钟,以保持一切“快速”。收到 AuthTimeoutException 的客户端应重新授权并重试,我们有一些防火墙规则来阻止暴力攻击。

Not directly. The only way to do this is to have an authentication method which creates a (temporary) key on the server, and then change all your methods so that the first argument is this key and they all additionally raise an not-authenticated error. For instance:

exception NotAuthorisedException {
    1: string errorMessage,
}

exception AuthTimeoutException {
    1: string errorMessage,
}

service MyAuthService {
    string authenticate( 1:string user, 2:string pass )
        throws ( 1:NotAuthorisedException e ),

    string mymethod( 1:string authstring, 2:string otherargs, ... )
        throws ( 1:AuthTimeoutException e, ... ),
}

We use this method and save our keys to a secured memcached instance with a 30min timeout for keys to keep everything "snappy". Clients who receive an AuthTimeoutException are expected to reauthorise and retry and we have some firewall rules to stop brute-force attacks.

深府石板幽径 2024-10-17 14:51:16

像自动授权和权限这样的任务不被视为 Thrift 的一部分,主要是因为这些东西(通常)与应用程序逻辑比与一般的 RPC/序列化概念更相关。 Thrift 目前唯一支持的就是 TSASLTransport。我自己不能对这个说太多,只是因为我从来没有觉得有必要使用它。

另一种选择可能是使用 THeaderTransport 不幸的是,在撰写本文时仅使用 C++ 实现。因此,如果您打算将其与其他语言一起使用,您可能需要投入一些额外的工作。不用说,我们接受捐款......

Tasks like autorisation and permissions are not considered as a part of Thrift, mostly because these things are (usually) more related to the application logic than to a general RPC/serialization concept. The only Thing that Thrift supports out of the box right now is the TSASLTransport. I can't say much about that one myself, simply because I never felt the need to use it.

The other option could be to make use of THeaderTransport which unfortunately at the time of writing is only implemented with C++. Hence, if you plan to use it with some other language you may have to invest some additional work. Needless to say that we accept contributions ...

蘑菇王子 2024-10-17 14:51:16

有点晚了(我猜很晚了),但几年前我已经为此修改了 Thrift 源代码。

刚刚向 https://issues.apache.org/jira/ 提交了带有补丁的票证浏览/THRIFT-4221就是为了这个。

看看那个。基本上,该提案是添加一个“BeforeAction”挂钩来完成此操作。

Golang 生成差异示例

+       // Called before any other action is called
+       BeforeAction(serviceName string, actionName string, args map[string]interface{}) (err error)
+       // Called if an action returned an error
+       ProcessError(err error) error
 }

 type MyServiceClient struct {
@@ -391,7 +395,12 @@ func (p *myServiceProcessorMyMethod) Process(seqId int32, iprot, oprot thrift.TP
        result := MyServiceMyMethodResult{}
        var retval string
        var err2 error
-       if retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_); err2 != nil {
+       err2 = p.handler.BeforeAction("MyService", "MyMethod", map[string]interface{}{"AuthString": args.AuthString, "OtherArgs_": args.OtherArgs_})
+       if err2 == nil {
+               retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_)
+       }
+       if err2 != nil {
+               err2 = p.handler.ProcessError(err2)

A bit late (I guess very late) but I had modified the Thrift Source code for this a couple of years ago.

Just submitted a ticket with the Patch to https://issues.apache.org/jira/browse/THRIFT-4221 for just this.

Have a look at that. Basically the proposal is to add a "BeforeAction" hook that does exactly that.

Example Golang generated diff

+       // Called before any other action is called
+       BeforeAction(serviceName string, actionName string, args map[string]interface{}) (err error)
+       // Called if an action returned an error
+       ProcessError(err error) error
 }

 type MyServiceClient struct {
@@ -391,7 +395,12 @@ func (p *myServiceProcessorMyMethod) Process(seqId int32, iprot, oprot thrift.TP
        result := MyServiceMyMethodResult{}
        var retval string
        var err2 error
-       if retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_); err2 != nil {
+       err2 = p.handler.BeforeAction("MyService", "MyMethod", map[string]interface{}{"AuthString": args.AuthString, "OtherArgs_": args.OtherArgs_})
+       if err2 == nil {
+               retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_)
+       }
+       if err2 != nil {
+               err2 = p.handler.ProcessError(err2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文