Merge ~litios/ubuntu-cve-tracker:aliases-customer-ppa into ubuntu-cve-tracker:master

Proposed by David Fernandez Gonzalez
Status: Merged
Merge reported by: David Fernandez Gonzalez
Merged at revision: b967ba813d484b6c1ab52c4afa0f8113351528b5
Proposed branch: ~litios/ubuntu-cve-tracker:aliases-customer-ppa
Merge into: ubuntu-cve-tracker:master
Diff against target: 116 lines (+64/-1)
4 files modified
scripts/check-syntax (+36/-1)
scripts/check-syntax-fixup (+8/-0)
scripts/cve_lib.py (+6/-0)
scripts/source_map.py (+14/-0)
Reviewer Review Type Date Requested Status
Eduardo Barretto Approve
Review via email: mp+434109@code.launchpad.net

Description of the change

This is the first approach to handle the aliases for projects where the name of the package is specific to it. For example, in project test package foo is actually named test-foo.

I'm relying on the structures that already exist for handling subprojects and adding a new field for taking care of the aliases for the packages.

We discussed naming them boilerplates but I wasn't sure about that because of the already existing boilerplates and because it's a different unrelated thing.

The solution detects if an aliases.yaml exists in the project and performs extra operations according to the aliases specified. Only two extra checks are performed: are all the aliases in the CVE and does the original package name appear (if not specified as an alias)?

The yaml file would be a list of packages and an array of aliases like:

```
foo: ["test-foo", "test2-foo"]
bar: ["test-bar", "test2-bar", "bar"]
```

As I said in the beginning, this is more of a first idea and I would love to get input from people with more experience with UCT.

To post a comment you must log in.
Revision history for this message
Eduardo Barretto (ebarretto) wrote :

in boilerplates we have the "release" as part of the structure. Here we have package to package mapping. Could this create some kind of issue? I can't think of one right now, so just trying to brainstorm.

Revision history for this message
Eduardo Barretto (ebarretto) wrote :

thanks for clarifying that this will be per subproject/release
Let's integrate this, and later we could remove the hardcoded part as we discussed

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/check-syntax b/scripts/check-syntax
2index cacdedf..a9a12a2 100755
3--- a/scripts/check-syntax
4+++ b/scripts/check-syntax
5@@ -421,9 +421,44 @@ for cve in args:
6 # Verify have required releases for each package
7 listed_releases = set(sorted(data["pkgs"][pkg].keys()))
8 all_required_releases = (set(cve_lib.all_releases + ["devel"]) - set([cve_lib.devel_release])) - set(cve_lib.eol_releases)
9- missing_releases = all_required_releases - listed_releases
10 # get the name of a release which is listed in the CVE so we can
11 # place the generated error message on this release's line etc
12+ nearby_rel = list(listed_releases)[0]
13+ aliases_releases = set()
14+
15+ # Check aliases
16+ for rel in all_required_releases:
17+ if rel in source and pkg in source[rel] and \
18+ 'aliases' in source[rel][pkg]:
19+ aliases_releases.add(rel)
20+
21+ # This package-release uses aliases,
22+ # it shouldn't be listed
23+ if rel in listed_releases and pkg \
24+ not in source[rel][pkg]['aliases']:
25+ filename = srcmap["pkgs"][pkg][nearby_rel][0]
26+ linenum = srcmap["pkgs"][pkg][nearby_rel][1]
27+ print(
28+ "%s: %d: package '%s' not in '%s'"
29+ % (filename, linenum, pkg, rel),
30+ file=sys.stderr,
31+ )
32+
33+ failed = 0
34+ for alias in source[rel][pkg]['aliases']:
35+ if alias not in data["pkgs"].keys():
36+ filename = srcmap["pkgs"][pkg][nearby_rel][0]
37+ linenum = srcmap["pkgs"][pkg][nearby_rel][1]
38+ print(
39+ "%s: %d: %s missing release '%s'"
40+ # put the error on a line near where this entry should go
41+ % (filename, linenum, alias, rel),
42+ file=sys.stderr,
43+ )
44+ cve_okay = False
45+ failed += 1
46+
47+ missing_releases = all_required_releases - listed_releases - aliases_releases
48 nearby_rel = list(listed_releases - missing_releases)[0]
49 for rel in missing_releases:
50 # only warn on active CVEs
51diff --git a/scripts/check-syntax-fixup b/scripts/check-syntax-fixup
52index e6b77f9..c7c77c2 100755
53--- a/scripts/check-syntax-fixup
54+++ b/scripts/check-syntax-fixup
55@@ -166,6 +166,14 @@ for line in args.infile:
56 elif "unknown package" in msg or "not in" in msg or "unknown release" in msg:
57 pkg, rel = get_pkg_rel_from_msg(msg)
58
59+ # remove this hard-coded hack one-day...
60+ if rel in cve_lib.external_releases or rel == "trusty/esm":
61+ cve = os.path.join(
62+ cve_lib.get_external_subproject_cve_dir(rel), os.path.basename(cve)
63+ )
64+ # linenum is only relevant to the original cve file
65+ linenum = 1
66+
67 # delete this line since
68 delete_from_file(cve, linenum, args.dry_run, args.verbose)
69
70diff --git a/scripts/cve_lib.py b/scripts/cve_lib.py
71index d8d6bf6..82ff330 100755
72--- a/scripts/cve_lib.py
73+++ b/scripts/cve_lib.py
74@@ -804,6 +804,12 @@ def load_external_subprojects():
75 "eol": False})
76 # an external subproject can append to an internal one
77 subprojects[rel]["packages"].append(supported_txt)
78+
79+ # check if aliases for packages exist
80+ if os.path.isfile(f'{supported_txt[:-len("supported.txt")]}aliases.yaml'):
81+ subprojects[rel].setdefault("aliases",
82+ f'{supported_txt[:-len("supported.txt")]}aliases.yaml')
83+
84 try:
85 # use config to populate other parts of the
86 # subproject settings
87diff --git a/scripts/source_map.py b/scripts/source_map.py
88index 741058b..d4044f3 100755
89--- a/scripts/source_map.py
90+++ b/scripts/source_map.py
91@@ -17,6 +17,7 @@ import re
92 import subprocess
93 import sys
94 import cve_lib
95+import yaml
96
97 apt_pkg.init_system()
98
99@@ -465,6 +466,19 @@ def load_subprojects_lists(releases=None):
100 map[rel][pkg] = dict()
101 map[rel][pkg]['pocket'] = ''
102 map[rel][pkg]['section'] = 'main'
103+
104+ if 'aliases' in details:
105+ with open(details['aliases'], 'r') as file:
106+ aliases = yaml.safe_load(file)
107+
108+ for pkg in aliases:
109+ if map[rel][pkg]:
110+ map[rel][pkg]['aliases'] = aliases[pkg]
111+ else:
112+ print("WARN: pkg %s found in aliases but not in supported. Skipping" % pkg)
113+ else:
114+ pass
115+
116 return map
117
118

Subscribers

People subscribed via source and target branches