vault icon indicating copy to clipboard operation
vault copied to clipboard

How do I setup ingress for HashiCorp Vault UI in Kubernetes

Open Marusyk opened this issue 7 years ago • 14 comments

I have just installed an HashiCorp Vault on my Kubernetes cluster using. I want it to work through my existing ingress controller so I have created a new ingress rule using the yaml below:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: vault-ingress
  namespace: vault
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /vault
        backend:
          serviceName: vault
          servicePort: 8200

To my service which runs as:

apiVersion: v1
kind: Service
metadata:
  name: vault
  namespace: vault
  labels:
    module: vault
spec:
  selector:
    module: vault
  ports:
  - port: 8200
    targetPort: 8200

However, when I try and access my URL: http://ingress.domain/vault/ui I get empty page with errors

13.72.65.96/:24 GET http://ingress.domain/ui/assets/vendor-854d73b9f9351c0ff2e27f8821dfcd09.js net::ERR_ABORTED 404 (Not Found)
13.72.65.96/:25 GET http://ingress.domain/ui/assets/vault-f8ac2e61e061b2fb490b6ad79fcd5c1f.js net::ERR_ABORTED 404 (Not Found)
13.72.65.96/:15 GET http://ingress.domain/ui/assets/vendor-895fbba1663c3b4fe68755a3fb7ae7b4.css net::ERR_ABORTED 404 (Not Found)
13.72.65.96/:16 GET http://ingress.domain/ui/assets/vault-8ed265cce923599eca663b1bb2e4a83f.css net::ERR_ABORTED 404 (Not Found)
13.72.65.96/:25 GET http://ingress.domain/ui/assets/vault-f8ac2e61e061b2fb490b6ad79fcd5c1f.js net::ERR_ABORTED 404 (Not Found)
favicon-68e1a9c89026b0efeddf718a48c282a5.png:1 
GET http://ingress.domain/ui/favicon-68e1a9c89026b0efeddf718a48c282a5.png 404 (Not Found)

My configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: vault
  namespace: vault
  labels:
    module: vault
data:
  config.json : '{
    "ui": "true",
    "disable_mlock": "true",
    "api_addr": "http://127.0.0.1:8200/vault",
    "listener": [
        {
            "tcp": {
                "address": "0.0.0.0:8200",
                "tls_disable": 1
            }
        }
    ]
}'

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vault
  namespace: vault
  labels:
    module: vault
spec:
  selector:
    matchLabels:
      module: vault
  replicas: 1
  template:
    metadata:
      labels:
        module: vault
    spec:
      containers:
      - name: vault
        image: vault
        imagePullPolicy: "Always"
        command: ["/bin/sh", "-c"]
        args:
        -  vault server -config /vault/config/config.json
        securityContext:
          capabilities:
            add:
              - IPC_LOCK
        volumeMounts:
          - name: configurations
            mountPath: /vault/config/config.json
            subPath: config.json
        env:
          - name: VAULT_ADDR
            value: "http://localhost:8200/vault/"
        ports:
        - containerPort: 8200
      imagePullSecrets:
        - name: regcred
      volumes:
        - name: configurations
          configMap:
            name: vault

ow do I setup ingress for Vault UI in Kubernetes? I have one domain for my Ingress, so the UI (and other services) should be : http://ingress.domain/{service name}. I need the Vault UI http://ingress.domain/vault

Marusyk avatar Jul 29 '19 22:07 Marusyk

I've got response on Vault forum:

this is (currently) not possible. Vault's UI (and API) is not able to work with domain subpathing.

Can it be considered as feature request?

Marusyk avatar Jul 30 '19 14:07 Marusyk

Thank you for your attention and quick response

Marusyk avatar Aug 13 '19 22:08 Marusyk

Is this still not implemented? I can't even set the ingress to work at root, I keep getting error 503: This is my ingress, the rest is similar to yours

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: vault-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, DELETE, PATCH, OPTIONS'
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: vault
          servicePort: 8200

DrissiReda avatar Jan 13 '20 15:01 DrissiReda

@Marusyk @DrissiReda I am facing the same issue. Few changes in the service of vault can make it work but it doesn't work with subpathing.

I am considering you are using nginx ingress controller.

edit your service to listen at port 80. kubectl edit svc vault-ui

then in ingress.yaml disable rewrite-redirect

  • backend: serviceName: vault-ui servicePort: 80 path: /

Since vault-ui service always redirects to /ui/ I was trying to do something like below with rewrite target but failed.

in path section added path: /(ui/.*) and in rewrite annotation add /$1. Till the service redirects to /ui it works but then service redirects to /v1 n it breaks, i guess we have to do something more with regex and capturing group.

But on root without rewrite it works fine. keep vault service port to 80-->8500(target port)

RavindraSingh12 avatar Jan 14 '20 05:01 RavindraSingh12

Facing the same while using nginx-ingress with the vault UI any updates on this issue?

chrisjaimon2012 avatar Apr 12 '21 21:04 chrisjaimon2012

Facing the same while using nginx-ingress with the vault UI any updates on this issue?

Like many other apps, they just didn't support subpaths in the ui. Best solution is using a host in the ingress at path: / something like: vault.your.domain.

DrissiReda avatar Apr 13 '21 07:04 DrissiReda

Vault UI has problem with the subpathing. You can do the following which worked for me: in the path section of ingress try using
path : /*

samrakshak avatar May 16 '22 05:05 samrakshak

@samrakshak that should not work for a specific path like /vault.

Polyhistor avatar Jul 01 '23 06:07 Polyhistor

+1 I want to change my vault to my-domain.com/vault via ingress.

songleo avatar Mar 11 '24 16:03 songleo

+1

so2bin avatar Oct 16 '24 09:10 so2bin

+1

danielvincenzi avatar Oct 31 '24 17:10 danielvincenzi

+1

brunobva avatar Aug 30 '25 22:08 brunobva

+1

Polyhistor avatar Aug 31 '25 00:08 Polyhistor

+1

hyperion1209 avatar Oct 06 '25 20:10 hyperion1209