Documentation
¶
Overview ¶
Package organization holds the single Organization of L1 and its settings (C-02.FR-23): the start-up step that creates it with the defaults of defaults.md together with its outbound address policy, and the read accessor that later capabilities use. Editing the settings arrives with C-03, C-19 and C-20.
Index ¶
- Constants
- Variables
- func Ensure(ctx context.Context, s Store, log *logging.Logger, now time.Time) error
- func ValidTimeZone(name string) bool
- type FieldError
- type Input
- type Notice
- type NoticeAudience
- type NoticeKind
- type Organization
- type OutboundMode
- type OutboundPolicies
- type OutboundPolicy
- type OutboundPolicyInput
- type OutboundPolicyResource
- type OutgoingHeartbeat
- type Proxy
- type ProxyInput
- type Retention
- type RuntimeState
- type SecretInput
- type SecretState
- type Service
- func (s *Service) Get(ctx context.Context) (Organization, error)
- func (s *Service) OutboundPolicy(ctx context.Context) (OutboundPolicyResource, error)
- func (s *Service) SeverityValues(ctx context.Context) (SeverityValues, error)
- func (s *Service) Update(ctx context.Context, r audit.Actor, t audit.Transport, addr netip.Addr, ...) (Organization, error)
- func (s *Service) UpdateOutboundPolicy(ctx context.Context, r audit.Actor, t audit.Transport, addr netip.Addr, ...) (OutboundPolicyResource, error)
- func (s *Service) WithKeyring(k *keyring.Keyring) *Service
- func (s *Service) WithLog(l *logging.Logger) *Service
- func (s *Service) WithOutboundPolicyChanged(f func()) *Service
- type Settings
- type SettingsQueries
- type SettingsStore
- type SeverityLevel
- type SeverityMapping
- type SeverityStyle
- type SeverityValue
- type SeverityValues
- type Store
- type TOTPPolicy
Constants ¶
const ( ActionUpdated = "organization.updated" ResourceType = "organization" HintOrganization = "organization" // HintSystemStatus is live.HintSystemStatus, which this package cannot import: a new or cleared URL of the // outgoing heartbeat clears its last result, which the System status shows. HintSystemStatus = "system-status" )
The Audit log action and resource type of the organization resource.
const ( FieldHeartbeatURL = "organizations.outgoing_heartbeat_url" FieldHeartbeatProxyPassword = "organizations.outgoing_heartbeat_proxy_password" )
The Secret fields of the organization resource, as the encrypted_values view names them: the key of the encryption binds each ciphertext to its field.
const ( CodeRequired = "required" CodeInvalidFormat = "invalid_format" CodeTooShort = "too_short" CodeTooLong = "too_long" CodeOutOfRange = "out_of_range" CodeDuplicate = "duplicate" CodeRetentionOrder = "retention_order" )
The codes of field errors, from the catalogue of the API (x-problem-codes).
const ( // MaxRetentionDays bounds every retention period: 100 years, far below the durations that would overflow. MaxRetentionDays = 36500 // MaxOIDCTokenGraceSeconds bounds auth.oidc_token_grace, as MaxRetentionDays the retention periods. MaxOIDCTokenGraceSeconds = MaxRetentionDays * 24 * 3600 )
const ( ActionOutboundPolicyUpdated = "outbound_policy.updated" ResourceOutboundPolicy = "outbound_policy" )
The Audit log action and resource type of the outbound address policy.
const OutboundPolicyChannel = "muster_outbound_policy"
OutboundPolicyChannel is the LISTEN/NOTIFY channel of changes of the outbound address policy: on it every replica drops its cached policy and closes its idle outbound connections. The payload is the Organization's id.
const OutboundPolicyMaxAge = 10 * time.Second
OutboundPolicyMaxAge is how long a replica keeps the outbound address policy it read before reading it again, the fallback when it missed the notification of a change.
const SeverityValuesWindow = 14 * day
SeverityValuesWindow is organization.severity_values_window: the values of the severity label seen in the last 14 days.
Variables ¶
var ErrVersionMismatch = errors.New("the organization changed since it was read")
ErrVersionMismatch is an If-Match that names another version of the organization resource.
Functions ¶
func Ensure ¶
Ensure is the start-up step of the Organization: it creates the Organization with Defaults when there is none, and its outbound address policy when that is missing. It changes nothing that exists, and does not create the Alert Group counter row, which only internal/groups writes. now is the business time.
func ValidTimeZone ¶
ValidTimeZone reports whether name is an IANA time zone that the Organization or a User profile may take: a name time.LoadLocation knows, never Local, the zone of the server.
Types ¶
type FieldError ¶
FieldError is a field of an update that is not valid, at a JSON pointer of the request body.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type Input ¶
type Input struct {
Name string
TimeZone string
// WorkdayStart and WeekStart are organization.workday_start and organization.week_start; nil keeps the stored one.
WorkdayStart *string
WeekStart *string
SeverityLabel string
SeverityMapping []SeverityMapping
SeverityStyles []SeverityStyle
CriticalIsUrgent bool
InstanceLabels []string
Retention Retention
TOTPRequired TOTPPolicy
OIDCTokenGraceSeconds int64
HeartbeatURL SecretInput
HeartbeatProxy ProxyInput
}
Input is an update of the organization resource.
type Notice ¶
type Notice struct {
Kind NoticeKind
Audience NoticeAudience
Since time.Time
Until time.Time
}
Notice is an active Organization-wide notice. A zero Since or Until is unknown or open.
func ActiveNotices ¶
ActiveNotices returns the notices active at now, a business time: "recovering after downtime" for everyone, from the end of the downtime until the end of the recovery window, and "no replica is leading" for Admins, since the last alive mark, while that mark is older than absence (leader.absence_notice) or missing.
type NoticeAudience ¶
type NoticeAudience string
NoticeAudience says who sees a notice.
const ( AudienceAll NoticeAudience = "all" AudienceAdmins NoticeAudience = "admins" )
type NoticeKind ¶
type NoticeKind string
NoticeKind is the kind of an Organization-wide notice, a SystemNotice kind of the API (C-02.FR-24).
const ( // NoticeRecoveringAfterDowntime is active during the recovery window after downtime (C-02.FR-12). NoticeRecoveringAfterDowntime NoticeKind = "recovering_after_downtime" // NoticeNoReplicaLeading is active while the Leader's alive mark is older than leader.absence_notice. NoticeNoReplicaLeading NoticeKind = "no_replica_leading" )
type Organization ¶
type Organization struct {
PublicID string
Name string
TimeZone string
// WorkdayStart and WeekStart are organization.workday_start and organization.week_start (C-20.FR-9).
WorkdayStart string
WeekStart string
SeverityLabel string
SeverityMapping []SeverityMapping
SeverityStyles []SeverityStyle
CriticalIsUrgent bool
InstanceLabels []string
Retention Retention
TOTPRequired TOTPPolicy
OIDCTokenGrace time.Duration
OutgoingHeartbeat OutgoingHeartbeat
Version int64
}
Organization is the organization resource (C-03.FR-20).
type OutboundMode ¶
type OutboundMode string
OutboundMode is the outbound address policy: standard or strict.
const ( OutboundStandard OutboundMode = "standard" OutboundStrict OutboundMode = "strict" )
type OutboundPolicies ¶
type OutboundPolicies struct {
// contains filtered or unexported fields
}
OutboundPolicies is the Organization's outbound address policy as the outbound package reads it: read from outbound_policies and cached per replica. A replica drops the cached policy at once on a notification on OutboundPolicyChannel (Invalidate); OutboundPolicyMaxAge of the real clock bounds its age when a notification was missed.
func NewOutboundPolicies ¶
func NewOutboundPolicies(s Store, orgID int64, c clock.Clock) *OutboundPolicies
NewOutboundPolicies reads the policy of the Organization orgID through s; c is the real clock.
func (*OutboundPolicies) Invalidate ¶
func (o *OutboundPolicies) Invalidate()
Invalidate drops the cached policy at once — on a notification on OutboundPolicyChannel, or a LISTEN that is back after a loss and may have missed one — and closes the idle outbound connections, so that the next request reads the policy again, dials, and is checked against it. A read in progress is not waited for: callers after Invalidate start a new one.
func (*OutboundPolicies) OutboundPolicy ¶
OutboundPolicy returns the cached policy, or reads it again when there is none or the cached one is older than OutboundPolicyMaxAge. One caller reads while the others wait for its result, each within its own context, outside the lock. An error leaves the cache empty, so the requests it serves fail and the next one reads again. A re-read that finds another policy than the cached one closes the idle outbound connections, as Invalidate would have; the read that follows an Invalidate does not close them again.
type OutboundPolicy ¶
type OutboundPolicy struct {
Mode OutboundMode
Allowed []string
Denied []string
}
OutboundPolicy is the outbound address policy with its allowed and denied networks, host names and domains.
type OutboundPolicyInput ¶
type OutboundPolicyInput struct {
Mode OutboundMode
Allowed []string
Denied []string
}
OutboundPolicyInput is an update of the outbound address policy.
type OutboundPolicyResource ¶
type OutboundPolicyResource struct {
Mode OutboundMode
Allowed []string
Denied []string
// AlwaysBlocked are the rules no allowed entry opens, outbound.AlwaysBlocked.
AlwaysBlocked []string
Version int64
}
OutboundPolicyResource is the outbound address policy as the API shows it (C-20.FR-3).
type OutgoingHeartbeat ¶
type OutgoingHeartbeat struct {
URL SecretState
Proxy Proxy
ProxyPassword SecretState
}
OutgoingHeartbeat is the outgoing heartbeat of the Organization as read: its URL and proxy password are Secrets.
type Proxy ¶
Proxy is a per-client proxy as stored (C-02.FR-22), without its password: the shared proxy settings object.
type ProxyInput ¶
ProxyInput is a per-client proxy as written: an omitted type, address or username keeps the stored one and a null username clears it.
type Retention ¶
type Retention struct {
StoredSnapshotsDays int64
AlertDetailsDays int64
AlertGroupSummariesDays int64
AuditLogDays int64
}
Retention are the retention periods, in days.
type RuntimeState ¶
RuntimeState is what the notices are derived from: the Leader's alive mark, the end of the recovery window and the end of the latest downtime; a zero time is absent.
type SecretInput ¶
type SecretInput = keyring.SecretInput
SecretInput is a Secret field of an update: omitted keeps the stored value, null clears it, a value replaces it.
type SecretState ¶
SecretState is what a read shows of a Secret: whether it is set and when it last changed.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads and changes the organization resource and the outbound address policy of the Organization.
func NewService ¶
NewService returns the Service of the Organization orgID; clock is the business clock.
func (*Service) Get ¶
func (s *Service) Get(ctx context.Context) (Organization, error)
Get reads the organization resource.
func (*Service) OutboundPolicy ¶
func (s *Service) OutboundPolicy(ctx context.Context) (OutboundPolicyResource, error)
OutboundPolicy reads the outbound address policy with the rules that always apply.
func (*Service) SeverityValues ¶
func (s *Service) SeverityValues(ctx context.Context) (SeverityValues, error)
SeverityValues lists the values of the Organization's severity label among the Alerts last seen within SeverityValuesWindow of the business clock, the most frequent first, each with its number of Alerts and the level of the current mapping (C-20.FR-1, AC-4).
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, r audit.Actor, t audit.Transport, addr netip.Addr, version *int64, in Input) (Organization, error)
Update applies an update of every field of the organization resource (C-20.FR-1, FR-8, FR-9, C-04.FR-8); an omitted start of the working day or first day of the week keeps the stored one. version is the version of If-Match, nil for any; another one is ErrVersionMismatch. An invalid field is a *FieldError at the full JSON pointer of the field, and changes nothing. A change is recorded in the Audit log as organization.updated with its before/after diff, in which the Secrets show only that they changed, and announced to the live-updates streams with an organization hint, in the transaction of the change. An update that changes nothing writes nothing. A new or cleared URL clears the result of the last outgoing heartbeat and also sends a system-status hint. Severity levels and Instance labels apply from the next evaluation: their readers read them in their own transactions (C-20.FR-2).
func (*Service) UpdateOutboundPolicy ¶
func (s *Service) UpdateOutboundPolicy(ctx context.Context, r audit.Actor, t audit.Transport, addr netip.Addr, version *int64, in OutboundPolicyInput) (OutboundPolicyResource, error)
UpdateOutboundPolicy replaces the outbound address policy and its lists (C-20.FR-3, C-02.FR-21). version is the version of If-Match, nil for any; another one is ErrVersionMismatch. An entry that does not parse is a *FieldError with invalid_format, a repeated one with duplicate, at /allowed/<i> or /denied/<i>. A change is recorded as outbound_policy.updated with its diff, and sends NOTIFY on OutboundPolicyChannel and the organization hint in its transaction, so that every replica applies it at once; after the commit the hook of WithOutboundPolicyChanged applies it on this replica. An update that changes nothing writes nothing.
func (*Service) WithKeyring ¶
WithKeyring gives the Service the Keyring that encrypts the Secrets of the outgoing heartbeat; without one, an update that sets one fails.
func (*Service) WithLog ¶
WithLog gives the Service the logger of organization_updated and outbound_policy_updated; without one, it logs nothing.
func (*Service) WithOutboundPolicyChanged ¶
WithOutboundPolicyChanged runs f after each committed change of the outbound address policy, on the replica that made it: the replica applies the change at once, without waiting for its own notification.
type Settings ¶
type Settings struct {
ID int64
PublicID string
Name string
TimeZone string
// WorkdayStart is organization.workday_start, HH:MM on the 24-hour clock.
WorkdayStart string
// WeekStart is organization.week_start, monday to sunday.
WeekStart string
SeverityLabel string
SeverityMapping []SeverityMapping
SeverityStyles []SeverityStyle
CriticalIsUrgent bool
InstanceLabels []string
Retention Retention
TOTPRequired TOTPPolicy
// OIDCTokenGrace is auth.oidc_token_grace.
OIDCTokenGrace time.Duration
Outbound OutboundPolicy
}
Settings are the Organization and its settings.
type SettingsQueries ¶
type SettingsQueries interface {
GetSettings(ctx context.Context, orgID int64) (dbgen.GetSettingsRow, error)
LockSettings(ctx context.Context, orgID int64) (int64, error)
GetOutgoingHeartbeatSecrets(ctx context.Context, orgID int64) (dbgen.GetOutgoingHeartbeatSecretsRow, error)
UpdateSettings(ctx context.Context, arg dbgen.UpdateSettingsParams) (int64, error)
GetOutboundPolicySettings(ctx context.Context, orgID int64) (dbgen.GetOutboundPolicySettingsRow, error)
LockOutboundPolicy(ctx context.Context, orgID int64) (int64, error)
UpdateOutboundPolicy(ctx context.Context, arg dbgen.UpdateOutboundPolicyParams) (int64, error)
ListSeverityValues(ctx context.Context, arg dbgen.ListSeverityValuesParams) ([]dbgen.ListSeverityValuesRow, error)
audit.Store
// Notify sends a live-update hint, in the transaction when the queries run in one.
Notify(ctx context.Context, h db.Hint) error
// NotifyOutboundPolicy sends NOTIFY on OutboundPolicyChannel, in the transaction when the queries run in one.
NotifyOutboundPolicy(ctx context.Context, orgID int64) error
}
SettingsQueries are the queries of the organization resource, with the insert of the Audit log and the hint.
type SettingsStore ¶
type SettingsStore interface {
SettingsQueries
InTx(ctx context.Context, f func(SettingsQueries) error) error
}
SettingsStore runs the queries alone or in one transaction.
func NewSettingsStore ¶
func NewSettingsStore(pool *pgxpool.Pool) SettingsStore
NewSettingsStore is the SettingsStore over the main pool.
type SeverityLevel ¶
type SeverityLevel string
SeverityLevel is one of the three Severity levels.
const ( SeverityCritical SeverityLevel = "critical" SeverityWarning SeverityLevel = "warning" SeverityInfo SeverityLevel = "info" )
type SeverityMapping ¶
type SeverityMapping struct {
Value string `json:"value"`
Level SeverityLevel `json:"level"`
}
SeverityMapping maps a value of the severity label to a Severity level.
type SeverityStyle ¶
type SeverityStyle struct {
Level SeverityLevel `json:"level"`
Emoji string `json:"emoji"`
Color string `json:"color"`
}
SeverityStyle is the emoji and colour of a Severity level in messages.
type SeverityValue ¶
type SeverityValue struct {
Value string
Count int64
Level SeverityLevel
Mapped bool
}
SeverityValue is a value of the severity label seen: the number of Alerts that carry it and its level by the current mapping; an unmapped value counts as warning.
type SeverityValues ¶
type SeverityValues struct {
Items []SeverityValue
WindowDays int
}
SeverityValues are the values of the severity label seen within the window of WindowDays days.
type Store ¶
type Store interface {
GetOrganization(ctx context.Context) (dbgen.GetOrganizationRow, error)
CreateOrganization(ctx context.Context, arg dbgen.CreateOrganizationParams) (int64, error)
CreateOutboundPolicy(ctx context.Context, arg dbgen.CreateOutboundPolicyParams) (int64, error)
GetOutboundPolicy(ctx context.Context, orgID int64) (dbgen.GetOutboundPolicyRow, error)
}
Store is the organization's part of the database. *dbgen.Queries implements it.
type TOTPPolicy ¶
type TOTPPolicy string
TOTPPolicy says who must use a second factor.
const ( TOTPNobody TOTPPolicy = "nobody" TOTPLocalUsers TOTPPolicy = "local_users" TOTPEveryone TOTPPolicy = "everyone" )
func (TOTPPolicy) Covers ¶
func (p TOTPPolicy) Covers(local bool) bool
Covers reports whether the policy demands TOTP of an account; local is an account that has a password (C-03.FR-10).