'2024/05'에 해당되는 글 2건

  1. 2024.05.07 postgres 특정테이블 권한설정
  2. 2024.05.03 mongoDB 사용자->특정collection 허용.



CREATE USER otheruser WITH PASSWORD 'password';


GRANT INSERT, UPDATE, DELETE ON othertable TO otheruser;

이렇게만 하면, 기존 사용자는 그대로 crud가 가능한 상태에서,
새로운 특정사용자에게 othertable 특정테이블만  권한을 주게된다. 


(확인)

SELECT grantee, privilege_type
FROM information_schema.table_privileges
WHERE table_name='mytable';

Posted by yongary
,

. 특정 컬렉션에 대한 접근 제한 설정

MongoDB에서는 특정 컬렉션에 직접적으로 접근을 제한하는 내장 기능을 제공하지 않습니다. 하지만, 역할 기반의 접근 제어(Role-Based Access Control, RBAC)를 사용하여 사용자 정의 역할을 생성하고, 이 역할을 통해 특정 컬렉션에 대한 접근을 제어할 수 있습니다.

먼저, mydatabase 데이터베이스에서 사용자 정의 역할을 생성합니다.

 

use mydatabase
db.createRole({
  role: "collectionReadWrite",
  privileges: [
    { resource: { db: "mydatabase", collection: "mycollection" }, actions: ["find", "update", "insert", "remove"] }
  ],
  roles: []
})

 

그런 다음, 이 역할을 사용자에게 할당합니다

 

db.updateUser("myUser", {
  roles: [
    { role: "collectionReadWrite", db: "mydatabase" }
  ]
})

 

 

======== 사전에 mongoDB에 사용자가 설정되지 않았다면 다음스텝 필요==========

1. MongoDB 인증 활성화

먼저 MongoDB 서버에서 인증을 활성화해야 합니다. 이는 위에서 설명한

 

mongod.conf 파일을 편집하여 security.authorization 옵션을 enabled로 설정함으로써 이루어집니다. 서버 재시작 후 인증이 필요하게 됩니다.

 

security:
  authorization: enabled

 

2. 관리자 생성

$ mongo

> use admin
> db.createUser({
  user: "admin",
  pwd: "password",
  roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
})

 

==> 모든 db에 비번에 필요할듯함. 

 

 

2.1 위에서 설명한 사용자 생성.

3. Spring Boot 애플리케이션 설정 변경

기존에 인증 없이 연결하던 Spring Boot 애플리케이션의 MongoDB 연결 설정을 업데이트하여 사용자 이름과 비밀번호를 포함하도록 해야 합니다. application.properties 또는 application.yml 파일에서 MongoDB 연결 URI를 다음과 같이 수정합니다:

 

# application.properties
spring.data.mongodb.uri=mongodb://username:password@host:port/database

Posted by yongary
,