Skip to content

Commit e0d8588

Browse files
authored
[fix](auth)Privatize the authentication methods in the Auth class to avoid being called incorrectly (#48033)
### What problem does this PR solve? - Privatize the authentication methods in the Auth class to avoid being called incorrectly - Change from calling Auth class to calling accessManager - Fix `InternalAccessController.checkCloudPriv` calling the wrong method
1 parent 81c8d3d commit e0d8588

19 files changed

Lines changed: 66 additions & 30 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/ShowClusterStmt.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public SelectStmt toSelectStmt(Analyzer analyzer) throws AnalysisException {
7272
public void analyze(Analyzer analyzer) throws AnalysisException {
7373
if (Config.isNotCloudMode()) {
7474
// just user admin
75-
if (!Env.getCurrentEnv().getAuth().checkGlobalPriv(ConnectContext.get().getCurrentUserIdentity(),
75+
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get().getCurrentUserIdentity(),
7676
PrivPredicate.of(PrivBitSet.of(Privilege.ADMIN_PRIV, Privilege.NODE_PRIV), Operator.OR))) {
7777
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
7878
}

‎fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/doris/RangerDorisAccessController.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,16 @@ private boolean checkColPrivInternal(UserIdentity currentUser, String ctl, Strin
243243
}
244244

245245
@Override
246-
public boolean checkCloudPriv(UserIdentity currentUser, String resourceName,
246+
public boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
247247
PrivPredicate wanted, ResourceTypeEnum type) {
248248
return false;
249249
}
250250

251+
@Override
252+
public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
253+
return false;
254+
}
255+
251256
@Override
252257
public boolean checkResourcePriv(UserIdentity currentUser, String resourceName, PrivPredicate wanted) {
253258
PrivBitSet checkedPrivs = PrivBitSet.of();

‎fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/hive/RangerHiveAccessController.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,16 @@ public void checkColsPriv(UserIdentity currentUser, String ctl, String db, Strin
177177
}
178178

179179
@Override
180-
public boolean checkCloudPriv(UserIdentity currentUser, String resourceName,
180+
public boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
181181
PrivPredicate wanted, ResourceTypeEnum type) {
182182
return false;
183183
}
184184

185+
@Override
186+
public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
187+
return false;
188+
}
189+
185190
@Override
186191
public boolean checkResourcePriv(UserIdentity currentUser, String resourceName, PrivPredicate wanted) {
187192
return false;

‎fe/fe-core/src/main/java/org/apache/doris/cloud/analysis/UseCloudClusterStmt.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
8989
if (Strings.isNullOrEmpty(cluster)) {
9090
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_CLUSTER_ERROR);
9191
}
92-
if (!Env.getCurrentEnv().getAuth().checkCloudPriv(ConnectContext.get().getCurrentUserIdentity(),
92+
if (!Env.getCurrentEnv().getAccessManager().checkCloudPriv(ConnectContext.get().getCurrentUserIdentity(),
9393
cluster, PrivPredicate.USAGE, ResourceTypeEnum.CLUSTER)) {
9494
throw new AnalysisException("USAGE denied to user '" + ConnectContext.get().getQualifiedUser()
9595
+ "'@'" + ConnectContext.get().getRemoteIP()

‎fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnv.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public long saveTransactionState(CountingDataOutputStream dos, long checksum) th
273273

274274
public void checkCloudClusterPriv(String clusterName) throws DdlException {
275275
// check resource usage privilege
276-
if (!Env.getCurrentEnv().getAuth().checkCloudPriv(ConnectContext.get().getCurrentUserIdentity(),
276+
if (!Env.getCurrentEnv().getAccessManager().checkCloudPriv(ConnectContext.get().getCurrentUserIdentity(),
277277
clusterName, PrivPredicate.USAGE, ResourceTypeEnum.CLUSTER)) {
278278
throw new DdlException("USAGE denied to user "
279279
+ ConnectContext.get().getQualifiedUser() + "'@'" + ConnectContext.get().getRemoteIP()

‎fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,7 +2754,7 @@ private boolean createOlapTable(Database db, CreateTableStmt stmt) throws UserEx
27542754
Pair<String, String> storageVaultInfoPair = PropertyAnalyzer.analyzeStorageVault(properties);
27552755

27562756
// Check if user has storage vault usage privilege
2757-
if (ConnectContext.get() != null && !env.getAuth()
2757+
if (ConnectContext.get() != null && !env.getAccessManager()
27582758
.checkStorageVaultPriv(ctx.getCurrentUserIdentity(),
27592759
storageVaultInfoPair.first, PrivPredicate.USAGE)) {
27602760
throw new DdlException("USAGE denied to user '" + ConnectContext.get().getQualifiedUser()

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/AccessControllerManager.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ public boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
267267
return defaultAccessController.checkCloudPriv(currentUser, cloudName, wanted, type);
268268
}
269269

270+
public boolean checkStorageVaultPriv(ConnectContext ctx, String storageVaultName, PrivPredicate wanted) {
271+
return checkStorageVaultPriv(ctx.getCurrentUserIdentity(), storageVaultName, wanted);
272+
}
273+
274+
public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
275+
return defaultAccessController.checkStorageVaultPriv(currentUser, storageVaultName, wanted);
276+
}
270277

271278
public boolean checkWorkloadGroupPriv(ConnectContext ctx, String workloadGroupName, PrivPredicate wanted) {
272279
return checkWorkloadGroupPriv(ctx.getCurrentUserIdentity(), workloadGroupName, wanted);

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/Auth.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public List<UserIdentity> getUserIdentityForLdap(String remoteUser, String remot
266266
}
267267

268268
// ==== Global ====
269-
public boolean checkGlobalPriv(UserIdentity currentUser, PrivPredicate wanted) {
269+
protected boolean checkGlobalPriv(UserIdentity currentUser, PrivPredicate wanted) {
270270
readLock();
271271
try {
272272
Set<Role> roles = getRolesByUserWithLdap(currentUser);
@@ -282,7 +282,7 @@ public boolean checkGlobalPriv(UserIdentity currentUser, PrivPredicate wanted) {
282282
}
283283

284284
// ==== Catalog ====
285-
public boolean checkCtlPriv(UserIdentity currentUser, String ctl, PrivPredicate wanted) {
285+
protected boolean checkCtlPriv(UserIdentity currentUser, String ctl, PrivPredicate wanted) {
286286
if (wanted.getPrivs().containsNodePriv()) {
287287
if (LOG.isDebugEnabled()) {
288288
LOG.debug("should not check NODE priv in catalog level. user: {}, catalog: {}",
@@ -305,7 +305,7 @@ public boolean checkCtlPriv(UserIdentity currentUser, String ctl, PrivPredicate
305305
}
306306

307307
// ==== Database ====
308-
public boolean checkDbPriv(UserIdentity currentUser, String ctl, String db, PrivPredicate wanted) {
308+
protected boolean checkDbPriv(UserIdentity currentUser, String ctl, String db, PrivPredicate wanted) {
309309
if (wanted.getPrivs().containsNodePriv()) {
310310
if (LOG.isDebugEnabled()) {
311311
LOG.debug("should not check NODE priv in Database level. user: {}, db: {}",
@@ -329,7 +329,7 @@ public boolean checkDbPriv(UserIdentity currentUser, String ctl, String db, Priv
329329
}
330330

331331
// ==== Table ====
332-
public boolean checkTblPriv(UserIdentity currentUser, String ctl, String db, String tbl, PrivPredicate wanted) {
332+
protected boolean checkTblPriv(UserIdentity currentUser, String ctl, String db, String tbl, PrivPredicate wanted) {
333333
if (wanted.getPrivs().containsNodePriv()) {
334334
if (LOG.isDebugEnabled()) {
335335
LOG.debug("should check NODE priv in GLOBAL level. user: {}, db: {}, tbl: {}", currentUser, db, tbl);
@@ -353,7 +353,7 @@ public boolean checkTblPriv(UserIdentity currentUser, String ctl, String db, Str
353353
// ==== Column ====
354354
// The reason why this method throws an exception instead of returning a boolean is to
355355
// indicate which col does not have permission
356-
public void checkColsPriv(UserIdentity currentUser, String ctl, String db, String tbl, Set<String> cols,
356+
protected void checkColsPriv(UserIdentity currentUser, String ctl, String db, String tbl, Set<String> cols,
357357
PrivPredicate wanted) throws AuthorizationException {
358358
Set<Role> roles = getRolesByUserWithLdap(currentUser);
359359
for (String col : cols) {
@@ -376,7 +376,7 @@ private boolean checkColPriv(String ctl, String db, String tbl,
376376
}
377377

378378
// ==== Resource ====
379-
public boolean checkResourcePriv(UserIdentity currentUser, String resourceName, PrivPredicate wanted) {
379+
protected boolean checkResourcePriv(UserIdentity currentUser, String resourceName, PrivPredicate wanted) {
380380
readLock();
381381
try {
382382
Set<Role> roles = getRolesByUserWithLdap(currentUser);
@@ -392,7 +392,7 @@ public boolean checkResourcePriv(UserIdentity currentUser, String resourceName,
392392
}
393393

394394
// ==== Storage Vault ====
395-
public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
395+
protected boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
396396
readLock();
397397
try {
398398
Set<Role> roles = getRolesByUserWithLdap(currentUser);
@@ -408,7 +408,7 @@ public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVau
408408
}
409409

410410
// ==== Workload Group ====
411-
public boolean checkWorkloadGroupPriv(UserIdentity currentUser, String workloadGroupName, PrivPredicate wanted) {
411+
protected boolean checkWorkloadGroupPriv(UserIdentity currentUser, String workloadGroupName, PrivPredicate wanted) {
412412
readLock();
413413
try {
414414
// currently stream load not support ip based auth, so normal should not auth temporary
@@ -430,7 +430,7 @@ public boolean checkWorkloadGroupPriv(UserIdentity currentUser, String workloadG
430430
}
431431

432432
// ==== cloud ====
433-
public boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
433+
protected boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
434434
PrivPredicate wanted, ResourceTypeEnum type) {
435435
readLock();
436436
try {

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/CatalogAccessController.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ void checkColsPriv(UserIdentity currentUser, String ctl, String db, String tbl,
7878
Set<String> cols, PrivPredicate wanted) throws AuthorizationException;
7979

8080
// ==== Cloud ====
81-
boolean checkCloudPriv(UserIdentity currentUser, String resourceName, PrivPredicate wanted, ResourceTypeEnum type);
81+
boolean checkCloudPriv(UserIdentity currentUser, String cloudName, PrivPredicate wanted, ResourceTypeEnum type);
82+
83+
boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted);
8284

8385
Optional<DataMaskPolicy> evalDataMaskPolicy(UserIdentity currentUser, String ctl, String db, String tbl,
8486
String col);

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/InternalAccessController.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ public boolean checkWorkloadGroupPriv(UserIdentity currentUser, String workloadG
7070
}
7171

7272
@Override
73-
public boolean checkCloudPriv(UserIdentity currentUser, String resourceName,
73+
public boolean checkCloudPriv(UserIdentity currentUser, String cloudName,
7474
PrivPredicate wanted, ResourceTypeEnum type) {
75-
return auth.checkResourcePriv(currentUser, resourceName, wanted);
75+
return auth.checkCloudPriv(currentUser, cloudName, wanted, type);
76+
}
77+
78+
@Override
79+
public boolean checkStorageVaultPriv(UserIdentity currentUser, String storageVaultName, PrivPredicate wanted) {
80+
return auth.checkStorageVaultPriv(currentUser, storageVaultName, wanted);
7681
}
7782

7883
@Override

0 commit comments

Comments
 (0)