Sourcegraph Accounts Management System (SAMS)
Sourcegraph Accounts Management System (SAMS) is the centralized accounts system for all of the Sourcegraph-operated systems, it provides:
- Single Sign-On (SSO) experience for users of those systems, and cross-system referenceable user ID.
- Out-of-the-box machine-to-machine authentication and authorization capabilities.
It is compliant with OAuth 2 and OIDC protocols but only exposes a subset of the full capabilities for security reasons. In particular, only the following flows are allowed:
The OpenID Discovery endpoint lays out all the protocol details that a Service Provider (aka. Relay Party) needs to know to integrate with SAMS.
System designs
Security measures
Here is a list of security measures that are notable to systems integrating with SAMS:
- Access tokens all have expiry with 1 hour, refresh tokens are always issued together with access tokens.
- Refresh tokens all have expiry with 30 days, and each refresh token can only be used at most once. A new refresh token is always issued upon refreshing the access token.
Internal documents
Service images
Images are published to a private image repository, us-central1-docker.pkg.dev/sourcegraph-dev/sourcegraph-accounts/accounts-server
, on every commit in main
using the insiders
tag. To pull down the published images locally, you need to request access via Entitle.
Publishing resources are provisioned in sourcegraph/infrastructure
.
Operations
For standard infrastructure operations, see Sourcegraph Accounts infrastructure operations.
Deployments
The SAMS service infrastructure is defined in sourcegraph/managed-services/services/sourcegraph-accounts
utilizing Managed Services Platform.
Update deployment secrets
- For production instance (https://accounts.sourcegraph.com), all secrets are stored in the same GCP project
sourcegraph-accounts-prod-csvc
.- Make an Entitle request to grant access to the project.
- Add/update the secrets in the GSM.
- Make a pull request to add/update the secrets references under the
id: prod > secretEnv
section in theservice.yaml
file. - Once the pull request is merged, roll out a new deployment to pick up the changes to the secrets.
- For testing instance (https://accounts.sgdev.org), all secrets are stored in a shared GCP project
sourcegraph-dev
.- Make an Entitle request to grant access to the project.
- Add/update the secrets in the GSM. Because this is shared project, make sure to prefix all secrets with
SAMS_
to avoid naming collisions. - Make a pull request to add/update the secrets references under the
id: dev > secretEnv
section in theservice.yaml
file. - Once the pull request is merged, roll out a new deployment to pick up the changes to the secrets.
Modify deployment manifest
To modify the deployment manifest:
- Update
service.yaml
file - In the repository root, run
sg msp generate sourcegraph-accounts prod
- Stage changes and make a pull request
- The Terraform Cloud rolls out changes
Re-deploy the same manifest
Go to the “Deploy revision” page of the Cloud Run service and click DEPLOY (bottom of the page) without changing any configuration. This will also happen whenever a Terraform change happens to the “cloudrun” stack.
Observability
Alerting
Alerts are sent to Sentry and then forwarded to Slack:
- #alerts-sourcegraph-accounts-dev for accounts.sgdev.org
- #alerts-sourcegraph-accounts-prod for accounts.sourcegraph.com
Metrics
The deployment’s Cloud Run metrics overview page provides basic observability into the service provided out-of-the-box by Cloud Run, such as instance count and resource utilization.
Development
The source code and CI are located in the sourcegraph/sourcegraph-accounts GitHub repository.