Documentation
¶
Overview ¶
Package config reads and validates the configuration from environment variables. Invalid, incomplete, or contradictory settings are errors, all reported at once, so a misconfigured service fails at startup instead of silently running with a feature disabled or a default it was not given.
Any value may be an AWS SSM Parameter Store ARN, which is replaced by the parameter's decrypted value.
Index ¶
Constants ¶
const ( DefaultListenAddr = ":8080" DefaultGitHubWebURL = "https://github.com" DefaultOktaGitHubUserField = "githubUsername" DefaultOktaSyncSafetyThreshold = 0.5 DefaultSecurityAlertsMinAgeDays = 30 DefaultSecurityAlertsMinSeverity = domain.SeverityHigh DefaultSlackAppName = "GitHub Ops" DefaultSlackCommand = "/github-ops" // MinAdminTokenLength is the shortest admin token accepted. MinAdminTokenLength = 16 )
Defaults for unset variables.
const ( // ReportRepeatEveryRun posts every report after every run. ReportRepeatEveryRun = "every-run" // ReportRepeatDaily posts a report when it changes, and once a day // when it hasn't. ReportRepeatDaily = "daily" )
How often a scheduled report that hasn't changed is posted again.
Variables ¶
var ( DefaultPRMonitoredBranches = []string{"main", "master"} DefaultOktaScopes = []string{"okta.groups.read", "okta.users.read"} )
Default lists for unset variables.
var DefaultReportDailyTime = TimeOfDay{Hour: 9}
DefaultReportDailyTime is when the day's unchanged reports are due.
Functions ¶
This section is empty.
Types ¶
type Bootstrap ¶ added in v1.0.0
Bootstrap is the configuration needed before the rest can be loaded: how to log, serve, and run the GitHub App installer. It doesn't need the GitHub App's credentials, so it loads before the app is set up. Like the rest, its APP_ values may be SSM ARNs; the installer's own variables are read as github-app-setup-go reads them, without SSM resolution.
func LoadBootstrap ¶ added in v1.0.0
LoadBootstrap reads the bootstrap configuration.
type Config ¶
type Config struct {
Bootstrap
// AdminToken guards the admin and scheduled endpoints. When empty,
// those endpoints are disabled.
AdminToken string
GitHub GitHub
PRCompliance PRCompliance
Okta Okta
SecurityAlerts SecurityAlerts
Slack Slack
Reports Reports
}
Config is the application's configuration.
func (*Config) Redacted ¶
func (c *Config) Redacted() RedactedConfig
Redacted returns the configuration with secrets redacted.
func (*Config) ShouldMonitorBranch ¶
ShouldMonitorBranch returns true if merges into branch are checked for compliance.
type Env ¶ added in v1.0.0
type Env struct {
// Lookup has the signature of os.LookupEnv.
Lookup func(key string) (string, bool)
// ResolveSSM returns the value of the SSM parameter an ARN names. When
// nil, parameters are read from AWS with the default credentials.
ResolveSSM func(ctx context.Context, arn string) (string, error)
}
Env is where configuration is read from.
func ProcessEnv ¶ added in v1.0.0
func ProcessEnv() Env
ProcessEnv reads the process environment and resolves SSM ARNs in AWS.
type GitHub ¶ added in v1.0.0
type GitHub struct {
Org string
AppID int64
// InstallationID is the app's installation on Org. When zero it is
// looked up.
InstallationID int64
PrivateKey []byte
WebhookSecret string
// BaseURL is the API URL for GitHub Enterprise Server, or empty.
BaseURL string
// WebURL is the web URL that links point to.
WebURL string
}
GitHub configures the GitHub App.
type Installer ¶ added in v1.0.0
type Installer struct {
Enabled bool
// StorageMode is where the installers save credentials: envfile or
// aws-ssm.
StorageMode string
// StorageDir is the env file path for the envfile mode.
StorageDir string
// SSMParameterPrefix is the parameter path for the aws-ssm mode.
SSMParameterPrefix string
// SSMKMSKeyID encrypts the parameters the aws-ssm mode writes; empty
// uses the aws/ssm key.
SSMKMSKeyID string
// GitHubOrg is the organization the app is created in.
GitHubOrg string
// GitHubURL is the GitHub web URL the app is created on.
GitHubURL string
}
Installer configures the GitHub App manifest installer, and where it and the Slack setup save credentials.
type Okta ¶ added in v1.0.0
type Okta struct {
Enabled bool
Domain string
ClientID string
PrivateKey []byte
PrivateKeyID string
Scopes []string
BaseURL string
GitHubUserField string
SyncRules []domain.SyncRule
SyncSafetyThreshold float64
OrphanedUserNotifications bool
}
Okta configures Okta group sync.
type PRCompliance ¶ added in v1.0.0
type PRCompliance struct {
Enabled bool
// MonitoredBranches are branch names or glob patterns, such as
// "release/*".
MonitoredBranches []string
}
PRCompliance configures PR compliance monitoring.
type RedactedConfig ¶
type RedactedConfig struct {
LogLevel string `json:"log_level"`
BasePath string `json:"base_path"`
PublicURL string `json:"public_url"`
InstallerEnabled bool `json:"installer_enabled"`
SlackSetupEnabled bool `json:"slack_setup_enabled"`
AdminToken string `json:"admin_token"`
GitHubOrg string `json:"github_org"`
GitHubAppID int64 `json:"github_app_id"`
GitHubInstallationID int64 `json:"github_installation_id"`
GitHubAppPrivateKey string `json:"github_app_private_key"`
GitHubWebhookSecret string `json:"github_webhook_secret"`
GitHubBaseURL string `json:"github_base_url"`
PRComplianceEnabled bool `json:"pr_compliance_enabled"`
PRMonitoredBranches []string `json:"pr_monitored_branches"`
OktaEnabled bool `json:"okta_enabled"`
OktaDomain string `json:"okta_domain"`
OktaClientID string `json:"okta_client_id"`
OktaPrivateKey string `json:"okta_private_key"`
OktaPrivateKeyID string `json:"okta_private_key_id"`
OktaScopes []string `json:"okta_scopes"`
OktaGitHubUserField string `json:"okta_github_user_field"`
OktaSyncRules []domain.SyncRule `json:"okta_sync_rules"`
OktaSyncSafetyThreshold float64 `json:"okta_sync_safety_threshold"`
OktaOrphanedUserNotifications bool `json:"okta_orphaned_user_notifications"`
SecurityAlertsEnabled bool `json:"security_alerts_enabled"`
SecurityAlertsMinAgeDays int `json:"security_alerts_min_age_days"`
SecurityAlertsMinSeverity string `json:"security_alerts_min_severity"`
SlackEnabled bool `json:"slack_enabled"`
SlackPending bool `json:"slack_pending"`
SlackToken string `json:"slack_token"`
SlackSigningSecret string `json:"slack_signing_secret"`
SlackAppName string `json:"slack_app_name"`
SlackCommand string `json:"slack_command"`
SlackCommandAllowedUsers []string `json:"slack_command_allowed_users"`
SlackChannel string `json:"slack_channel"`
SlackChannelPRBypass string `json:"slack_channel_pr_bypass"`
SlackChannelOktaSync string `json:"slack_channel_okta_sync"`
SlackChannelOrphanedUsers string `json:"slack_channel_orphaned_users"`
SlackChannelSecurityAlerts string `json:"slack_channel_security_alerts"`
ReportRepeat string `json:"report_repeat"`
ReportDailyTime string `json:"report_daily_time"`
ReportTimezone string `json:"report_timezone"`
ReportStateSSMPrefix string `json:"report_state_ssm_prefix"`
ReportStateFile string `json:"report_state_file"`
}
RedactedConfig is the configuration with secrets redacted, safe to log or return from the admin API.
type Reports ¶ added in v1.1.0
type Reports struct {
// Repeat is ReportRepeatEveryRun or ReportRepeatDaily.
Repeat string
// DailyTime is when, in Location, the day's unchanged reports are due.
// They post at the first run on or after it.
DailyTime TimeOfDay
Location *time.Location
// StateSSMPrefix or StateFile is where what each report last posted is
// kept. With neither, it is kept in memory and lost on restart.
StateSSMPrefix string
StateFile string
}
Reports configures how often scheduled reports are posted to Slack.
type SecurityAlerts ¶ added in v1.0.0
SecurityAlerts configures stale security alert reports.
type Server ¶ added in v1.0.0
type Server struct {
// ListenAddr is the TCP address to listen on, such as ":8080".
ListenAddr string
// BasePath is the path every route is mounted under: empty, or a path
// with a leading slash and no trailing slash.
BasePath string
// PublicURL is the external URL of the service, including BasePath. It
// is used to build the installer's redirect and webhook URLs; when
// empty, they are derived from each request.
PublicURL string
}
Server configures the HTTP server.
type Slack ¶ added in v1.0.0
type Slack struct {
// Enabled is true when the token and channel are set.
Enabled bool
// Pending is true while the Slack setup is enabled and the token or
// channel isn't set yet. Slack stays off until both are.
Pending bool
Token string
// SigningSecret verifies requests from Slack. Setting it, with Enabled,
// turns on the slash command.
SigningSecret string
// CommandAllowedUsers are the Slack user IDs that may run the slash
// command's actions. Anyone may ask it for help.
CommandAllowedUsers []string
Channel string
ChannelPRBypass string
ChannelOktaSync string
ChannelOrphanedUsers string
ChannelSecurityAlerts string
APIURL string
}
Slack configures notifications and the slash command.
func (Slack) CommandsEnabled ¶ added in v1.1.0
CommandsEnabled returns true when the slash command is turned on.
type SlackApp ¶ added in v1.1.0
type SlackApp struct {
// SetupEnabled serves /slack/setup, which creates and installs the
// Slack app and saves its credentials where the GitHub App installer
// saves its own. While it is enabled, Slack credentials it hasn't saved
// yet are not an error.
SetupEnabled bool
// Name is the app's name in Slack.
Name string
// Command is the slash command, such as /github-ops.
Command string
}
SlackApp describes the Slack app: what the setup page creates, and the slash command it answers.