일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 허리디스크
- 변태는
- open redirect
- Sequoia
- react
- XSS
- NUGU
- 취약점
- CryptoJS
- self-signed
- 채팅환전사기
- 거래사기
- Frida
- 모의해킹
- esbuild
- 보이스피싱 #대검찰청 #명의도용 #비밀번호 #계좌번호 #공공기관 #가짜검찰청
- 로맨스스캠
- 척추관협착증
- 많다..
- MongoDB #NoSQL #CreateUser #DropUser #mongod #mognod.conf
- 네이버카페
- ue4dumper
- Malware Sample
- intelmac
- ssrf
- 중고나라
- 안전결제
- speed-measure-webpack-plugin
- CJ대한통운 #쿠팡 #통관번호오류 #통관고유번호오류 #안주원팀장 #모건인베스트
- shell_gpt
- Today
- Total
annyoung
MongoDB 유저생성 및 데이터베이스 생성 본문
회사에서 맨날 MongoDB를 사용하고 있는데 설정한다고 구글 검색하기가 귀찮아서 따로 만들어봤다.
public으로 설정이 잘못되어 있어서 하마터면 털릴뻔했다 ㅡㅡ..
MongoDB port(27017)을 인바운드와 noauth로 열어주는 경우엔 잘못하면 털린다.
그렇다면 이 설정을 어떻게 피하냐면.. 다음과 같이 하면 된다.
몽고디비를 새로 설치한 후 초기 셋팅이라고 생각하면 된다.
1. 초기에는 authorization이 disabled 되어 있으므로 그냥 mongo 쉘 커맨드로 접속하면 된다.
mongo
2. admin DB를 생성하여 모든 DB에 접속할 권한을 준다.
use admin
db.createUser({ user: "<username>",
pwd: "<password>",
roles: [
"userAdminAnyDatabase",
"dbAdminAnyDatabase",
"readWriteAnyDatabase"
]
})
3. 다음은 사용자가 원하는 DB를 만들때 셋팅이다. (이 경우 해당 디비에만 권한을 받는다.)
use myDB
db.createUser({ user: "<username>",
pwd: "<password>",
roles: [
"dbAdmin",
"readWrite"
]
})
+ 사용자를 drop 시킬때 쓰는 명령이다. (거의 쓸일 없다)
use admin
db.dropUser("<username>")
4. 몽고로 쉘 커맨드로 접속하여 나오는 버전명을 보고 케이스를 나눠서 진행한다. (솔직히 2버전대 아니면 별 의미없는것 같다.)
Case1 : MongoDB shell version v4.0.4, MongoDB server version: 4.0.4
sudo vi /etc/mongod.conf
# mongod.conf
storage:
dbPath: /data/db
#dbPath: /var/lib/mongodb
# if you want to custom MongoDB Path, modify dbPath line.
journal:
enabled: true
net:
bindIp: 127.0.0.1
port: 27017
security:
authorization: "enabled"
#authorization: "disabled"
# if you want to disable authorization, uncomment disabled line.
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# If you use this timeZoneInfo, will be following your localtime
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# If path permission has root:root, executed user(general user) can't access that file.
# Check path's permission. it followed executed permission.
Case2 : MongoDB shell version v3.6.7, MongoDB server version: 3.6.5
sudo vi /etc/mongod.conf
# mongod.conf
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# If path permission has root:root, executed user(general user) can't access that file.
# Check path's permission. it followed executed permission.
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# If you use this timeZoneInfo, will be following your localtime
security:
authorization: "enabled"
#authorization: "disabled"
# if you want to disable authorization, uncomment disabled line.
이렇게 하고 robo로 접속 테스팅해본다.
참고로..bindIp를 걸어놓으면 로컬로 밖에 접속을 못하니 robo에서는 SSH 터널링을 통해 접속해야한다.
DB가 털리는 상황은 bindIp를 주석처리하고 authorization을 disabled하는 경우다. 올바른 설정을 위해선 bindIp를 걸어주거나 authorization을 enabled해준다. 둘중 하나만 설정되어 있다면 털릴 걱정 안해도 된다.
+ 참고 및 출처 : http://blog.freezner.com/archives/1040
'데이터베이스' 카테고리의 다른 글
mongodb combine two queries with aggregate (0) | 2022.01.25 |
---|---|
Install MongoDB + phpMongoDriver in Mac OSX High Sierra (0) | 2018.09.13 |
[mongodb] how to find dictionary not null (0) | 2018.04.30 |
mongodb not authorized? how to create database in mongodb (0) | 2018.04.18 |