# Github App

{% hint style="info" %}
This feature is supported from Terrakube 2.23.0
{% endhint %}

{% hint style="warning" %}
NOTE: Token generation and refresh in 'Github App' mode are primarily driven by the `APP ID`. If multiple VCS instances share the same `APP ID`, the system will only regenerate the token for the first one encountered.

For more details, see: [Github Issue](https://github.com/terrakube-io/terrakube/issues/2938)
{% endhint %}

For using repositories from GitHub.com with Terrakube workspaces and modules you will need to follow these steps:

{% hint style="info" %}
**Manage VCS Providers** permission is required to perform this action, please check [team-management](https://docs.terrakube.io/user-guide/organizations/team-management "mention") for more info.
{% endhint %}

Navigate to the desired organization and click the **Settings** button, then on the left menu select **VCS Providers**

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-014b437189fd580494cb401e7ebf8663972010c0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Select the option for Github App

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-3293251441bc40a1788ac5a79ca89242cc7460c7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

In the next page click <https://github.com/settings/apps/new> to create a new application adding the required information

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-64783f7c63fac88f9b9ffd61b7592f6dec5e07b4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Complete the information like the following:

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-3f15218297bb7ed8eb6af6a4fad61f6f0bc7f7ed%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Disable webhook option.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-12e52fd9dc85d35807e42bd92e91c72770fd7608%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Grant the require repository, organization or account permissions and in which type of account you will do the installation.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-b1dbd6c2297f0a643af7ef8db8d25be75f8c3333%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Add "Contents" with "Read-Only"

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-91e0aab23cdaae73dc6e3a25981c15a2124c9647%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Add "Webhooks" with "Read and Write"

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-d0e31dbfacd816c76f3e04f2b474137410d21a6a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Webhooks are need it if you will create workspace with webhooks enabled
{% endhint %}

Add "Commit statuses" to "Read and write"

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-f5ce2882e14313b2629f54bd96dd1ed856b9e083%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Finally click "Create Github App"

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-64998919f1e21a2c54eaa1afbce636383a993a90%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

After creating the application you need to copy the APP Id to the Terrakube UI

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-fdfd9e27ebfa3abc78ca90049e1ec177eb7bc859%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Scroll down and search for "Generate Private Key" and generate a new private key.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-1b871cfff0ae8e62c1a8ffb0fe3586b77f18a1a9%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

After downloading the private key we need to to transform the key to PKCS8 using the following command:

```
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in my-terrakube-app.private-key.pem -out pkcs8.key
```

{% hint style="warning" %}
The above command assumes the downloaded key from github name is "my-terrakube-app.private-key.pem" and that you want to save the key to a file called "kcs8.key"
{% endhint %}

Now we can add the private key in the Terrakube UI.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-9606e94b10f3a4948e43c164d3492f89820f9b9b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The github app will be added to Terrakube and will be shown like this:

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-84d7633aa3f71e8489c2938de6c117ec4bd6e719%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The final step will be to install the application to your Github account like this.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-6f9e90e3d01b128527591bbe1ab390eafa5b7482%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

And select which repositories will be used with terrakube

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-aa9d1250fc7c82bb3984695ad90d9666f3cd4421%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

The installation should look like this

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-9f3a495d2838183cbf66e8626f189acae7a323f2%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Now to use the Github Application when creating a new workspace we just need to add our new connection.

<figure><img src="https://4014930676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfAN3V983Y82_trlbcu%2Fuploads%2Fgit-blob-bc55bd7d8e566fc6d404627d374313e962e907b5%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
