Documentation
¶
Index ¶
- Variables
- func BuildInstallURL(appSlug string, state string, redirectURI string) (string, error)
- func NormalizeAppSlug(value string) (string, error)
- func NormalizeBaseURL(value string) (string, error)
- func OrganizationPostureFindings(posture OrganizationPosture, repository string, detectedAt time.Time) []domain.Finding
- func OrganizationPostureInconclusiveLifecycleKeys(posture OrganizationPosture, repository string) []string
- func ParsePrivateKey(privateKeyPEM string) (*rsa.PrivateKey, error)
- func RepositoryPostureFindings(posture RepositoryPosture, detectedAt time.Time) []domain.Finding
- func RepositoryPostureInconclusiveLifecycleKeys(posture RepositoryPosture) []string
- func SignAppJWT(creds AppCredentials, now time.Time) (string, error)
- func ValidatePATShape(token string) error
- func VerifyWebhookSignature(secret string, payload []byte, signature string) bool
- type AppCredentials
- type CodeScanningAlert
- type CodeScanningAlertInstance
- type CodeScanningLocation
- type CodeScanningMessage
- type CodeScanningRule
- type CodeScanningTool
- type DependabotAdvisoryIdentity
- type DependabotAlert
- type DependabotDependency
- type DependabotPackage
- type DependabotPatchVersion
- type DependabotSecurityAdvisory
- type DependabotVulnerability
- type GitHubRateLimitState
- type InstallationEvent
- type InstallationRepositoriesEvent
- type InstallationToken
- type InstallationTokenClient
- type InstallationTokenMinter
- type OrganizationPosture
- type PATValidationResult
- type PATValidator
- type Repository
- type RepositoryClient
- func (c RepositoryClient) CollectOrganizationPosture(ctx context.Context, installationID int64, organization string, ...) (OrganizationPosture, error)
- func (c RepositoryClient) CollectRepositoryPosture(ctx context.Context, installationID int64, repository string) (RepositoryPosture, error)
- func (c RepositoryClient) ListCodeScanningAlerts(ctx context.Context, installationID int64, repository string) ([]CodeScanningAlert, error)
- func (c RepositoryClient) ListDependabotAlerts(ctx context.Context, installationID int64, repository string) ([]DependabotAlert, error)
- func (c RepositoryClient) ListInstallationRepositories(ctx context.Context, installationID int64) ([]Repository, error)
- func (c RepositoryClient) ListSecretScanningAlerts(ctx context.Context, installationID int64, repository string) ([]SecretScanningAlert, error)
- type RepositoryPosture
- type RepositoryPostureCheck
- type RepositoryPostureState
- type SecretScanningAlert
- type UserOAuthClient
- type VerifiedInstallation
Constants ¶
This section is empty.
Variables ¶
var ErrInstallationNotOwned = errors.New("github installation not accessible to authorizing user")
ErrInstallationNotOwned indicates the GitHub user who authorized the connect flow does not have access to the supplied installation. This is the signal that a caller attempted to bind an installation they do not control.
Functions ¶
func BuildInstallURL ¶
BuildInstallURL returns the GitHub App target-picker URL with an opaque state.
func NormalizeAppSlug ¶
NormalizeAppSlug validates the GitHub App slug used in install URLs.
func NormalizeBaseURL ¶
NormalizeBaseURL validates and canonicalizes the GitHub Enterprise base URL.
func OrganizationPostureFindings ¶ added in v1.0.2
func OrganizationPostureFindings(posture OrganizationPosture, repository string, detectedAt time.Time) []domain.Finding
OrganizationPostureFindings converts non-secure organization posture checks into durable repository findings scoped to the repository that inherited the organization policy.
func OrganizationPostureInconclusiveLifecycleKeys ¶ added in v1.0.2
func OrganizationPostureInconclusiveLifecycleKeys(posture OrganizationPosture, repository string) []string
OrganizationPostureInconclusiveLifecycleKeys returns the lifecycle keys of organization posture checks this collection could not conclusively evaluate, scoped to the repository that inherits the organization policy.
func ParsePrivateKey ¶
func ParsePrivateKey(privateKeyPEM string) (*rsa.PrivateKey, error)
ParsePrivateKey parses a PEM-encoded RSA private key in PKCS#1 or PKCS#8 form.
func RepositoryPostureFindings ¶ added in v1.0.2
func RepositoryPostureFindings(posture RepositoryPosture, detectedAt time.Time) []domain.Finding
RepositoryPostureFindings converts non-secure repository posture checks into durable repository findings. Secure checks and unsupported plan/account surfaces are intentionally skipped.
func RepositoryPostureInconclusiveLifecycleKeys ¶ added in v1.0.2
func RepositoryPostureInconclusiveLifecycleKeys(posture RepositoryPosture) []string
RepositoryPostureInconclusiveLifecycleKeys returns the lifecycle keys of repository posture checks this collection could not conclusively evaluate. Callers must not close a durable finding for these keys: the control was never re-checked, so its absence from the promoted findings says nothing about whether the gap was fixed.
func SignAppJWT ¶
func SignAppJWT(creds AppCredentials, now time.Time) (string, error)
SignAppJWT signs a short-lived RS256 JWT accepted by GitHub App APIs.
func ValidatePATShape ¶
ValidatePATShape checks whether a token looks like a GitHub classic PAT.
Types ¶
type AppCredentials ¶
AppCredentials contains the non-tenant GitHub App credentials used by the hosted SaaS connector flow.
type CodeScanningAlert ¶
type CodeScanningAlert struct {
Number int `json:"number"`
State string `json:"state"`
Rule CodeScanningRule `json:"rule"`
Tool CodeScanningTool `json:"tool"`
MostRecentInstance CodeScanningAlertInstance `json:"most_recent_instance"`
HTMLURL string `json:"html_url"`
}
CodeScanningAlert is the GitHub API shape needed for repository finding ingestion.
type CodeScanningAlertInstance ¶
type CodeScanningAlertInstance struct {
Ref string `json:"ref"`
AnalysisKey string `json:"analysis_key"`
Category string `json:"category"`
State string `json:"state"`
CommitSHA string `json:"commit_sha"`
Message CodeScanningMessage `json:"message"`
Location CodeScanningLocation `json:"location"`
}
type CodeScanningLocation ¶
type CodeScanningMessage ¶
type CodeScanningMessage struct {
Text string `json:"text"`
}
type CodeScanningRule ¶
type CodeScanningTool ¶
type DependabotAdvisoryIdentity ¶ added in v1.0.2
type DependabotAlert ¶ added in v1.0.2
type DependabotAlert struct {
Number int `json:"number"`
State string `json:"state"`
Dependency DependabotDependency `json:"dependency"`
SecurityAdvisory DependabotSecurityAdvisory `json:"security_advisory"`
SecurityVulnerability DependabotVulnerability `json:"security_vulnerability"`
HTMLURL string `json:"html_url"`
URL string `json:"url"`
}
DependabotAlert is the subset of GitHub's Dependabot alert API needed to normalize alerts into Identrail repo findings. None of these fields carry secret material.
type DependabotDependency ¶ added in v1.0.2
type DependabotDependency struct {
Package DependabotPackage `json:"package"`
ManifestPath string `json:"manifest_path"`
Scope string `json:"scope"`
}
type DependabotPackage ¶ added in v1.0.2
type DependabotPatchVersion ¶ added in v1.0.2
type DependabotPatchVersion struct {
Identifier string `json:"identifier"`
}
type DependabotSecurityAdvisory ¶ added in v1.0.2
type DependabotSecurityAdvisory struct {
GHSAID string `json:"ghsa_id"`
CVEID string `json:"cve_id"`
Summary string `json:"summary"`
Severity string `json:"severity"`
Identifiers []DependabotAdvisoryIdentity `json:"identifiers"`
}
type DependabotVulnerability ¶ added in v1.0.2
type DependabotVulnerability struct {
Package DependabotPackage `json:"package"`
Severity string `json:"severity"`
VulnerableVersionRange string `json:"vulnerable_version_range"`
FirstPatchedVersion DependabotPatchVersion `json:"first_patched_version"`
}
type GitHubRateLimitState ¶
type GitHubRateLimitState struct {
Limit int `json:"limit,omitempty"`
Remaining int `json:"remaining,omitempty"`
ResetAt *time.Time `json:"reset_at,omitempty"`
}
GitHubRateLimitState captures the latest observed GitHub REST rate-limit headers for posture calls.
type InstallationEvent ¶
InstallationEvent is the subset of GitHub installation webhooks Identrail needs to bind and clean up GitHub App connectors.
func ParseInstallationEvent ¶
func ParseInstallationEvent(payload []byte) (InstallationEvent, error)
ParseInstallationEvent extracts the action, installation id, and account.
type InstallationRepositoriesEvent ¶
type InstallationRepositoriesEvent struct {
Action string
InstallationID int64
AddedRepositories []string
RemovedRepositories []string
}
InstallationRepositoriesEvent is the subset of GitHub repository-selection webhooks needed to keep connector repository allowlists current.
func ParseInstallationRepositoriesEvent ¶
func ParseInstallationRepositoriesEvent(payload []byte) (InstallationRepositoriesEvent, error)
ParseInstallationRepositoriesEvent extracts added and removed repositories from an installation_repositories webhook.
type InstallationToken ¶
InstallationToken represents one GitHub App installation token response.
type InstallationTokenClient ¶
type InstallationTokenClient struct {
Credentials AppCredentials
HTTPClient *http.Client
APIBaseURL string
Now func() time.Time
// contains filtered or unexported fields
}
InstallationTokenClient mints and caches installation tokens.
func (*InstallationTokenClient) Mint ¶
func (c *InstallationTokenClient) Mint(ctx context.Context, installationID int64) (InstallationToken, error)
Mint returns a cached token unless it is close to expiry.
type InstallationTokenMinter ¶
type InstallationTokenMinter interface {
Mint(ctx context.Context, installationID int64) (InstallationToken, error)
}
InstallationTokenMinter mints GitHub App installation access tokens.
type OrganizationPosture ¶ added in v1.0.2
type OrganizationPosture struct {
Organization string `json:"organization"`
InstallationID int64 `json:"installation_id,omitempty"`
CollectedAt time.Time `json:"collected_at"`
Checks []RepositoryPostureCheck `json:"checks"`
RateLimit *GitHubRateLimitState `json:"rate_limit,omitempty"`
}
OrganizationPosture describes organization-level GitHub security policy that is inherited by every repository in the organization. It is collected separately from RepositoryPosture so consumers can distinguish risk that is local to a repository from risk inherited from the organization policy plane.
type PATValidationResult ¶
PATValidationResult captures the minimum identity and scope proof for a PAT.
type PATValidator ¶
PATValidator validates classic GitHub PATs against GitHub.com or GHES.
func (PATValidator) Validate ¶
func (v PATValidator) Validate(ctx context.Context, baseURL string, token string) (PATValidationResult, error)
Validate confirms the token is accepted and has read-oriented repository scope.
func (PATValidator) ValidateGitHubPAT ¶
func (v PATValidator) ValidateGitHubPAT(ctx context.Context, baseURL string, token string) (PATValidationResult, error)
ValidateGitHubPAT adapts PATValidator to the API service dependency.
type Repository ¶
Repository describes the GitHub repository metadata Identrail needs for selection and scan target storage.
type RepositoryClient ¶
type RepositoryClient struct {
TokenClient InstallationTokenMinter
HTTPClient *http.Client
APIBaseURL string
Now func() time.Time
}
RepositoryClient lists repositories visible to one GitHub App installation.
func (RepositoryClient) CollectOrganizationPosture ¶ added in v1.0.2
func (c RepositoryClient) CollectOrganizationPosture(ctx context.Context, installationID int64, organization string, repository string) (OrganizationPosture, error)
CollectOrganizationPosture collects normalized organization-level security posture for the organization that owns a scanned repository. Each endpoint contributes one check; permission-limited, unavailable, unsupported, and unknown states are reported explicitly and never collapse into "secure".
func (RepositoryClient) CollectRepositoryPosture ¶
func (c RepositoryClient) CollectRepositoryPosture(ctx context.Context, installationID int64, repository string) (RepositoryPosture, error)
CollectRepositoryPosture collects normalized security posture from GitHub API endpoints that require an installation token. Each endpoint contributes a check even when the setting is unavailable or permission-limited.
func (RepositoryClient) ListCodeScanningAlerts ¶
func (c RepositoryClient) ListCodeScanningAlerts(ctx context.Context, installationID int64, repository string) ([]CodeScanningAlert, error)
ListCodeScanningAlerts returns all open GitHub code-scanning alerts for a repository.
func (RepositoryClient) ListDependabotAlerts ¶ added in v1.0.2
func (c RepositoryClient) ListDependabotAlerts(ctx context.Context, installationID int64, repository string) ([]DependabotAlert, error)
ListDependabotAlerts returns all open GitHub Dependabot alerts for a repository. It follows GitHub pagination using the installation token.
func (RepositoryClient) ListInstallationRepositories ¶
func (c RepositoryClient) ListInstallationRepositories(ctx context.Context, installationID int64) ([]Repository, error)
ListInstallationRepositories returns all repositories available to the installation, following GitHub pagination.
func (RepositoryClient) ListSecretScanningAlerts ¶ added in v1.0.2
func (c RepositoryClient) ListSecretScanningAlerts(ctx context.Context, installationID int64, repository string) ([]SecretScanningAlert, error)
ListSecretScanningAlerts returns all open GitHub secret-scanning alerts for a repository. It follows GitHub pagination using the installation token.
type RepositoryPosture ¶
type RepositoryPosture struct {
Repository string `json:"repository"`
InstallationID int64 `json:"installation_id,omitempty"`
CollectedAt time.Time `json:"collected_at"`
Checks []RepositoryPostureCheck `json:"checks"`
RateLimit *GitHubRateLimitState `json:"rate_limit,omitempty"`
}
RepositoryPosture describes GitHub-hosted repository security settings that are not visible from git content alone.
type RepositoryPostureCheck ¶
type RepositoryPostureCheck struct {
ID string `json:"id"`
Category string `json:"category"`
State RepositoryPostureState `json:"state"`
Reason string `json:"reason,omitempty"`
Summary string `json:"summary"`
Evidence map[string]any `json:"evidence,omitempty"`
}
RepositoryPostureCheck is one normalized GitHub repository posture signal.
type RepositoryPostureState ¶
type RepositoryPostureState string
RepositoryPostureState is a normalized posture state for one GitHub control.
const ( RepositoryPostureStateSecure RepositoryPostureState = "secure" RepositoryPostureStateInsecure RepositoryPostureState = "insecure" RepositoryPostureStatePermissionLimited RepositoryPostureState = "permission_limited" // RepositoryPostureStateUnsupported marks a control GitHub does not expose // for the repository/account plan (for example a GHAS-only org setting on a // plan without GitHub Advanced Security). RepositoryPostureStateUnsupported RepositoryPostureState = "unsupported" // RepositoryPostureStateUnknown marks a control that was reachable but could // not be classified from the response GitHub returned. RepositoryPostureStateUnknown RepositoryPostureState = "unknown" )
type SecretScanningAlert ¶ added in v1.0.2
type SecretScanningAlert struct {
Number int `json:"number"`
State string `json:"state"`
SecretType string `json:"secret_type"`
SecretTypeDisplayName string `json:"secret_type_display_name"`
Validity string `json:"validity"`
Resolution string `json:"resolution"`
PushProtectionBypass bool `json:"push_protection_bypassed"`
HTMLURL string `json:"html_url"`
}
SecretScanningAlert is the GitHub API shape needed for repository finding ingestion. The raw `secret` value GitHub returns is intentionally omitted so the credential material is never deserialized, stored, logged, or returned.
type UserOAuthClient ¶ added in v1.0.2
type UserOAuthClient struct {
ClientID string
ClientSecret string
// OAuthBaseURL is the web origin that serves the OAuth token exchange
// (https://github.com for github.com, the GHES host for Enterprise).
OAuthBaseURL string
// APIBaseURL is the REST API origin (https://api.github.com for github.com).
APIBaseURL string
HTTPClient *http.Client
Now func() time.Time
}
UserOAuthClient performs the GitHub App "request user authorization during installation" flow: it exchanges the post-install OAuth code for a user-to-server token, then confirms the supplied installation_id is one the authorizing user can actually access. This binds installation_id to a human who has rights on the target account, closing the cross-tenant IDOR where a caller could name any installation id.
func (UserOAuthClient) Configured ¶ added in v1.0.2
func (c UserOAuthClient) Configured() bool
Configured reports whether the client has the credentials required to run the OAuth verification. Completion paths fail closed when this is false.
func (UserOAuthClient) VerifyInstallationOwnership ¶ added in v1.0.2
func (c UserOAuthClient) VerifyInstallationOwnership(ctx context.Context, code string, installationID int64) (VerifiedInstallation, error)
VerifyInstallationOwnership exchanges the post-install OAuth code for a user token and confirms the user can access installationID. On success it returns the GitHub-reported account for the installation, which callers should persist in place of any client-supplied account value.
type VerifiedInstallation ¶ added in v1.0.2
VerifiedInstallation describes an installation whose ownership has been confirmed against the authorizing GitHub user's accessible installations.