gitlablifecycle

package
v0.47.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gitlablifecycle implements GitLab-specific role ownership, credential attribution and trigger-owner transport. Repository policy owns elevation ordering, safety decisions, containment and project leases.

The live TriggerOwner deliberately does not implement repos.GitLabPollerQuiescenceVerifier: GitLab offers no server-side drain barrier for requests accepted with revoked credentials, so the webhook fast path keeps deferring trigger creation and rotation, and polling remains the dispatch path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PollerCredentialRejected

func PollerCredentialRejected(err error) bool

PollerCredentialRejected reports whether GitLab refused the installed Poller credential itself (expired, revoked, or blocked account), as opposed to a transient or unrelated failure.

func RoleTokenName

func RoleTokenName(role gitlabroles.Role) string

RoleTokenName is the GitLab token name a role's credential carries: the fixed name of a built-in role, or the derived name of a custom one.

Types

type TriggerOwner

type TriggerOwner struct {
	Admin *gitlab.LiveClient
	// NewClient builds a client for a token; tests override it.
	NewClient func(token, baseURL string) (*gitlab.LiveClient, error)
	// Now is the clock for credential expiry; tests override it.
	Now func() time.Time
}

TriggerOwner mints the webhook trigger token authenticated as the Poller service account and changes the Poller's membership, all with installer authority. The Poller's distributed runtime credential (FULLSEND_GITLAB_POLLER_TOKEN) is never used to create the trigger: it is revoked before the elevation, and an installer-only bootstrap personal access token, held in memory only, authenticates the trigger creation.

func NewTriggerOwner

func NewTriggerOwner(admin *gitlab.LiveClient) *TriggerOwner

NewTriggerOwner binds installer-authorized GitLab transport to the lifecycle.

func (*TriggerOwner) AttributeSuppliedRole

func (o *TriggerOwner) AttributeSuppliedRole(ctx context.Context, owner, repo string, role gitlabroles.Role) (int64, error)

AttributeSuppliedRole identifies the owner of a supplied non-Poller role credential enrolled without a recorded owner by authenticating with the installed secret. A credential that is no longer installed or no longer authenticates cannot be attributed, which fails closed.

func (*TriggerOwner) ContainPoller

func (o *TriggerOwner) ContainPoller(ctx context.Context, owner, repo string, userID int64) error

ContainPoller revokes the managed Poller service account's active personal access tokens (runtime and bootstrap) and removes the installed Poller CI/CD secret with the admin credential when that secret's credential authenticates as this account, so a Poller that could not be returned to Developer access stops authenticating. Credentials of other identities are preserved. Every step is attempted; failures are joined. Active tokens that fullsend does not manage are left untouched but reported as incomplete containment. Token revocation and secret removal each run on their own bounded context detached from ctx, so one step exhausting its budget cannot stop the other.

func (*TriggerOwner) CreatePipelineTriggerTokenAsPoller

func (o *TriggerOwner) CreatePipelineTriggerTokenAsPoller(ctx context.Context, owner, repo, description string, bootstrap *repos.PollerBootstrap) (*forge.PipelineTriggerToken, error)

CreatePipelineTriggerTokenAsPoller creates the trigger token as the Poller identity by authenticating with the bootstrap credential.

func (*TriggerOwner) CreatePollerBootstrap

func (o *TriggerOwner) CreatePollerBootstrap(ctx context.Context, owner, repo string, userID int64) (*repos.PollerBootstrap, error)

CreatePollerBootstrap creates the installer-only bootstrap personal access token for the Poller service account with the administrator credential. Any bootstrap token left by an interrupted run is revoked first, so at most one exists. The value is returned to the caller and never stored.

func (*TriggerOwner) CreatePollerRuntimeToken

func (o *TriggerOwner) CreatePollerRuntimeToken(ctx context.Context, owner, repo string, userID int64, expiresAt string) (*repos.PollerRuntimeToken, error)

CreatePollerRuntimeToken creates the replacement runtime personal access token for the Poller service account. The caller stores it.

func (*TriggerOwner) CurrentSuppliedAccountIDs

func (o *TriggerOwner) CurrentSuppliedAccountIDs(ctx context.Context, owner, repo string) ([]int, error)

CurrentSuppliedAccountIDs lists the accounts that own a currently installed supplied credential: the subset of the exclusions that is not merely historical, for the operational token inventory.

func (*TriggerOwner) ManagedPollerUserIDs

func (o *TriggerOwner) ManagedPollerUserIDs(ctx context.Context, owner, repo string) ([]int64, error)

ManagedPollerUserIDs lists every managed Poller service account, lowest ID first, so install reconciles duplicates as uninstall does.

func (*TriggerOwner) PollerActiveJobIDs

func (o *TriggerOwner) PollerActiveJobIDs(ctx context.Context, owner, repo string, userID int64) ([]int, error)

PollerActiveJobIDs returns the IDs of unfinished project jobs that run as the Poller (or as a user GitLab did not report).

func (*TriggerOwner) PollerSSHKeyIDs

func (o *TriggerOwner) PollerSSHKeyIDs(ctx context.Context, userID int64) ([]int, error)

PollerSSHKeyIDs returns the IDs of the Poller account's usable SSH authentication keys.

func (*TriggerOwner) PollerScheduleIDs

func (o *TriggerOwner) PollerScheduleIDs(ctx context.Context, owner, repo string, userID int64) ([]int, error)

PollerScheduleIDs returns the IDs of pipeline schedules owned by the Poller (or by a user GitLab did not report).

func (*TriggerOwner) PollerTriggerIDs

func (o *TriggerOwner) PollerTriggerIDs(ctx context.Context, owner, repo string, userID int64) ([]int, error)

PollerTriggerIDs lists all trigger resources owned by the identity, including those whose owner GitLab omits. Unlike the unmanaged query, it includes the managed webhook trigger and is suitable for account-deletion verification.

func (*TriggerOwner) PollerUserID

func (o *TriggerOwner) PollerUserID(ctx context.Context, owner, repo string) (int64, error)

PollerUserID identifies the fullsend-managed fullsend-poller project service account from the administrator's service-account inventory, so identification does not depend on the distributed runtime credential, which is revoked during every trigger-creation transaction. A credential that is installed and still authenticates must belong to that managed account and be its managed personal access token: a Poller enrolled as a human's personal access token (--gitlab-role-token) or a project access token bot reports forge.ErrNotFound, so install never changes a person's membership or replaces an administrator-supplied credential. A missing, expired, revoked, or blocked installed credential cannot say who it is; the managed account is then taken from the inventory alone, which is how an interrupted run is recovered.

func (*TriggerOwner) RefuseUnknownRoleProvenance

func (o *TriggerOwner) RefuseUnknownRoleProvenance(ctx context.Context, owner, repo string, provs map[gitlabroles.Role]repos.RoleProvenance) error

RefuseUnknownRoleProvenance fails closed when a registered non-Poller own-credential role has an installed secret but rotation state does not establish who provisioned it. The roles come from the trusted registry, not from the rotation document, so a role with no entry at all is still examined. The Poller's own unknown provenance is handled by SuppliedPollerUserID.

func (*TriggerOwner) ResolveExcludedAccounts

func (o *TriggerOwner) ResolveExcludedAccounts(ctx context.Context, owner, repo string) ([]int64, map[gitlabroles.Role]int, error)

ResolveExcludedAccounts is excludedAccountIDs that also returns the owners it attributed by authenticating, keyed by role, for supplied credentials whose rotation entry did not record one. Callers that are about to delete those credentials persist them so a retry does not need the credential again.

func (*TriggerOwner) RevokePollerBootstrap

func (o *TriggerOwner) RevokePollerBootstrap(ctx context.Context, owner, repo string, userID int64) error

RevokePollerBootstrap revokes every active bootstrap personal access token of the Poller service account and verifies that none remains active. It finds orphans by token name, so no secret value has to be persisted.

func (*TriggerOwner) RevokePollerRuntimeCredentials

func (o *TriggerOwner) RevokePollerRuntimeCredentials(ctx context.Context, owner, repo string, userID int64) error

RevokePollerRuntimeCredentials invalidates the distributed Poller runtime credential with installer authority. The CI/CD variable is removed first, so a run interrupted afterwards leaves the secret absent and the next install provisions a replacement instead of trusting a dead value. The managed runtime personal access tokens are then revoked and their revocation is verified: removing the variable alone would leave copies held by running jobs valid. Credentials fullsend does not manage are never touched.

func (*TriggerOwner) SetProjectMemberAccessLevel

func (o *TriggerOwner) SetProjectMemberAccessLevel(ctx context.Context, owner, repo string, userID int64, accessLevel int) error

SetProjectMemberAccessLevel changes the Poller's direct project membership with the installer credential.

func (*TriggerOwner) SuppliedAccountIDs

func (o *TriggerOwner) SuppliedAccountIDs(ctx context.Context, owner, repo string) ([]int, error)

SuppliedAccountIDs lists the service accounts that own administrator-supplied credentials, for the shared token client's exclusions.

func (*TriggerOwner) SuppliedPollerUserID

func (o *TriggerOwner) SuppliedPollerUserID(ctx context.Context, owner, repo string) (int64, bool, error)

SuppliedPollerUserID returns the user that owns the installed Poller credential when rotation state records that credential as administrator-supplied. supplied is false when the credential is managed or there is no installed credential. The owner recorded at enrollment is used without authenticating, so an expired or revoked supplied credential keeps its owner's account excluded and can be replaced through the normal path. Unknown provenance is not "managed": when a Poller credential is installed but rotation state has no record of it, or a supplied credential has no recorded owner and cannot be attributed by authenticating, the result is an error wrapping repos.ErrPollerSuppliedUnresolved and the caller fails closed instead of treating a same-named account as managed.

func (*TriggerOwner) SuppliedTokenIDs

func (o *TriggerOwner) SuppliedTokenIDs(ctx context.Context, owner, repo string) (map[int][]repos.SuppliedTokenRef, error)

SuppliedTokenIDs maps each supplied owner account to the token IDs of the credentials enrolled for it, from rotation state. An owner whose enrolled credential has no recorded token ID for any role is omitted, so every token of its account stands in for the credential. Each token carries the token name of the role it was enrolled for.

func (*TriggerOwner) VerifyPollerCredentialsRevoked

func (o *TriggerOwner) VerifyPollerCredentialsRevoked(ctx context.Context, owner, repo string, userID int64) error

VerifyPollerCredentialsRevoked rejects every active PAT, including managed names, after runtime revocation and before bootstrap creation.

func (*TriggerOwner) VerifyPollerElevationSafe

func (o *TriggerOwner) VerifyPollerElevationSafe(ctx context.Context, owner, repo string, userID int64) error

VerifyPollerElevationSafe refuses elevation unless every active credential of the Poller account is accounted for: personal access tokens must be the managed runtime credential or the installer's bootstrap credential (both revoked by the install itself before the elevation), pipeline trigger tokens must be the managed ones, and the account must have no usable SSH authentication key and no unfinished job may run as the Poller (job tokens outlive the revocation of the account's tokens). Failure containment cannot revoke credentials fullsend does not manage, and they would gain Maintainer access during the create window. An inventory that cannot be read fails closed.

type UninstallTokenClient

type UninstallTokenClient struct {
	repos.ServiceAccountTokenClient
	// contains filtered or unexported fields
}

UninstallTokenClient is the role token client for uninstall. In addition to the shared inventory it reconciles every managed Poller service account (duplicates included) before credential cleanup. It also retains, per project, the account that owns an administrator-supplied Poller credential so reconciliation and revocation leave that account and its tokens alone.

func NewUninstallTokenClient

func NewUninstallTokenClient(admin *gitlab.LiveClient, role repos.ServiceAccountTokenClient) UninstallTokenClient

NewUninstallTokenClient adds uninstall reconciliation and durable supplied attribution caching to the role inventory configured by the caller.

func (UninstallTokenClient) ListProjectAccessTokens

func (u UninstallTokenClient) ListProjectAccessTokens(ctx context.Context, owner, repo string) ([]repos.ProjectAccessToken, error)

ListProjectAccessTokens is the shared inventory without the tokens of an administrator-supplied Poller account.

func (UninstallTokenClient) ListProjectAccessTokensStrict

func (u UninstallTokenClient) ListProjectAccessTokensStrict(ctx context.Context, owner, repo string) ([]repos.ProjectAccessToken, error)

ListProjectAccessTokensStrict is the destructive-cleanup inventory without the tokens of an administrator-supplied Poller account.

func (UninstallTokenClient) ReconcileGitLabPollersForUninstall

func (u UninstallTokenClient) ReconcileGitLabPollersForUninstall(ctx context.Context, client forge.Client, owner, repo string) error

ReconcileGitLabPollersForUninstall restores and verifies Developer access of every managed Poller service account and revokes their bootstrap credentials. Only a positively absent service-account API (not found or not supported) means there is nothing to reconcile; a forbidden or failed listing cannot establish that and fails the uninstall.

A same-named service account that owns the administrator-supplied Poller credential is not managed: it is excluded from reconciliation and its tokens from later revocation. When the supplied credential cannot be attributed the uninstall fails closed with repos.ErrPollerSuppliedUnresolved.

Jump to

Keyboard shortcuts

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