Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Mongo Express connect to Mongodb via a service in Kubernetes does not require authentication? #1476

Open
tdtu98 opened this issue Mar 21, 2024 · 1 comment

Comments

@tdtu98
Copy link

tdtu98 commented Mar 21, 2024

In my project, I create a local k8s cluster using minikube. In this cluster, I deployed mongodb and mongo express with the configurations:

# mongo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
      - name: mongo
        image: arm64v8/mongo:latest
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INIT_ROOT_USERNAME
          value: admin
        - name: MONGO_INIT_ROOT_PASSWORD
          value: secret
---
apiVersion: v1
kind: Service
metadata: 
  name: mongodb-service
  labels:
    app: mongo
spec:
  selector:
    app: mongo
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017
# mongo-express.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
      - name: mongo-express
        image: arm64v8/mongo-express:latest
        ports:
        - containerPort: 8081
        env:
        - name: ME_CONFIG_MONGODB_URL
          value: "mongodb://mongodb-service:27017/"
---
apiVersion: v1
kind: Service
metadata: 
  name: mongo-express-service
spec:
  selector:
    app: mongo-express
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30000

The next commands are:

kubectl apply -f mongo.yaml
kubectl apply -f mongo-express.yaml
minikube service [mongo-express-service]

I successfully connected to the mongodb deployment via mongodb-service using ME_CONFIG_MONGODB_URL:

- name: ME_CONFIG_MONGODB_URL
          value: "mongodb://mongodb-service:27017/"

The problem is even though I do not set any environment variable for username and password related to mongodb in mongo-express config, I can still connect to it.

@xTudoS
Copy link
Contributor

xTudoS commented Mar 23, 2024

but isn't it the default ?

screenshot from readme.md

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants