# 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](/user-guide/organizations/team-management.md) 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="/files/a9QAbsWKRTZzMR0mzvO0" alt=""><figcaption></figcaption></figure>

Select the option for Github App

<figure><img src="/files/0Napd89760MO9dnTeseg" 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="/files/Ccig5IhNeHxihs9sxUSx" alt=""><figcaption></figcaption></figure>

Complete the information like the following:

<figure><img src="/files/YiKn9QfeQCb6jHTB35er" alt=""><figcaption></figcaption></figure>

Disable webhook option.

<figure><img src="/files/01irRdcgatJLVdXc0unh" 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="/files/QeXHzDh9Rd5FrvjL4Dta" alt=""><figcaption></figcaption></figure>

Add "Contents" with "Read-Only"

<figure><img src="/files/MiFNliN2tkofoKm2Bbgu" alt=""><figcaption></figcaption></figure>

Add "Webhooks" with "Read and Write"

<figure><img src="/files/JZnlYZFJQ9BDPHgAL2jS" 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="/files/fGLfke098Hi0LmiMO1Fs" alt=""><figcaption></figcaption></figure>

Finally click "Create Github App"

<figure><img src="/files/dvTgOlAeGWqGcm3lnm2U" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/1kIvaBIC3gJHPiTc74y7" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/EJqKmB9rFvs6Ili4GPKp" 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="/files/5XtdB9MvDsa68koT3NR7" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/ecqc9DGx2eIMYNks2Jxu" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/hjJHU7GC5Hpgo2qFnmFq" alt=""><figcaption></figcaption></figure>

And select which repositories will be used with terrakube

<figure><img src="/files/4wwiRwx5aPMOaCRHmvIB" alt=""><figcaption></figcaption></figure>

The installation should look like this

<figure><img src="/files/dTnlNFliB6W5kjQBP7mf" 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="/files/rdd48iY3htaKc9XoQPxt" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.terrakube.io/user-guide/vcs-providers/github-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
