dan-v / rattlesnakeos-stack

Build your own privacy and security focused Android OS in the cloud.
MIT License
568 stars 87 forks source link
android aosp aws aws-lambda chromium custom ec2 f-droid golang ota-update privacy security signing-keys spot-instances terraform verified-boot

NOTICE: This project is no longer being maintained

Overview

Build your own customized Android OS for Google Pixel phones using AWS cloud infrastructure. The default OS that this tools builds without any customizations is called RattlesnakeOS. If there is something you don't like about the default OS, you can add customizations on top of it or start with a completely blank slate and build your own OS.

Features

Overview

The default OS built by this tool, RattlesnakeOS, is just stock AOSP and has all the baseline privacy and security features from there. Unlike other alternative Android OSes, it aims to keep security on par with stock Android by keeping critical security features like verified boot enabled and ensuring monthly OTA security updates not only update the OS but also the device specific drivers and firmware.

Rather than providing random binaries of an Android OS to install on your phone, I've gone the route of creating a cross platform tool, rattlesnakeos-stack, that provisions a "stack", which is just all the AWS cloud infrastructure needed to continuously build your own personal Android OS, with your own signing keys, and your own OTA updates. It uses AWS Lambda to provision EC2 spot instances that build the OS and upload artifacts to S3. Resulting OS builds are configured to receive over the air updates from this environment. It only costs a few dollars a month to run (see FAQ for detailed cost breakdown).

Table of Contents

Prerequisites

Installation

The rattlesnakeos-stack tool needs to be installed on your local computer. The easiest way is to download a pre-built binary from the Github Releases page. The other option is to build from source.

Configuration

The rattlesnakeos-stack config subcommand should be run first to initialize a config file which will be stored in $HOME/.rattlesnakeos.toml. By default, an autogenerated stack name will be generated for <rattlesnakeos-stackname>; if you want to customize this name beware that the name must be globally unique in AWS or deployment will fail.

./rattlesnakeos-stack config

Device is the device codename (e.g. sunfish).
device: sunfish

Stack name is used as an identifier for all the AWS components that get deployed. THIS NAME MUST BE UNIQUE OR DEPLOYMENT WILL FAIL.
Stack name: <rattlesnakeos-stackname>

Stack region is the AWS region where you would like to deploy your stack. Valid options: us-west-2, us-east-1, us-east-2, us-west-1, eu-west-1, eu-west-2, eu-west-3, ap-northeast-3, ap-northeast-2, ap-northeast-1, sa-east-1, ap-southeast-1, ca-central-1, ap-southeast-2, ap-south-1, eu-central-1, cn-north-1, cn-northwest-1
Stack region: us-west-2

Email address you would like to send build notifications to.
Email: user@domain.com

SSH keypair name is the name of your EC2 keypair that imported into AWS.
SSH Keypair Name: rattlesnakeos

INFO[0005] rattlesnakeos-stack config file has been written to /Users/username/.rattlesnakeos.toml

Deployment

The rattlesnakeos-stack deploy subcommand handles deploying (and updating) your stack. After stack deployment, you will need to manually start a build. By default, it is configured to automatically build once a month on the 10th of the month so that monthly security updates can be picked up and built without the need for manual builds. Anytime you make a config change, you will first need to deploy those changes using this command before starting a new build.

Default Examples

Deploy stack using default generated config file:

./rattlesnakeos-stack deploy

INFO[0000] Using config file: /Users/user/.rattlesnakeos.toml
INFO[0000] Current settings:
chromium-version: ""
device: taimen
email: user@domain.com
hosts-file: ""
instance-regions: us-west-2,us-west-1,us-east-2
instance-type: c5.4xlarge
max-price: "1.00"
name: <rattlesnakeos-stackname>
region: us-west-2
schedule: rate(14 days)
skip-price: "0.68"
ssh-key: rattlesnakeos

Do you want to continue? [y/N]

You can override values in the config file with CLI flags:

./rattlesnakeos-stack deploy --region "us-west-2"
...

You can also persist values you override to the config file if desired:

./rattlesnakeos-stack deploy --region "us-west-2" --save-config
...

Or you can specify a different config file to use

./rattlesnakeos-stack deploy --config-file foo.toml
...

To see full list of options you can run rattlesnakeos-stack deploy -h. These flags can also be set as config values in the config file.

Advanced Examples

Here is an example of a more advanced config file that: disables chromium build (warning: if you do this - you should provide your own up to date webview), disables scheduled monthly builds, specifies a custom configuration repo (more on that in customization section), and uses a much larger c5.24xlarge instance type.

chromium-build-disabled = true
chromium-version = ""
cloud = "aws"
core-config-repo = "https://github.com/rattlesnakeos/core"
custom-config-repo = "https://github.com/myrepo/custom"
device = "sunfish"
email = "dan@vittegleo.com"
instance-regions = "us-west-2,us-west-1,us-east-2"
instance-type = "c5.24xlarge"
latest-url = "https://raw.githubusercontent.com/RattlesnakeOS/latest/11.0/latest.json"
max-price = "5.00"
name = "sunfish-cyoydyw3j2"
region = "us-east-2"
schedule = ""
skip-price = "5.00"
ssh-key = "rattlesnakeos"

First Time Setup After Deployment

Customizations

It is possible to customize OS builds to your liking by specifying a custom config repo with the config option custom-config-repo = "https://github.com/yourrepo/name". This git repo needs to adhere to a specific format that will be covered below.

IMPORTANT: using any Git repo here that is not in your control is a security risk, as you are giving control of your build process to the owner of the repo. They could steal your signing keys, inject malicious code, etc.

Custom Config Repo format

The custom config git repo needs to be laid out in a specific format to work with the build process. An example repo can be found here: https://github.com/RattlesnakeOS/example-custom-config-repo. The directory structure looks like this:

hooks/
local_manifests/
vendor/

FAQ

General

Should I use rattlesnakeos-stack?

Use this at your own risk.

Where can I get help, ask questions, keep up to date on development?

Costs

How much does this cost to run?

The costs are going to be variable by AWS region and by day and time you are running your builds, as spot instances have a variable price depending on market demand. Below is an example scenario that should give you a rough estimate of costs:

Builds

How do I change build frequency?

By default, it is configured to automatically build once a month on the 10th of the month so that monthly updates can be picked up and built without the need for manual builds. There is a config option to specify how frequently builds are kicked off automatically. For example you could set schedule = "rate(14 days)" in the config file to build every 14 days. Also note, the default behavior is to only run a build if there have been version updates in stack, AOSP, or Chromium versions.

How do I manually start a build?

You can manually kick off a build with the CLI. Note that this shouldn't normally be necessary as builds are set to happen automatically on a cron schedule.

./rattlesnakeos-stack build start

Where do I find logs for a build?

On build failure/success, the instance should terminate and upload its logs to S3 bucket called <rattlesnakeos-stackname>-logs and it's in a file called <device>/<timestamp>.

How can I see live build status?

There are a few steps required to be able to do this:

Security

How secure is this?

Your ability to secure your signing keys determines how secure RattlesnakeOS is. RattlesnakeOS generates and stores signing keys in AWS, which means the security of your AWS account becomes critical to ensuring the security of your device. If you aren't able to properly secure your local workstation, and your AWS account, then these additional security protections like verified boot become less useful.

Cloud based builds are never going to be as secure as a locally built AOSP signed with highly secured keys generated from an HSM or air gapped computer, so if this is the level of security you require then there really is no other way. Would I recommend cloud builds like this for a large OEM or a company like CopperheadOS where the signing key being generated is protecting thousands of users? No, this becomes a high profile target as getting a hold of these keys essentially gives an attacker access to thousands of devices. On the other hand, for a single user generating their own key protecting a single device, there is less concern in my mind unless your threat profile includes very targeted attacks.

What are some security best practices for AWS accounts?

Some minimum steps worth considering are having an account solely for building RattlesnakeOS with a strong password, enabling two-factor authentication, enabling auditing with CloudTrail, and locking down access to your AWS API credentials.

Uninstalling

Remove AWS resources

If you decide this isn't for you and you want to remove all the provisioned AWS resources, there's a command for that.

./rattlesnakeos-stack remove --name <rattlesnakeos-stackname> --region us-west-2

IMPORTANT NOTE: this will not terminate any running EC2 instances that may have launched, and these will need to be terminated manually.

Revert back to stock Android

You'll need to clear the configured AVB public key after unlocking the bootloader and before locking it again with the stock factory images.

fastboot erase avb_custom_key

Donations

Powered by

Build from Source