Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d3252a0
Initial Debian DLA DSA DTSA converter in Go instead of Python
jess-lowe Mar 3, 2026
bae6f45
Rewrite first package finder in go
jess-lowe Mar 4, 2026
7b2dc30
clean up
jess-lowe Mar 4, 2026
3110228
fix lints
jess-lowe Mar 4, 2026
011eb73
Do the upload without the script
jess-lowe Mar 4, 2026
6c15d89
fit gemini nit
jess-lowe Mar 4, 2026
ec60ee9
upload with gcs in go
jess-lowe Mar 4, 2026
a287545
fixed some lint stuff
jess-lowe Mar 4, 2026
181140f
Update the deploy
jess-lowe Mar 4, 2026
d081726
fix some of the dockerfile stuff
jess-lowe Mar 5, 2026
6396bf4
i dub thee
jess-lowe Mar 5, 2026
9440485
fix thing
jess-lowe Mar 5, 2026
5867ccd
Merge branch 'master' into feat/rewrite-deb-in-go
jess-lowe Mar 5, 2026
7a13f0d
Merge branch 'master' into feat/rewrite-deb-in-go
jess-lowe Mar 6, 2026
3e2f249
add back some comments
jess-lowe Mar 9, 2026
654dbd0
update comments and add logger instead of slog
jess-lowe Mar 9, 2026
8124db8
fix lint
jess-lowe Mar 9, 2026
5b887ee
fix lints and nits
jess-lowe Mar 9, 2026
2371713
lint
jess-lowe Mar 9, 2026
fbc2bcd
Merge branch 'master' into feat/rewrite-deb-in-go
jess-lowe Mar 9, 2026
018bbfd
update mod/sum files
jess-lowe Mar 9, 2026
b104f4d
lint
jess-lowe Mar 9, 2026
ee992a3
use json.Indent for indent marshalling
jess-lowe Mar 9, 2026
0e463f6
Merge branch 'master' into feat/rewrite-deb-in-go
jess-lowe Mar 17, 2026
6a1c42b
Merge branch 'master' into feat/rewrite-deb-in-go
jess-lowe Mar 19, 2026
870d017
Merge remote-tracking branch 'upstream/master' into feat/rewrite-deb-…
jess-lowe Mar 25, 2026
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
33 changes: 33 additions & 0 deletions go/cmd/first_package_finder/Dockerfile
Comment thread
michaelkedar marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.24.0-alpine@sha256:2d40d4fc278dad38be0777d5e2a88a2c6dee51b0b29c97a764fc6c6a11ca893c AS GO_BUILD

RUN mkdir /src
WORKDIR /src

COPY ./go.mod /src/go.mod
COPY ./go.sum /src/go.sum
RUN go mod download

COPY ./ /src/
RUN go build -o first_package_finder_bin ./tools/debian/first_package_finder/

FROM gcr.io/google.com/cloudsdktool/google-cloud-cli:alpine@sha256:d2f3fd4000e4c9c641ab75898da682b771528f60f08f65e0c3a88fcdff2eaf92

WORKDIR /src
Comment thread
jess-lowe marked this conversation as resolved.
Resolved
COPY --from=GO_BUILD /src/first_package_finder_bin ./first_package_finder_bin
COPY vulnfeeds/tools/debian/run_*.sh ./

RUN chmod +x ./run_*.sh
Comment thread
jess-lowe marked this conversation as resolved.
Resolved
253 changes: 253 additions & 0 deletions go/cmd/first_package_finder/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
// Package main finds the first package versions for Debian releases.
package main

import (
"bufio"
"compress/gzip"
"encoding/csv"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"
)

const (
debianReleaseVersionsURL = "https://salsa.debian.org/debian/distro-info-data/-/raw/main/debian.csv"
debianSnapshotURL = "https://snapshot.debian.org/archive/debian/%s/dists/"
debianSourcesURLExt = "%s/main/source/Sources.gz"
firstReleaseLookahead = 10
packageKey = "Package: "
versionKey = "Version: "
)

var (
ignoredDebianVersions = map[string]bool{
"experimental": true,
"buzz": true,
"rex": true,
"bo": true,
"hamm": true,
"slink": true,
"potato": true,
}
firstSnapshotDate = time.Date(2005, 3, 12, 0, 0, 0, 0, time.UTC)
)
Comment thread
jess-lowe marked this conversation as resolved.
Resolved

func convertDatetimeToStrDatetime(t time.Time) string {
return t.UTC().Format("20060102T150405Z")
}

func getDebianSourcesURL(date time.Time, version string) string {
formattedDate := convertDatetimeToStrDatetime(date)
return fmt.Sprintf(debianSnapshotURL, formattedDate) + fmt.Sprintf(debianSourcesURLExt, version)
}

type DebianVersionInfo struct {
Series string
Version string
Release time.Time
Sources map[string]string
}

func retrieveCodenameToVersion() (map[string]*DebianVersionInfo, error) {
resp, err := http.Get(debianReleaseVersionsURL)
Comment thread
jess-lowe marked this conversation as resolved.
Resolved
if err != nil {
return nil, err
}
defer resp.Body.Close()

reader := csv.NewReader(resp.Body)
reader.FieldsPerRecord = -1
records, err := reader.ReadAll()
if err != nil {
return nil, err
}

if len(records) == 0 {
return nil, errors.New("empty csv")
}

headers := records[0]
seriesIdx, versionIdx, releaseIdx, createdIdx := -1, -1, -1, -1
for i, h := range headers {
switch h {
case "series":
seriesIdx = i
case "version":
versionIdx = i
case "release":
releaseIdx = i
case "created":
createdIdx = i
}
}

if seriesIdx == -1 || versionIdx == -1 || releaseIdx == -1 || createdIdx == -1 {
return nil, errors.New("missing required columns in csv")
}

result := make(map[string]*DebianVersionInfo)
for _, row := range records[1:] {
var series string
if seriesIdx < len(row) {
series = row[seriesIdx]
}
var version string
if versionIdx < len(row) {
version = row[versionIdx]
}
if version == "" {
version = series
}

var releaseStr string
if releaseIdx < len(row) {
releaseStr = row[releaseIdx]
}
if releaseStr == "" && createdIdx < len(row) {
releaseStr = row[createdIdx]
}

releaseDate, err := time.Parse("2006-01-02", releaseStr)
if err != nil {
log.Printf("Warning: failed to parse date %s for series %s", releaseStr, series)
continue
}

result[series] = &DebianVersionInfo{
Series: series,
Version: version,
Release: releaseDate,
}
}

return result, nil
}

func parseCreatedDatesAndSetTime(date time.Time) time.Time {
result := date.Add(24 * time.Hour)
if result.Before(firstSnapshotDate) {
return firstSnapshotDate
}

return result
}

func loadSources(date time.Time, dist string) (map[string]string, error) {
url := getDebianSourcesURL(date, dist)
//nolint:gosec // URL is constructed from trusted source
resp, err := http.Get(url)
Comment thread
jess-lowe marked this conversation as resolved.
Resolved
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP %d", resp.StatusCode)
}

gzReader, err := gzip.NewReader(resp.Body)
if err != nil {
return nil, err
}
defer gzReader.Close()

scanner := bufio.NewScanner(gzReader)
packageVersionDict := make(map[string]string)
var currentPackage string

for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, packageKey) {
currentPackage = line[len(packageKey):]
continue
}
if strings.HasPrefix(line, versionKey) {
packageVersionDict[currentPackage] = line[len(versionKey):]
continue
}
}

return packageVersionDict, scanner.Err()
}

func loadFirstPackages() (map[string]*DebianVersionInfo, error) {
codenameToVersion, err := retrieveCodenameToVersion()
if err != nil {
return nil, err
}

for series, info := range codenameToVersion {
if ignoredDebianVersions[series] {
continue
}

date := parseCreatedDatesAndSetTime(info.Release)
for i := 0; i <= firstReleaseLookahead; i++ {
actualDate := date.Add(time.Duration(i) * 24 * time.Hour)
log.Printf("attempting load of version %s at %s", series, actualDate)

sources, err := loadSources(actualDate, series)
if err == nil {
info.Sources = sources
log.Printf("loaded version %s at %s", series, actualDate)

break
}

if !strings.Contains(err.Error(), "HTTP 404") {
log.Printf("Error loading sources for %s at %s: %v", series, actualDate, err)
}
Comment thread
jess-lowe marked this conversation as resolved.
Resolved

if actualDate.After(time.Now()) {
break
}
}
}

return codenameToVersion, nil
}

func main() {
var outputDir string
flag.StringVar(&outputDir, "o", "first_package_output", "Output folder")
flag.StringVar(&outputDir, "output-dir", "first_package_output", "Output folder")
flag.Parse()

log.SetFlags(log.LstdFlags | log.Lshortfile)

codenameToVersion, err := loadFirstPackages()
if err != nil {
log.Fatalf("Failed to load first packages: %v", err)
}

log.Println("first_package loaded, begin writing out data")

if err := os.MkdirAll(outputDir, 0755); err != nil {
log.Fatalf("Failed to create output directory: %v", err)
}

for _, info := range codenameToVersion {
if info.Sources == nil {
continue
}

outPath := filepath.Join(outputDir, info.Version+".json")
b, err := json.Marshal(info.Sources)
if err != nil {
log.Printf("Failed to marshal sources for %s: %v", info.Version, err)
continue
}

//nolint:gosec // 0644 is fine for public vulnerability data
if err := os.WriteFile(outPath, b, 0644); err != nil {
log.Printf("Failed to write to %s: %v", outPath, err)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ OUTPUT_BUCKET="${OUTPUT_GCS_BUCKET:=debian-osv}"
cd "$(dirname "$0")"

# Use the first_package_finder script to generate a first version cache.
pushd ./debian_converter
echo "Finding first packages"
poetry run python3 first_package_finder.py

FINDER_CMD="go run main.go"
if [ -f "./first_package_finder_bin" ]; then
FINDER_CMD="./first_package_finder_bin"
fi

$FINDER_CMD

echo "Syncing with cloud first_package_output ${OUTPUT_BUCKET}"
gsutil -q -m rsync -c -d 'first_package_output' "gs://${OUTPUT_BUCKET}/first_package_output"
echo "Successfully synced with cloud"

popd
echo "Successfully synced with cloud"
33 changes: 33 additions & 0 deletions vulnfeeds/cmd/converters/dsa-dla-dtsa/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.24.0-alpine@sha256:2d40d4fc278dad38be0777d5e2a88a2c6dee51b0b29c97a764fc6c6a11ca893c AS GO_BUILD

RUN mkdir /src
WORKDIR /src

COPY ./go.mod /src/go.mod
COPY ./go.sum /src/go.sum
RUN go mod download

COPY ./ /src/
RUN go build -o convert_debian_bin ./cmd/converters/dsa-dla-dtsa/

FROM gcr.io/google.com/cloudsdktool/google-cloud-cli:alpine@sha256:d2f3fd4000e4c9c641ab75898da682b771528f60f08f65e0c3a88fcdff2eaf92

WORKDIR /src
COPY --from=GO_BUILD /src/convert_debian_bin ./convert_debian_bin
COPY cmd/converters/dsa-dla-dtsa/run_convert_debian.sh ./

RUN chmod +x ./run_convert_debian.sh
Comment thread
jess-lowe marked this conversation as resolved.
Resolved
38 changes: 38 additions & 0 deletions vulnfeeds/cmd/converters/dsa-dla-dtsa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Debian advisory converter

## Prerequisites

Clone the following two repositories:
- https://salsa.debian.org/security-tracker-team/security-tracker.git
- https://salsa.debian.org/webmaster-team/webwml.git

`git` also has to be installed and on the `PATH`,
used to read modified dates of files.

## Run converter

### Usage:
```
go run main.go -o OUTPUT_DIR -adv-type {DSA,DLA,DTSA} -webwml WEBWML_REPO -security-tracker SECURITY_TRACKER_REPO
```

#### Options:
`-adv-type`: Specify advisory type:

- `DSA`: Debian security advisory
- `DLA`: Debian LTS security advisory
- `DTSA`: Debian testing security advisory

`-o`:
Output directory to place the converted osv `.json` files

`-webwml`:
Path to the cloned webwml repository

`-security-tracker`:
Path to the cloned security-tracker repository

### Example:
```
go run main.go -adv-type DSA -o ./output -webwml path/to/webwml/ -security-tracker path/to/security-tracker/
```
Loading
Loading