Skip to Content
RcmadeDocs
Ray secretsConcepts

Tokens & Authentication

Understand identity models, cryptographic token structure, OAuth PKCE flows, and the 3-tier auth resolution precedence hierarchy in Ray Secrets.

Ray Secrets enforces strict identity separation between human developers and automated machine workloads through two dedicated token types: Personal Access Tokens (PATs) and Service Tokens.


1. Dual-Identity Security Architecture

Secure credential management requires distinguishing between human operators and headless automation:

Personal Access Tokens (PAT)

  • Identity Domain: Represents an individual human engineer authenticated via OAuth 2.0.
  • Permission Model: Inherits Role-Based Access Control (RBAC) permissions granted to the user across all authorized workspaces and projects.
  • Workload Target: Interactive terminal sessions, local development loops, and administrative CLI workflows.
  • Prefix: ray_pat_ (e.g. ray_pat_example_000000).

Service Tokens

  • Identity Domain: Represents an unprivileged, headless machine workload.
  • Permission Model: Strictly locked to exactly one Project and one Environment (e.g. staging or production). A Service Token scoped to staging cannot decrypt or read production secrets.
  • Workload Target: Continuous integration runners (GitHub Actions, GitLab CI), Kubernetes pods, Docker multi-stage builds, and scheduled automation daemons.
  • Prefix: ray_st_ (e.g. ray_st_example_000000).

2. Cryptographic Token Construction & Entropy

Both token types are generated using cryptographically secure pseudorandom number generators (CSPRNG):

  • Entropy: Every token incorporates 256 bits of cryptographically secure entropy, formatted as a Base62 alphanumeric string.
  • Type Prefixing: The explicit prefix (ray_pat_ or ray_st_) enables immediate secret scanning tools (e.g. GitHub Secret Scanning) to detect exposed tokens and trigger automated revocation webhooks.
  • Scope Immutability: Service Token signatures are cryptographically bound to specific project and environment identifiers at creation time. Modifying the token payload invalidates the cryptographic signature, causing the Ray Secrets API gateway to reject requests immediately.

3. Authentication Protocols & Storage Architecture

Human Authentication: OAuth 2.0 RFC 7636 PKCE

When an engineer executes interactive login, the CLI initiates an OAuth 2.0 Authorization Code flow with Proof Key for Code Exchange (PKCE, RFC 7636):

ray login

For headless or scripted developer workstation login, pass an explicit token via --token:

ray login --token ray_pat_example_000000
Flag / OptionTypeDescription
-t, --token <token>stringAuthentication token (PAT or Service Token) to authenticate without interactive login prompts
  1. Cryptographic Challenge: The CLI generates a 32-byte cryptographically secure random code_verifier, hashes it using SHA-256 (code_challenge), and generates a 16-byte state parameter for CSRF mitigation.
  2. Ephemeral Loopback Server: The CLI starts an ephemeral local HTTP server bound exclusively to 127.0.0.1 on an available port.
  3. Browser Consent: The developer authenticates in their browser. Upon consent, the authorization server redirects to the loopback address with the authorization code.
  4. Token Exchange: The CLI exchanges the authorization code and code_verifier at the /token endpoint for an access token and refresh token.
  5. Client-Side Encryption at Rest: The token is saved in ~/.config/ray/config.json (or $XDG_CONFIG_HOME/ray/config.json) with restricted POSIX mode 0600. Tokens are encrypted client-side using AES-256-GCM via device-derived keys before writing to disk.
  6. Proactive Rotation: The CLI proactively rotates expiring access tokens using refresh tokens prior to expiration (CLI_TOKEN_REFRESH_BUFFER_MS).

Machine Authentication: Zero-Disk Service Tokens

Service Tokens follow a strict zero-disk persistence policy:

  • Service Tokens are never written to local configuration files (~/.config/ray/config.json or .ray/workspace.json).
  • Automated runners receive Service Tokens exclusively at runtime through the RAY_TOKEN environment variable.
  • When the container or runner finishes, the process memory is reclaimed by the operating system kernel with zero residual credential footprint.

4. Deterministic 2-Tier Runtime Precedence Engine

When resolving authentication for runtime commands (ray run, ray pull, ray get), Ray CLI enforces a strict 2-tier resolution precedence:

flowchart TD
  Env["1. Process Environment: RAY_TOKEN=<token>"] -->|Highest Runtime Precedence| Engine[Auth Resolution Engine]
  Local["2. Encrypted Global Config: ~/.config/ray/config.json"] -->|Fallback| Engine

  classDef primary fill:hsl(var(--primary)/0.1),stroke:hsl(var(--primary)/0.4),color:hsl(var(--primary));
  classDef neutral fill:hsl(var(--muted)/0.5),stroke:hsl(var(--border)),color:hsl(var(--foreground));
  class Env,Local neutral;
  class Engine primary;
  1. Process Environment (RAY_TOKEN): Highest precedence. Used in CI/CD pipelines, container runners, and automated scripts. If RAY_TOKEN is present in the process environment, Ray CLI authenticates immediately with this token:
    RAY_TOKEN=ray_st_example_000000 ray run -- npm start
  2. Encrypted Global Config Cache (~/.config/ray/config.json): Default fallback for local workstation development. Uses the client-encrypted token stored during interactive or scripted ray login.

To verify the currently active authenticated identity, permission scope, and linked workspace at any time:

ray whoami

To remove stored credentials and revoke the active local session:

ray logout

5. Zero-Downtime Rotation Lifecycle

Rotating credentials in production without interrupting active deployments requires zero-downtime rotation semantics:

  • Dual-Token Overlap Window: Ray Secrets allows overlapping Service Tokens for a single environment. When generating a new token, the previous token remains valid until explicitly revoked.
  • Atomic CI Secret Update: The new Service Token is updated in CI/CD secret stores (e.g. GitHub Secrets or GitLab CI Masked Variables). Subsequent pipelines immediately adopt the new token.
  • Instant Cache Invalidation: Revoking the deprecated Service Token in the Developer Console pushes an immediate invalidation event across the Ray Secrets edge vault cluster, terminating the deprecated credential instantly.

6. Comparative Specification

PropertyPersonal Access Token (PAT)Service Token
Target IdentityIndividual human developerAutomated CI/CD runner or container daemon
Permission ScopeUser RBAC across authorized workspacesStrictly locked to 1 Project + 1 Environment
Interactive AuthOAuth 2.0 PKCE via browser (ray login)Non-interactive bearer token only
At-Rest Storage~/.config/ray/config.json (client AES-256-GCM encrypted, 0600)Zero-disk persistence (injected via RAY_TOKEN)
Token LifecycleProactive OAuth refresh rotationConfigurable lifespan or perpetual with manual rotation
API PermissionsFull administrative access (create, edit, delete)Read-only vault injection (run, pull)

Ready to eliminate plaintext secrets?

Create a workspace to organize environments, invite your team, and generate scoped Service Tokens for CI/CD.