감사쟁이야
감사쟁이의 성장기록
감사쟁이야
  • 분류 전체보기 (130)
    • Java-Spring (0)
    • ComputerScience (0)
    • Project (64)
      • TIL, WIL (57)
      • Project Retrospect (7)
    • Problem Solving (63)
    • Book Review (1)
    • Culture & Discovery (0)
    • Daily Log (2)

블로그 메뉴

  • 홈
  • 깃허브
  • 방명록
hELLO · Designed By 정상우.
감사쟁이야

감사쟁이의 성장기록

TIL(15) 21-10-06 : MongoDB Auth, API URL 컨벤션 완료
Project/TIL, WIL

TIL(15) 21-10-06 : MongoDB Auth, API URL 컨벤션 완료

2021. 10. 18. 13:25

Facts

✅ MongoDB 인증 처리

✅ API URL 수정 최종 점검

 

Findings

MongoDB Auth 기능 추가

계정 생성

  • 먼저, administrator 계정을 생성한다.
    • admin 내에서 앞으로 생성할 db와 user를 관리할 수 있는 administrator 계정을 생성한다.
      • user id : adminer
      • 기본db명 : admin
use admin 
db.createUser({ 
	user: "adminer", 
        pwd: "사용할 Password", // 사용할 password 
        roles: [{role: "userAdminAnyDatabase", db: "admin"}] 
 })
  • 새로운 계정 추가방법
    • admin db에 adminer계정으로 접속한 후에 새로운 db와 이를 사용할 계정 생성한다.
use admin 
db.auth("adminer", "password") // 접속 성공 시 1 출력 
use test_db // test db 생성  
db.createUser({ 
	user: "계정 이름", 
	pwd: "사용할 password", // 사용할 password 
        roles: [{role: "readWrite", db: "test_db"}] // test_db에 대한 readWrite 권한 부여 
})

 

Roles (권한)

  • Database Administration Roles
    • 'readWrite' : Provides all the privileges of the read role plus ability to modify data on all non-system collections and the system.js collection.
  • Database User Roles
    • 'dbAdmin' : Provides the ability to perform administrative tasks such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management.
    • 'dbOwner' : The database owner can perform any administrative action on the database. This role combines the privileges granted by the readWrite, dbAdmin and userAdmin roles.
    • 'userAdmin' : Provides the ability to create and modify roles and users on the current database. Since the userAdmin role allows users to grant any privilege to any user, including themselves, the role also indirectly

 

접속 방법

  • URL
mongodb://{account_id}:{password}@127.0.0.1
  • mongoDB 접속
mongo -u {account_id} -p {password}
  • robo3T 연결 방법
    • mongodb에서 사용할 db와 계정 생성 후 robo3t 접속
    • File > Connect > Create >Address : localhost / port: 27017Database: adminPassword: user password
      • [Connection 설정]
        Address : localhost / port: 27017
      • [Authentication 설정]
        Database: admin
        User Name: mongo db의 user name
        Password: user password
        Auth Mechanism: SCRAM-SHA-1

 

참고 자료

 

mongoDB admin 권한 설정방법 How to enable access control for mongo DB

** WARNING: Access control is not enabled for the database. ** Read and write access to data and configuration is unrestricted. 해결...

code.eoullim.me

 

Built-In Roles — MongoDB Manual

Docs Home → MongoDB ManualMongoDB grants access to data and commands through role-based authorization and provides built-in roles that provide the different levels of access commonly needed in a database system. You can additionally create user-defined r

docs.mongodb.com

 

'Project > TIL, WIL' 카테고리의 다른 글

TIL(17) 21-10-08 : 로그인 기능 구현  (0) 2021.10.18
TIL(16) 21-10-07 : why?를 하자  (0) 2021.10.18
TIL(14) 21-10-05 : 2차 프로젝트 시작, How to 협업 💡  (0) 2021.10.05
TIL(13) 21-10-04 : 피드백, 방향 잡기  (0) 2021.10.04
TIL(12) 21-10-01 : 1차 프로젝트 완료🚀 되돌아보기  (0) 2021.10.02
    'Project/TIL, WIL' 카테고리의 다른 글
    • TIL(17) 21-10-08 : 로그인 기능 구현
    • TIL(16) 21-10-07 : why?를 하자
    • TIL(14) 21-10-05 : 2차 프로젝트 시작, How to 협업 💡
    • TIL(13) 21-10-04 : 피드백, 방향 잡기
    감사쟁이야
    감사쟁이야
    sunzero0116@gmail.com

    티스토리툴바