Redis를 사용한 데이터베이스 접근
Redis Cluster를 구성하려면 Redis Cluster를 사용한 데이터베이스 접근을 참조하십시오. Teleport can provide secure access to Redis via the Teleport Database Service.
Redis Cluster를 구성하려면 Redis Cluster를 사용한 데이터베이스 접근을 참조하십시오.
Teleport can provide secure access to Redis via the Teleport Database Service. This allows for fine-grained access control through the Teleport RBAC system.
The Teleport Database Service proxies traffic from database clients to self-hosted databases in your infrastructure. Teleport maintains a certificate authority (CA) for database clients. You configure your database to trust the Teleport database client CA, and the Teleport Database Service presents certificates signed by this CA when proxying user traffic. With this setup, there is no need to store long-lived credentials for self-hosted databases.
Meanwhile, the Teleport Database Service verifies self-hosted databases by checking their TLS certificates against either the Teleport database CA or a custom CA used with the database.
In this guide, you will:
- Configure your Redis database for Teleport access.
- Add the database to your Teleport cluster.
- Connect to the database via Teleport.
동작 원리#
The Teleport Database Service authenticates to your self-hosted Redis database using mutual TLS. Redis trusts the Teleport certificate authority for database clients, and presents a certificate signed by either the Teleport database CA or a custom CA. When a user initiates a database session, the Teleport Database Service presents a certificate signed by Teleport. The authenticated connection then proxies client traffic from the user.


사전 요구사항#
-
A running Teleport cluster. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.
-
The
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Determine the version of your Teleport cluster. The
tctlandtshclients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at/v1/webapi/findand use a JSON query tool to obtain your cluster version. Replace with the web address of your Teleport Proxy Service:$ TELEPORT_DOMAIN= $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
Follow the instructions for your platform to install
tctlandtshclients:
-
-
Redis 버전
6.0이상.NoteRESP3 (REdis Serialization Protocol)은 현재 지원되지 않습니다.
-
redis-cli버전6.2이상이 설치되어 시스템의PATH환경 변수에 추가되어 있어야 합니다. -
Teleport Database Service를 실행할 호스트.
자세한 내용은 설치를 참조하십시오.
-
선택 사항: 셀프 호스팅 데이터베이스에 인증서를 발급하는 인증 기관.
To check that you can connect to your Teleport cluster, sign in with
tsh login, then verify that you can runtctlcommands using your current credentials.For example, run the following command, assigning to the domain name of the Teleport Proxy Service in your cluster and to your Teleport username:
$ tsh login --proxy= --user= $ tctl status # Cluster (=teleport.url=) # Version (=teleport.version=) # CA pin (=presets.ca_pin=)If you can connect to the cluster and run the
tctl statuscommand, you can use your current credentials to run subsequenttctlcommands from your workstation. If you host your own Teleport cluster, you can also runtctlcommands on the computer that hosts the Teleport Auth Service for full permissions.1/5단계. Teleport Database Service 설정#
The Database Service requires a valid join token to join your Teleport cluster. Run the following
tctlcommand and save the token output in/tmp/tokenon the server that will run the Database Service:$ tctl tokens add --type=db --format=text (=presets.tokens.first=)Teleport Database Service를 실행할 위치에 Teleport를 설치하고 구성합니다:
To install a Teleport Agent on your Linux server:
The recommended installation method is the cluster install script. It will select the correct version, edition, and installation mode for your cluster.
-
Assign to your Teleport cluster hostname and port, but not the scheme (https://).
-
Run your cluster's install script:
$ curl "https:///scripts/install.sh" | sudo bash
On the host where you will run the Teleport Database Service, start Teleport with the appropriate configuration.
Note that a single Teleport process can run multiple different services, for example multiple Database Service agents as well as the SSH Service or Application Service. The step below will overwrite an existing configuration file, so if you're running multiple services add
--output=stdoutto print the config in your terminal, and manually adjust/etc/teleport.yaml.Run the following command to generate a configuration file at
/etc/teleport.yamlfor the Database Service. Update to use the host and port of the Teleport Proxy Service:$ sudo teleport db configure create \ -o file \ --token=/tmp/token \ --proxy=:443 \ --name=example-redis \ --protocol=redis \ --uri=rediss://redis.example.com:6379 \ --labels=env=devTo configure the Teleport Database Service to trust a custom CA:
-
Export a CA certificate for the custom CA and make it available at
/var/lib/teleport/db.caon the Teleport Database Service host. -
Run a variation of the command above that uses the
--ca-cert-fileflag. This configures the Teleport Database Service to use the CA certificate atdb.cato verify traffic from the database:$ sudo teleport db configure create \ -o file \ --token=/tmp/token \ --proxy=:443 \ --name=example-redis \ --protocol=redis \ --uri=rediss://redis.example.com:6379 \ --ca-cert-file="/var/lib/teleport/db.ca" \ --labels=env=dev
If your database servers use certificates that are signed by a public CA such as ComodoCA or DigiCert, you can use the
trust-system-cert-pooloption without exporting the CA:$ sudo teleport db configure create \ -o file \ --token=/tmp/token \ --proxy=:443 \ --name=example-redis \ --protocol=redis \ --uri=rediss://redis.example.com:6379 \ --trust-system-cert-pool \ --labels=env=dev(!docs/pages/includes/start-teleport.mdx service="the Teleport Database Service"!)
Teleport는 Kubernetes 클러스터에 Teleport Database Service를 설치하기 위한 Helm 차트를 제공합니다.
Configure Helm to fetch Teleport charts from the Teleport Helm repository:
$ helm repo add teleport (=teleport.helm_repo_url=)Refresh the local Helm cache by fetching the latest charts:
$ helm repo updateInstall a Teleport Agent into your Kubernetes Cluster with the Teleport Database Service configuration.
Create a file called
values.yamlwith the following content. UpdateFlag Description --rolesList of roles to assign to the user. The builtin accessrole allows them to connect to any database server registered with Teleport.--db-usersList of database usernames the user will be allowed to use when connecting to the databases. A wildcard allows any user. --db-namesList of logical databases (aka schemas) the user will be allowed to connect to within a database server. A wildcard allows any database. For more detailed information about database access controls and how to restrict access see RBAC documentation.
3/5단계. Redis 사용자 생성#
Each Redis user must be protected by a strong password. We recommend using OpenSSL to generate passwords:
openssl rand -hex 32Create a
users.aclfile, which defines users for your Redis deployment, passwords required to log in as a given user, and sets of ACL rules. Redis allows you to provide passwords in plaintext or an SHA256 hash. We strongly recommend using an SHA256 hash instead of plaintext passwords.You can use the command below to generate an SHA256 hash from a password.
echo -n STRONG_GENERATED_PASSWORD | sha256sumuser alice on #57639ed88a85996453555f22f5aa4147b4c9614056585d931e5d976f610651e9 allcommands allkeys user default offFor more ACL examples refer to the Redis documentation.
4/5단계. 상호 TLS 설정#
Teleport uses mutual TLS authentication with self-hosted databases. These databases must be able to verify certificates presented by the Teleport Database Service. Self-hosted databases also need a certificate/key pair that Teleport can verify.
By default, the Teleport Database Service trusts certificates issued by a certificate authority managed by the Teleport Auth Service. You can either:
- Configure your self-hosted database to trust this CA, and instruct Teleport to issue a certificate for the database to present to the Teleport Database Service.
- Configure the Database Service to trust a custom CA.
Redis 서버에서 상호 TLS를 활성화하려면 이 파일들이 필요합니다.
생성된 시크릿을 사용하여
redis.conf구성 파일에서 상호 TLS를 활성화하고 데이터베이스를 재시작합니다:tls-port 6379 port 0 aclfile /path/to/users.acl tls-ca-cert-file /path/to/server.cas tls-cert-file /path/to/server.crt tls-key-file /path/to/server.key tls-protocols "TLSv1.2 TLSv1.3"상호 TLS가 활성화되면 유효한 클라이언트 인증서 없이는 더 이상 클러스터에 연결할 수 없습니다.
tls-auth-clients optional설정을 사용하면 인증서를 제공하지 않는 클라이언트의 연결을 허용할 수 있습니다.자세한 내용은 Redis 문서의 TLS 지원을 참조하십시오.
5/5단계. 연결#
Log into your Teleport cluster and see available databases:
To connect to a particular database instance:
$ tsh db connect example-redisYou can optionally specify the database user to use by default when connecting to the database instance:
$ tsh db connect --db-user=alice example-redisIf flag
--db-useris not provided, Teleport logs in as thedefaultuser.Now you can log in as the previously created user using the below command:
AUTH alice STRONG_GENERATED_PASSWORDTo log out of the database and remove credentials:
# Remove credentials for a particular database instance. $ tsh db logout example-redis # Remove credentials for all database instances. $ tsh db logout지원되는 Redis 명령어#
스탠드얼론 모드의 Redis는 아래 명령어를 지원하지 않습니다. 나열된 명령어 중 하나가 호출되면 Teleport는
오류를 반환합니다.ERR Teleport: not supported by TeleportHELLOPUNSUBSCRIBESSUBSCRIBESUNSUBSCRIBE
다음 단계#
-
Learn how to restrict access to certain users and databases.
-
View the High Availability (HA) guide.
-
Take a look at the YAML configuration reference.
-
See the full CLI reference.
-
