Merge ~jugmac00/launchpad-buildd:fetch-service-provision-build-environment into launchpad-buildd:master

Proposed by Jürgen Gmach
Status: Merged
Approved by: Jürgen Gmach
Approved revision: a71e7756c421bcc208eccdcf96b660de8b3fdbf9
Merge reported by: Jürgen Gmach
Merged at revision: a71e7756c421bcc208eccdcf96b660de8b3fdbf9
Proposed branch: ~jugmac00/launchpad-buildd:fetch-service-provision-build-environment
Merge into: launchpad-buildd:master
Diff against target: 116 lines (+82/-1)
2 files modified
lpbuildd/target/build_snap.py (+23/-1)
lpbuildd/target/tests/test_build_snap.py (+59/-0)
Reviewer Review Type Date Requested Status
Ines Almeida Approve
Review via email: mp+462893@code.launchpad.net

Commit message

Install ca certificate for the fetch service

This is necessary so the fetch service can man in the middle all
requests when builds are fetching dependencies.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Looks good!

review: Approve
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thanks for the review and let the nits coming! :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
2index f613e99..f29e3d5 100644
3--- a/lpbuildd/target/build_snap.py
4+++ b/lpbuildd/target/build_snap.py
5@@ -110,10 +110,26 @@ class BuildSnap(
6 )
7 parser.add_argument(
8 "--fetch-service-mitm-certificate",
9- help=("content of the ca certificate"),
10+ type=str,
11+ help="content of the ca certificate",
12 )
13 parser.add_argument("name", help="name of snap to build")
14
15+ def install_mitm_certificate(self):
16+ """Install ca certificate for the fetch service
17+
18+ This is necessary so the fetch service can man-in-the-middle all
19+ requests when fetching dependencies.
20+ """
21+ with self.backend.open(
22+ "/usr/local/share/ca-certificates/local-ca.crt", mode="w"
23+ ) as local_ca_cert:
24+ local_ca_cert.write(self.args.fetch_service_mitm_certificate)
25+ self.backend.run(["update-ca-certificates"])
26+ # XXX jugmac00 2024-04-17: We might need to restart snapd
27+ # so the new certificate will be used
28+ # snapd folks are unsure, so we need to try ourselves
29+
30 def install_svn_servers(self):
31 proxy = urlparse(self.args.proxy_url)
32 svn_servers = dedent(
33@@ -182,7 +198,13 @@ class BuildSnap(
34 ]
35 )
36 if self.args.proxy_url:
37+ # XXX jugmac00 2024-04-17: this is configuring an SVN server;
38+ # it is currently unclear whether this is still necessary for
39+ # building snaps
40+ # jugmac00 reached out both to William and Claudio to figure out
41 self.install_svn_servers()
42+ if self.args.use_fetch_service:
43+ self.install_mitm_certificate()
44
45 def repo(self):
46 """Collect git or bzr branch."""
47diff --git a/lpbuildd/target/tests/test_build_snap.py b/lpbuildd/target/tests/test_build_snap.py
48index 8719e57..4788029 100644
49--- a/lpbuildd/target/tests/test_build_snap.py
50+++ b/lpbuildd/target/tests/test_build_snap.py
51@@ -194,6 +194,65 @@ class TestBuildSnap(TestCase):
52 build_snap.backend.backend_fs["/root/.subversion/servers"],
53 )
54
55+ def test_install_certificate(self):
56+ args = [
57+ "buildsnap",
58+ "--backend=fake",
59+ "--series=xenial",
60+ "--arch=amd64",
61+ "1",
62+ "--git-repository",
63+ "lp:foo",
64+ "--proxy-url",
65+ "http://proxy.example:3128/",
66+ "test-snap",
67+ "--use_fetch_service",
68+ "--fetch-service-mitm-certificate",
69+ "content_of_cert",
70+ ]
71+ build_snap = parse_args(args=args).operation
72+ build_snap.bin = "/builderbin"
73+ self.useFixture(FakeFilesystem()).add("/builderbin")
74+ os.mkdir("/builderbin")
75+ with open("/builderbin/lpbuildd-git-proxy", "w") as proxy_script:
76+ proxy_script.write("proxy script\n")
77+ os.fchmod(proxy_script.fileno(), 0o755)
78+ build_snap.install()
79+ self.assertThat(
80+ build_snap.backend.run.calls,
81+ MatchesListwise(
82+ [
83+ RanAptGet(
84+ "install", "python3", "socat", "git", "snapcraft"
85+ ),
86+ RanCommand(["mkdir", "-p", "/root/.subversion"]),
87+ RanCommand(["update-ca-certificates"]),
88+ ]
89+ ),
90+ )
91+ self.assertEqual(
92+ (b"proxy script\n", stat.S_IFREG | 0o755),
93+ build_snap.backend.backend_fs["/usr/local/bin/lpbuildd-git-proxy"],
94+ )
95+ self.assertEqual(
96+ (
97+ b"[global]\n"
98+ b"http-proxy-host = proxy.example\n"
99+ b"http-proxy-port = 3128\n",
100+ stat.S_IFREG | 0o644,
101+ ),
102+ build_snap.backend.backend_fs["/root/.subversion/servers"],
103+ )
104+ self.assertEqual(
105+ (
106+ b"content_of_cert",
107+ stat.S_IFREG | 0o644,
108+ ),
109+ build_snap.backend.backend_fs[
110+ "/usr/local/share/ca-certificates/local-ca.crt"
111+ ],
112+ )
113+
114 def test_install_channels(self):
115 args = [
116 "buildsnap",

Subscribers

People subscribed via source and target branches