Skip to content

Phase 2c: User mode support (auth_mode awareness) #16

Closed

Description

@james-in-a-box

Summary

Restore user mode support that allows the gateway to distinguish between bot operations and human-attributed operations. This is important for scenarios where commits should be attributed to a personal GitHub account rather than the bot.

Background

jib supports two authentication modes:

  • Bot mode: Operations attributed to the GitHub App bot identity
  • User mode: Operations attributed to a personal GitHub account (via PAT)

The egg extraction simplified this to bot-only mode, losing user mode capabilities.

Components to Update

1. gateway/policy.py

Add auth_mode parameter to these methods:

  • check_branch_ownership(repo, branch, auth_mode="bot")
  • check_pr_ownership(repo, pr_number, auth_mode="bot")

Add missing method:

  • check_pr_create_allowed(repo, auth_mode="bot") - blocks PR creation in user mode

Add configured user support:

  • _get_configured_user() - get GitHub username from config
  • _is_configured_user_author() - check if PR/branch author matches configured user

Add branch existence check for user mode:

  • branch_exists() check to allow pushing to NEW branches in user mode
  • Fail-closed logic when API check fails

2. gateway/github_client.py

Add user mode validation:

  • is_user_token_valid() - check if user token is configured
  • get_authenticated_user() - get GitHub username for authenticated token
  • validate_user_mode_config() - validate user token matches configured github_user
  • get_user_mode_client() - convenience function for user mode client

Add private mode enforcement:

  • GH_COMMANDS_BLOCKED_IN_PRIVATE_MODE constant (blocks gh search)

3. gateway/repo_config.py

Extend to full functionality (currently only 3 functions):

  • get_github_username()
  • get_writable_repos() / get_readable_repos()
  • is_writable_repo() / is_readable_repo()
  • get_default_reviewer()
  • get_auth_mode(repo) - returns "bot" or "user"
  • is_user_mode_repo(repo)
  • get_user_mode_config() - git_name, git_email, github_user
  • get_bot_username()

4. gateway/gateway.py

Pass auth_mode to policy checks:

policy_result = policy.check_branch_ownership(repo, branch, auth_mode=auth_mode)

Acceptance Criteria

  • auth_mode parameter added to policy methods
  • check_pr_create_allowed() method implemented
  • Configured user support in policy checks
  • Branch existence check with fail-closed logic
  • User mode validation in github_client
  • Full repo_config.py functionality
  • Gateway passes auth_mode to policy checks
  • Documentation updated for user mode configuration

Reference

  • jib policy.py: james-in-a-box/gateway-sidecar/policy.py
  • jib github_client.py: james-in-a-box/gateway-sidecar/github_client.py
  • jib repo_config.py: james-in-a-box/config/repo_config.py

Authored-by: jib

Activity

  1. added a commit that references this issue on Feb 3, 2026
    fa72f49
  2. jwbron commented on Feb 3, 2026

    @jwbron
    Owner
  3. added a commit that references this issue on Feb 3, 2026
    94eb54d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions