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

Android 11 and Debian 10 base image #31

Merged

Conversation

ypid
Copy link
Collaborator

@ypid ypid commented Nov 22, 2020

I decided to push my draft WIP state now because I just found https://github.com/mobilesec/reproducible-builds-aosp which has many similarities with this project and I would like sync up with @mpoel.

Closes: #31

Hi @mpoel

It seems you have started a project on 2019-10-16 that is similar to this one. It might make sense to join forces? I would also be interested if you considered any of the known projects (refs: 1, 2) in the AOSP-based hardening community? I checked your code right now. You have slightly different goals than this project does, but still pretty similar direction. I am also very interested in reproducible builds. What your project does not do is locking all it’s build inputs. I will probably read over your Bachelor’s thesis the next days. Until then, I just want to ping you as you also worked on your project today, same as me.

This PR is a draft, but it can give you an idea of the current state of the project. Note that I have not tested building AOSP with this PR. I just built GrapheneOS with it for now.

@ypid ypid marked this pull request as draft November 22, 2020 22:50
@ypid ypid changed the title WIP: Feature/android 11 and debian 10 base image WIP: Android 11 and Debian 10 base image Nov 22, 2020
@mpoel
Copy link
Contributor

mpoel commented Nov 23, 2020

Hello,

Thanks for pinging me and the the interest in https://github.com/mobilesec/reproducible-builds-aosp . It's a project from the Institute of Networks and Security at the Johannes Kepler University Linz, with me being the main developer currently. There are indeed quite a few similarities between our project and this one. I did stumble upon this repository when researching the requirements for our project, but in the end settled to implement simple shell scripts based on the instruction from https://source.android.com myself. The primary goal of our project is to perform the official build instructions, only deviating when there's no other way (e.g. additional APT dependencies that are not properly documented), and analyzing the output w.r.t. to reference builds. Inspecting the scripts of this repository leads me to believe that there are certain changes that deviate from the reference instructions (e.g. apply_patches in scripts/build). Undoubtedly there are good valid reasons for your project to do this, but that is one of the reasons why I've settled on creating a new project with our very specific goals in mind. I'm not sure yet about specific collaboration efforts, in part since I would probably need to coordinate this with others folks at the INS department at the university. However, if you have any questions about our project, please don't be shy with asking :)

With regards to the other projects you mentioned (GrapheneOS, LineageOS, and similar): A similar argument to the one from above applies to these. Many of them are focused on augmenting the standard AOSP builds with additional features or security measures, which is interesting in its own right, not quite what we need. If you know of any other project that aims to build AOSP in a completely unchanged way, please let me know (minus robotnix, whose author @danielfullmer we are already in touch with).

However, you are fully correct that the lack of a locking mechanism of the input dependencies (i.e. apt and pip packages) is a weakness of our project as of now and something worth looking into for the future.

@ypid
Copy link
Collaborator Author

ypid commented Nov 23, 2020

Thanks for your answer.

(e.g. apply_patches in scripts/build).

This is configurable from the config file ;-)

So to clarify, this project https://github.com/hashbang/aosp-build is then exactly what you are looking for. A build system for unmodified or with only necessary changes to build it AOSP. The stuff I was talking about is just my use case that is developed in another repo (https://github.com/hashbang/os) which just uses the Docker image and bundled default scripts aosp-build provides.

I don’t know other projects except the once we already mentioned. Except https://ci.android.com which would be interesting to look at. But even if we had access to the scripts, I guess their use case and threat model is different.

Lets do it like this, I can ping you when the Android 11 and Debian 10 work has been merged into master, and I have possibly tested building an unmodified AOSP with it, then you can take a look and discuss this in your department.

It could be discussed if this exception might not be useful for linting
purposes of the config.yml, but for development it is not useful to have
the script fail just because remove_groups and remove_paths both match.
This is expected to improve security because the AOSP build system uses
nsjail so this sandbox can be way more confined than what we can create
with Docker here.
Further work on build isolation improvements should be done with nsjail
so that it can benefit all AOSP users.
If you want the steps to run together, you can still call make with both
targets. I just found that during development, I always want to run
those steps separately and then inspect the `config.yml` before running
the next step. Also, manifest takes much longer so it makes even more
sense to review in between. config is pretty fast.
Unable to find latest build tag for factory build RP1A.201005.004 for device taimen
Unable to find latest build tag for factory build RP1A.201005.004 for device walleye
Needed for using a different manifest source for example GrapheneOS.
A git repo per device is needed for the repo command. Before, it was
confusing because there were to git repos created, on top repo
`config/manifests` and then additionally one per device by the fetch
script.
Before if an error happened you could not tell in which repo the issue occurred.
Now `-p` helps with this.

```
  -e, --abort-on-errors
                        Abort if a command exits unsuccessfully
    -p                  Show project headers before output
    -v, --verbose       Show command error messages
```
It seems the repo command runs this single only one job by default. So
depending on your built system, using --jobs gives you a real
performance gain. I have tested this an can confirm it.
@ypid
Copy link
Collaborator Author

ypid commented Feb 9, 2021

Lets do it like this, I can ping you when the Android 11 and Debian 10 work has been merged into master, and I have possibly tested building an unmodified AOSP with it, then you can take a look and discuss this in your department.

@mpoel
I did not do exactly that, but something else. I implemented signature verification of build inputs #32 and redefined the way other projects can make use of aosp-build (hashbang/os#49). I did not test building AOSP but there should only be very minimal changes needed, if any. I could kick of a build if it helps. I looked into your bachelor thesis, nice work! Some day I might come back to that in case I decide to work on the HashbangMobile project goal of multisig requirement for the updater. Until then, let me know if I can help. You could consider aosp-build now for your own use.

@mpoel
Copy link
Contributor

mpoel commented Feb 14, 2021

Thanks for keeping me updated. I tested your work on this PR (as of commit a550c23) in a clean installation of an Ubuntu 20.04 VM, attempting build a standard AOSP build for the crosshatch device. As instructed in the README I simply executed make DEVICE=crosshatch to perform a build with the local backend. Here are my findings:

  1. Initially the build process failed due to the missing Python Jinja library (on the host system, not in the docker container). Obviously trivial to fix via apt-get install python-jinja2, I'd recommend documenting this requirement
  2. I opted to add my user to the docker group and thus execute docker commands without sudo. With a clean clone of the aosp-build repo this results in the creation of some directories with root ownership (needed for the volumes, I assume the docker deamon creates these). Since the docker run command uses id 1000, this subsequently gave me permission denied errors inside docker. My temporary workaround is to create these folder ahead of the Makefile invocation with my local user myself. Specifically these folders are build, release and keys. Not sure how to propely handle this.
  3. Some of the pinned version in the packages-pinned.list are already outdated. My most recent docker build command was executed roughly 48 hours ago and I had to update several package versions (see attached patch for details). I fully agree that pinned dependencies are necessary for reproducible builds, that's just an unfortunate side effects of the fast moving package ecosystem.
  4. Building the kernel initially aborted with the error /home/build/build/external/kernel/crosshatch/private/msm-google/scripts/sign-file.c:25:10: fatal error: 'openssl/opensslv.h' file not found. Fixed by adding libssl-dev to the package.list
  5. Finally there seems to be some inconsistency with the targeted android version and build ids scattered across the files. Notabley for crosshatch I've encountered: a) In the config/config.yml the platform_ref has the value android-11.0.0_r29, but b) the config/manifests/crosshatch/base.xml file points to the android-10.0.0_r22 release (including your fork for android-prepare-vendor, which does not support API-30 for Android 11 yet). This resulted in an error as well, for now I've opted to adjust the values in the config/config.yml to the older àndroid-10.0.0_r22 release.

Attached you find a full patch that encompasses the points mentioned above and enabled me run a full build. I hope this helps and is interesting to you. Obviously, feel free to ask for more details. I like your project and it's great to offer multiple backends (SOAP effectively has 3 as well, native, docker and Jenkins), but I don't want to promise you too much. We've already got our infrastructure set up and running well with our Jenkins integration for some basic monitoring. You probably know the saying with the running systems and such. But it would definitely be interesting to perform builds with aosp-build in addition to our SOAP builds and generate SOAP difference reports for them.

Patch:
patch.zip

thestinger and others added 4 commits February 14, 2021 20:20
Commit in updater after which the new metadata format is required:

commit b51bf7a3c16b34539cce8b2792fbc8b89c05a89d
Author: Daniel Micay <[email protected]>
Date:   2020-06-02 13:47:14 -0400

    sanity check channel name
@ypid
Copy link
Collaborator Author

ypid commented Feb 14, 2021

That is very valuable feedback. Thank you! It also means that I did not break Android 10 support which is good to know :)

the config/manifests/crosshatch/base.xml file points to the android-10.0.0_r22

I did not bother to update manifests for devices other than sargo to be honest. Did that now.

Some of the pinned version in the packages-pinned.list are already outdated.

I have been thinking about this as well. I will need to switch to https://snapshot.debian.org/.

You probably know the saying with the running systems and such.

Got it :)

I will go over your other points in a few weeks.

@ypid
Copy link
Collaborator Author

ypid commented Mar 8, 2021

I have been thinking about this as well. I will need to switch to https://snapshot.debian.org/.

Done that.

@ypid ypid changed the title WIP: Android 11 and Debian 10 base image Android 11 and Debian 10 base image Aug 7, 2021
@ypid ypid marked this pull request as ready for review August 7, 2021 09:28
@ypid
Copy link
Collaborator Author

ypid commented Aug 7, 2021

I should probably merge that. Otherwise people would need to submit patches/base their work on my branch/this PR.

@ypid ypid merged commit 49511ef into hashbang:master Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants