Skip to content

Conversation

@suryasai87
Copy link

Summary

This PR adds a new subproject oauth_auto_token_rotation that provides automatic OAuth token rotation for Databricks PostgreSQL (Lakebase) connections.

Problem Statement

Databricks OAuth tokens expire after 60 minutes, requiring manual regeneration or resulting in connection failures for PostgreSQL/Lakebase connections that rely on OAuth authentication.

Solution

A background service that automatically refreshes OAuth tokens every 50 minutes (with a 10-minute safety margin) and atomically updates the .pgpass file.

Key Features

  • Automatic Token Rotation - Refreshes OAuth tokens every 50 minutes (before 60-minute expiry)
  • Zero Downtime - Atomic .pgpass file updates prevent connection interruptions
  • Dual Authentication - Supports both OAuth M2M (production) and Databricks CLI (development)
  • Background Service - Runs as macOS LaunchAgent or Linux systemd service
  • Comprehensive Logging - Rotating logs with detailed operation tracking
  • Cross-Platform - Works on macOS and Linux

Installation

pip install git+https://github.com/suryasai87/oauth_auto_token_rotation.git

Usage

# Test rotation
databricks-oauth-rotator --once

# Install as background service
databricks-oauth-install \
  --workspace-url https://your-workspace.cloud.databricks.com \
  --pg-host instance-xyz.database.cloud.databricks.com \
  --pg-username your-email@company.com

Test plan

  • Verify README follows sandbox frontmatter format
  • Test installation via pip from original repo
  • Verify token rotation works with Databricks CLI auth
  • Verify token rotation works with OAuth M2M auth
  • Test background service installation on macOS
  • Test background service installation on Linux

Related Links

🤖 Generated with Claude Code

This adds a new subproject for automatic OAuth token rotation for
Databricks PostgreSQL (Lakebase) connections.

Features:
- Automatic token rotation every 50 minutes (before 60-min expiry)
- Zero downtime with atomic .pgpass file updates
- Dual authentication: OAuth M2M (production) and CLI (development)
- Background service support: macOS LaunchAgent / Linux systemd
- Comprehensive logging with rotation
- Cross-platform support (macOS, Linux)

This tool solves a critical automation problem where Databricks OAuth
tokens expire after 60 minutes, eliminating manual token regeneration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@suryasai87 suryasai87 requested a review from a team as a code owner December 7, 2025 22:16
@suryasai87 suryasai87 requested a review from fjakobs December 7, 2025 22:16
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

All commits in PR should be signed ('git commit -S ...'). See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@alexott alexott requested a review from Copilot December 8, 2025 09:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new oauth_auto_token_rotation subproject that provides automatic OAuth token rotation for Databricks PostgreSQL (Lakebase) connections. The solution addresses the problem of OAuth tokens expiring after 60 minutes by implementing a background service that refreshes tokens every 50 minutes and atomically updates the .pgpass file.

Key changes include:

  • Background service implementation supporting both OAuth M2M (production) and Databricks CLI (development) authentication
  • Cross-platform support for macOS (LaunchAgent) and Linux (systemd)
  • Command-line interface with comprehensive configuration options

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
oauth_auto_token_rotation/rotator.py Core rotation logic with dual authentication methods and atomic file updates
oauth_auto_token_rotation/cli.py Command-line interface for running the rotator
oauth_auto_token_rotation/install.py Service installation and management for macOS and Linux
oauth_auto_token_rotation/templates/launchd.plist.template macOS LaunchAgent configuration template
oauth_auto_token_rotation/init.py Package initialization and exports
oauth_auto_token_rotation/README.md Comprehensive documentation with usage examples
oauth_auto_token_rotation/requirements.txt Python package dependencies
CODEOWNERS Added ownership entry for the new subproject

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +124 to +127
def get_token_info(self, token: str) -> Dict[str, Any]:
"""Extract information from JWT token"""
try:
decoded = jwt.decode(token, options={"verify_signature": False})
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling JWT signature verification poses a security risk. Tokens should be verified to ensure they haven't been tampered with. Consider verifying the signature using the appropriate public key or removing this verification entirely if it's only for informational logging purposes.

Suggested change
def get_token_info(self, token: str) -> Dict[str, Any]:
"""Extract information from JWT token"""
try:
decoded = jwt.decode(token, options={"verify_signature": False})
def get_token_info(self, token: str, public_key: str, algorithms: list = ["RS256"]) -> Dict[str, Any]:
"""Extract information from JWT token, verifying its signature"""
try:
decoded = jwt.decode(token, public_key, algorithms=algorithms)

Copilot uses AI. Check for mistakes.
<array>
<string>{{PYTHON_PATH}}</string>
<string>-m</string>
<string>databricks_oauth_rotator.cli</string>
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name 'databricks_oauth_rotator.cli' is inconsistent with the package name 'oauth_auto_token_rotation'. The module path should likely be 'oauth_auto_token_rotation.cli' to match the directory structure.

Suggested change
<string>databricks_oauth_rotator.cli</string>
<string>oauth_auto_token_rotation.cli</string>

Copilot uses AI. Check for mistakes.
<array>
<string>{python_path}</string>
<string>-m</string>
<string>databricks_oauth_rotator.cli</string>
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name 'databricks_oauth_rotator.cli' is inconsistent with the package name 'oauth_auto_token_rotation'. Both occurrences should use 'oauth_auto_token_rotation.cli' to match the directory structure.

Suggested change
<string>databricks_oauth_rotator.cli</string>
<string>oauth_auto_token_rotation.cli</string>

Copilot uses AI. Check for mistakes.

[Service]
Type=simple
ExecStart={python_path} -m databricks_oauth_rotator.cli{cmd_args}
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name 'databricks_oauth_rotator.cli' is inconsistent with the package name 'oauth_auto_token_rotation'. Both occurrences should use 'oauth_auto_token_rotation.cli' to match the directory structure.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants