enterprise

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package enterprise provides the foundational domain models for Identrail's enterprise-tier controls: SCIM provisioning, SAML federation, data-residency policy enforcement, and executive risk reporting.

This package is intentionally I/O-free. It defines the types, validation, and aggregation logic that API and persistence layers later wire to HTTP endpoints and storage. Keeping the models pure makes them testable in isolation and reusable across CLI, API, and worker entry points.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTransitionSAMLStatus

func CanTransitionSAMLStatus(from, to SAMLConnectionStatus) bool

CanTransitionSAMLStatus reports whether a SAML connection may move from one status to another. Connections must enroll via pending → active before they can be disabled/re-enabled; jumping straight from pending to disabled is rejected so that a connection cannot be parked in a disabled state without ever having proved a successful IdP handshake.

func IsRecognizedResidencyRegion

func IsRecognizedResidencyRegion(region string) bool

IsRecognizedResidencyRegion reports whether region is a known data-residency region. Comparison is case-insensitive.

func ParseSAMLCertificate

func ParseSAMLCertificate(pemEncoded string) (*x509.Certificate, error)

ParseSAMLCertificate parses a PEM-encoded X.509 certificate and returns it. Exported so API and persistence layers can reuse the same parse path.

Types

type AttributeMapping

type AttributeMapping struct {
	Email  string `json:"email"`
	Name   string `json:"name,omitempty"`
	Groups string `json:"groups,omitempty"`
}

AttributeMapping describes how IdP-provided SAML attributes map onto Identrail's internal user attributes. Empty values fall back to sensible defaults at the consumer.

type ExecutiveReport

type ExecutiveReport struct {
	OrganizationID    string                         `json:"organization_id"`
	GeneratedAt       time.Time                      `json:"generated_at"`
	WindowStart       time.Time                      `json:"window_start"`
	WindowEnd         time.Time                      `json:"window_end"`
	TotalOpenFindings int                            `json:"total_open_findings"`
	OpenBySeverity    map[domain.FindingSeverity]int `json:"open_by_severity"`
	OpenByType        map[domain.FindingType]int     `json:"open_by_type"`
	TopFindingTypes   []TopFindingType               `json:"top_finding_types"`
	WeekOverWeek      WeekOverWeekTrend              `json:"week_over_week"`
	MeanTimeToResolve *MTTRSummary                   `json:"mean_time_to_resolve,omitempty"`
}

ExecutiveReport is a deterministic rollup of finding state suitable for leadership consumption: open volume by severity, top finding types, week-over-week trend, and mean time to resolve.

MeanTimeToResolve is derived strictly from the FindingTriage.ResolvedAt timestamp, which is set only when a finding actually enters the resolved state. The mutable UpdatedAt timestamp is never used, so the figure cannot be skewed by comment-only or assignee edits. The field is omitted entirely when no resolved finding carries a reliable ResolvedAt, so leadership never sees a guessed number.

func BuildExecutiveReport

func BuildExecutiveReport(findings []domain.Finding, opts ReportOptions) ExecutiveReport

BuildExecutiveReport aggregates a finding slice into an ExecutiveReport. The function is pure (no I/O) and deterministic given fixed inputs, which keeps it cheap to call from the API layer and easy to unit-test.

type MTTRSummary

type MTTRSummary struct {
	ResolvedCount int     `json:"resolved_count"`
	Seconds       float64 `json:"seconds"`
}

MTTRSummary reports mean time to resolve across findings that carry a trustworthy FindingTriage.ResolvedAt. Seconds is the mean of (ResolvedAt - CreatedAt) over ResolvedCount findings.

type ReportOptions

type ReportOptions struct {
	OrganizationID string
	Now            func() time.Time
	TopN           int
}

ReportOptions parameterizes BuildExecutiveReport. Now defaults to time.Now() when nil so callers in tests can inject a deterministic clock.

type ResidencyDecision

type ResidencyDecision struct {
	Allowed bool
	Reason  string
}

ResidencyDecision is the outcome of evaluating one write against a policy.

type ResidencyMode

type ResidencyMode string

ResidencyMode controls how strictly the policy is enforced.

const (
	// ResidencyModeAdvisory records violations but does not block writes; useful
	// during initial rollout.
	ResidencyModeAdvisory ResidencyMode = "advisory"
	// ResidencyModeStrict refuses writes whose target region is not in the
	// allowlist.
	ResidencyModeStrict ResidencyMode = "strict"
)

type ResidencyPolicy

type ResidencyPolicy struct {
	OrganizationID string        `json:"organization_id"`
	AllowedRegions []string      `json:"allowed_regions"`
	Mode           ResidencyMode `json:"mode"`
	UpdatedAt      time.Time     `json:"updated_at"`
}

ResidencyPolicy is the per-organization data-residency contract. A workspace or scan whose target region is not in AllowedRegions must be rejected under strict mode and recorded as a violation under advisory mode.

func (ResidencyPolicy) Evaluate

func (p ResidencyPolicy) Evaluate(region string) ResidencyDecision

Evaluate decides whether a write targeted at the given region is permitted. Under advisory mode the decision always allows the write, but Reason carries any violation so the caller can record it for governance.

func (ResidencyPolicy) SortedAllowedRegions

func (p ResidencyPolicy) SortedAllowedRegions() []string

SortedAllowedRegions returns a copy of the allowlist with deterministic ordering, convenient for hashing/comparison and stable rendering.

func (ResidencyPolicy) Validate

func (p ResidencyPolicy) Validate() error

Validate enforces ResidencyPolicy invariants.

type SAMLConnection

type SAMLConnection struct {
	ID               string               `json:"id"`
	OrganizationID   string               `json:"organization_id"`
	DisplayName      string               `json:"display_name"`
	EntityID         string               `json:"entity_id"`
	SSOURL           string               `json:"sso_url"`
	CertificatePEM   string               `json:"certificate_pem"`
	AttributeMapping AttributeMapping     `json:"attribute_mapping"`
	Status           SAMLConnectionStatus `json:"status"`
	CreatedAt        time.Time            `json:"created_at"`
	UpdatedAt        time.Time            `json:"updated_at"`
}

SAMLConnection models a federated SAML identity provider trust between an Identrail organization and an external IdP. The certificate is stored as a PEM-encoded X.509 string so the operator can hot-rotate via update without touching DER blobs.

func (SAMLConnection) Validate

func (c SAMLConnection) Validate() error

Validate enforces SAML connection invariants relevant for safe federation. The SSO URL must use https (the SAML POST binding embeds the assertion in the response body; plaintext transport would leak credentials), and the certificate must be a parseable X.509 PEM block.

type SAMLConnectionStatus

type SAMLConnectionStatus string

SAMLConnectionStatus tracks the rollout state of a SAML connection.

const (
	SAMLConnectionPending  SAMLConnectionStatus = "pending"
	SAMLConnectionActive   SAMLConnectionStatus = "active"
	SAMLConnectionDisabled SAMLConnectionStatus = "disabled"
)

type SCIMEmail

type SCIMEmail struct {
	Value   string `json:"value"`
	Type    string `json:"type,omitempty"`
	Primary bool   `json:"primary,omitempty"`
}

SCIMEmail mirrors one entry of the SCIM `emails` multi-valued attribute.

type SCIMMeta

type SCIMMeta struct {
	ResourceType string    `json:"resourceType,omitempty"`
	Created      time.Time `json:"created,omitempty"`
	LastModified time.Time `json:"lastModified,omitempty"`
	Location     string    `json:"location,omitempty"`
	Version      string    `json:"version,omitempty"`
}

SCIMMeta carries the SCIM `meta` complex attribute. Only the fields Identrail relies on are modeled.

type SCIMProvisioningEvent

type SCIMProvisioningEvent struct {
	Op            SCIMProvisioningOp `json:"op"`
	User          SCIMUser           `json:"user"`
	SourceTenant  string             `json:"source_tenant"`
	OccurredAt    time.Time          `json:"occurred_at"`
	CorrelationID string             `json:"correlation_id,omitempty"`
}

SCIMProvisioningEvent records one provisioning operation for audit and downstream workflow routing. It is emitted by the SCIM endpoint handler and can be persisted, dispatched to the workflow router for governance, or replayed against secondary stores.

func (SCIMProvisioningEvent) Validate

func (e SCIMProvisioningEvent) Validate() error

Validate enforces the invariants every provisioning consumer relies on.

Per RFC 7644, SCIM `id` is server-assigned on POST /Users (create), so it is intentionally optional on create events; update/deactivate/delete events must carry the resource id since they reference an existing user. The SCIM DELETE protocol does not carry a user body at all — only the id in the path — so this method skips the full SCIMUser.Validate for that op.

type SCIMProvisioningOp

type SCIMProvisioningOp string

SCIMProvisioningOp enumerates the lifecycle operations a SCIM source can apply to a user. These mirror SCIM 2.0 protocol verbs (POST/PUT/PATCH/DELETE) reduced to the semantic transitions Identrail persists.

const (
	SCIMProvisioningCreate     SCIMProvisioningOp = "create"
	SCIMProvisioningUpdate     SCIMProvisioningOp = "update"
	SCIMProvisioningDeactivate SCIMProvisioningOp = "deactivate"
	SCIMProvisioningDelete     SCIMProvisioningOp = "delete"
)

type SCIMUser

type SCIMUser struct {
	ID          string      `json:"id"`
	ExternalID  string      `json:"externalId,omitempty"`
	UserName    string      `json:"userName"`
	DisplayName string      `json:"displayName,omitempty"`
	Active      bool        `json:"active"`
	Emails      []SCIMEmail `json:"emails,omitempty"`
	Groups      []string    `json:"groups,omitempty"`
	Meta        SCIMMeta    `json:"meta"`
}

SCIMUser is the subset of the SCIM 2.0 core user schema Identrail consumes for enterprise provisioning. Fields map to the canonical schema URN "urn:ietf:params:scim:schemas:core:2.0:User"; only the attributes required for tenant onboarding and lifecycle are modeled here so a directory-sync provider can drive create / update / deactivate without leaking provider specifics into the rest of the system.

JSON tags follow the SCIM 2.0 on-wire shape so the future /scim/v2/Users handler can decode standard provider payloads directly into this struct without an intermediate wire DTO. In particular, email addresses are carried in the SCIM `emails` multi-valued attribute and resource timestamps live under the SCIM `meta` complex attribute (`meta.created`, `meta.lastModified`).

func (SCIMUser) PrimaryEmail

func (u SCIMUser) PrimaryEmail() string

PrimaryEmail returns the canonical login identifier for the user: the primary entry in Emails when one is marked, otherwise the first non-empty value. Empty string when no usable email is present.

func (SCIMUser) Validate

func (u SCIMUser) Validate() error

Validate enforces SCIM core schema invariants relevant to Identrail. The `id` attribute is intentionally NOT required here because SCIM 2.0 servers assign it on a successful POST /Users create — the resource arrives without one. Operations that semantically require an existing identifier (update/deactivate/delete) are enforced in SCIMProvisioningEvent.Validate.

At most one email entry may be marked primary. Standard SCIM clients honor the multi-valued `primary` sub-attribute and assume it is unique; accepting duplicates silently would let a provider quirk reorder the login-identity selection on every payload.

The selected primary email must be a plain addr-spec (e.g. "alice@example.com") rather than the mailbox display syntax accepted by net/mail ("Alice <alice@example.com>"). The downstream provisioning path upserts this string into the users/identities tables as a login identifier, so accepting display syntax would persist a non-canonical email.

type SCIMUserActiveStatus

type SCIMUserActiveStatus bool

SCIMUserActiveStatus reflects whether a SCIM-provisioned principal is enabled.

type TopFindingType

type TopFindingType struct {
	Type  domain.FindingType `json:"type"`
	Count int                `json:"count"`
}

TopFindingType records the count of one finding type within the report window, used for the executive top-N callout.

type WeekOverWeekTrend

type WeekOverWeekTrend struct {
	CurrentCount  int `json:"current_count"`
	PreviousCount int `json:"previous_count"`
	Delta         int `json:"delta"`
}

WeekOverWeekTrend captures the delta in created-findings volume between the trailing 7-day window and the prior 7-day window.

Jump to

Keyboard shortcuts

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