github

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package github implements the GitHub credential provider.

The GitHub provider acquires and manages GitHub tokens for container runs. Tokens can be obtained from:

  • Environment variables (GITHUB_TOKEN, GH_TOKEN)
  • The gh CLI (gh auth token)
  • Interactive PAT prompt

The provider configures the proxy to inject Bearer tokens for api.github.com and github.com. Containers receive a format-valid placeholder token that passes gh CLI local validation, while the real token is injected at the network layer by the proxy.

Token refresh is supported for CLI and environment sources (30 minute interval). PATs entered interactively are static and cannot be refreshed.

Index

Constants

View Source
const (
	SourceCLI = "cli" // From `gh auth token` - refreshable
	SourceEnv = "env" // From GITHUB_TOKEN/GH_TOKEN env var - refreshable
	SourcePAT = "pat" // Interactive PAT entry - static
)

Token source values stored in Credential.Metadata[provider.MetaKeyTokenSource].

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct{}

Provider implements provider.CredentialProvider for GitHub.

func (*Provider) CanRefresh

func (p *Provider) CanRefresh(cred *provider.Credential) bool

CanRefresh reports whether this credential can be refreshed. Returns false for static credentials (PATs) and legacy credentials without metadata.

func (*Provider) Cleanup

func (p *Provider) Cleanup(cleanupPath string)

Cleanup cleans up GitHub resources.

func (*Provider) ConfigureProxy

func (p *Provider) ConfigureProxy(proxy provider.ProxyConfigurer, cred *provider.Credential)

ConfigureProxy sets up proxy headers for GitHub.

func (*Provider) ContainerEnv

func (p *Provider) ContainerEnv(cred *provider.Credential) []string

ContainerEnv returns environment variables for GitHub.

GH_TOKEN: Used by gh CLI for API authentication. We set a format-valid placeholder (ghp_...) that passes gh CLI's local validation. The proxy intercepts HTTPS requests and injects the real token via Authorization headers.

GIT_TERMINAL_PROMPT: Set to 0 to disable interactive credential prompts from git.

func (*Provider) ContainerMounts

func (p *Provider) ContainerMounts(cred *provider.Credential, containerHome string) ([]provider.MountConfig, string, error)

ContainerMounts returns mounts for GitHub. Copies user's gh CLI config (for aliases, preferences) if it exists. Authentication is handled via GH_TOKEN environment variable. Returns the temp directory path for cleanup when the run ends.

func (*Provider) Grant

func (p *Provider) Grant(ctx context.Context) (*provider.Credential, error)

Grant acquires GitHub credentials interactively or from environment.

Token acquisition order:

  1. GITHUB_TOKEN or GH_TOKEN environment variable
  2. gh CLI token via `gh auth token`
  3. Interactive PAT prompt

func (*Provider) ImpliedDependencies

func (p *Provider) ImpliedDependencies() []string

ImpliedDependencies returns dependencies implied by this provider.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider identifier.

func (*Provider) Refresh

Refresh re-acquires a fresh token from the original source and updates the proxy. Returns ErrRefreshNotSupported if the credential cannot be refreshed.

func (*Provider) RefreshInterval

func (p *Provider) RefreshInterval() time.Duration

RefreshInterval returns how often to attempt refresh.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL