Skip to content

Commit 52c8f75

Browse files
committed
Check sid existence in ACL operation
1 parent 79c5b8f commit 52c8f75

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ydb/core/tx/schemeshard/schemeshard__operation_modify_acl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ class TModifyACL: public TSubOperationBase {
5151
return result;
5252
}
5353

54+
if (acl) {
55+
NACLib::TDiffACL diffACL(acl);
56+
for (const NACLibProto::TDiffACE& diffACE : diffACL.GetDiffACE()) {
57+
if (static_cast<NACLib::EDiffType>(diffACE.GetDiffType()) == NACLib::EDiffType::Add) {
58+
if (!context.SS->LoginProvider.Sids.contains(diffACE.GetACE().GetSID())) {
59+
result->SetError(NKikimrScheme::StatusPreconditionFailed, "Sid not found");
60+
return result;
61+
}
62+
} // remove diff type is allowed in any case
63+
}
64+
}
65+
if (owner) {
66+
if (!context.SS->LoginProvider.Sids.contains(owner)) {
67+
result->SetError(NKikimrScheme::StatusPreconditionFailed, "Sid not found");
68+
return result;
69+
}
70+
}
71+
5472
THashSet<TPathId> subTree;
5573
if (acl || (owner && path.Base()->IsTable())) {
5674
subTree = context.SS->ListSubTree(path.Base()->PathId, context.Ctx);

ydb/core/tx/schemeshard/ut_login/ut_login.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
9191
TTestEnv env(runtime);
9292
ui64 txId = 100;
9393
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
94+
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user2", "password2");
9495
auto resultLogin = Login(runtime, "user1", "password1");
9596
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "");
9697

@@ -150,6 +151,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
150151
TTestEnv env(runtime);
151152
ui64 txId = 100;
152153
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
154+
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user2", "password2");
153155
auto resultLogin = Login(runtime, "user1", "password1");
154156
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "");
155157

@@ -222,11 +224,38 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
222224
}
223225
}
224226

227+
Y_UNIT_TEST(AddAccess_NonExisting) {
228+
TTestBasicRuntime runtime;
229+
TTestEnv env(runtime);
230+
ui64 txId = 100;
231+
232+
AsyncMkDir(runtime, ++txId, "/MyRoot", "Dir1");
233+
TestModificationResult(runtime, txId, NKikimrScheme::StatusAccepted);
234+
235+
{
236+
NACLib::TDiffACL diffACL;
237+
diffACL.AddAccess(NACLib::EAccessType::Allow, NACLib::GenericUse, "user1");
238+
AsyncModifyACL(runtime, ++txId, "/MyRoot", "Dir1", diffACL.SerializeAsString(), "");
239+
TestModificationResult(runtime, txId, NKikimrScheme::StatusPreconditionFailed);
240+
}
241+
242+
{
243+
AsyncModifyACL(runtime, ++txId, "/MyRoot", "Dir1", NACLib::TDiffACL{}.SerializeAsString(), "user1");
244+
TestModificationResult(runtime, txId, NKikimrScheme::StatusPreconditionFailed);
245+
}
246+
247+
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
248+
249+
TestDescribeResult(DescribePath(runtime, "/MyRoot/Dir1"),
250+
{NLs::HasNoRight("+U:user1"), NLs::HasNoEffectiveRight("+U:user1"), NLs::HasOwner("root@builtin")});
251+
}
252+
225253
Y_UNIT_TEST(RemoveLogin_Owner) {
226254
TTestBasicRuntime runtime;
227255
TTestEnv env(runtime);
228256
ui64 txId = 100;
229257
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
258+
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user2", "password2");
230259
auto resultLogin = Login(runtime, "user1", "password1");
231260
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "");
232261

0 commit comments

Comments
 (0)