gravitational / teleport

The easiest, and most secure way to access and protect all of your infrastructure.
https://goteleport.com
GNU Affero General Public License v3.0
17.69k stars 1.77k forks source link

Teleport to MongoDB Replicaset Architecture #49450

Open kachi-app opened 4 days ago

kachi-app commented 4 days ago

Background: I deployed Teleport and MongoDB through Helm Charts. Here the config i used to deploy: Teleport Kube Agent

apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: teleport-kube-agent
spec:
  interval: 5m
  values:
    roles: app,db
    joinParams:
      method: "kubernetes"
      tokenName: "provision-token"
    databases:
      - name: "mongodb-main"
        protocol: "mongodb"
        uri: "mongodb://kachi.example.com:27017,kachi.example.com:27017/?replicaSet=rs0"
        description: "Proxy to MongoDB Main Service"
        tls:
          mode: insecure
        admin_user:
          name: "teleport-admin"
        static_labels:
          type: database

Teleport Role

apiVersion: resources.teleport.dev/v1
kind: TeleportRoleV7
metadata:
  name: db-admin
spec:
  options:
    # create_db_user_mode enables automatic user provisioning for matching databases
    create_db_user_mode: keep
  allow:
    db_labels:
      '*': '*'
    db_names:
      - "*"
    db_roles:
      - "{{internal.db_roles}}"
      - "{{external.db_roles}}"

proxyListenerMode: multiplex chartMode: gcp MongoDB: tls disabled

I am able to access the mongodb using mongosh "mongodb://kachi.example.com:27017", also through port forwarding using kubectl port-forward However failed when proxying through teleport, by running

tsh db connect mongodb-main

or

tsh proxy db mongodb-main --tunnel --insecure --db-name kachi --port 27017
mongosh "mongodb://kachi.example.com:27017?serverSelectionTimeoutMS=60000"

Please note: I have read the documentation below few times:

Expected behavior: tsh proxy / tsh db connect should be able to connect to mongodb

Current behavior:

MongoServerSelectionError: your Teleport role requires automatic database user provisioning but an attempt to activate database user "kachi-app" failed due to the following error: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: kachi.example.com:27017, Type: Unknown, Last error: EOF }, { Addr: kachi.example.com:27017, Type: Unknown, Last error: EOF }, ] }

Bug details: