Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty rolie #357

Merged
merged 24 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fbc6b80
Create ROLIE feed if summaries are empty
Apr 20, 2023
8a69cf5
Formatting, Remove sorting of 0 elements
Apr 20, 2023
fc64727
Handle minimum entry length error as warning in checker
Apr 20, 2023
6884277
Use empty array instead of creating an empty array to reference
Apr 21, 2023
f3b800f
Change schema to allow for empty entry arrays
Apr 27, 2023
71de55f
Use https://raw.githubusercontent.com/oasis-tcs/csaf/81b2663697958bc5…
May 5, 2023
2a833be
Change label name from empty to undefined
May 8, 2023
418d93b
Change default of create_service_document for csaf_provider to true
May 8, 2023
543c7f2
Config
May 8, 2023
4f9c2a9
Count entries in csaf-checker, warn if there are none.
May 10, 2023
ec4bdbe
Add Comments to csaf/rolie.go's CountEntries function
May 10, 2023
83a3b9e
Merge branch 'main' into empty_ROLIE
s-l-teichmann Jun 8, 2023
7729a83
Delete index.txt and changes.csv in aggregator if there are no entries.
s-l-teichmann Jun 9, 2023
3cb5030
Create an empty ROLIE feed document when setting up folders during cr…
Jun 9, 2023
14b08da
nit: set update time stamp in structure init.
s-l-teichmann Jun 9, 2023
78dede9
Instantiate label checker only once.
s-l-teichmann Jun 16, 2023
6b52081
Ignore domain not having roles.
s-l-teichmann Jun 19, 2023
c495006
provider: Create empty entry section in ROLIE feed.
s-l-teichmann Jun 19, 2023
7a63832
Stop check for domain if PMD check fails
Jun 29, 2023
bf461e6
Add missing continue statement
Jun 29, 2023
f7ed10a
Report missing ROLIE feed entries in ROLIE feed, not Provider Metadata
Jun 29, 2023
26a4d2e
Do not ommit empty entries in ROLIE feeds.
s-l-teichmann Jun 30, 2023
30c2218
Merge branch 'main' into empty_ROLIE
s-l-teichmann Jun 30, 2023
89e69a7
Fixed error handling problem introduced by faulty merge. Removed unus…
s-l-teichmann Jun 30, 2023
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
72 changes: 67 additions & 5 deletions cmd/csaf_aggregator/indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ func (w *worker) writeInterims(label string, summaries []summary) error {

func (w *worker) writeCSV(label string, summaries []summary) error {

fname := filepath.Join(w.dir, label, changesCSV)

// If we don't have any entries remove existing file.
if len(summaries) == 0 {
// Does it really exist?
if err := os.RemoveAll(fname); err != nil {
return fmt.Errorf("unable to remove %q: %w", fname, err)
}
return nil
}

f, err := os.Create(fname)
if err != nil {
return err
}

// Do not sort in-place.
ss := make([]summary, len(summaries))
copy(ss, summaries)
Expand All @@ -100,11 +116,6 @@ func (w *worker) writeCSV(label string, summaries []summary) error {
ss[j].summary.CurrentReleaseDate)
})

fname := filepath.Join(w.dir, label, changesCSV)
f, err := os.Create(fname)
if err != nil {
return err
}
out := util.NewFullyQuotedCSWWriter(f)

record := make([]string, 2)
Expand Down Expand Up @@ -137,6 +148,16 @@ func (w *worker) writeCSV(label string, summaries []summary) error {
func (w *worker) writeIndex(label string, summaries []summary) error {

fname := filepath.Join(w.dir, label, indexTXT)

// If we don't have any entries remove existing file.
if len(summaries) == 0 {
// Does it really exist?
if err := os.RemoveAll(fname); err != nil {
return fmt.Errorf("unable to remove %q: %w", fname, err)
}
return nil
}

f, err := os.Create(fname)
if err != nil {
return err
Expand All @@ -157,6 +178,46 @@ func (w *worker) writeIndex(label string, summaries []summary) error {
return err2
}

func (w *worker) writeROLIENoSummaries(label string) error {

labelFolder := strings.ToLower(label)

fname := "csaf-feed-tlp-" + labelFolder + ".json"

feedURL := w.processor.cfg.Domain + "/.well-known/csaf-aggregator/" +
w.provider.Name + "/" + labelFolder + "/" + fname

links := []csaf.Link{{
Rel: "self",
HRef: feedURL,
}}

if w.provider.serviceDocument(w.processor.cfg) {
links = append(links, csaf.Link{
Rel: "service",
HRef: w.processor.cfg.Domain + "/.well-known/csaf-aggregator/" +
w.provider.Name + "/service.json",
})
}

rolie := &csaf.ROLIEFeed{
Feed: csaf.FeedData{
ID: "csaf-feed-tlp-" + strings.ToLower(label),
Title: "CSAF feed (TLP:" + strings.ToUpper(label) + ")",
Link: links,
Category: []csaf.ROLIECategory{{
Scheme: "urn:ietf:params:rolie:category:information-type",
Term: "csaf",
}},
Updated: csaf.TimeStamp(time.Now().UTC()),
Entry: []*csaf.Entry{},
},
}

path := filepath.Join(w.dir, labelFolder, fname)
return util.WriteToFile(path, rolie)
}

func (w *worker) writeROLIE(label string, summaries []summary) error {

labelFolder := strings.ToLower(label)
Expand Down Expand Up @@ -311,6 +372,7 @@ func (w *worker) writeService() error {
func (w *worker) writeIndices() error {

if len(w.summaries) == 0 || w.dir == "" {
w.writeROLIENoSummaries("undefined")
return nil
}

Expand Down
12 changes: 8 additions & 4 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ func (p *processor) run(domains []string) (*Report, error) {
if err == errContinue || err == errStop {
continue
}
return nil, err
} else {
log.Printf("Failed to find valid provider-metadata.json for domain %s. "+
"Continuing with next domain.", d)
continue
}
domain := &Domain{Name: d}

Expand Down Expand Up @@ -503,12 +506,15 @@ func (p *processor) rolieFeedEntries(feed string) ([]csaf.AdvisoryFile, error) {
var rolieDoc any
err = json.NewDecoder(bytes.NewReader(all)).Decode(&rolieDoc)
return rfeed, rolieDoc, err

}()
if err != nil {
p.badProviderMetadata.error("Loading ROLIE feed failed: %v.", err)
return nil, errContinue
}

if rfeed.CountEntries() == 0 {
p.badROLIEFeed.warn("No entries in %s", feed)
}
errors, err := csaf.ValidateROLIE(rolieDoc)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1208,8 +1214,6 @@ func (p *processor) checkProviderMetadata(domain string) bool {
}

if !lpmd.Valid() {
p.badProviderMetadata.error("No valid provider-metadata.json found.")
p.badProviderMetadata.error("STOPPING here - cannot perform other checks.")
return false
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/csaf_provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
defaultWeb = "/var/www/html" // Default web path.
defaultNoWebUI = true
defaultUploadLimit = 50 * 1024 * 1024 // Default limit size of the uploaded file.
defaultServiceDocument = true
)

type providerMetadataConfig struct {
Expand Down Expand Up @@ -226,7 +227,8 @@ func loadConfig() (*config, error) {

// Preset defaults
cfg := config{
NoWebUI: defaultNoWebUI,
NoWebUI: defaultNoWebUI,
ServiceDocument: defaultServiceDocument,
}

md, err := toml.DecodeFile(path, &cfg)
Expand Down
47 changes: 47 additions & 0 deletions cmd/csaf_provider/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"path"
"path/filepath"
"strings"
"time"
"unicode"

"github.com/ProtonMail/gopenpgp/v2/crypto"
Expand Down Expand Up @@ -153,10 +154,56 @@ func createFeedFolders(c *config, wellknown string) error {
return err
}
}
// Create an empty ROLIE feed document
if err := createROLIEfeed(c, t, tlpLink); err != nil {
return err
}
}
return nil
}

// createROLIEfeed creates an empty ROLIE feed
func createROLIEfeed(c *config, t tlp, folder string) error {
ts := string(t)
feedName := "csaf-feed-tlp-" + ts + ".json"

feed := filepath.Join(folder, feedName)

feedURL := csaf.JSONURL(
c.CanonicalURLPrefix +
"/.well-known/csaf/" + ts + "/" + feedName)

tlpLabel := csaf.TLPLabel(strings.ToUpper(ts))

links := []csaf.Link{{
Rel: "self",
HRef: string(feedURL),
}}
// If we have a service document we need to link it.
if c.ServiceDocument {
links = append(links, csaf.Link{
Rel: "service",
HRef: c.CanonicalURLPrefix + "/.well-known/csaf/service.json",
})
}
rolie := &csaf.ROLIEFeed{
Feed: csaf.FeedData{
ID: "csaf-feed-tlp-" + ts,
Title: "CSAF feed (TLP:" + string(tlpLabel) + ")",
Link: links,
Category: []csaf.ROLIECategory{{
Scheme: "urn:ietf:params:rolie:category:information-type",
Term: "csaf",
}},
Updated: csaf.TimeStamp(time.Now().UTC()),
tschmidtb51 marked this conversation as resolved.
Show resolved Hide resolved
Entry: []*csaf.Entry{},
},
}

return util.WriteToFile(feed, rolie)

}

// createOpenPGPFolder creates an openpgp folder besides
// the provider-metadata.json in the csaf folder.
func createOpenPGPFolder(c *config, wellknown string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/csaf_provider/rolie.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (c *controller) extendROLIE(
Scheme: "urn:ietf:params:rolie:category:information-type",
Term: "csaf",
}},
Entry: []*csaf.Entry{},
},
}
}
Expand Down
7 changes: 6 additions & 1 deletion csaf/rolie.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type FeedData struct {
Link []Link `json:"link,omitempty"`
Category []ROLIECategory `json:"category,omitempty"`
Updated TimeStamp `json:"updated"`
Entry []*Entry `json:"entry,omitempty"`
Entry []*Entry `json:"entry"`
}

// ROLIEFeed is a ROLIE feed.
Expand Down Expand Up @@ -238,3 +238,8 @@ func (rf *ROLIEFeed) SortEntriesByUpdated() {
return time.Time(entries[j].Updated).Before(time.Time(entries[i].Updated))
})
}

// CountEntries returns the number of entries within the feed
func (rf *ROLIEFeed) CountEntries() int {
return len(rf.Feed.Entry)
tschmidtb51 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading