athurner
athurner

Reputation: 111

Using Pact-Broker Behind Reverse Proxy And URL Rewrite in Kubernetes & Istio

I deployed the pact-broker docker image (latest version) in a local Kubernetes cluster with the following deployment.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-pact-broker
...
    spec:
      containers:
      - name: my-pact-broker
        image: pactfoundation/pact-broker
        ports:
          - containerPort: 9292
        env:
        - name: PACT_BROKER_ALLOW_PUBLIC_READ
          value: "true"
        - name: PACT_BROKER_BASIC_AUTH_USERNAME
          value: "****"
        - name: PACT_BROKER_BASIC_AUTH_PASSWORD
          value: "****
        - name: PACT_BROKER_PORT 
          value: "9292"   
        - name: PACT_BROKER_LOG_LEVEL
          value: "DEBUG"
        - name: PACT_BROKER_SQL_LOG_LEVEL
          value: "DEBUG"
... 

An virtual service is configured for the istio ingress controller

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-pact-broker
  namespace: default
spec:

.....

  http:
    - match:
        - uri:
            prefix: /pactbroker/
        - uri:
            prefix: /pactbroker            
      rewrite:
        uri: /
      route:    
        - destination:
            port:
              number: 9292
            host: my-pact-broker.default.svc.cluster.local
          headers:
            request:
              add:
                X-Forwarded-Scheme: "https"
                X-Forwarded-Host: "my-domain.com"
                X-Forwarded-Port: "80"

The pact-broker api works fine. I successfully posted a pact to https://my-domain.com/pactbroker/pacts/provider/test-provider/consumer/test-consumer/version/1.0.0

The problem is with the pact-broker UI. When requesting https://my-domain.com/pactbroker the response is incomplete. The resources are pointing to root.

...
<body>
<link href='/stylesheets/index.css' rel='stylesheet'>
<link href='/stylesheets/material-menu.css' rel='stylesheet'>
<link href='/stylesheets/material-icon.css' rel='stylesheet'>
<link href='/stylesheets/jquery-confirm.min.css' rel='stylesheet'>
<script src='/javascripts/jquery.tablesorter.min.js' type='text/javascript'></script>
<script src='/javascripts/material-menu.js' type='text/javascript'></script>
<script src='/javascripts/index.js' type='text/javascript'></script>
<script src='/javascripts/clipboard.js' type='text/javascript'></script>
<script src='/javascripts/jquery-confirm.min.js' type='text/javascript'></script>

<div class='container'>
<nav class='navbase-default' id='navigation' role='navigation'>
<div class='container-fluid'>
<div class='navbar-header'></div>
<ul class='navbar-right' id='top-left-menu'>
<li>
<a href='?tags=true'>
Show latest tags
</a>
<a href='/hal-browser/browser.html'>
API Browser
</a>
</li>
</ul>
</div>
</nav>
....

The HAL-Browser has a similar problem:

The references in the URI Template are not showing the uri prefix "pactbroker"

What do I have to do to make this work correctly.

Upvotes: 0

Views: 651

Answers (1)

athurner
athurner

Reputation: 111

I found the missing information in the Changelog of the pact-broker project.

Adding the environment variable PACT_BROKER_BASE_URL fixed the issue

        - name: "PACT_BROKER_BASE_URL"
          value: "https://my-domain.com/pactbroker"

Upvotes: 2

Related Questions