Three main components, or projects:
In addition there is a module called secrets_handler which is used for en-/decryption and up-/downloading of secrets.
Note:
- This README, and all READMEs for all components, assume that the state of this project is production.
- When using Python scripts for the different components (
api.py,app.pyorcloud.py) for development, end all commands with the--devflag.
Example:python cloud.py start-api --dev
The setup for each component is described in separate READMEs, found under the components' root. Nevertheless, there are a few steps which are considered "general", so we will go through them here.
Download and install Docker Community Edition. The API is deployed as a .jar file running inside a Docker container, and both the api and cloud components needs a running Docker daemon to create and push container images.
One of the reccommended ways to gain access to the GC project and automated tools like gcloud is by using what's called a service account. This is a non-personal account where access and permissions can be set just as with any normal user account.
It is recommended to use a service account to authenticate CLI tools, even for local development.
This project depends on two service accounts: one with Owner permissions to use during development, and one with restricted permissions for automated use.
The (restricted) service account needs a certain set of permissions to work properly:
-
Project permission
- cloudkms.keyRings.list
-
Bucket permissions
(The artifact bucket / registry where Docker images are pushed to.)- Manually set the service account as Storage Admin for the bucket.
-
Crypto Key permissions
- cloudkms.cryptoKeyVersions.get
- cloudkms.cryptoKeyVersions.list
- cloudkms.cryptoKeyVersions.useToDecrypt
- cloudkms.cryptoKeys.get
- cloudkms.cryptoKeys.list
- cloudkms.keyRings.get
- cloudkms.keyRings.list
- resourcemanager.projects.get
Note:
Individual permissions can't be set in GCloud, but must be set indirectly via a role. It is recommended to create a new role to list key rings, and another for the usage of crypto keys.
This link provides some help with setting and removing roles via the CLI.
- Log in to Google Cloud Platform.
- Via the top-left triple-dash menu, open IAM & admin > Service accounts.
- Click Create Service Account in the top bar.
- Create a name and an ID for the account.
Note: The ID is what will be used for identifying the account, while "Name" is just a convenience tag. - Set a role for the account. This role will have "Project" as scope.
Use "Owner" for the development account.
Use the custom role with the cloudkms.keyRings.list permission for the automated account.
- Create a name and an ID for the account.
- Set permissions for the automated service account according to the steps above.
- Log in to Google Cloud Platform.
- Via the top-left triple-dash menu, open IAM & admin > Service accounts.
- Find the service account with "Owner" permissions, click on the triple-dot menu on its far right, and click on Create key.
- Select JSON and click Create.
- Download the JSON file to a desired location on your local hard drive.
- Create a permanent environment variable called
GOOGLE_APPLICATION_CREDENTIALSand set its value to be the full path of your JSON service account key. - Now create and download a key for the automated service account, and save the file as
hlf/secrets/credentials.json.
Python is used for a good many scripts and commands in this project, and is required for everything to work properly.
- Download and install Python. The scripts were written and tested with Python 3.6.6, so that's the recommended version.
- Upgrade pip to the latest version:
python -m pip install --upgrade pip - Make sure your current directory is
hlf, and create a new virtual environment for Python:
python -m venv venv
(the firstvenvis the command, and the second is the folder (environment) name).venvis the recommended tool for creating virtual environments after Python 3.5.virtualenvis deprecated after Python 3.6.- For more information about
venv, and how to (de)activate the environment for your system, visit the python venv user guide
- Activate your new environment
- Install the required packages:
pip install -r requirements.txt- If, for some reason, pip isn't installing the packages in the correct location:
- Check (and triple-check) that your environment is activated
- Install the requirements with the prefix
python -m:
python -m pip install -r requirements.txt
- If, for some reason, pip isn't installing the packages in the correct location:
Secrets are encrypted and stored in a bucket on Google Cloud Platform. The uploading and downloading of secrets are done in a similar matter: by using either the upload_secret.py or download_secret.py script found in the secrets_handler folder. (Usage is documented in the Secrets README.)
The most important file to download is the one called secrets.json.
The pipeline is as follows:
- Follow the steps in api to
- Build the server application as a
.jar - Build a Docker image
- Build the server application as a
- Follow the steps in cloud to
- Push the Docker image
- Build a server image
- Setup the infrastructure with Terraform, and start a server instance
- Start the server application
- Follow the steps in app to build the mobile application to Android and/or iOS