webiny-js icon indicating copy to clipboard operation
webiny-js copied to clipboard

Headless CMS Security Scopes

Open Andrei199991 opened this issue 6 years ago • 2 comments

Addressing the Security Scopes mentioned in #829 and #1018

Here's how I envision headless security scopes:

Front End

Toggling Model security scopes
  • we add a new section under Security > Headless CMS called Models (see ss #1)
  • in this section, you select an existing environment (see ss #2)
  • then, you select read / preview / manage api (imagine 3 different tabs) and you see a list with all resolvers associated to - that env & api type
  • all resolvers above have 1 "Authorization Required" checkbox
  • (checkboxes can be disabled and set to true/false for values we don't want to modify, ie: allow full AT access to read/preview api)
New user permissions
  • we add a new accordion section in /users admin app route where we can set which headless cms resolvers the selected user can use (see ss #3)
  • just as above, we will see a list with all resolvers
  • the environment is selectable via a <select> input or sth similar

Back End

  • valid JWTs & PATs are automatically resolved into context.user.id, context.user.access.scopes, context.user.access.fullAccess... In the same fashion we can also resolve a new context.user.access.headlessCmsScopes field which contains our aforementioned cms permissions set via checkboxes
eg:

context.user.access.headlessCmsScopes = {
    production: [
        "createBlogPost",
        "getBlogPost",
         ...
    ], 
    bassCannon: [
        "listBlogPosts",
         ...
    ],
    ...
}

User stories solved (see #1018)

~~us [1] - already done~~ us [1.1] - we can add a disable / delete button in /settings/cms/accessTokens?id=... us [1.2] - we can add a button that disables all Security > Headless CMS > Models > /read API checkboxes and sets them to false by default ~~us [2] - fixed in my PR #1018~~ (but i could rename the plugin from "context-cms-validate-access-token" to "context-cms-authorize" as it'll be more clear) us [3] - whatever.

  • we could give add an option under Settings > Headless CMS that allows users to set if the APIs are public by default, thus setting the earlier checkbox's default value (mentioned above at [1.2]).
  • we could also give them a note stating Bro, your API is public by default. make sure you check your security scopes or you're gonna get your corporation's data crawled by russian hackers and exposed on liveleak.com when they create a new model

us [4] - (actual TODO) will solve as explained above if we find it a good approach us [5] - (actual TODO) will solve as explained above if we find it a good approach

Questions / Remarks

ps / question #1: "The MANAGE API only needs JWT auth." actually, PATs should (and do currently) authenticate the user as well as the JWT does ps #2: i didn't use hasScope (mentioned in #829) because i didn't need to

image image image

Andrei199991 avatar Jun 18 '20 14:06 Andrei199991

Update

  • ~Add scopes to /settings/cms/accessTokens (just like in /roles)~
  • ~Improve ScopesMultiAutoComplete to allow a filter function and use it in /settings/cms/accessTokens (show only read scopes)~
  • add cms.listEnvironments.data.contentModels field in graphql (returns only modelId) ^add a commodo model with 1 field: modelId

+ ofc, make it work in the back end

CMS scope format: cms:<read/manage>:<environment>:<CmsContentModel.modelId>:

ps: use the main /graphql api (containing cms, pageBuilder, ...)

ps 2: /preview follows the same scopes as /read

My personal notes

/read (and implicitly /preview) api is protected by default (fullAccess: true or scopes: [...])

"cms:<read/manage>:<environment>:<CmsContentModel.modelId>"
"cms:read:production:book";
"cms:read:*:book";

Andrei199991 avatar Jun 18 '20 15:06 Andrei199991

Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Slack Community or ping one of the reviewers. Thank you for your contributions!

adrians5j avatar Oct 10 '20 01:10 adrians5j