* feat(state): durable operator alerts owned by the State Store Alerts dedup on org+kind+subject, resolve themselves when a condition clears, and are raised, resolved, dismissed and listed through the state contract. Task transitions raise needs-human and failed alerts in the same transaction; the store checks service health and prunes closed alerts. Each raise and resolve queues a webhook delivery whose attempts are kept. * feat(notify): deliver operator alerts to the webhook; raise config and release alerts notify.webhook now receives raised and resolved alerts above a severity threshold with HMAC-signed payloads, bounded retry and every attempt recorded on the alert. archied raises model alias, provider and credential-binding alerts from the effective configuration, an update alert from the release channel, and a credential-rejected alert from the egress resolver. The dashboard API lists and dismisses the caller's org's alerts. * feat(ui): alert bell in the top bar and webhook alert settings The bell lists the org's open alerts by severity with dismiss and a link per alert, and refreshes from the event stream. The task settings page gains the webhook severity threshold and signing secret. ui/dist rebuilt.
97 lines
3.3 KiB
Go
97 lines
3.3 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/daemon"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
|
)
|
|
|
|
// runCredentialResolver is the egress proxy's Resolver: it resolves a Kit
|
|
// credential for the run a run credential names, when the request is made,
|
|
// from the live grants and bindings. A revoked credential, a grant removed
|
|
// mid-run or a binding in another org stops resolving at once.
|
|
//
|
|
// A setup session's token names no task, so the resolver consults the session
|
|
// grants first: the session is bound for the org's bindings of the Kit's
|
|
// declared services, which is the intersection the operator's update-on-secret
|
|
// authorisation covers.
|
|
type runCredentialResolver struct {
|
|
runs interface {
|
|
TaskForCredential(ctx context.Context, token string) (*workflow.Task, error)
|
|
}
|
|
sessions interface {
|
|
GrantedFor(token string) (org string, services []string, ok bool)
|
|
}
|
|
// models answers a task's org's own providers. Nil grants only the
|
|
// instance providers.
|
|
models daemon.TaskModels
|
|
config *config.Holder
|
|
secrets interface {
|
|
Resolve(config.SecretRef) (string, error)
|
|
}
|
|
// credentials, when set, is told whether each bound secret resolved.
|
|
credentials *credentialWatch
|
|
}
|
|
|
|
func (r runCredentialResolver) Resolve(ctx context.Context, credential, service string) (string, error) {
|
|
if r.sessions != nil {
|
|
if org, services, ok := r.sessions.GrantedFor(credential); ok {
|
|
return r.resolveBinding(ctx, org, services, service)
|
|
}
|
|
}
|
|
task, err := r.runs.TaskForCredential(ctx, credential)
|
|
if err != nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
cfg := r.config.Get()
|
|
_, granted := cfg.CredentialAccess(task.Identity)
|
|
org := task.OrgOrDefault()
|
|
// A configured model provider's key is granted to every run of the org:
|
|
// any agent stage needs model access.
|
|
if r.isModelProvider(ctx, cfg, task, service) {
|
|
granted = append(slices.Clone(granted), service)
|
|
}
|
|
return r.resolveBinding(ctx, org, granted, service)
|
|
}
|
|
|
|
// resolveBinding resolves service from the org's binding when the run or
|
|
// session is granted it. An OAuth binding resolves to the empty string: the
|
|
// proxy supplies the org's token set itself.
|
|
func (r runCredentialResolver) resolveBinding(ctx context.Context, org string, granted []string, service string) (string, error) {
|
|
cfg := r.config.Get()
|
|
binding, ok := cfg.Containers.BoundCredentials(org, granted, []string{service})[service]
|
|
if !ok {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
if binding.Secret == (config.SecretRef{}) {
|
|
return "", nil
|
|
}
|
|
if r.secrets == nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
value, err := r.secrets.Resolve(binding.Secret)
|
|
r.credentials.observe(ctx, org, service, err != nil)
|
|
return value, err
|
|
}
|
|
|
|
// isModelProvider reports whether service is a provider the task's models
|
|
// run on: an instance provider, or one of its org's own.
|
|
func (r runCredentialResolver) isModelProvider(ctx context.Context, cfg config.Config, task *workflow.Task, service string) bool {
|
|
if _, ok := cfg.Providers[service]; ok {
|
|
return true
|
|
}
|
|
if r.models == nil {
|
|
return false
|
|
}
|
|
models, err := r.models.TaskModels(ctx, task.ID)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
_, ok := models.Providers[service]
|
|
return ok
|
|
}
|