Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic access authentication for http/https #31648

Merged
merged 19 commits into from
Dec 1, 2021
Merged

basic access authentication for http/https #31648

merged 19 commits into from
Dec 1, 2021

Conversation

michael1589
Copy link
Contributor

@michael1589 michael1589 commented Nov 23, 2021

Changelog category:

  • New Feature

Changelog entry:

  • Basic access authentication for http/url functions

Detailed description / Documentation draft:

issue here: Basic Auth for http/url functions not supported

Basic auth for http/https is not supported before 21.11. You can see this error such like:

root@b0ebdb3a98f3:/# clickhouse-client --query="select * FROM url('https://guest:guest@jigsaw.w3.org/HTTP/Basic/','RawBLOB', 'a String');"
Received exception from server (version 21.11.3):
Code: 86. DB::Exception: Received from localhost:9000. DB::Exception: Received error from remote server /HTTP/Basic/. HTTP status code: 401 , body: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
               "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <title>Unauthorized</title>
</head>
<body>
<h1>Unauthorized access</h1><p>You are denied access to this resource.</body>
</html>: While executing URL. (RECEIVED_ERROR_FROM_REMOTE_IO_SERVER)
(query: select * FROM url('https://guest:guest@jigsaw.w3.org/HTTP/Basic/','RawBLOB', 'a String');)

Now we can access a format avro schema registry url like this:

peng-liudemacbook-pro.local :) select * from url('https://guest:guest@127.0.0.1:32345', CSV, 'word String, value UInt64');

SELECT *
FROM url('http://guest:guest@127.0.0.1:32345', CSV, 'word String, value UInt64')

Query id: 63625678-f39b-45c6-9379-09589168f940

┌─word──┬─value─┐
│ Hello │     1 │
│ World │     2 │
└───────┴───────┘

2 rows in set. Elapsed: 0.007 sec.

Basic auth for http/https is supported now.
HTTP Authentication: Basic and Digest Access Authentication

@robot-clickhouse robot-clickhouse added doc-alert pr-feature Pull request with new product feature labels Nov 23, 2021
@CLAassistant
Copy link

CLAassistant commented Nov 23, 2021

CLA assistant check
All committers have signed the CLA.

@kssenii kssenii self-assigned this Nov 23, 2021
src/Storages/StorageURL.cpp Outdated Show resolved Hide resolved
@@ -136,6 +148,7 @@ namespace
timeouts,
credentials,
context->getSettingsRef().max_http_get_redirects,
userInfo.length() == 0 ? Poco::Net::HTTPBasicCredentials{} : Poco::Net::HTTPBasicCredentials(ostr.str()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little strange, this is now not consistent with ReadWriteBufferFromHTTP constructor, I think build check will fail now.
Probably merged with master incorrectly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will chang to if...else...patten.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is what I meant, credentials arguments is passed 2 lines above. See

explicit ReadWriteBufferFromHTTP(
Poco::URI uri_,
const std::string & method_,
OutStreamCallback out_stream_callback_,
const ConnectionTimeouts & timeouts,
const Poco::Net::HTTPBasicCredentials & credentials_,
const UInt64 max_redirects = 0,
size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE,
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! It was a mistake of merge codes. I will push again.

@@ -0,0 +1 @@
select * FROM url('https://guest:guest@jigsaw.w3.org/HTTP/Basic/','RawBLOB', 'a String');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I believe this test will not work in ci from docker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Can the docker evironment access outside internet such as www.jigsaw.w3.org?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it will be ok, this is not good.
Can you please try to use http server in python in stateless tests like here https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/00646_url_engine.python?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will write a python script to run this test later.

@michael1589 michael1589 requested a review from kssenii November 28, 2021 13:24
@michael1589
Copy link
Contributor Author

/ClickHouse/src/Storages/StorageURL.cpp:135: if(n != std::string::npos)
This check fails, can you tell me why, pls?

Copy link
Member

@kssenii kssenii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ClickHouse/src/Storages/StorageURL.cpp:135: if(n != std::string::npos)
This check fails, can you tell me why, pls?

When you run this locally, did you try to print user_info string and see how it looks?

@@ -128,6 +128,17 @@ namespace

try
{
std::string userInfo = request_uri.getUserInfo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string userInfo = request_uri.getUserInfo();
std::string user_info = request_uri.getUserInfo();

Copy link
Contributor Author

@michael1589 michael1589 Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do. userInfo string is "guest:guest" when input "https://guest:guest@localhost:someport/".
By the way, FunctionalStatelessTestAsan fails(01622_defaults_for_url_engine.sh). I think that's none business with my commit.

2021-11-29 01:11:23 /usr/share/clickhouse-test/queries/0_stateless/01622_defaults_for_url_engine.sh: line 38: 67794 Killed timeout $TIMEOUT bash -c "thread1 $PORT" > /dev/null 2>&1
2021-11-29 01:11:23
2021-11-29 01:11:23 stdout:
2021-11-29 01:11:23 Ok
2021-11-29 01:11:23
2021-11-29 01:11:23
2021-11-29 01:11:23 Database: test_momh37

Copy link
Member

@kssenii kssenii Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks like it must work, are you sure that the problem is in if(n != std::string::npos)?

I think that's none business with my commit.

yes, it is not related.

Copy link
Contributor Author

@michael1589 michael1589 Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userInfo string stores "username:password" string. Now the condition judge( if(n != std::string::npos)) passed the test in the file src/Storages/StorageURL.cpp. I think the other fails are none business with my commit.

try
                    {
                        std::string userInfo = request_uri.getUserInfo();
                        if (!userInfo.empty())
                        {
                            std::size_t n = userInfo.find(":");
                            if(n != std::string::npos)
                            {
                                credentials.setUsername(userInfo.substr(0, n));
                                credentials.setPassword(userInfo.substr(n+1));
                            }
                        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ClickHouse/src/Storages/StorageURL.cpp:135: if(n != std::string::npos)

This is style check, I did not get about what check were you talking about, and thought you solution fails on this if statement check...

You are just missing a space between if and (

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also build check is related:

src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o.d -o src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o -c ../src/Storages/StorageURL.cpp
2021-11-29 07:13:08 /build/obj-x86_64-linux-gnu/../src/Storages/StorageURL.cpp:131:37: error: invalid case style for local variable 'userInfo' [readability-identifier-naming,-warnings-as-errors]
2021-11-29 07:13:08                         std::string userInfo = request_uri.getUserInfo();
2021-11-29 07:13:08                                     ^~~~~~~~
2021-11-29 07:13:08                                     user_info
2021-11-29 07:13:08 /build/obj-x86_64-linux-gnu/../src/Storages/StorageURL.cpp:134:59: error: 'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character [performance-faster-string-find,-warnings-as-errors]
2021-11-29 07:13:08                             std::size_t n = userInfo.find(":");
2021-11-29 07:13:08                                                           ^~~
2021-11-29 07:13:08                                                           ':'
2021-11-29 07:13:08 91053 warnings generated.

Other checks are not related.

@michael1589 michael1589 requested a review from kssenii November 30, 2021 06:00
@kssenii
Copy link
Member

kssenii commented Nov 30, 2021

Can you please fix build check, it is still broken

src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o.d -o src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o -c ../src/Storages/StorageURL.cpp
2021-11-30 08:16:47 /build/obj-x86_64-linux-gnu/../src/Storages/StorageURL.cpp:131:37: error: invalid case style for local variable 'userInfo' [readability-identifier-naming,-warnings-as-errors]
2021-11-30 08:16:47                         std::string userInfo = request_uri.getUserInfo();
2021-11-30 08:16:47                                     ^~~~~~~~
2021-11-30 08:16:47                                     user_info
2021-11-30 08:16:47 91052 warnings generated.

@michael1589
Copy link
Contributor Author

Can you please fix build check, it is still broken

src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o.d -o src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o -c ../src/Storages/StorageURL.cpp
2021-11-30 08:16:47 /build/obj-x86_64-linux-gnu/../src/Storages/StorageURL.cpp:131:37: error: invalid case style for local variable 'userInfo' [readability-identifier-naming,-warnings-as-errors]
2021-11-30 08:16:47                         std::string userInfo = request_uri.getUserInfo();
2021-11-30 08:16:47                                     ^~~~~~~~
2021-11-30 08:16:47                                     user_info
2021-11-30 08:16:47 91052 warnings generated.

Sorry, finished a few minutes ago!

@michael1589 michael1589 requested a review from kssenii December 1, 2021 01:23
@michael1589
Copy link
Contributor Author

ClickHouse Functional Stateless Tests fail (02098_date32_comparison | FAIL). I think this fail is none business with my commit. And ClickHouse Stress Test(Hung check failed/FLAKY). Can you give me more info pls?

@kssenii
Copy link
Member

kssenii commented Dec 1, 2021

Functional stateless tests (release, DatabaseReplicated) — fail: 1 -- not related to changes (02098_date32_comparison)
Stress test -- not related to changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants