Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ webhooks.
## Status

The CRDs are defined. The operator sets owners and reviewers in admission,
reconciles votes, follows and submission reviews, and stores attachments.
Triage, security reports and digests are tracked as sub-issues of the epic.
reconciles votes, follows, submission reviews and security reports, and
stores attachments. Triage, notifications and digests, audit and search
config are tracked as sub-issues of the epic.

| Resource | Who writes it | Who reads it |
| --- | --- | --- |
Expand Down Expand Up @@ -87,6 +88,19 @@ GET /{submissions|securityreports}/{name}/attachments/{ref} (staff)
- **Lifecycle rule.** The bucket's lifecycle rule should delete `uploads/` after a day.
- **Configuration.** Set the bucket in the `feedback-config` ConfigMap (`attachments-bucket`). The operator and the upload service share it.

## Security reports

- **Admission** (`securityreport` webhook):
- Credit links must be http(s), and public credit needs a name.
- Reports with no owner (logged by the Security Team for someone without an account) need the reporter's email or GitHub username.
- Status updates can add timeline entries but not change or remove them. A phase change needs an entry for the new phase; the `securitytimeline` webhook adds it if the update didn't. `NotApplicable` and `Duplicate` need a reason, credit rewards need an amount, and advisories need an https link.
- **`security-report` reconciler:**
- A new report starts in `Received` with its first timeline entry.
- It creates the report's `SecurityReportTriage` for the Security Team's private notes.
- It copies attachments under `security-reports/<name>/` and deletes them with the report.
- A `Fixed` or `Disclosed` report with public credit gets a `SecurityAcknowledgement` with the name, link, month and severity. It's deleted if that stops being true.
- **`move-to-security` reconciler:** carries out `MoveToSecurity` review decisions. It creates a report owned by the submitter, named `<submission>-<submission UID>` and annotated with the submission's name and UID (`feedback.miloapis.com/moved-from-submission`, `-uid`). It reads the report back and checks the name, UID and owner before it copies the attachments and deletes the submission, which takes its review and files with it. If a report it didn't create already has that name, it keeps the submission and its files and sets `Applied=False` with reason `ReportNameTaken` on the review; the move is tried again when a report is deleted. Only the operator can set the moved-from annotations, and they can't change.

## Roles

| Role | For |
Expand Down
6 changes: 3 additions & 3 deletions config/milo/rbac/feedback-operator.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# feedback-operator reconciles every feedback resource: it watches them all,
# writes post votes and delivery, follows and votes it creates for users,
# review outcomes, reports moved from submissions, acknowledgements and
# digests. It never writes a post's GitHub fields or a user's spec.
# review outcomes, reports moved from submissions, empty triage objects for
# new reports, acknowledgements and digests. It never writes a post's GitHub fields or a user's spec.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand All @@ -17,7 +17,7 @@ rules:
resources: [posts/status, votes/status, submissions/status, submissionreviews/status, securityreports/status]
verbs: [get, update, patch]
- apiGroups: [feedback.miloapis.com]
resources: [votes, subscriptions, submissionreviews, securityreports, securityacknowledgements, feedbackdigests]
resources: [votes, subscriptions, submissionreviews, securityreports, securityreporttriages, securityacknowledgements, feedbackdigests]
verbs: [create, update, patch, delete]
# delete for reports moved to the security track; update and patch only to
# add and remove the attachments finalizer.
Expand Down
40 changes: 40 additions & 0 deletions config/milo/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,52 @@ webhooks:
resources:
- submissionreviews
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: feedback-operator-webhook
namespace: feedback-system
path: /mutate-securityreport-status
failurePolicy: Fail
name: securitytimeline.feedback.miloapis.com
rules:
- apiGroups:
- feedback.miloapis.com
apiVersions:
- v1alpha1
operations:
- UPDATE
resources:
- securityreports/status
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: feedback-operator-webhook
namespace: feedback-system
path: /validate-securityreport
failurePolicy: Fail
name: securityreport.feedback.miloapis.com
rules:
- apiGroups:
- feedback.miloapis.com
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- securityreports
- securityreports/status
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
250 changes: 250 additions & 0 deletions internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package controller

import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"sync"
"testing"
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -446,3 +449,250 @@ func TestSubmissionAttachments(t *testing.T) {
return nil
})
}

func TestSecurityReports(t *testing.T) {
ctx := context.Background()
files, err := attachments.Open(ctx, "mem://")
if err != nil {
t.Fatal(err)
}
c := start(t, &clock{now: time.Now()}, files)
get := func(obj client.Object) error { return c.Get(ctx, client.ObjectKeyFromObject(obj), obj) }

t.Run("a new report is received, with private triage", func(t *testing.T) {
rep := &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: "sec-1"}, Spec: v1.SecurityReportSpec{
UserRef: &v1.UserReference{Name: "u1"}, Title: "t", Description: "d",
Credit: &v1.SecurityCredit{Public: true, Name: "Ada L.", URL: "https://example.com"}}}
if err := c.Create(ctx, rep); err != nil {
t.Fatal(err)
}
eventually(t, "received", func() error {
if err := get(rep); err != nil {
return err
}
if rep.Status.Phase != v1.SecurityReportPhaseReceived || len(rep.Status.Timeline) != 1 {
return errorf("status " + string(rep.Status.Phase))
}
return get(&v1.SecurityReportTriage{ObjectMeta: metav1.ObjectMeta{Name: "sec-1"}})
})

// Fixed, with public credit: acknowledged.
rep.Status.Phase, rep.Status.Severity = v1.SecurityReportPhaseFixed, v1.SeverityHigh
rep.Status.Timeline = append(rep.Status.Timeline, v1.SecurityTimelineEntry{
Phase: v1.SecurityReportPhaseFixed, At: metav1.NewTime(time.Date(2026, 10, 30, 0, 0, 0, 0, time.UTC))})
if err := c.Status().Update(ctx, rep); err != nil {
t.Fatal(err)
}
ack := &v1.SecurityAcknowledgement{ObjectMeta: metav1.ObjectMeta{Name: "sec-1"}}
eventually(t, "acknowledged", func() error {
if err := get(ack); err != nil {
return err
}
if ack.Status.Name != "Ada L." || ack.Status.Month != "2026-10" || ack.Status.Severity != v1.SeverityHigh {
return errorf("ack " + ack.Status.Month)
}
return nil
})
})

t.Run("no public credit, no acknowledgement", func(t *testing.T) {
rep := &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: "sec-2"}, Spec: v1.SecurityReportSpec{
Reporter: &v1.ExternalReporter{Email: "r@example.com"}, Title: "t", Description: "d"}}
if err := c.Create(ctx, rep); err != nil {
t.Fatal(err)
}
eventually(t, "received", func() error {
if err := get(rep); err != nil {
return err
}
if rep.Status.Phase == "" {
return errorf("no phase")
}
return nil
})
rep.Status.Phase = v1.SecurityReportPhaseDisclosed
if err := c.Status().Update(ctx, rep); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
if err := get(&v1.SecurityAcknowledgement{ObjectMeta: metav1.ObjectMeta{Name: "sec-2"}}); !apierrors.IsNotFound(err) {
t.Errorf("acknowledgement exists: %v", err)
}
})

// submit creates a submission by u7 with an attachment and waits for the
// operator to copy the file under it.
submit := func(t *testing.T, name string) (*v1.Submission, string) {
t.Helper()
ref, _, err := files.Upload(ctx, attachments.Submission, "u7", "poc.txt", "text/plain", []byte("poc"))
if err != nil {
t.Fatal(err)
}
sub := &v1.Submission{ObjectMeta: metav1.ObjectMeta{Name: name}, Spec: v1.SubmissionSpec{
UserRef: v1.UserReference{Name: "u7"}, Kind: v1.SubmissionKindBug, Title: "Viewer reads secrets", Body: "steps",
Attachments: []v1.AttachmentReference{{UploadRef: ref}}}}
if err := c.Create(ctx, sub); err != nil {
t.Fatal(err)
}
eventually(t, "submission's files copied", func() error {
if err := get(sub); err != nil {
return err
}
if len(sub.Finalizers) == 0 {
return errorf("no finalizer")
}
return nil
})
return sub, ref
}
decide := func(t *testing.T, sub *v1.Submission) *v1.SubmissionReview {
t.Helper()
r := &v1.SubmissionReview{ObjectMeta: metav1.ObjectMeta{Name: sub.Name}}
eventually(t, "decide", func() error {
if err := get(r); err != nil {
return err
}
r.Spec = v1.SubmissionReviewSpec{Decision: v1.ReviewDecisionMoveToSecurity, Affected: "secrets"}
return c.Update(ctx, r)
})
return r
}
// moved waits for sub to become the report rep, with its file.
moved := func(t *testing.T, sub *v1.Submission, ref string, rep *v1.SecurityReport) {
t.Helper()
eventually(t, "moved", func() error {
if err := get(rep); err != nil {
return err
}
if rep.Spec.UserRef == nil || rep.Spec.UserRef.Name != "u7" || rep.Spec.Affected != "secrets" {
return errorf("report spec")
}
if !movedFrom(rep, sub) {
return errorf("report doesn't name the submission")
}
if err := get(&v1.Submission{ObjectMeta: metav1.ObjectMeta{Name: sub.Name}}); !apierrors.IsNotFound(err) {
return errorf("submission still there")
}
if _, err := files.Get(ctx, attachments.Submission, sub.Name, "", ref); err == nil {
return errorf("submission's copy not deleted")
}
_, err := files.Get(ctx, attachments.SecurityReport, rep.Name, "", ref)
return err
})
}

t.Run("a misfiled submission moves to the security track", func(t *testing.T) {
sub, ref := submit(t, "sub-sec")
// A report filed under the submission's own name is someone else's
// and is left alone.
other := &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: sub.Name}, Spec: v1.SecurityReportSpec{
UserRef: &v1.UserReference{Name: "u8"}, Title: "other", Description: "d"}}
if err := c.Create(ctx, other); err != nil {
t.Fatal(err)
}
decide(t, sub)
moved(t, sub, ref, &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: v1.MovedReportName(sub.Name, sub.UID)}})
if err := get(other); err != nil || other.Spec.Title != "other" {
t.Errorf("the other report changed: %v", err)
}
})

t.Run("a move finishes when its report already exists", func(t *testing.T) {
// As if the operator stopped after creating the report.
sub, ref := submit(t, "sub-sec-retry")
rep := movedReport(sub, &v1.SubmissionReview{Spec: v1.SubmissionReviewSpec{Affected: "secrets"}}, v1.MovedReportName(sub.Name, sub.UID))
if err := c.Create(ctx, rep); err != nil {
t.Fatal(err)
}
decide(t, sub)
moved(t, sub, ref, rep)
})

for _, tc := range []struct {
name string
taken func(sub *v1.Submission) *v1.SecurityReport
}{
{"an unrelated report", func(sub *v1.Submission) *v1.SecurityReport {
return &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: v1.MovedReportName(sub.Name, sub.UID)},
Spec: v1.SecurityReportSpec{UserRef: &v1.UserReference{Name: "u8"}, Title: "other", Description: "d"}}
}},
{"a report naming the submission, for someone else", func(sub *v1.Submission) *v1.SecurityReport {
rep := movedReport(sub, &v1.SubmissionReview{}, v1.MovedReportName(sub.Name, sub.UID))
rep.Spec.UserRef.Name = "u8"
rep.Finalizers = nil
return rep
}},
{"a report naming another submission with the same name", func(sub *v1.Submission) *v1.SecurityReport {
rep := movedReport(sub, &v1.SubmissionReview{}, v1.MovedReportName(sub.Name, sub.UID))
rep.Annotations[v1.MovedFromSubmissionUIDAnnotation] = "00000000-0000-0000-0000-000000000000"
rep.Finalizers = nil
return rep
}},
} {
t.Run("a move is refused when "+tc.name+" has the name", func(t *testing.T) {
sub, ref := submit(t, fmt.Sprintf("sub-sec-taken-%d", time.Now().UnixNano()))
taken := tc.taken(sub)
if err := c.Create(ctx, taken); err != nil {
t.Fatal(err)
}
before := taken.DeepCopy()
review := decide(t, sub)
eventually(t, "refused", func() error {
if err := get(review); err != nil {
return err
}
cond := meta.FindStatusCondition(review.Status.Conditions, ConditionApplied)
if cond == nil || cond.Status != metav1.ConditionFalse || cond.Reason != ReasonReportNameTaken {
return errorf("no ReportNameTaken condition")
}
return nil
})
// Give a wrong move time to happen.
time.Sleep(time.Second)
if err := get(&v1.Submission{ObjectMeta: metav1.ObjectMeta{Name: sub.Name}}); err != nil {
t.Fatalf("submission: %v", err)
}
if _, err := files.Get(ctx, attachments.Submission, sub.Name, "", ref); err != nil {
t.Errorf("submission's file: %v", err)
}
if _, err := files.Get(ctx, attachments.SecurityReport, taken.Name, "", ref); err == nil {
t.Errorf("file copied to the other report")
}
if err := get(taken); err != nil || taken.UID != before.UID || !reflect.DeepEqual(taken.Spec, before.Spec) {
t.Errorf("the other report changed: %v", err)
}

// Once that report is gone, the move goes ahead.
if err := c.Delete(ctx, taken); err != nil {
t.Fatal(err)
}
moved(t, sub, ref, &v1.SecurityReport{ObjectMeta: metav1.ObjectMeta{Name: taken.Name}})
})
}
}

func TestMovedFrom(t *testing.T) {
sub := &v1.Submission{ObjectMeta: metav1.ObjectMeta{Name: "s", UID: "uid-1"}, Spec: v1.SubmissionSpec{UserRef: v1.UserReference{Name: "u1"}}}
for _, tc := range []struct {
name string
edit func(*v1.SecurityReport)
want bool
}{
{"made from it", func(*v1.SecurityReport) {}, true},
{"no annotations", func(r *v1.SecurityReport) { r.Annotations = nil }, false},
{"another submission's name", func(r *v1.SecurityReport) { r.Annotations[v1.MovedFromSubmissionAnnotation] = "t" }, false},
{"another submission's UID", func(r *v1.SecurityReport) { r.Annotations[v1.MovedFromSubmissionUIDAnnotation] = "uid-2" }, false},
{"another owner", func(r *v1.SecurityReport) { r.Spec.UserRef.Name = "u2" }, false},
{"no owner", func(r *v1.SecurityReport) { r.Spec.UserRef = nil }, false},
} {
rep := movedReport(sub, &v1.SubmissionReview{}, v1.MovedReportName(sub.Name, sub.UID))
tc.edit(rep)
if got := movedFrom(rep, sub); got != tc.want {
t.Errorf("%s: movedFrom = %v", tc.name, got)
}
}
if movedFrom(&v1.SecurityReport{Spec: v1.SecurityReportSpec{UserRef: &v1.UserReference{Name: "u1"}}},
&v1.Submission{ObjectMeta: metav1.ObjectMeta{Name: ""}, Spec: v1.SubmissionSpec{UserRef: v1.UserReference{Name: "u1"}}}) {
t.Error("a submission without a UID matched a report without annotations")
}
}
Loading
Loading