Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

For the slide deck on RBAC and implementation design, please check out - https://docs.google.com/presentation/d/1wNp1re47Isc_BX_wZWPjmJkOgnSqrlfhiNKRqJrirFE/edit#slide=id.p

Design discussion that has been signed off / agreed upon as of date

  • Use OPA and Envoy as sidecars in backend microservices for authorization

  • A program which can convert the json schema definitions to OPA rego code

  • Sample schema definition (Work in progress, but the design is more or less as it looks below, some parts of the json keys can change to make more meaningful naming convention)

Schema in YAML
---
- name: createContent
  uris: "/content/v1/create"
  upstream_url: http://knowledge-mw:5000/v1/content/create
  role_check:
    config.allowed_roles:
    - CONTENT_CREATOR
    - COURSE_CREATOR
  org_check:
    config.look_in:
    - body
    - header
    config.operator: and
    config.body: request.content.createdFor[*]
    config.header: X-Org-Id
  owner_check:
    config.look_in:
    - header
    config.header: X-User-Id
Schema in JSON
[
  {
    "name": "createContent",
    "uris": "/content/v1/create",
    "upstream_url": "http://knowledge-mw:5000/v1/content/create",
    "role_check": {
      "config.allowed_roles": [
        "CONTENT_CREATOR",
        "COURSE_CREATOR"
      ]
    },
    "org_check": {
      "config.look_in": [
        "body",
        "header"
      ],
      "config.operator": "and",
      "config.body": "request.content.createdFor[*]",
      "config.header": "X-Org-Id"
    },
    "owner_check": {
      "config.look_in": [
        "header"
      ],
      "config.header": "X-User-Id"
    }
  }
]
  • Schema can use the config.operator or can omit. The config.operator takes and or values which signify AND and ORoperation. If AND is used, then both keys are checked against the token and both need to match, if OR is used, then one of the key should match in the token

  • For a given check, the schema will not allow both AND OR operation to be used (example a && b || c). These type of checks will be treated as custom checks and will be directly implemented in rego. But these will work aa || bb || cc aa && bb && cc

  • Sample token structure

{
  "iss": "mykey",
  "aud": "project-sunbird-stage-client",
  "sub": "7e726898-0635-44cf-81ff-3b3a889c8dba",
  "typ": "Bearer",
  "exp": 1622744532,
  "iat": 1622658132,
  "roles": [
    {
      "scope": [
        {
          "orgId": "01269878797503692810"
        }
      ],
      "role": "COURSE_CREATOR"
    },
    {
      "scope": [
        {
          "orgId": "ORG_001"
        },
        {
          "orgId": "ORG_002"
        }
      ],
      "role": "BOOK_CREATOR"
    }
  ]
}

Design disucssion that is yet to be signed off / agreed

New proposed flow on Portal and Mobile for anonymous and logged sessions

  • The portal and mobile both will do a recaptcha check and pass the recaptcha response to backend for verification (portal backend in case of portal, android recapthca check in case of mobile)

  • Once recaptcha response is verified, an API call is made for anonymous session to fetch a token for the user

  • As of now we will allow only the portal and mobile app to invoke these register APIs on behalf of the user. The register API is protected by a JWT token that is injected only in mobile and portal

  • These tokens (which are issued to portal and mobile on behalf of the user) will have a higher rate limit (maybe 500 per hour)

  • A anonymous user can also directly obtain a token, how to do that is mentioned somewhere below in this post, but such token will have a very low ratelimit (maybe like 100 per hour)

  • Kong ACL’s will be removed as we will not require any ACL checks, the API authroriztion check will be handled by OPA and Envoy sidecars

Internal communication between services

  • Backend services can invoke APIs such as system APIs, metadata APIs etc anytime within the system (say backend batch job, Flink jobs, Samza jobs etc)

  • The services will be either injected with a token that is accepted by all services (and also passes the OPA checks) OR they will be routed via a separate service like private ingress which will attach a token to the request and forward to the backend

  • This token will have no expiry and can be used only for invoking the system, meta APIs

  • Using this token, user context APIs cannot be invoked

  • User context APIs will always require a user token

Registered users can obtain a token

  • As a registered user on the system you can obtain access tokens to invoke APIs for use cases like development, bulk content creation etc

  • There are two ways you can invoke the APIs

    • First option is to login on the system using Portal and use the connect.sid cookie for all your APIs via postman / curl. These APIs need to be routed via Portal endpoint and cannot use the /api endpoint

    • Second way is to obtain a token first from keycloak, then use the keycloak’s refresh token to obtain a new token from adminutils which will have your roles information. You can use the access token issued by adminutils to invoke APIs using the /api endpoints

  • In either approach, what APIs you can access is decided by what roles you have on the system

  • Note: Kong validating the Keycloak’s refresh token is not yet tested. But since the refresh token from keycloak is of type HS256, and we know the secret to be used to verify the HS256 signature and the iss to be used in Kong for validation (the domain), so we should be able to validate the keycloak token signature in kong also by onboarding a consumer with iss and the secret

External systems can obtain a token

  • Any external system that requires access to API’s, can sigup as an user on Sunbird and then use one of the mentioned flows to generate access token

  • API access as usual will be based on the role of the user account on Sunbird

  • Any special API access can be granted by Sunbird admin by assigning the appropriate roles on the system

  • If the external system requires user context API’s for other users, then they can authenticate on Sunbird as the user and then use the user specific token for any use cases involved in their end (similar to VDN authentication)

  • We can also have a button on the portal UI to get the access token after login (similar to the ops support tool)

Design discussion that are still open

External systems can obtain a token as anonymous

  • These are some special scenarios

  • In this design, anonymous access can only be done using the Portal / Mobile

  • For other systems where they need anonymous APIs access, we can expose an open endpoint (rate limitted by IP) from where a token will be issued

  • These will have very low rate limits to avoid APIs being accessed unknowingly as telemetry data, streaming url etc, will go unnoticed

  • This use case should be avoided if possible and APIs / tokens can be accessed / obtained only by signing up as a user on the system

Adding more fine grained roles and Rate Limits

  • We should have more fine grained roles so we can have ensure a user gets only specific set of APIs and not a wider set of APIs

  • Additional roles like below can be identified and introduced in the system

    • ORG_MANAGER

    • CONTENT_PUBLISHER

  • We can also introduce redis for storing rate limits as this will be a true ratelimit, instead of the local pod based rate limits in Kong

  • No labels