Search code examples
amazon-web-servicesamazon-ec2telnetvault

How to connect to remote hashicorp vault server


Let me explain my use-case here,

I wanted to give a try to vault in my local, so I configured VAULT_ADDR as:

$ echo $VAULT_ADDR 
http://127.0.0.1:8200

then I started vault in dev mode (vault server -dev) and everything was ok, I was able to connect to the server.

Then I wrote a really simple config file:

$ cat vault.config 
backend "inmem" {}

listener "tcp" {
  address = "127.0.0.1:8200"
  tls_disable = 1
}

disable_mlock = true

and I restarted the server with vault server -config=vault.config, This too worked fine.

Now I want to use vault server which is deployed in remote server (aws ec2 instance). I have changed content my config file to below

backend "inmem" {}

listener "tcp" {
  address = "123.456.789.1:8200" (aws ec2 public ip)
  tls_disable = 1
}

disable_mlock = true

now this is throwing error

Error checking seal status: Get "http://123.456.789.1:8200/v1/sys/seal-status": dial tcp 123.456.789.1:8200: connect: connection refused'

when i am trying to check connectivity using telnet command, that too failed.

  telnet 123.456.789.1 8200
telnet: Unable to connect to remote host: Connection refused

I have opened 8200 port in security group of aws, and both instances are in same vpc. What I am missing here? Any help?


Solution

  • I was able to figure out solution for above issue. Basically I executed below steps.

    1. First I started vault server in above machine ( '123.456.XXX.X' ) by below command
    vault server -dev -dev-listen-address="123.456.789.1:8200"
    
    

    here 123.456.789.1 --> This is private IP of my ec2 instance, where my vault server is running.

    1. Next, In my source machine (the one from which i am invoking vault server in 123.456.XXX.X ), I set below parameters
    export VAULT_ADDR='http://123.456.789.1:8200'
    export VAULT_TOKEN='*****************'
    
    1. Now when I am trying to do telnet to 123.456.XXX.X server, it is working as expected
    telnet 123.456.789.1 8200
    

    output

    Trying 123.456.789.1...
    Connected to 123.456.789.1.
    Escape character is '^]'.