forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix](auth)Http api check auth (apache#40688)
- add auth for `api/meta/namespaces/internal/databases` - add auth for `api/show_table_data`
- Loading branch information
Showing
9 changed files
with
395 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
regression-test/suites/auth_p0/test_http_meta_databases_auth.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import org.junit.Assert; | ||
|
||
suite("test_http_meta_databases_auth","p0,auth,nonConcurrent") { | ||
String suiteName = "test_http_meta_databases_auth" | ||
String dbName = context.config.getDbNameByFile(context.file) | ||
String tableName = "${suiteName}_table" | ||
String user = "${suiteName}_user" | ||
String pwd = 'C123_567p' | ||
try_sql("DROP USER ${user}") | ||
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'""" | ||
try { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "true"); """ | ||
def getDatabases = { check_func -> | ||
httpTest { | ||
basicAuthorization "${user}","${pwd}" | ||
endpoint "${context.config.feHttpAddress}" | ||
uri "/rest/v2/api/meta/namespaces/default_cluster/databases" | ||
op "get" | ||
check check_func | ||
} | ||
} | ||
|
||
getDatabases.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertFalse("${body}".contains("${dbName}")) | ||
} | ||
|
||
sql """grant select_priv on ${dbName} to ${user}""" | ||
|
||
getDatabases.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertTrue("${body}".contains("${dbName}")) | ||
} | ||
|
||
try_sql("DROP USER ${user}") | ||
} finally { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "false"); """ | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
regression-test/suites/auth_p0/test_http_meta_tables_auth.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import org.junit.Assert; | ||
|
||
suite("test_http_meta_tables_auth","p0,auth,nonConcurrent") { | ||
String suiteName = "test_http_meta_tables_auth" | ||
String dbName = context.config.getDbNameByFile(context.file) | ||
String tableName = "${suiteName}_table" | ||
String user = "${suiteName}_user" | ||
String pwd = 'C123_567p' | ||
try_sql("DROP USER ${user}") | ||
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'""" | ||
sql """drop table if exists `${tableName}`""" | ||
sql """ | ||
CREATE TABLE `${tableName}` ( | ||
`k1` int, | ||
`k2` int | ||
) ENGINE=OLAP | ||
DISTRIBUTED BY random BUCKETS auto | ||
PROPERTIES ('replication_num' = '1') ; | ||
""" | ||
try { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "true"); """ | ||
def getTables = { check_func -> | ||
httpTest { | ||
basicAuthorization "${user}","${pwd}" | ||
endpoint "${context.config.feHttpAddress}" | ||
uri "/rest/v2/api/meta/namespaces/default_cluster/databases/${dbName}/tables" | ||
op "get" | ||
check check_func | ||
} | ||
} | ||
|
||
getTables.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertFalse("${body}".contains("${tableName}")) | ||
} | ||
|
||
sql """grant select_priv on ${dbName}.${tableName} to ${user}""" | ||
|
||
getTables.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertTrue("${body}".contains("${tableName}")) | ||
} | ||
|
||
sql """drop table if exists `${tableName}`""" | ||
try_sql("DROP USER ${user}") | ||
} finally { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "false"); """ | ||
} | ||
|
||
|
||
} |
69 changes: 69 additions & 0 deletions
69
regression-test/suites/auth_p0/test_http_meta_tables_schema_auth.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import org.junit.Assert; | ||
|
||
suite("test_http_meta_tables_schema_auth","p0,auth,nonConcurrent") { | ||
String suiteName = "test_http_meta_tables_schema_auth" | ||
String dbName = context.config.getDbNameByFile(context.file) | ||
String tableName = "${suiteName}_table" | ||
String user = "${suiteName}_user" | ||
String pwd = 'C123_567p' | ||
try_sql("DROP USER ${user}") | ||
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'""" | ||
sql """drop table if exists `${tableName}`""" | ||
sql """ | ||
CREATE TABLE `${tableName}` ( | ||
`k1` int, | ||
`k2` int | ||
) ENGINE=OLAP | ||
DISTRIBUTED BY random BUCKETS auto | ||
PROPERTIES ('replication_num' = '1') ; | ||
""" | ||
|
||
try { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "true"); """ | ||
def getSchema = { check_func -> | ||
httpTest { | ||
basicAuthorization "${user}","${pwd}" | ||
endpoint "${context.config.feHttpAddress}" | ||
uri "/rest/v2/api/meta/namespaces/default_cluster/databases/${dbName}/tables/${tableName}/schema" | ||
op "get" | ||
check check_func | ||
} | ||
} | ||
|
||
getSchema.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertTrue("${body}".contains("401")) | ||
} | ||
|
||
sql """grant select_priv on ${dbName}.${tableName} to ${user}""" | ||
|
||
getSchema.call() { | ||
respCode, body -> | ||
log.info("body:${body}") | ||
assertTrue("${body}".contains("${tableName}")) | ||
} | ||
|
||
sql """drop table if exists `${tableName}`""" | ||
try_sql("DROP USER ${user}") | ||
} finally { | ||
sql """ ADMIN SET ALL FRONTENDS CONFIG ("enable_all_http_auth" = "false"); """ | ||
} | ||
} |
Oops, something went wrong.