This document formally defines the token scope specification for Sourcegraph Accounts Management System (SAMS) :

  1. Components of a token scope, i.e. how do token scopes look?
  2. Token scope matching strategy, i.e. how authorization works?

These scopes are used for user access tokens, as well as SAMS M2M (machine-to-machine) authentication and authorization.

Basic format

A scope is always consists of three parts: service, permission hierarchy, and action, and are separated by double colons ::, e.g. sams::user.roles::read, ssc::subscriptions::read:

  1. The total length of a scope cannot exceed 255 characters.
  2. Service: the slug of the service name, up to 30 characters.
  3. Permission hierarchy: the hierarchy of the permissions under the given service, up to 215 characters.
  4. Action: the allowed action for the given permission of the given service, up to 10 characters.

Scope alias

This is initially intended for making OIDC scopes be compatible with our design (profile -> sams::user.profile::read), but could also be a useful extension in the future, e.g. in the event of scope renaming efforts.

How to add new token scopes

  1. Add desired scopes to the sourcegraph/sourcegraph-accounts-sdk-go repository, e.g. https://github.com/sourcegraph/sourcegraph-accounts-sdk-go/pull/94.
  2. Once merged, update the sourcegraph/sourcegraph-accounts repository to pull the SDK version that has your newly added scopes, e.g. https://github.com/sourcegraph/sourcegraph-accounts/pull/387.
  3. Once merged, make sure a new SAMS deployment that has the new scopes is rolled out your desired environment (SAMS-dev and/or SAMS-prod) before deploying your service that requires these new scopes. Otherwise, authentication failure will occur due to missing required scopes.

References