traPtitech / traQ

traQ - traP Internal Messenger Application Backend
MIT License
420 stars 28 forks source link

権限制御を細やかにする #2463

Open kyosu-1 opened 2 months ago

kyosu-1 commented 2 months ago

権限制御周りの実装は主に以下で行われてる https://github.com/traPtitech/traQ/blob/master/router/middlewares/user_authenticate.go https://github.com/traPtitech/traQ/blob/master/router/middlewares/access_control.go https://github.com/traPtitech/traQ/tree/master/service/rbac

エンドポイントごとに必要なpermissionが設定されており、そのpermissionをアクセスしてきたものが持っているかをチェックしている。permissionはroleに紐づいており、ユーザーやbotはこのroleを持っている。またroleの中でもoauthのscopeパラメータとして指定されうるものがある。 ミドルウェアでのアクセス制御としては

をチェックしている。

permissionによって許可されるエンドポイントはrouterを見れば分かる。 https://github.com/traPtitech/traQ/blob/4ac16404c3a12e44ef1503b0d8cd9b2899deeede/router/v3/router.go#L88

課題として、現状permissionによる権限制御の粒度がやや大きく、OAuthのclient credentials grant でclient持たせたい権限を付与できない問題がある。 https://github.com/traPtitech/traQ/pull/2433#discussion_r1648827153

新しいpermissionを追加・調整するなどして、権限制御を必要十分に細かくする形で対応したい。