모범 사례 및 튜토리얼

HashiCorp Vault와 Couchbase Server

9 분 읽기

In today’s fast-paced world, data security is of utmost importance, especially when dealing with sensitive information. A key component of data security is authentication, which protects data from being stolen. HashiCorp Vault is one of the technologies that can help businesses further secure access to their Couchbase database.

How can HashiCorp help me to further increase my database security?

HashiCorp Vault can securely store and manage database credentials, such as usernames and passwords, and dynamically generate new ones when they are needed. This reduces the risk of accidental or intentional credential exposure and makes it easier to revoke or rotate credentials when they are no longer needed.

Vault can also provide detailed audit logs of all database access and credential use, which can help organizations comply with various regulatory requirements and monitor for suspicious activity.

In this tutorial blog post, we will look at how to integrate Couchbase Server with HashiCorp Vault.

Step 1: Setting up Vault

The first step is to set up a HashiCorp Vault instance. You can download the Vault binary from the official website, you can use a package manager like Homebrew or Chocolatey or you can run Vault using Docker. In this blog post we will use Docker to set up the environment.

  • Set up the Docker network

  • Start Vault in a Docker container. To start Vault in developer mode with a root password of 비밀번호, simply use the command below.

The above Docker command starts the Vault server in development mode, which is not recommended for production use. It creates an in-memory data store that is wiped out when the server is shut down. However, it is perfect for testing purposes.

The vault UI is running at https://localhost:8200

You can use a “password”  as a token to login into the Vault UI as we specified that to be the root token.

Step 2: Checking the configuration of Vault

Once the Vault server is up and running, you need to make sure that the Couchbase database plugin is installed.

Run the following command to check if the plugin is installed:

Please note: in the earlier command, we named the container couchbase_vault, using the command above executes vault commands inside the container running HashiCorp Vault.

The output of this command should list the couchbase plugin:

If you would like to experiment with Vault you can use the command below to open a shell inside the container running Vault:

You can authenticate with the root token we set up earlier:

If you are not familiar with Vault make sure you check out the commands documentation.

Step 3: Start a demo Couchbase server

Open a new terminal window and run the following command to start Couchbase:

Step 4: Configure Couchbase Server

Open a third terminal. We will use this to execute Docker commands to configure Vault and Couchbase in the next steps.

  • Initialize our Couchbase cluster

  • Import some sample data

It is time to inspect our cluster using the UI. You can open the 콘솔 at https://localhost:8091 and use 관리자 as username and 비밀번호 as password to log in.

Step 5: Creating a Couchbase Server user

Now that the Vault is configured, and Couchbase Server is running, we need to create a Couchbase user. This user will be used by the Couchbase Vault plugin to access Couchbase Server and to create users on demand.

Once the user is created, it will show up as a user in the UI as well:

Step 6: Integrating Vault and Couchbase Server

Now that both Vault and Couchbase Server are configured, we need to integrate them. Follow these steps:

  • Enable Vault’s database engine

0

  • Initialize the Couchbase Server plugin

1

Let me explain the command above a little bit more in detail.

  1. Using wget we download the certificate from Couchbase Server as we need it later on.
  2. Login into Vault with vault login.
  3. Create a demo-db configuration using the couchbase-database-plugin. We need to specify our Couchbase server and a user (couchbase-vault-user) to connect to it.

Please note: we specified allowed_roles to be * which is not recommended in production as it will permit the creation of a Couchbase user with any available roles.

  • Rotate the password of the couchbase user

Since we used a very insecure password to set up the connection between Couchbase Server and Vault, it is important to change the password by executing the command below:

2

Lets validate that the password indeed has been changed. We can do this by trying to log in as couchbase-vault-user using the Couchbase UI.

You should see an error message Login failed. This confirms that Vault was able to rotate the password of the user that Vault uses to talk to Couchbase Server:

Step 7: Create a demo Vault policy

Finally we need to create a Vault policy. Use the command vault policy. This policy will be used to create new users in Couchbase

The command below will create a HashiCorp Vault role that can create users with ro_admin roles in Couchbase.

3

Step 8: Testing the Integration

Now that the integration is complete, we can test it. Follow these steps:

  • Create a user

4

If all configured properly you should see a new user created like the one below:

5

You can now use this user to log into Couchbase or use the UI to see if the user indeed exists:

Please note: This user has a five minute lease. If you wait five minutes then the user will be deprovisioned by Vault automatically. You can use Vault to extend the lease or to create a new user. For further information consult Vault’s documentation.

결론

Integrating Couchbase Server with HashiCorp Vault is a great way to secure access to your data. In this blog post, we have seen how to do just that. By following the steps outlined above, you can easily integrate Couchbase Server with HashiCorp Vault.

Keeping in mind the steps we’ve outlined are intended solely for testing and demonstrations, it is crucial to understand that when it comes to secure production deployments, adhering to industry best practices is paramount. To guarantee that both your Vault and Couchbase server are appropriately configured and fortified, which falls beyond the scope of this article, we strongly advise following these recommended practices.

There are a few things to consider when you create user accounts in Couchbase. User creation is asynchronous in ns_server. It will only be 100% available on the node in which the request was made and then they are created on the other nodes asynchronously. As an example, if you were to create  a user every minute and delete it, you would reach 525600 deleted users in a year which is still safe for many years. Just keep in mind that creating millions of users could have an impact on your cluster’s user creation performance and creating many millions of users is beyond anything we have tested so far.

이 기사 공유하기

작가

이슈반 오르반(Istvan Orban)은 카우치베이스(Couchbase)의 수석 제품 관리자(Principal Product Manager)이며 영국에 거주하고 있습니다. 이슈반은 풀스택 소프트웨어 엔지니어, 팀 리더, 데브옵스 엔지니어로서 폭넓은 경력을 가지고 있습니다. 그의 주된 관심 분야는 보안과 싱글 사인온(SSO)입니다. 이슈반은 20년의 전문 경력 동안 여러 대규모 프로젝트를 이끌었습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.