Install and map self-hosted GitLab resources in Service Catalog

Uses: Service Catalog Konnect API
TL;DR

Authorize the GitLab integration in the Konnect UI using self-hosted setup. Create a Service Catalog service and associate it with your project resource to display metadata and enable event tracking.

Prerequisites

If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. The following Konnect items are required to complete this tutorial:
    • Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
  2. Set the personal access token as an environment variable:

    export KONNECT_TOKEN='YOUR KONNECT TOKEN'
    

You need the Integration Admin role in Konnect to install and authorize Service Catalog integrations.

You must have the Owner role in the GitLab group to authorize the integration. If you’re using a self-hosted GitLab instance, it must be accessible from the public internet or is otherwise reachable by Konnect.

  1. Create a group-owned application in your GitLab instance.
    • Set the redirect URI to:
      https://cloud.konghq.com/$KONNECT_REGION/service-catalog/integrations/gitlab
    • Ensure the app has the api scope.
    • Be sure to copy your application ID and secret to use in Konnect.
  2. Copy and save your GitLab self-hosted base URL, token endpoint, and auth endpoint. They should be in the following format:
    • Base URL: https://$GITLAB_HOST/api/v4
    • Token Endpoint: https://$GITLAB_HOST/oauth/token
    • Authorization Endpoint: https://$GITLAB_HOST/oauth/authorize

Authorize the self-managed GitLab integration

  1. In the Konnect UI, navigate to the GitLab integration and click Add GitLab instance.
  2. Select GitLab Dedicated or Self-managed, and enter the full URL to your GitLab API in the GitLab API Base URL field, ending in /api/v4. For example: https://$GITLAB_HOST/api/v4
  3. Fill out the authorization fields using the values from your GitLab OAuth application:
    • Application ID: The Application ID from your GitLab app
    • Application Secret: The secret associated with your GitLab app
    • Token Endpoint: https://$GITLAB_HOST/oauth/token
    • Authorization Endpoint: https://$GITLAB_HOST/oauth/authorize
  4. Click Authorize to complete the connection.
  5. Name your instance gitlab.

Once authorized, resources from your GitLab account will be discoverable in the UI.

Create a service in Service Catalog

Create a service that you’ll map to your GitLab resources:

 curl -X POST "https://us.api.konghq.com/v1/catalog-services" \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "name": "billing",
       "display_name": "Billing Service"
     }'

Export the service ID:

export GITLAB_SERVICE_ID='YOUR-SERVICE-ID'

List GitLab resources

Before you can map your GitLab resources to a service in Service Catalog, you first need to find the resources that are pulled in from GitLab:

 curl -X GET "https://us.api.konghq.com/v1/resources?filter%5Bintegration.name%5D=gitlab" \
     -H "Authorization: Bearer $KONNECT_TOKEN"

You might need to manually sync your GitLab integration for resources to appear. From the Konnect UI by navigating to the GitLab integration you just installed and selecting Sync Now from the Actions dropdown menu.

Export the resource ID you want to map to the service:

export GITLAB_RESOURCE_ID='YOUR-RESOURCE-ID'

Map resources to a service

Now, you can map the GitLab resource to the service:

 curl -X POST "https://us.api.konghq.com/v1/resource-mappings" \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "service": "billing",
       "resource": "'$GITLAB_RESOURCE_ID'"
     }'

Validate the mapping

To confirm that the GitLab resource is now mapped to the intended service, list the service’s mapped resources:

 curl -X GET "https://us.api.konghq.com/v1/catalog-services/$GITLAB_SERVICE_ID/resources" \
     -H "Authorization: Bearer $KONNECT_TOKEN"
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!