gcf

package
v0.46.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package gcf implements the dispatch.Dispatcher interface using a GCP Cloud Function as the token mint. The mint validates GitHub OIDC tokens via Workload Identity Federation and issues scoped installation tokens for each agent role.

Index

Constants

View Source
const (

	// DefaultInferencePool is the WIF pool used by inference commands.
	// Separate from the mint pool (defaultPool) so that mint and inference
	// lifecycle operations don't interfere with each other.
	DefaultInferencePool = mintcore.DefaultInferencePool
)
View Source
const PlaceholderOrg = "x0fullsend0placeholder"

PlaceholderOrg is the deploy-time placeholder used in the WIF condition before any real orgs are added. Must pass mintcore.GitHubOrgPattern validation (used by Provision), but should not collide with any real GitHub org. The CLI rejects this value at enrollment time.

View Source
const WIFProviderStateActive = "ACTIVE"

WIFProviderStateActive is the State of a provider that is not soft-deleted.

Variables

View Source
var ErrFunctionNotFound = errors.New("mint function not found")

ErrFunctionNotFound is returned when the mint function does not exist.

View Source
var ErrSecretNotFound = errors.New("secret not found")

ErrSecretNotFound is returned when a Secret Manager secret does not exist.

Functions

func DefaultFunctionSourceDir

func DefaultFunctionSourceDir() string

DefaultFunctionSourceDir returns the default path to the Cloud Function source directory. This assumes the CLI is run from the repository root.

func DeletedSecretIDs added in v0.34.0

func DeletedSecretIDs(client GCFClient) []string

DeletedSecretIDs returns the secret IDs passed to DeleteSecret calls on a fake client, for cross-package test assertions. Returns nil if client isn't a fake.

func LastWIFProviderCondition added in v0.31.0

func LastWIFProviderCondition(client GCFClient) string

LastWIFProviderCondition returns the AttributeCondition passed to the most recent CreateWIFProvider or UpdateWIFProvider call on a fake client, for cross-package test assertions. Returns "" if client isn't a fake or no call was made yet.

func MintServiceAccountEmail added in v0.34.0

func MintServiceAccountEmail(projectID string) string

MintServiceAccountEmail returns the email address of the fullsend-mint service account for the given GCP project.

func ProjectIAMBindingCount added in v0.34.0

func ProjectIAMBindingCount(client GCFClient) int

ProjectIAMBindingCount returns the number of SetProjectIAMBinding calls recorded on a fake client, for cross-package test assertions. Returns 0 if client isn't a fake.

func RecordedCalls added in v0.36.0

func RecordedCalls(client GCFClient) []string

RecordedCalls returns the method names recorded on a fake client, for cross-package test assertions. Returns nil if client isn't a fake.

func ValidateProjectID added in v0.12.0

func ValidateProjectID(id string) bool

ValidateProjectID checks if a string is a valid GCP project ID.

func ValidateRegion added in v0.12.0

func ValidateRegion(region string) bool

ValidateRegion checks if a string is a valid GCP region.

func ValidateRepoSlug added in v0.12.0

func ValidateRepoSlug(slug string) bool

ValidateRepoSlug checks if a string is a valid GitHub repository name.

Types

type Config

type Config struct {
	ProjectID         string
	Region            string // default: "us-central1"
	WIFPoolName       string // default: "fullsend-pool"
	WIFProvider       string // default: "github-oidc"
	GitHubOrgs        []string
	Repo              string // "owner/repo" to register/scope WIF for one repo; empty = no repo registration (Provision) or org-scoped WIF (inference ProvisionWIF)
	FunctionSourceDir string // path to Cloud Function source directory

	// AgentPEMs maps role → PEM private key data for all agent Apps.
	AgentPEMs map[string][]byte

	// AgentAppIDs maps role → GitHub App ID for all agent Apps.
	AgentAppIDs map[string]string

	// MintURL, if set, skips infrastructure deployment and uses the
	// existing mint at this URL for PEM storage, per-repo WIF, and PEM
	// auto-copy.
	MintURL string

	// DeployMode controls function deployment: auto (default) or skip.
	DeployMode DeployMode

	// Version is the fullsend semver (e.g. "0.27.0") to stamp on the
	// deployed mint. Embedded directly into the source code at bundle time.
	Version string
	// Commit is the git commit SHA to stamp on the deployed mint.
	// Embedded directly into the source code at bundle time.
	Commit string
	// PublicMint bootstraps PER_REPO_WIF_REPOS=* and a permissive WIF provider CEL.
	PublicMint bool

	// StatusGitHub holds the GitHub status auth config stamped into
	// the source at bundle time alongside Version and Commit.
	StatusGitHub StatusGitHubAuth
}

Config holds the inputs for GCF mint provisioning.

type DeployMode

type DeployMode int

DeployMode controls Cloud Function deployment behavior.

const (
	// DeployAuto compares source hash; skips deploy if unchanged.
	DeployAuto DeployMode = iota
	// DeploySkip never redeploys; reuses the existing function URL.
	DeploySkip
)

type FakeGCFOption added in v0.19.0

type FakeGCFOption func(*fakeGCFClient)

FakeGCFOption configures a client from NewFakeGCFClient.

func WithFakeErrors added in v0.19.0

func WithFakeErrors(errs map[string]error) FakeGCFOption

func WithFakeFunctionInfo added in v0.19.0

func WithFakeFunctionInfo(info *FunctionInfo) FakeGCFOption

func WithFakeRevisionInfo added in v0.19.0

func WithFakeRevisionInfo(info *ServiceRevisionInfo) FakeGCFOption

func WithFakeSecrets added in v0.19.0

func WithFakeSecrets(secrets map[string]bool) FakeGCFOption

func WithFakeTrafficEnvVars added in v0.19.0

func WithFakeTrafficEnvVars(env map[string]string) FakeGCFOption

func WithFakeWIFProvider added in v0.19.0

func WithFakeWIFProvider(p *WIFProviderInfo) FakeGCFOption

type FunctionConfig

type FunctionConfig struct {
	ServiceAccount string
	EnvVars        map[string]string
	StorageSource  json.RawMessage // structured object from generateUploadUrl response
	EntryPoint     string
	Runtime        string
}

FunctionConfig holds parameters for creating a Cloud Function.

type FunctionInfo

type FunctionInfo struct {
	Name    string
	State   string
	URI     string
	Region  string
	EnvVars map[string]string
}

FunctionInfo holds metadata about a deployed Cloud Function.

type GCFClient

type GCFClient interface {
	// Service account operations
	CreateServiceAccount(ctx context.Context, projectID, saName, displayName string) error
	DeleteServiceAccount(ctx context.Context, projectID, saEmail string) error

	// WIF operations
	CreateWIFPool(ctx context.Context, projectNumber, poolID, displayName string) error
	DeleteWIFPool(ctx context.Context, projectNumber, poolID string) error
	CreateWIFProvider(ctx context.Context, projectNumber, poolID, providerID string, cfg OIDCProviderConfig) error
	GetWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) (*WIFProviderInfo, error)
	UpdateWIFProvider(ctx context.Context, projectNumber, poolID, providerID string, cfg OIDCProviderConfig) error
	DisableWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) error
	DeleteWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) error

	// Secret Manager
	GetSecret(ctx context.Context, projectID, secretID string) error
	CreateSecret(ctx context.Context, projectID, secretID string) error
	AddSecretVersion(ctx context.Context, projectID, secretID string, data []byte) error
	AccessSecretVersion(ctx context.Context, projectID, secretID string) ([]byte, error)
	DisableSecretVersion(ctx context.Context, projectID, secretID string) error
	EnableSecretVersion(ctx context.Context, projectID, secretID string) error
	DeleteSecret(ctx context.Context, projectID, secretID string) error

	// IAM bindings
	SetSecretIAMBinding(ctx context.Context, resource, member, role string) error
	// ReplaceSecretIAMBinding sets the IAM binding for a role on a Secret
	// Manager resource, replacing all existing members for that role with
	// the specified member. This is destructive: any other members bound
	// to the same role on the resource are removed. Use this instead of
	// SetSecretIAMBinding when re-install with a different service account
	// should revoke the old account's access.
	ReplaceSecretIAMBinding(ctx context.Context, resource, member, role string) error
	// SetProjectIAMBinding adds an IAM binding on a Cloud Resource Manager
	// project. This is intentionally additive (unlike ReplaceSecretIAMBinding)
	// because project-level roles may have multiple legitimate members.
	SetProjectIAMBinding(ctx context.Context, projectID, member, role string) error

	// Cloud Run IAM (for function invoker policy)
	SetCloudRunInvoker(ctx context.Context, projectID, region, serviceName string) error

	// Cloud Functions v2
	DeleteFunction(ctx context.Context, projectID, region, functionName string) error
	GetFunction(ctx context.Context, projectID, region, functionName string) (*FunctionInfo, error)
	// GetCloudRunServiceURI returns the public URI of the Cloud Run service
	// backing a Gen2 Cloud Function (same name as the function).
	GetCloudRunServiceURI(ctx context.Context, projectID, region, serviceName string) (string, error)
	UploadFunctionSource(ctx context.Context, projectID, region string, sourceZip []byte) (storageSource json.RawMessage, err error)
	CreateFunction(ctx context.Context, projectID, region, functionName string, cfg FunctionConfig) (string, error)
	UpdateFunction(ctx context.Context, projectID, region, functionName string, cfg FunctionConfig) (string, error)
	UpdateFunctionEnvVars(ctx context.Context, projectID, region, functionName string, envVars map[string]string) (string, error)
	// UpdateServiceEnvVars updates environment variables on the underlying
	// Cloud Run service directly, bypassing the Cloud Functions API. This
	// avoids triggering a source rebuild — only a new revision is created
	// reusing the existing container image. Uses a multi-step approach:
	// GETs the current service, PATCHes the template to create a new
	// revision, GETs the service again to discover the revision name,
	// then PATCHes traffic to pin 100% to that revision (REVISION-pinned,
	// matching Cloud Functions deploy behavior). Returns the new revision
	// name.
	UpdateServiceEnvVars(ctx context.Context, projectID, region, serviceName string, envVars map[string]string) (string, error)

	// GetServiceRevisionInfo returns Cloud Run service details including the
	// traffic-serving revision, template revision, allocation type, and recent
	// revision history. Used by mint status for revision awareness.
	GetServiceRevisionInfo(ctx context.Context, projectID, region, serviceName string) (*ServiceRevisionInfo, error)

	// GetServiceTrafficEnvVars reads environment variables from the Cloud Run
	// revision currently serving traffic, rather than from the service template.
	// This avoids reading stale data when the template and traffic-serving
	// revision have diverged.
	GetServiceTrafficEnvVars(ctx context.Context, projectID, region, serviceName string) (map[string]string, error)

	WaitForOperation(ctx context.Context, operationName string) error

	// Project number lookup
	GetProjectNumber(ctx context.Context, projectID string) (string, error)
}

GCFClient abstracts GCP API operations needed by the provisioner.

func NewFakeGCFClient added in v0.19.0

func NewFakeGCFClient(opts ...FakeGCFOption) GCFClient

NewFakeGCFClient returns an in-memory GCFClient for tests.

type LiveGCFClient

type LiveGCFClient struct {
	*gcp.Client
	// contains filtered or unexported fields
}

LiveGCFClient implements GCFClient using GCP REST APIs. It embeds *gcp.Client for shared ADC auth.

func NewLiveGCFClient

func NewLiveGCFClient(quotaProject string) *LiveGCFClient

NewLiveGCFClient creates a new LiveGCFClient. The quotaProject is set as x-goog-user-project on every request so API quota is billed to the target project, not the shared ADC OAuth client project.

func (*LiveGCFClient) AccessSecretVersion

func (c *LiveGCFClient) AccessSecretVersion(ctx context.Context, projectID, secretID string) ([]byte, error)

AccessSecretVersion reads the latest version of a Secret Manager secret.

func (*LiveGCFClient) AddSecretVersion

func (c *LiveGCFClient) AddSecretVersion(ctx context.Context, projectID, secretID string, data []byte) error

AddSecretVersion adds a new version with the given data to an existing secret.

func (*LiveGCFClient) CreateFunction

func (c *LiveGCFClient) CreateFunction(ctx context.Context, projectID, region, functionName string, cfg FunctionConfig) (string, error)

CreateFunction creates a Cloud Function v2.

func (*LiveGCFClient) CreateSecret

func (c *LiveGCFClient) CreateSecret(ctx context.Context, projectID, secretID string) error

CreateSecret creates a Secret Manager secret.

func (*LiveGCFClient) CreateServiceAccount

func (c *LiveGCFClient) CreateServiceAccount(ctx context.Context, projectID, saName, displayName string) error

CreateServiceAccount creates a new service account. Retries on HTTP 429 (quota exhaustion) with exponential backoff via doWIFRequestWithRetry.

func (*LiveGCFClient) CreateWIFPool

func (c *LiveGCFClient) CreateWIFPool(ctx context.Context, projectNumber, poolID, displayName string) error

CreateWIFPool creates a new WIF pool. Retries on HTTP 429 (quota exhaustion) with exponential backoff via doWIFRequestWithRetry.

func (*LiveGCFClient) CreateWIFProvider

func (c *LiveGCFClient) CreateWIFProvider(ctx context.Context, projectNumber, poolID, providerID string, cfg OIDCProviderConfig) error

CreateWIFProvider creates a WIF OIDC provider.

func (*LiveGCFClient) DeleteFunction added in v0.36.0

func (c *LiveGCFClient) DeleteFunction(ctx context.Context, projectID, region, functionName string) error

DeleteFunction permanently deletes a Cloud Function v2.

func (*LiveGCFClient) DeleteSecret added in v0.12.0

func (c *LiveGCFClient) DeleteSecret(ctx context.Context, projectID, secretID string) error

DeleteSecret permanently deletes a Secret Manager secret and all its versions.

func (*LiveGCFClient) DeleteServiceAccount added in v0.36.0

func (c *LiveGCFClient) DeleteServiceAccount(ctx context.Context, projectID, saEmail string) error

DeleteServiceAccount permanently deletes a service account.

func (*LiveGCFClient) DeleteWIFPool added in v0.36.0

func (c *LiveGCFClient) DeleteWIFPool(ctx context.Context, projectNumber, poolID string) error

DeleteWIFPool permanently deletes a WIF pool and all its providers.

func (*LiveGCFClient) DeleteWIFProvider added in v0.12.0

func (c *LiveGCFClient) DeleteWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) error

DeleteWIFProvider permanently deletes a WIF provider.

func (*LiveGCFClient) DisableSecretVersion added in v0.12.0

func (c *LiveGCFClient) DisableSecretVersion(ctx context.Context, projectID, secretID string) error

DisableSecretVersion disables the latest version of a Secret Manager secret. The disable API rejects the "latest" alias, so we first resolve it to a numeric version via GET, then disable that version.

func (*LiveGCFClient) DisableWIFProvider added in v0.12.0

func (c *LiveGCFClient) DisableWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) error

DisableWIFProvider sets a WIF provider's disabled state to true.

func (*LiveGCFClient) EnableSecretVersion added in v0.12.0

func (c *LiveGCFClient) EnableSecretVersion(ctx context.Context, projectID, secretID string) error

EnableSecretVersion enables the latest version of a Secret Manager secret. Mirrors DisableSecretVersion: resolves "latest" to a numeric version, then enables it. No-op if the version is already enabled or does not exist.

func (*LiveGCFClient) GetCloudRunServiceURI added in v0.30.0

func (c *LiveGCFClient) GetCloudRunServiceURI(ctx context.Context, projectID, region, serviceName string) (string, error)

GetCloudRunServiceURI returns the public URI of a Cloud Run service.

func (*LiveGCFClient) GetFunction

func (c *LiveGCFClient) GetFunction(ctx context.Context, projectID, region, functionName string) (*FunctionInfo, error)

GetFunction checks if a Cloud Function exists and returns its info.

func (*LiveGCFClient) GetProjectNumber

func (c *LiveGCFClient) GetProjectNumber(ctx context.Context, projectID string) (string, error)

GetProjectNumber looks up the project number for a project ID.

func (*LiveGCFClient) GetSecret

func (c *LiveGCFClient) GetSecret(ctx context.Context, projectID, secretID string) error

GetSecret checks that a Secret Manager secret exists.

func (*LiveGCFClient) GetServiceRevisionInfo added in v0.14.0

func (c *LiveGCFClient) GetServiceRevisionInfo(ctx context.Context, projectID, region, serviceName string) (*ServiceRevisionInfo, error)

GetServiceRevisionInfo returns Cloud Run service details including the traffic-serving revision, template revision, allocation type, and recent revision history.

func (*LiveGCFClient) GetServiceTrafficEnvVars added in v0.14.0

func (c *LiveGCFClient) GetServiceTrafficEnvVars(ctx context.Context, projectID, region, serviceName string) (map[string]string, error)

GetServiceTrafficEnvVars reads environment variables from the Cloud Run revision that is currently serving traffic, rather than from the service template. Although UpdateServiceEnvVars now pins traffic to the new revision, divergence can still occur if the traffic PATCH fails (partial failure) or from historical deployments before traffic pinning was added. This method resolves that by finding the revision that has traffic allocated and reading its container env vars directly.

Uses the trafficStatuses field (observed state) rather than the traffic field (desired config) so that revision names are always resolved — even for TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST entries — and the data reflects actual serving state rather than desired configuration.

func (*LiveGCFClient) GetWIFProvider

func (c *LiveGCFClient) GetWIFProvider(ctx context.Context, projectNumber, poolID, providerID string) (*WIFProviderInfo, error)

GetWIFProvider reads an existing WIF OIDC provider's configuration.

func (*LiveGCFClient) ReplaceSecretIAMBinding added in v0.34.0

func (c *LiveGCFClient) ReplaceSecretIAMBinding(ctx context.Context, resource, member, role string) error

ReplaceSecretIAMBinding sets the IAM binding for a role on a Secret Manager resource, replacing all existing members for that role with the specified member. This is destructive: any other members bound to the same role are silently removed. Safe for fullsend-managed bot token secrets which have a single expected accessor.

func (*LiveGCFClient) SetCloudRunInvoker

func (c *LiveGCFClient) SetCloudRunInvoker(ctx context.Context, projectID, region, serviceName string) error

SetCloudRunInvoker ensures allUsers has roles/run.invoker on the Cloud Run service backing a Cloud Function. Uses read-modify-write with retry on 409 (etag conflict) to preserve existing bindings. The function's own OIDC validation is the security boundary.

func (*LiveGCFClient) SetProjectIAMBinding

func (c *LiveGCFClient) SetProjectIAMBinding(ctx context.Context, projectID, member, role string) error

SetProjectIAMBinding sets an IAM binding on a GCP project. Uses read-modify-write with retry on 409 Conflict (etag mismatch). Retries up to 7 times with exponential backoff and jitter (500ms base, capped at 10s) to handle concurrent read-modify-write contention when multiple callers (e.g. parallel behaviour test pool repos) update the same project-level IAM policy simultaneously.

func (*LiveGCFClient) SetSecretIAMBinding

func (c *LiveGCFClient) SetSecretIAMBinding(ctx context.Context, resource, member, role string) error

SetSecretIAMBinding sets an IAM binding on a Secret Manager resource. Uses read-modify-write with retry on 409 Conflict (etag mismatch). The member is added to the existing binding for the role (additive).

func (*LiveGCFClient) UpdateFunction

func (c *LiveGCFClient) UpdateFunction(ctx context.Context, projectID, region, functionName string, cfg FunctionConfig) (string, error)

UpdateFunction updates an existing Cloud Function v2 using the PATCH API. It returns a long-running operation name that can be polled with WaitForOperation.

func (*LiveGCFClient) UpdateFunctionEnvVars

func (c *LiveGCFClient) UpdateFunctionEnvVars(ctx context.Context, projectID, region, functionName string, envVars map[string]string) (string, error)

UpdateFunctionEnvVars updates only the environment variables of a Cloud Function v2, leaving build config and other service config untouched.

func (*LiveGCFClient) UpdateServiceEnvVars added in v0.12.0

func (c *LiveGCFClient) UpdateServiceEnvVars(ctx context.Context, projectID, region, serviceName string, envVars map[string]string) (string, error)

UpdateServiceEnvVars updates environment variables on the underlying Cloud Run service directly via the Cloud Run Admin API v2, bypassing the Cloud Functions API entirely. This avoids triggering a source rebuild — only a new Cloud Run revision is created reusing the existing container image.

Uses a multi-step approach to match Cloud Functions deploy behavior:

  1. GET current service to preserve container config
  2. PATCH template to create a new revision with updated env vars
  3. GET service to discover the new revision name
  4. PATCH traffic to pin 100% to the new revision (REVISION-pinned)

This ensures explicit revision-pinned traffic routing. If the traffic PATCH fails, the old revision continues serving — no traffic is lost. Returns the new revision name for CLI reporting and rollback reference.

See https://github.com/fullsend-ai/fullsend/issues/1844.

func (*LiveGCFClient) UpdateWIFProvider

func (c *LiveGCFClient) UpdateWIFProvider(ctx context.Context, projectNumber, poolID, providerID string, cfg OIDCProviderConfig) error

UpdateWIFProvider patches an existing WIF OIDC provider's attribute condition and allowed audiences.

func (*LiveGCFClient) UploadFunctionSource

func (c *LiveGCFClient) UploadFunctionSource(ctx context.Context, projectID, region string, sourceZip []byte) (json.RawMessage, error)

UploadFunctionSource generates a signed upload URL and uploads the source zip. Returns the storage source URI for use in CreateFunction.

func (*LiveGCFClient) WaitForOperation

func (c *LiveGCFClient) WaitForOperation(ctx context.Context, operationName string) error

WaitForOperation polls a long-running operation until it completes or the context is canceled. Polls every 5 seconds for up to 10 minutes.

type MintDiscovery

type MintDiscovery struct {
	URL             string
	RoleAppIDs      map[string]string
	PerRepoWIFRepos []string
}

MintDiscovery holds the results of a single GetFunction call, providing the URL, existing role-to-app-ID mappings, and per-repo WIF repos.

type OIDCProviderConfig

type OIDCProviderConfig struct {
	IssuerURI          string
	AttributeCondition string
	AllowedAudiences   []string
}

OIDCProviderConfig holds configuration for a WIF OIDC provider.

type Provisioner

type Provisioner struct {
	// contains filtered or unexported fields
}

Provisioner creates GCP infrastructure for OIDC-based token minting.

func NewProvisioner

func NewProvisioner(cfg Config, gcpAPI GCFClient) *Provisioner

NewProvisioner creates a new Provisioner with defaults applied.

func (*Provisioner) AddRoleToMint added in v0.19.0

func (p *Provisioner) AddRoleToMint(ctx context.Context, role, appID string) error

AddRoleToMint registers a role's app ID in ROLE_APP_IDS and updates ALLOWED_ROLES on the traffic-serving Cloud Run revision.

func (*Provisioner) AddWorkflowHostRepo added in v0.34.0

func (p *Provisioner) AddWorkflowHostRepo(ctx context.Context, repo string) error

AddWorkflowHostRepo adds a repo to the mint's WORKFLOW_HOST_REPOS env var so the mint accepts workflows hosted in that repo for per-repo callers. Idempotent — skips repos already listed.

func (*Provisioner) DeleteAgentPEM added in v0.19.0

func (p *Provisioner) DeleteAgentPEM(ctx context.Context, role string) error

DeleteAgentPEM permanently deletes the Secret Manager secret for the given role.

func (*Provisioner) DeleteMintFunction added in v0.36.0

func (p *Provisioner) DeleteMintFunction(ctx context.Context) error

DeleteMintFunction permanently deletes the mint Cloud Function.

func (*Provisioner) DeleteMintServiceAccount added in v0.36.0

func (p *Provisioner) DeleteMintServiceAccount(ctx context.Context) error

DeleteMintServiceAccount permanently deletes the mint service account.

func (*Provisioner) DeleteMintWIFPool added in v0.36.0

func (p *Provisioner) DeleteMintWIFPool(ctx context.Context) error

DeleteMintWIFPool permanently deletes the WIF pool and all its providers.

func (*Provisioner) DeleteWIFProvider added in v0.12.0

func (p *Provisioner) DeleteWIFProvider(ctx context.Context, providerID string) error

DeleteWIFProvider permanently deletes a WIF provider.

func (*Provisioner) DisableWIFProvider added in v0.12.0

func (p *Provisioner) DisableWIFProvider(ctx context.Context, providerID string) error

DisableWIFProvider sets a WIF provider's disabled field to true.

func (*Provisioner) DiscoverMint

func (p *Provisioner) DiscoverMint(ctx context.Context) (*MintDiscovery, error)

DiscoverMint fetches the mint service once and returns its URL and ROLE_APP_IDS. Gen2 mint is backed by Cloud Run; when the Cloud Functions API is unavailable (common for WIF principals with run.admin only), discovery falls back to the Cloud Run API.

func (*Provisioner) EnsureMintServiceAccount added in v0.14.0

func (p *Provisioner) EnsureMintServiceAccount(ctx context.Context) error

EnsureMintServiceAccount creates the mint service account if it does not already exist. Call this before StoreAgentPEM so the IAM binding on secrets can reference the service account.

func (*Provisioner) GetExistingRoleAppIDs

func (p *Provisioner) GetExistingRoleAppIDs(ctx context.Context) (map[string]string, error)

GetExistingRoleAppIDs reads ROLE_APP_IDS from the deployed mint function. Returns (nil, nil) if the function doesn't exist or has no ROLE_APP_IDS.

func (*Provisioner) GetFunctionURL

func (p *Provisioner) GetFunctionURL(ctx context.Context) (string, error)

GetFunctionURL returns the URL of the deployed mint function.

func (*Provisioner) GetServiceRevisionInfo added in v0.14.0

func (p *Provisioner) GetServiceRevisionInfo(ctx context.Context) (*ServiceRevisionInfo, error)

GetServiceRevisionInfo queries the Cloud Run service for revision details including traffic routing, template divergence, and recent revision history.

func (*Provisioner) GetServiceTrafficEnvVars added in v0.14.0

func (p *Provisioner) GetServiceTrafficEnvVars(ctx context.Context) (map[string]string, error)

GetServiceTrafficEnvVars reads env vars from the traffic-serving Cloud Run revision. This is a convenience wrapper around the GCFClient method.

func (*Provisioner) Name

func (p *Provisioner) Name() string

Name returns the dispatcher identifier.

func (*Provisioner) OrgSecretNames

func (p *Provisioner) OrgSecretNames() []string

OrgSecretNames returns nil — the mint uses Secret Manager, not org secrets.

func (*Provisioner) OrgVariableNames

func (p *Provisioner) OrgVariableNames() []string

OrgVariableNames returns the org variables this dispatcher manages.

func (*Provisioner) Provision

func (p *Provisioner) Provision(ctx context.Context) (map[string]string, error)

Provision creates the GCP infrastructure for the token mint.

When MintURL is empty, deploys the full mint infrastructure:

  1. Look up project number
  2. Create/verify service account
  3. Create/verify WIF pool + provider (no org entry is added to a new provider's condition, and an existing provider's condition is preserved)
  4. Store all agent PEMs in Secret Manager
  5. Grant SA access to all role secrets
  6. Deploy Cloud Function
  7. Register the repo for per-repo WIF when Repo is set
  8. Return FULLSEND_MINT_URL

No org-level Agent Platform grants are created or modified.

When MintURL is set, reuses an existing mint:

  1. Store all agent PEMs in Secret Manager
  2. Return the provided MintURL

func (*Provisioner) ProvisionRepoWIFProvider added in v0.34.0

func (p *Provisioner) ProvisionRepoWIFProvider(ctx context.Context) (string, error)

ProvisionRepoWIFProvider creates a dedicated per-repo WIF provider without granting any IAM roles. This is used by mint enrollment, which only needs the WIF provider for OIDC verification — Vertex AI access is granted separately by the inference provision code path.

Returns the full WIF provider resource path. All operations are idempotent.

func (*Provisioner) ProvisionWIF

func (p *Provisioner) ProvisionWIF(ctx context.Context) (wifProvider string, err error)

ProvisionWIF creates the WIF infrastructure (service account, pool, provider, principal binding) needed for GitHub Actions to authenticate via OIDC. All operations are idempotent. Returns the full WIF provider resource path and service account email.

func (*Provisioner) RegisterPerRepoWIF

func (p *Provisioner) RegisterPerRepoWIF(ctx context.Context, repo string) error

RegisterPerRepoWIF adds a repo to the mint's PER_REPO_WIF_REPOS env var so the mint routes OIDC tokens from that repo to a dedicated WIF provider. Idempotent — skips repos already listed. Not safe for concurrent calls — run per-repo installs sequentially when sharing a mint.

func (*Provisioner) RemoveOrgFromWIFCondition added in v0.12.0

func (p *Provisioner) RemoveOrgFromWIFCondition(ctx context.Context, org string) error

RemoveOrgFromWIFCondition removes an org from the org-level WIF provider's attribute condition. WARNING: read-modify-write without locking — concurrent calls may race.

func (*Provisioner) RemoveRepoFromMint added in v0.12.0

func (p *Provisioner) RemoveRepoFromMint(ctx context.Context, repo string) error

RemoveRepoFromMint removes a repo from PER_REPO_WIF_REPOS. Uses read-modify-write via UpdateServiceEnvVars.

func (*Provisioner) RemoveRoleFromMint added in v0.19.0

func (p *Provisioner) RemoveRoleFromMint(ctx context.Context, role string) error

RemoveRoleFromMint removes a role-only entry from ROLE_APP_IDS and updates ALLOWED_ROLES on the traffic-serving Cloud Run revision.

func (*Provisioner) RemoveWorkflowHostRepo added in v0.34.0

func (p *Provisioner) RemoveWorkflowHostRepo(ctx context.Context, repo string) error

RemoveWorkflowHostRepo removes a repo from WORKFLOW_HOST_REPOS.

func (*Provisioner) SecretExists

func (p *Provisioner) SecretExists(ctx context.Context, role string) (bool, error)

SecretExists checks whether the Secret Manager secret for the given role exists.

func (*Provisioner) StoreAgentPEM

func (p *Provisioner) StoreAgentPEM(ctx context.Context, role string, pemData []byte) error

StoreAgentPEM persists a role's PEM in Secret Manager. Called during App setup so each PEM is stored immediately after creation.

type RevisionSummary added in v0.14.0

type RevisionSummary struct {
	Name       string // short name, e.g. "fullsend-mint-00114-fm9"
	CreateTime string // RFC3339 timestamp
	Active     bool   // true if the revision has conditions indicating it is active/ready
}

RevisionSummary is a brief snapshot of a Cloud Run revision.

type ServiceRevisionInfo added in v0.14.0

type ServiceRevisionInfo struct {
	// TrafficRevision is the full resource name of the revision currently serving traffic.
	TrafficRevision string
	// TrafficRevisionShort is the short revision name (e.g., "fullsend-mint-00114-fm9").
	TrafficRevisionShort string
	// TrafficAllocType is the traffic allocation type (e.g., "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST").
	TrafficAllocType string
	// TrafficPercent is the percentage of traffic the serving revision receives.
	TrafficPercent int
	// TemplateRevision is the revision name from the service template (latest created).
	TemplateRevision string
	// TemplateMatchesTraffic is true when the template's latest revision matches
	// the traffic-serving revision.
	TemplateMatchesTraffic bool
	// RecentRevisions lists the most recent revisions (up to 5), newest first.
	RecentRevisions []RevisionSummary
	// TrafficEnvVars holds the env vars from the traffic-serving revision.
	TrafficEnvVars map[string]string
	// TrafficEnvVarsFromTemplate is true when TrafficEnvVars were taken from
	// the service template because the traffic-serving revision could not be
	// read. Such values may not reflect what the mint is actually serving.
	TrafficEnvVarsFromTemplate bool
}

ServiceRevisionInfo holds Cloud Run service details including which revision is serving traffic, recent revision history, and whether the service template diverges from the traffic-serving revision.

type StatusGitHubAuth added in v0.37.0

type StatusGitHubAuth struct {
	// Group is the ORG/TEAM slug for the GitHub status validator.
	Group string
}

StatusGitHubAuth bundles the GitHub status auth configuration passed through provisioner and bundle functions.

type WIFProviderInfo

type WIFProviderInfo struct {
	AttributeCondition string
	AllowedAudiences   []string
	IssuerURI          string
	// State is the provider's lifecycle state ("ACTIVE" or "DELETED").
	// providers.get returns soft-deleted providers with HTTP 200 and
	// State "DELETED" rather than 404, so a non-nil WIFProviderInfo does
	// not by itself mean the provider can exchange tokens.
	State string
	// Disabled reports whether the provider has been disabled. A disabled
	// provider cannot exchange tokens.
	Disabled bool
}

WIFProviderInfo holds metadata about a WIF OIDC provider.

func (*WIFProviderInfo) Usable added in v0.44.0

func (i *WIFProviderInfo) Usable() bool

Usable reports whether the provider can exchange tokens: not disabled and not soft-deleted. An absent State is treated as active.

Jump to

Keyboard shortcuts

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