If you have a project with one or more submodules or other private repository dependencies (for example, CocoaPods repositories), you have to grant access to all repositories for a successful build.
There are two ways to achieve this:
- Register the same SSH key for every repository you have to access during the build, as “Deployment keys”. This is the best, most secure way but not supported by all git hosting services (GitHub, for example, doesn’t support it).
- Register an SSH key for a user account. Simply add a “bot” / “machine” user with the SSH key to the repositories. Add the SSH key you would like to use to the user and add the user to the projects. It is enough to assign read permissions to the bot user. After that, you can use the SSH key to clone to the repository or any submodule.
GitHub itself recommends this method for accessing multiple repositories.
On GitLab and Bitbucket it’s possible to register a single SSH key as a “Deployment key” to multiple repositories, without the need to create a “bot” / “machine” user.
Using a machine user to access private repositories ⚓
A machine or bot user is a GitHub user that is not used by humans, instead it is exclusively used for automation. This is the best way to access a private repository: you create a machine user, add a public SSH key to the user, and then provide the user read access to the repository.
Adding the machine user to your repository ⚓
- Create a new GitHub user account, one that will serve as the machine user.
- Go to your repository on GitHub and select the Settings tab.
On the left side menu, select Collaborators & teams.
- Scroll down to the Collaborators window.
- In the search input field, search for the username of your newly created account.
- Click Add Collaborator.
Change the user permission to Read.
By default, the invited collaborator’s permission is Write. You can keep it that way, of course, but a Read permission is enough for Bitrise.
Adding the SSH key to the machine user ⚓
In order for Bitrise to be able to use the machine user to access your repository, you must add the same SSH key to the machine user and the app on Bitrise.
When adding a new app:
- Start the process of adding your app on Bitrise.
When prompted to setup repository access, you can choose either Automatic or Add own SSH:
- If you choose Add own SSH, you can generate your own SSH keypair. Provide the generated SSH key for the app and add the public key to your GitHub machine user.
- If you choose Automatic, click I need to when asked if you need to use an additional private repository. Copy the SSH public key to your GitHub machine user.
- Finish the process.
If your app already exists:
- Open your app on Bitrise.
- Go to the Settings tab.
- Scroll down to SSH settings.
- Click the Click to show SSH public key button.
- Copy the SSH public key and add it to your GitHub machine user.
Git cloning submodules and repository dependencies ⚓
There is one important detail to keep in mind when you want to give access to all submodules or private repository dependencies for an app: the app’s privacy settings determine what git URL should you use.
- If you have a private app: use SSH URLs everywhere! Most services support SSH key based authentication only for SSH URLs
firstname.lastname@example.org:bitrise-io/bitrise.git). Therefore every private repository you want to use have to be addressed with the SSH URL. If you have direct private git repo references in your CocoaPods
Podfileyou’ll have to use the SSH URL there as well! The same applies for submodules and every other private git repository URL you want to use with the SSH key you register on Bitrise.io!
- If you have a public app: use HTTPS URLs everywhere! SSH URLs require SSH keys even if the repository is public. For security reasons, public apps CANNOT have SSH keys. As HTTPS git clone URLs do not require any authentication in the case of public repositories, they should be used for public Bitrise apps.
Creating SSH keys for a new private app ⚓
There are three options to grant Bitrise access to your repository:
- Auto-add SSH keypair: Don’t use this option if you use submodules. This option adds the SSH key to the main repository only.
- Generate SSH keypair: this generates a key for you on the Bitrise website and you will have to copy it manually to the given user. This is the recommended option if you want to use submodules or have to access multiple repositories during your build.
- Use your own SSH keypair: can be used if you also have the private key of the given user. You just have to paste the private key and Bitrise will be able to access the repositories. Keep in mind that the SSH key has to be an RSA key, without a passphrase! You can find an example of how you can generate a key like that here.
Managing SSH keys of an existing private app ⚓
You can find the public SSH key of the app in the
Settings of the given
app on Bitrise. Scroll down to the
SSH settings section
Show SSH Public Key.
Copy the key to the given user and you are ready to build!
If necessary, update the given app’s SSH key by clicking the
Change SSH Keypair button and choosing one of the three options.
This guide explains how to grant access for bitrise.io to your Bitbucket team, and to check if you denied access for any reason.
This guide explains how to grant access for bitrise.io to your GitHub Organization. This way Bitrise can access the Organization's repositories.
If you want to do manual SSH key configuration on bitrise.io, you can generate an appropriate SSH keypair with a simple Command Line / Terminal command.