Skip to content

Feature/s3 session token - #57850

Merged
Avogar merged 3 commits into
ClickHouse:masterfrom
shanielh:feature/s3-session-token
Dec 20, 2023
Merged

Avogar merged 3 commits into
ClickHouse:masterfrom
shanielh:feature/s3-session-token

Conversation

@shanielh

@shanielh shanielh commented Dec 14, 2023 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Allow passing optional SESSION_TOKEN to s3 table function

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)
  • I need help with ru documentation

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@CLAassistant

CLAassistant commented Dec 14, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@shanielh
shanielh marked this pull request as ready for review December 14, 2023 08:40
@Avogar Avogar added the can be tested Allows running workflows for external contributors label Dec 15, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-feature Pull request with new product feature label Dec 15, 2023
@robot-ch-test-poll4

robot-ch-test-poll4 commented Dec 15, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 5f38e1d with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker server and keeper imagesThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Docs checkThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Fast testsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success
Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure

@Avogar Avogar self-assigned this Dec 15, 2023
Comment thread src/IO/S3Common.cpp Resolved
Comment thread src/Storages/StorageS3.cpp Resolved
Comment thread src/Storages/StorageS3.cpp Resolved
Comment thread src/Storages/StorageS3.cpp Resolved
Comment thread src/TableFunctions/TableFunctionS3.h Resolved
Comment thread src/TableFunctions/TableFunctionS3.cpp Resolved
Comment thread src/TableFunctions/TableFunctionS3.cpp Resolved
Comment thread src/TableFunctions/TableFunctionS3.cpp Resolved
@Avogar

Avogar commented Dec 15, 2023

Copy link
Copy Markdown
Member

We should add a test for each new signatures with session_token, and a test with named collection containing session_token. Probably the best way is to add an integration test (see test test_storage_s3/test.py::test_signatures as an example). Not sure if it will be easy to test the real session token (can we setup it in minio that is used in integration tests?).

@shanielh
shanielh force-pushed the feature/s3-session-token branch from 4fb76af to 4c29544 Compare December 17, 2023 08:23
This sets the infrastructure of loading session_token and passing it directly
to all AWSCredentials instances that are created using the AuthSettings.

The default SESSION_TOKEN is set to an empty string as documented in AWS SDK
reference: https://sdk.amazonaws.com/cpp/api/0.12.9/d4/d27/class_aws_1_1_auth_1_1_a_w_s_credentials.html
@shanielh
shanielh force-pushed the feature/s3-session-token branch from 4c29544 to 8aa9c8f Compare December 17, 2023 08:29
@shanielh

shanielh commented Dec 17, 2023 •

Copy link
Copy Markdown
Contributor Author

We should add a test for each new signatures with session_token, and a test with named collection containing session_token. Probably the best way is to add an integration test (see test test_storage_s3/test.py::test_signatures as an example). Not sure if it will be easy to test the real session token (can we setup it in minio that is used in integration tests?).

Hi, Thanks for the review, I think I did everything except the tests 😄 , I didn't manage to run them locally, is there a guide somewhere so I can try to test that locally, even testing that a faulty session_token is passed should be sufficient, right?

edit: I've checked and it seems that MinIO doesn't support setting a session_token, these are all the environment variables that can be set in order to set the root credentials

@shanielh
shanielh requested a review from Avogar December 17, 2023 12:07
@Avogar

Avogar commented Dec 18, 2023

Copy link
Copy Markdown
Member

Is there a guide somewhere so I can try to test that locally

https://github.com/ClickHouse/ClickHouse/blob/master/tests/integration/README.md

even testing that a faulty session_token is passed should be sufficient, right?

Yes, even if MinIO doesn't support session_token, we should at least check that all new signatures with session_token works

@shanielh

Copy link
Copy Markdown
Contributor Author

https://github.com/ClickHouse/ClickHouse/blob/master/tests/integration/README.md

Any chance this works on Mac OS too?

Yes, even if MinIO doesn't support session_token, we should at least check that all new signatures with session_token works

👍 Will do.

@Avogar

Avogar commented Dec 18, 2023

Copy link
Copy Markdown
Member

Any chance this works on Mac OS too?

Don't know, sorry. You can try, if you will have any problems, you can share them here, I will ask my colleagues

@shanielh

shanielh commented Dec 18, 2023 •

Copy link
Copy Markdown
Contributor Author

Don't know, sorry. You can try, if you will have any problems, you can share them here, I will ask my colleagues

I'm getting the following error:

Can't start docker daemon, timeout exceeded.

Note:

  • I used some file for the odbc-bridge-binary since I'm not running on windows and I couldn't find the binary.
  • I had to add --platform linux/amd64 for the command to run since the clickhouse/integration-tests-runner image is not multi-platform compatible and I'm running on M1 processor
➜ ./runner --binary ../../build/programs/clickhouse --base-configs-dir ../../build/programs/server/ --odbc-bridge-binary ../../build/programs/CTestTestfile.cmake 'test_storage_s3 -ss'
2023-12-18 16:21:50,037 [ 42429 ] INFO : ClickHouse root is not set. Will use /Users/shanielharrar/Documents/GitHub/ClickHouse (runner:42, check_args_and_update_paths)
2023-12-18 16:21:50,037 [ 42429 ] INFO : Cases dir is not set. Will use /Users/shanielharrar/Documents/GitHub/ClickHouse/tests/integration (runner:90, check_args_and_update_paths)
2023-12-18 16:21:50,037 [ 42429 ] INFO : utils dir is not set. Will use /Users/shanielharrar/Documents/GitHub/ClickHouse/utils (runner:101, check_args_and_update_paths)
2023-12-18 16:21:50,037 [ 42429 ] INFO : base_configs_dir: /Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/server, binary: /Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/clickhouse, cases_dir: /Users/shanielharrar/Documents/GitHub/ClickHouse/tests/integration  (runner:103, check_args_and_update_paths)
clickhouse_integration_tests_volume
Running pytest container as: 'docker run --net=host -it --rm --name clickhouse_integration_tests_tknz6q --platform linux/amd64 --privileged --dns-search='.' --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/CTestTestfile.cmake:/clickhouse-odbc-bridge --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/clickhouse:/clickhouse --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/clickhouse-library-bridge:/clickhouse-library-bridge --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/server:/clickhouse-config --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/tests/integration:/ClickHouse/tests/integration --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/utils/backupview:/ClickHouse/utils/backupview --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/utils/grpc-client/pb2:/ClickHouse/utils/grpc-client/pb2 --volume=/run:/run/host:ro --volume=clickhouse_integration_tests_volume:/var/lib/docker   -e DOCKER_CLIENT_TIMEOUT=300 -e COMPOSE_HTTP_TIMEOUT=600  -e PYTHONUNBUFFERED=1 -e PYTEST_ADDOPTS=" 'test_storage_s3 -ss'   -vvv" clickhouse/integration-tests-runner:latest '.
Can't start docker daemon, timeout exceeded.
Traceback (most recent call last):
  File "/Users/shanielharrar/Documents/GitHub/ClickHouse/tests/integration/./runner", line 461, in <module>
    subprocess.check_call(cmd, shell=True)
  File "/opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'docker run --net=host -it --rm --name clickhouse_integration_tests_tknz6q --platform linux/amd64 --privileged --dns-search='.' --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/CTestTestfile.cmake:/clickhouse-odbc-bridge --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/clickhouse:/clickhouse --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/clickhouse-library-bridge:/clickhouse-library-bridge --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/build/programs/server:/clickhouse-config --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/tests/integration:/ClickHouse/tests/integration --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/utils/backupview:/ClickHouse/utils/backupview --volume=/Users/shanielharrar/Documents/GitHub/ClickHouse/utils/grpc-client/pb2:/ClickHouse/utils/grpc-client/pb2 --volume=/run:/run/host:ro --volume=clickhouse_integration_tests_volume:/var/lib/docker   -e DOCKER_CLIENT_TIMEOUT=300 -e COMPOSE_HTTP_TIMEOUT=600  -e PYTHONUNBUFFERED=1 -e PYTEST_ADDOPTS=" 'test_storage_s3 -ss'   -vvv" clickhouse/integration-tests-runner:lates

Edit: Anyway, I'm pushing the tests, it might run on the CI (?)

This can help users that want to pass temporary credentials that
issued by AWS in order to load data from S3 without changing
configuration or creating an IAM User.

Fixes ClickHouse#57848
@shanielh
shanielh force-pushed the feature/s3-session-token branch from 1b051d9 to afe6ff6 Compare December 19, 2023 06:06
@shanielh

shanielh commented Dec 19, 2023 •

Copy link
Copy Markdown
Contributor Author

Ok @Avogar Seems like I forgot to change the number of arguments validation, so I just fixed it and I hope the CI is going to pass, I'll be happy if you can take a look at it today. Thank you.

edit: One more fix to test_wrong_s3_syntax just pushed.

@shanielh
shanielh force-pushed the feature/s3-session-token branch from afe6ff6 to 5f38e1d Compare December 19, 2023 08:50
@UnamedRus

UnamedRus commented Feb 27, 2024 •

Copy link
Copy Markdown
Contributor

Despite, session_token is being pushed to auto credentials = Aws::Auth::AWSCredentials struct,
It's not being provided for client itself : client = S3::ClientFactory::instance().create(...

credentials.GetAWSSecretKey(),

However it should, there is separate overload of function for temporary creds with session_token:
https://github.com/ClickHouse/ClickHouse/blob/63b445799136fa9fc4be362df35181064692fb48/src/IO/S3/Client.cpp#L877C1-L877C34

So, s3 table function doesn't work with session_token currently.

@aser86

aser86 commented Mar 12, 2024

Copy link
Copy Markdown

Do a workaround exist to use session_token?

@UnamedRus

Copy link
Copy Markdown
Contributor

You can pass them as enviromental variable, so aws sdk directly consume it from here

@aser86

aser86 commented Mar 12, 2024

Copy link
Copy Markdown

You can pass them as enviromental variable, so aws sdk directly consume it from here

I passed the variables in this way:
export access_key_id=my_access_key_id
export secret_access_key=my_secret_access_key
export session_token=my_session_token

and copied the s3.xml to /opt/bitnami/clickhouse/etc/conf.d
but it doesn't work.

<clickhouse> <s3> <my_endpoint> <use_environment_credentials>true</use_environment_credentials> </my_endpoint> </s3> </clickhouse>

I get this error message:

SQL-Fehler [499] [07000]: Code: 499. DB::Exception: Access Denied: while reading key: bucket_name/5014bb6a-263e-425c-98c0-97615db3fe3e.csv, from bucket: bucket_name: The data format cannot be detected by the contents of the files. You can specify the format manually: (in file/uri... (S3_ERROR) (version 24.2.1.2248 (official build)) , server ClickHouseNode [uri=http://localhost:8123/default, options={use_server_time_zone=false,use_time_zone=false}]@-1974819624

achettyiitr added a commit to rudderlabs/rudder-server that referenced this pull request Sep 9, 2026
…py engine (#7353)

# Description

`ObjectStorageType` reports `S3` whenever `useRudderStorage` is set, so
`UseS3CopyEngineForLoading` engaged and `credentials()` then read
`accessKeyID` / `accessKey` off the destination config — which describes
the customer's bucket, not Rudder's. They came back empty and were
interpolated into the `s3` table function as `''`, which the server
rejects as an access error that says nothing about where the keys should
have come from.

### Rudder storage is not the only destination without keys

| destination shape | holds keys in config? |
| --- | --- |
| rudder storage (`useRudderStorage`) | no — Rudder's bucket, reached
via the SDK credential chain |
| role-based (`iamRoleARN`) | no |
| shared copy user (neither keys nor role) | no — keys live in the
server's env, see `misc.GetObjectStorageConfig` |
| static keys | yes |

All three keyless shapes authenticate through the AWS SDK credential
chain, which the `s3` table function cannot use because it only takes
literals.

### The fix

Mint the literals instead of enumerating which shape the destination is.
`whutils.GetTemporaryS3Cred` already covers every one of them, and
`redshift`, `snowflake` and `deltalake` all build their copy credentials
from it unconditionally for exactly this reason:

```go
case warehouseutils.S3:
	accessKeyID, secretAccessKey, sessionToken, err = ch.TemporaryS3Cred(&ch.Warehouse.Destination)
```

ClickHouse can do the same because the `s3` table function has taken a
session token as its **fourth positional argument since 24.1**
([ClickHouse/ClickHouse#57850](ClickHouse/ClickHouse#57850)):

```
s3(url, access_key_id, secret_access_key, session_token, format, structure, compression_method)
```

So the copy engine stays available to every aws destination rather than
falling back to downloading each load file — which is the larger win,
since that engine is the fastest path we have.

### Compatibility

- The token is **omitted from the statement when there is none**, so
minio and any static-key path send the six arguments they always sent.
Nothing regresses on a server older than 24.1.
- v1 keeps skipping the engine for rudder storage: it has no
temporary-credential path and runs against ClickHouse 21, which predates
the argument entirely.
- The query-log mask (`s3CredentialsRegex`) widens to cover a third
credential argument.

### Behaviour change worth noting

A **static-key** S3 destination now also goes through STS, so it needs
`sts:GetSessionToken` on the IAM user, and the statement carries a
credential that expires after `Warehouse.awsCredsExpiryInS` (1h default)
rather than the customer's long-term secret. That is the same trade
redshift, snowflake and deltalake already make.

### Tests

- Unit: four destination shapes — rudder storage, role, no credentials
at all, static keys — all asserted to reach the same mint call; minio
asserted never to.
- Integration: a new `Load Table round trip` case reaches the same minio
bucket as an **aws** destination, minting from **minio's own STS**, so
the session token the statement carries is one the bucket actually
validates end to end.

## Linear Ticket


https://linear.app/rudderstack/issue/INT-7100/crew-workspace-loading-is-taking-lot-of-time

## Security

- [ ] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants