apisix icon indicating copy to clipboard operation
apisix copied to clipboard

help request: Upstream services require different consumers to return different information on how to place their username in the header, and whether this header can be used as the username for casbin

Open cverdela opened this issue 3 years ago • 16 comments

Description

Upstream services require different consumers to return different information on how to place their username in the header, and whether this header can be used as the username for casbin

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):

cverdela avatar Apr 06 '23 03:04 cverdela

can you provider more info about the http body ?

casbin is responsible for authorization, not authentication. maybe you should process authorization by your self by Casbin.

of course , you can set http header by the proxy-rewrite plugin.

reference: https://apisix.apache.org/docs/apisix/plugins/proxy-rewrite/

Sn0rt avatar Apr 12 '23 02:04 Sn0rt

I'm not talking about authorization, but how to solve the problem of authorization and authentication at the same time

cverdela avatar Apr 12 '23 07:04 cverdela

In addition, identity information is passed to the upstream through the gateway, and the upstream returns different results according to different identities in the same route

cverdela avatar Apr 12 '23 07:04 cverdela

are you read this https://apisix.apache.org/zh/docs/apisix/plugins/authz-casbin/ ? maybe it's useful for you

Sn0rt avatar Apr 12 '23 08:04 Sn0rt

You didn't understand what I meant

cverdela avatar Apr 12 '23 08:04 cverdela

Can you give a specific example? I can't imagine your scene in one or two sentences

Sn0rt avatar Apr 12 '23 08:04 Sn0rt

There are three consumers a, b, and c. A and b have the same organization as 1, and c has the same organization as 2. The authentication of a, b, and c needs to be different. When accessing the same upstream, a and b return 11, and c return 22. Upstream only returns based on the organizational judgment passed in the header, without consumer information

cverdela avatar Apr 14 '23 00:04 cverdela

And abc has different permission controls for different upstream

cverdela avatar Apr 14 '23 00:04 cverdela

I need to prevent a from obtaining 22 through any means

cverdela avatar Apr 14 '23 00:04 cverdela

What is the execution order of the three plugins key-auth ,proxy-rewrite and authz-casbin ? How to make them execute in the order of key-auth ,proxy-rewrite and authz-casbin

cverdela avatar Apr 14 '23 07:04 cverdela

`"key-auth": {}, "proxy-rewrite": { "headers": { "add": { "tenant": "$consumer_group_id" } } }, "authz-casbin": { "model": "[request_definition] r = sub, obj, act

        [policy_definition]
        p = sub, obj, act

        [role_definition]
        g = _, _

        [policy_effect]
        e = some(where (p.eft == allow))

        [matchers]
        m = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && keyMatch(r.act, p.act)",

        "policy": "p, *, web1, GET
        p, admin, *, *
        g, 1000, admin",

        "username": "tenant"
    }
},`

cverdela avatar Apr 14 '23 07:04 cverdela

I want to use proxy rewrite to write consumer group information to the header, and then use casbin to confirm permissions. Upstream users can also obtain header information

cverdela avatar Apr 14 '23 07:04 cverdela

`{ "name": "web1-rewrite", "status": 1, "methods": [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE" ], "priority": 0, "labels": {}, "uri": "/web1/*", "plugins": {

    "proxy-rewrite": {
        "_meta": {
        	"priority": 1
    	},
        "headers": {
            "set": {
                "tenant": "$consumer_group_id"
            }
        }
    },
     "key-auth": {
        "_meta": {
        	"priority": 2
    	}
    },
    "authz-casbin": {
        "_meta": {
        	"priority": 0
    	},
        "model": "[request_definition]
        r = sub, obj, act

        [policy_definition]
        p = sub, obj, act

        [role_definition]
        g = _, _

        [policy_effect]
        e = some(where (p.eft == allow))

        [matchers]
        m = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && keyMatch(r.act, p.act)",

        "policy": "p, *, web1, GET
        p, admin, *, *
        g, 2080, admin",

        "username": "tenant"
    }
},

"upstream_id": "452002436731634371" }`

cverdela avatar Apr 14 '23 08:04 cverdela

I have 1 consumer group 2080. Jack is a consumer in 2080. I added the header as the ID of the consumer group using proxy rewrite, and verified the header using casbin. Surprisingly, the header. add implemented my idea, but the header. set failed

cverdela avatar Apr 14 '23 08:04 cverdela

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Mar 29 '24 10:03 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Apr 13 '24 10:04 github-actions[bot]