Merge lp:~robru/cupstream2distro/no-source-build-deps into lp:cupstream2distro
| Status: | Merged |
|---|---|
| Approved by: | Robert Bruce Park on 2016-03-23 |
| Approved revision: | 1459 |
| Merged at revision: | 1384 |
| Proposed branch: | lp:~robru/cupstream2distro/no-source-build-deps |
| Merge into: | lp:cupstream2distro |
| Diff against target: |
758 lines (+146/-371) 20 files modified
Makefile (+2/-1) chroot-tools/.pbuilderrc (+0/-41) chroot-tools/buildsource-chroot (+0/-117) chroot-tools/create-chroot (+0/-42) chroot-tools/pbuilder-clean (+0/-8) citrain/jenkins-templates/upgrade-chroot.xml.tmpl (+0/-58) citrain/recipes/base.py (+1/-2) citrain/recipes/merge.py (+1/-0) citrain/recipes/secondary.py (+1/-0) citrain/setup_citrain.py (+0/-1) cupstream2distro/packagemanager.py (+13/-17) cupstream2distro/settings.py (+1/-1) files/sudoers.conf (+0/-3) tests/unit/test_packagemanager.py (+43/-75) tests/unit/test_recipe_base.py (+1/-3) tests/unit/test_recipe_merge.py (+2/-0) tests/unit/test_recipe_secondary.py (+2/-0) tests/unit/test_script_setup_citrain.py (+0/-2) tools/buildpackage.sh (+38/-0) tools/run_hook.sh (+41/-0) |
| To merge this branch: | bzr merge lp:~robru/cupstream2distro/no-source-build-deps |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Martin Pitt | Approve on 2016-03-22 | ||
| Robert Bruce Park (community) | Approve on 2016-03-21 | ||
|
Review via email:
|
|||
Commit Message
Stop installing build deps at source package build time.
- 1385. By Robert Bruce Park on 2016-03-18
-
Drop unused var.
- 1386. By Robert Bruce Park on 2016-03-18
-
Add new tools.
- 1387. By Robert Bruce Park on 2016-03-18
-
Call aa-exec directly.
- 1388. By Robert Bruce Park on 2016-03-18
-
Run package hook for secondary builds too.
- 1389. By Robert Bruce Park on 2016-03-18
-
Fix docstring.
- 1390. By Robert Bruce Park on 2016-03-18
-
Fix tests.
- 1391. By Robert Bruce Park on 2016-03-18
-
100% tests.
- 1392. By Robert Bruce Park on 2016-03-18
-
Fix some docstrings.
- 1393. By Robert Bruce Park on 2016-03-18
-
Exclude debian dir from orig.tar.
- 1394. By Robert Bruce Park on 2016-03-18
-
Fix tools path.
- 1395. By Robert Bruce Park on 2016-03-18
-
Fix permissions.
- 1396. By Robert Bruce Park on 2016-03-18
-
Fix tar.
- 1397. By Robert Bruce Park on 2016-03-18
-
Iterate.
- 1398. By Robert Bruce Park on 2016-03-18
-
Log to stderr.
- 1399. By Robert Bruce Park on 2016-03-18
-
Bah
- 1400. By Robert Bruce Park on 2016-03-18
-
Lowercase non-env var.
- 1401. By Robert Bruce Park on 2016-03-18
-
--human-readable.
- 1402. By Robert Bruce Park on 2016-03-18
-
Try quilt format.
- 1403. By Robert Bruce Park on 2016-03-18
-
Fix upstream tarball name.
- 1404. By Robert Bruce Park on 2016-03-18
-
Include .bzr-builddeb in upstream tarball.
- 1405. By Robert Bruce Park on 2016-03-18
-
orig.tar.gz for now.
- 1406. By Robert Bruce Park on 2016-03-18
-
What happens when debian/source is missing?
- 1407. By Robert Bruce Park on 2016-03-18
-
dpkg-buildpackage -i
- 1408. By Robert Bruce Park on 2016-03-18
-
Ignore bzr-builddeb.
- 1409. By Robert Bruce Park on 2016-03-18
-
Ignore a lot more.
- 1410. By Robert Bruce Park on 2016-03-18
-
Add comments.
- 1411. By Robert Bruce Park on 2016-03-19
-
Add new deps.
- 1412. By Robert Bruce Park on 2016-03-19
-
Full path to aa-exec because $PATH is wrong.
- 1413. By Robert Bruce Park on 2016-03-19
-
Force apparmor_parser.
- 1414. By Robert Bruce Park on 2016-03-19
-
Fix path.
- 1415. By Robert Bruce Park on 2016-03-19
-
Allow find and xgettext.
- 1416. By Robert Bruce Park on 2016-03-19
-
Allow sort and uniq.
- 1417. By Robert Bruce Park on 2016-03-19
-
Allow readlink.
- 1418. By Robert Bruce Park on 2016-03-19
-
Define $SERIES env var.
| Martin Pitt (pitti) wrote : | # |
What's the purpose of these hooks? If they are meant to be able to install additional build dependencies to be able to build a source package, then this won't work. It seems they are meant to be limited to reading/writing files from their own source tree, but most of that could already be done in the bzr branch? Do you have an example what such a hook should do? Why is that coupled to not building the source in pbuilder?
I'm doubtful about the apparmor stuff and I found some smaller issues, see the inline comments.
| Robert Bruce Park (robru) wrote : | # |
On Mon, Mar 21, 2016 at 4:20 AM, Martin Pitt <email address hidden> wrote:
> What's the purpose of these hooks? If they are meant to be able to install additional build dependencies to be able to build a source package, then this won't work. It seems they are meant to be limited to reading/writing files from their own source tree, but most of that could already be done in the bzr branch? Do you have an example what such a hook should do? Why is that coupled to not building the source in pbuilder?
The purpose of these hooks is to allow people to munge debian/control
prior to source-build-time, eg, if you want to build vivid & xenial
builds out of the same source tree, but they build different package
names due to SONAME changes due to gcc abi breakage between vivid &
xenial. Here is one such example:
Another usage is to update translation templates automatically prior
to building:
http://
> You don't use patchutils and diffstat anywhere. But you do need to add dpkg-dev.
Ah, sorry. This work was actually backported from a much larger branch
where I do use patchutils and diffstat, I wasn't paying attention when
I copied over the updated deps.
> It seems to me that creating and maintaining this list is quite some busy-work -- if the package hooks will actually get used for anything, then they will hit a wall fairly quickly. What's the point of restricting package hooks to only run some of these commands, but not others? sed and dash by themselves are powerful enough to emulate pretty much everything else. This hook runs as some "ci train" user, right?
>
> But consider your trust model: If you cannot trust the contents of branches, then with sed, sh, and shipping/
>
> I think it would be both safer (and also avoid maintaining the above list) to create a temporary "silo-XXXXX" unix user, do the "unpack source/run hook" and the dpkg-buildpackage -S as that user, chown the resulting .dsc back to the CI train user and deluser the temporary silo-XXXX one again.
Hmmm, not sure. The silo dirs are short-lived (eg they are empty while
not actively being built, so the idea of a hook script being malicious
and attacking other silo dirs doesn't bother me that much. The main
reason for the apparmor profile is to prevent the script from being
able to read/write sensitive files in ~ and /tmp, eg to avoid leaking
GPG keys and other sensitive state, which the apparmor profile
successfully prevents.
What would a chown solution look like? Note that we explicitly do not
install build deps or run debian/rules from dpkg-buildpackage so
isolating that is not necessary, just the hook script. But we'd need
to chown the source tree to the temp user and then chown it back
after. Doesn't it require root to change the ownership of something
you don't own back to your own user? I guess we could make t...
| Robert Bruce Park (robru) wrote : | # |
On Mon, Mar 21, 2016 at 7:45 AM, Barry Warsaw <email address hidden> wrote:
>> + rm -rf /etc/sudoers.
>
> Maybe prepend the line with - to ignore the error if the file doesn't exist, during the transition?
>
> https:/
'rm -rf does_not_exist' exits with 0 though?
> Is that safer and more robust in the long run than building the source package in a container, e.g. an schroot, lxc or other container? I agree with Martin about the current model, so his suggestion does improve things, and there may be problems with getting the artifacts of the source build out of whatever container you create, but it feels cleaner to use a container than to do the temporary user creation. But anyway if you do that, be sure to handle any errors and clear out any allocated resources (e.g. the temp silo-XXXX user) when things fail.
No, containers/chroots is what we already were doing, and it didn't
make any sense. We spent a lot of time debootstrapping whole systems
and keeping them updated and installing build dependencies that were
entirely unused. The apparmor profile is actually significantly more
secure than the chroot it's replacing because if you look at the
chroot it just bindmounts ~ which means any malicious `debian/rules
clean` could actually leak our GPG keys, but the apparmor profile does
not allow access to ~.
> The other thing to consider is local reproducibility. With all automated systems (e.g. autopkgtest, source->binary builds), things *will* fail and they will fail in mysterious ways. IMHO it's always better to have a system where the environment is both well-documented and locally reproducible so developers can try to debug the problems on their own. Otherwise, mysterious failures will fall on you to debug and that doesn't scale.
I believe this approach is more reproducible because it is simpler and
more direct than the previous approach. Somebody trying to reproduce
the old way would need a chroot, but reproducing the new way just
requires dpkg-buildpackage. And the code is open of course so they can
view it and run what it does with significantly less setup.
But dpkg-buildpackage isn't really something that can fail because it
doesn't invoke any custom code in debian/rules (at least not the way
I'm invoking it). So making the source package is essentially just the
tar, then dpkg-genchanges, then signing it, then uploading. The only
real failure modes that people are going to encounter are a) merge
conflicts prior to the source build happening, and b) binary package
build failures in the PPA.
>
> I understand that a container-based approach may be slower, but I still would trade speed for robustness and reproducibility.
Everybody has been clamoring for speed improvements in the train as in
some cases it takes nearly 2 hours to build source packages, which is
really pathetic when you consider that a source package isn't much
more than a tarball. I took an example silo from production and build
it with this branch and the *source* package build time (not counting
binary builds in PPA) decreased from 100 minutes to 35 mi...
- 1419. By Robert Bruce Park on 2016-03-21
-
Fix deps as per pitti.
| Martin Pitt (pitti) wrote : | # |
Robert Bruce Park [2016-03-21 19:03 -0000]:
> The purpose of these hooks is to allow people to munge debian/control
> prior to source-build-time, eg, if you want to build vivid & xenial
> builds out of the same source tree, but they build different package
> names due to SONAME changes due to gcc abi breakage between vivid &
> xenial. Here is one such example:
>
> http://
Ah, thanks. This particular case could also be done with substvars.
> Another usage is to update translation templates automatically prior
> to building:
>
> http://
That's a better use case. Normally these should be done during binary
package build (as that's also the time when Launchpad will import
them), but for upstream translations it's important to have them up to
date in the source tree indeed. But this is also a rather complex use
case which is prone to use /tmp, as well as tools like intltool-update
(which isn't in your whitelist)?
> Hmmm, not sure. The silo dirs are short-lived (eg they are empty while
> not actively being built, so the idea of a hook script being malicious
> and attacking other silo dirs doesn't bother me that much. The main
> reason for the apparmor profile is to prevent the script from being
> able to read/write sensitive files in ~ and /tmp, eg to avoid leaking
> GPG keys and other sensitive state, which the apparmor profile
> successfully prevents.
Running it as a different user will also do all that, but in a much
more robust manner (IMHO).
> What would a chown solution look like?
A sketch:
U=citrain-
sudo adduser $U
cat <<EOF | su - $U
bzr branch proj...
cd proj*
dpkg-buildpackage -S -us -uc ...
EOF
cp ~$U/proj_* some/ci-
sudo deluser --remove-home $U
debsign -k... some/ci-
> But we'd need to chown the source tree to the temp user and then
> chown it back after.
Not really, you just need to chown (or copy) the generated .dsc/tar.
> Doesn't it require root to change the ownership of something you
> don't own back to your own user?
Yes, it does. More importantly, you require root to create/remove/run
something as temporary user.
> I guess we could make the directory group-writable and also create a
> temporary group for the temporary user. The idea of allowing jenkins
> user to 'sudo chown' without restrictions sounds somewhat
> terrifying.
You could restrict the sudo capabilities to alling adduser and deluser
if you want (even with adding the "citrain-" user name prefix).
> Nah, at any given time, there will only be one or two silo dirs
> present, so a malicious script trying to trample on other people's
> silos would be limited by timing.
Well, bugs happen, not necessarily out of malice. Gems like
"rm -rf $TMPDIR/" have destroyed the world more than once already :-)
> Thanks for the tip about --with-colons, but the purpose of this code
> is to sort lexically and then choose the newest key
That should still be easier and more reliable using --with-colons;
that is meant to be a machin...
- 1420. By Robert Bruce Park on 2016-03-21
-
gpg --with-colons thanks to pitti.
- 1421. By Robert Bruce Park on 2016-03-21
-
Creation date, not expiry date.
- 1422. By Robert Bruce Park on 2016-03-21
-
Run hooks as temp user.
- 1423. By Robert Bruce Park on 2016-03-21
-
Resurrect sudoers.
- 1424. By Robert Bruce Park on 2016-03-21
-
Drop apparmor dep.
- 1425. By Robert Bruce Park on 2016-03-21
-
Fix perms.
- 1426. By Robert Bruce Park on 2016-03-21
-
Absolute paths in sudoers.
- 1427. By Robert Bruce Park on 2016-03-21
-
Run run_hook.sh as root.
- 1428. By Robert Bruce Park on 2016-03-21
-
Change ownership back.
- 1429. By Robert Bruce Park on 2016-03-21
-
Use absolute paths.
- 1430. By Robert Bruce Park on 2016-03-21
-
Stop hard-coding jenkins username.
- 1431. By Robert Bruce Park on 2016-03-21
-
Abort earlier.
- 1432. By Robert Bruce Park on 2016-03-21
-
Fix traps.
- 1433. By Robert Bruce Park on 2016-03-21
-
Drop unused job.
| Robert Bruce Park (robru) wrote : | # |
Hi Martin, Barry, please re-review. I've switched to a temporary-user based security approach, which you can see working here:
https:/
+ hook=./
+ [ -s ./debian/
+ trap userdel --force "$tmpuser"; rm --force "$tmpfile" EXIT
+ pwd
+ source_
+ stat -c %U /var/lib/
+ orig_owner=jenkins
+ mktemp --tmpdir citrain-
+ tmpfile=
+ basename /tmp/citrain-
+ tmpuser=
+ useradd citrain-
+ chown --recursive citrain-
+ su --preserve-
+ chown --recursive jenkins /var/lib/
+ userdel --force citrain-
+ rm --force /tmp/citrain-
- 1434. By Robert Bruce Park on 2016-03-22
-
Fix permissions on lp creds.
- 1435. By Robert Bruce Park on 2016-03-22
-
Fix permissions on openstack creds.
- 1436. By Robert Bruce Park on 2016-03-22
-
Moar permissions.
- 1437. By Robert Bruce Park on 2016-03-22
-
EVEN MOAR permissions.
| Robert Bruce Park (robru) wrote : | # |
Here's an example malicious script:
And here's the output:
https:/
It gets a directory listing for ~, which the apparmor profile wouldn't have allowed, but all the creds are only readable by owner so none of the attempts at leaking creds are successful.
let me know if there's other nefarious things to try in a malicious script. I want to make sure this is really secure.
Thanks!
- 1438. By Robert Bruce Park on 2016-03-22
-
Fix docstring.
- 1439. By Robert Bruce Park on 2016-03-22
-
More comments.
- 1440. By Robert Bruce Park on 2016-03-22
-
Tweak environment.
- 1441. By Robert Bruce Park on 2016-03-22
-
Tweak environment again.
- 1442. By Robert Bruce Park on 2016-03-22
-
Apparently unnecessary.
- 1443. By Robert Bruce Park on 2016-03-22
-
Fix comment.
- 1444. By Robert Bruce Park on 2016-03-22
-
Fix tests.
| Martin Pitt (pitti) wrote : | # |
Chowning the entire source tree twice is a bit more work than I had in mind, but it doesn't take that much time. This should work fine now. I just found one nitpick in the shell trap, otherwise LGTM, thanks!
- 1445. By Robert Bruce Park on 2016-03-22
-
Trap more signals.
- 1446. By Robert Bruce Park on 2016-03-22
-
Decrease log noise.
- 1447. By Robert Bruce Park on 2016-03-22
-
Simplify
| Robert Bruce Park (robru) wrote : | # |
On Tue, Mar 22, 2016 at 1:13 AM, Martin Pitt <email address hidden> wrote:
> Review: Approve
>
> Chowning the entire source tree twice is a bit more work than I had in mind, but it doesn't take that much time.
Due to the architecture of the train it's easier to just chown it and
chown it back within one little hook script rather than trying to keep
it as a unique owner all the time as we do a lot of transformations on
the source tree (lots of merges, variable substitutions in debian/
files, commits, etc). Would have taken lots of big changes to make it
always sudo to the owner of the files every time we want to touch it.
>> +trap 'userdel --force "$tmpuser"; rm --force "$tmpfile"' EXIT
>
> Please add INT QUIT PIPE too, as these are also common modes how a shell script can abort.
I played with this a little bit and found that when I trap INT QUIT
and PIPE, the trap runs twice when those signals are sent, but the
trap isn't run on just EXIT (I read some documentation that claimed
that EXIT fires on any exit, whether there was a signal or not, but
that doesn't seem to be the case according to my experiments). Still,
deleting the user twice is better than not at all.
Of course trapping INT QUIT and PIPE stops the script from actually
exiting when those are trapped so I had to add an exit statement, fun
times.
--
robru
- 1448. By Robert Bruce Park on 2016-03-22
-
Ensure we always chown source tree back to $orig_owner.
- 1449. By Robert Bruce Park on 2016-03-22
-
Add a warning for packages that may require transitioning.
- 1450. By Robert Bruce Park on 2016-03-22
-
Duh
- 1451. By Robert Bruce Park on 2016-03-22
-
debug
- 1452. By Robert Bruce Park on 2016-03-22
-
debug ls
- 1453. By Robert Bruce Park on 2016-03-22
-
Why isn't this working?
- 1454. By Robert Bruce Park on 2016-03-22
-
Sigh
- 1455. By Robert Bruce Park on 2016-03-22
-
Simplify.
- 1456. By Robert Bruce Park on 2016-03-22
-
All output to STDERR for logging.
- 1457. By Robert Bruce Park on 2016-03-23
-
Fix GLES builds.
- 1458. By Robert Bruce Park on 2016-03-23
-
Clean up logging a bit.
- 1459. By Robert Bruce Park on 2016-03-23
-
Stop deleting debian/watch

Here's some successful runs in staging if you want to see this in action:
https:/ /ci-train. staging. ubuntu. com/job/ ubuntu- landing- 008-1-build/ 12/console
https:/ /ci-train. staging. ubuntu. com/job/ ubuntu- landing- 009-1-build/ 15/console