# Enabling HTTPS for Vault inside a container

**URL:** <https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828>\
**Category:** Vault\
**Created:** [October 18, 2021, 9:35am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828 "2021-10-18T09:35:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 18, 2021, 9:35am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/1 "2021-10-18T09:35:57Z")

</div>

We are running vault inside a Docker container.

In the vault documentation it was mentioned that to enable https we should specify the path of the .cer and .pem file in the vault config.hcl file.

Should we do the same when vault is running inside the container?

Can anyone help me on this.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [October 18, 2021, 10:08am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/2 "2021-10-18T10:08:20Z")

</div>

Is this straight Docker or an orchestration system like Nomad, Kubernetes, etc.?

Generally you’d use volume mounts to expose those files into the container - for Kubernetes that would be using secrets, while for straight Docker it would me mounting a path from the underlying server into the container.

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 18, 2021, 11:35am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/3 "2021-10-18T11:35:35Z")

</div>

Thanks Stuart. Its just Docker. Instead of mounting a path from underlying server onto the container, mapping the container port on to the server port on which https is enabled will also work right?

Please correct me if i am wrong.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [October 18, 2021, 12:11pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/4 "2021-10-18T12:11:21Z")

</div>

There are two things you need to do:

1. Map the path from the server into the container for the certificate files
2. Expose port 443 from the container to the outside world

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 18, 2021, 3:35pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/5 "2021-10-18T15:35:23Z")

</div>

if i dont map the path from the server into the container for the certificate files and instead just map the port 8200 in the container to the port 443 (i.e the port for which https is enabled on the server) on the server. It should also work right?

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [October 18, 2021, 5:01pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/6 "2021-10-18T17:01:27Z")

</div>

You can map the files easily enough as readonly (:ro). For certs I rather map them individually rather than the whole cert directory. I’m just a little paranoid with mapping drives.

Yes, you either have TLS enabled or not on port 8200, 443 it not necessary when you enable TLS on a listener.

Normally you map 443 to 8200 on a load balancer as a TLS pass thru then enable TLS on the 8200 listener. That way it terminates the SSL session on the node.

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 20, 2021, 9:06am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/7 "2021-10-20T09:06:52Z")

</div>

So then, i can enable https on port 443 on the server and map this to the port 8200 on the container instead of mapping the certificate files on the server to the container.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [October 20, 2021, 9:22am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/8 "2021-10-20T09:22:02Z")

</div>

It isn’t an OR it is a BOTH.

You need to expose the port as well as mapping the certificate files.

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [October 20, 2021, 11:06am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/9 "2021-10-20T11:06:25Z")

</div>

Depends on how you use Vault and what your VAULT\_ADDR is set to:

VAULT\_ADDR=https://vault…  
then: -p 443:8200

VAULT\_ADDR=https://vault…:8200  
then: -p 8200:8200

As @stuart-c said, you need to map and include the cert files.

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 20, 2021, 3:02pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/10 "2021-10-20T15:02:00Z")

</div>

Followed the steps but got the following error while executing vault commands inside the container

vault status

Error checking seal status: Get “[https://127.0.0.1:8200/v1/sys/seal-status](https://127.0.0.1:8200/v1/sys/seal-status)”: x509: cannot validate certificate for 127.0.0.1 because it doesn’t contain any IP SANs

Referred the following GitHub issue [SSL/TLS Question · Issue #212 · hashicorp/vault · GitHub](https://github.com/hashicorp/vault/issues/212)

and when i add tls-skip-verify it works.

vault status -tls-skip-verify

Is this because the .cer has a different host name than the container on which it is executing?  
Can i ignore this error

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [October 20, 2021, 3:14pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/11 "2021-10-20T15:14:45Z")

</div>

Make sure 127.0.0.1 is in SAN while generating the SSL cert. In k8s you need to define very pod/container name combo in the SAN list. Ours has like 20 aliases defined.

You can ignore it, but that’s not exactly the best way to do it.

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 20, 2021, 3:41pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/12 "2021-10-20T15:41:28Z")

</div>

Thanks Aram.This is very helpful.  
Since vault is running inside the container, in the vault config file can i define the api and cluster addr as below or should i use the docker host domain name

api\_addr= “[http://127.0.0.1:8200](http://127.0.0.1:8200)”  
cluster\_addr = “[http://127.0.0.1:8201](http://127.0.0.1:8201)”

Following message is getting displayed in vault logs

[ERROR] core: error during forwarded RPC request: error=“rpc error: code = Unavailable desc = connection error: desc = “transport: Error while dialing remote error: tls: internal error””  
2021-10-20T15:57:10.612Z [ERROR] core: forward request error: error=“error during forwarding RPC request”

http: TLS handshake error  
remote error: tls: unknown certificate

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [October 20, 2021, 7:42pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/13 "2021-10-20T19:42:36Z")

</div>

Your SSL cert is not setup correctly. Verify the cert and key for the name you’re using makes sure its either in a Kubernetes secret or mounted.

---

<div class="post-metadata">

**Author:** ![bhardwaj.nithin131](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bhardwaj.nithin131/32/17579_2.png) [@bhardwaj.nithin131](https://discuss.hashicorp.com/u/bhardwaj.nithin131)\
**Post date:** [October 21, 2021, 8:55am UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/14 "2021-10-21T08:55:19Z")

</div>

But from the browser i am able to make https requests. May be is this because the certificate has a CN corresponding to docker host and not 127.0.0.1

---

<div class="post-metadata">

**Author:** ![aram](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aram](https://discuss.hashicorp.com/u/aram)\
**Post date:** [October 21, 2021, 12:02pm UTC](https://discuss.hashicorp.com/t/enabling-https-for-vault-inside-a-container/30828/15 "2021-10-21T12:02:51Z")

</div>

When you’re on the host, the default is to access via [https://127.0.0.1:8200](https://127.0.0.1:8200) so set your VAULT\_ADDR to avoid the error.
