Role-Based Access Control
MongoDB, BUILT-IN, ROLES, DETA, hai — read, readWrite (DATABASE-SPECIFIC), aur, dbAdmin, userAdmin (ADMINISTRATIVE, TASKS, ke, liye). CUSTOM, ROLES, BHI, banaye, ja, sakte, HAIN, VERY, SPECIFIC, PERMISSIONS, ke, liye.
"PRINCIPLE, OF, LEAST, PRIVILEGE" FOLLOW, karna, CHAHIYE — HAR, USER/APPLICATION, ko, SIRF, UTNI, PERMISSIONS, DENI, CHAHIYE, JITNI, ZAROORI, HAI, "root" YA, ADMIN, ROLES, EVERYWHERE, USE, karna, RISKY, hai.
// readWrite role, sirf, EK, specific, database, PAR:
db.createUser({
user: "appUser",
pwd: "appPassword",
roles: [{ role: "readWrite", db: "myApp" }]
});
// Read-only user, reporting, ke, liye:
db.createUser({
user: "reportUser",
pwd: "reportPassword",
roles: [{ role: "read", db: "myApp" }]
});- RBAC = users, ko, roles, assign, kiye, jaate, hain, jo, permissions, DEFINE, karte, hain
- Built-in roles: read, readWrite, dbAdmin, userAdmin — custom, roles, bhi, possible
- "Principle of least privilege" — jitni, zaroorat, utni, hi, permission
Kuch, roles, (jaise, readWrite) EK, SPECIFIC, database, tak, LIMITED, hote, hain. Cluster-wide, roles, (jaise, clusterAdmin) POORE, deployment, PAR, apply, hote, HAIN — replica, set, ya, sharded, cluster, KO, MANAGE, karne, ke, liye.
createRole(), se, EK, custom, role, banaya, ja, sakta hai, jisme, EXACTLY, WOHI, actions, (jaise, sirf, find, sirf, insert) allowed, hain, jo, ZAROORI, hain — built-in, roles, se, MORE, granular, control.
db.createRole({
role: "readOnlyOrders",
privileges: [{ resource: { db: "myApp", collection: "orders" }, actions: ["find"] }],
roles: []
});