-
Notifications
You must be signed in to change notification settings - Fork 2k
[Feature][Zeta] Support basic authentication for web ui #9171
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b960775
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi 1e1292c
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi 8ca473d
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi 3824d47
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi b904c8a
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi 624a54f
Merge remote-tracking branch 'upstream/dev' into feature_http_auth
CosmosNi 9cdd190
Merge remote-tracking branch 'upstream/dev' into feature_http_auth
CosmosNi 8e692cb
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi 67734dc
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi afc3e98
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi b87ecd3
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi fb0ce8b
[Feature][Zeta] Support Basic Authentication for web ui
CosmosNi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
266 changes: 266 additions & 0 deletions
266
...atunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/BasicAuthenticationIT.java
This file contains hidden or 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,266 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.seatunnel.engine.e2e; | ||
|
||
import org.apache.seatunnel.engine.server.rest.RestConstant; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
|
||
import java.io.IOException; | ||
import java.util.Base64; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.apache.seatunnel.e2e.common.util.ContainerUtil.PROJECT_ROOT_PATH; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
/** Integration test for basic authentication in SeaTunnel Engine. */ | ||
public class BasicAuthenticationIT extends SeaTunnelEngineContainer { | ||
|
||
private static final String HTTP = "http://"; | ||
private static final String COLON = ":"; | ||
private static final String USERNAME = "testuser"; | ||
private static final String PASSWORD = "testpassword"; | ||
private static final String BASIC_AUTH_HEADER = "Authorization"; | ||
private static final String BASIC_AUTH_PREFIX = "Basic "; | ||
|
||
@Override | ||
@BeforeEach | ||
public void startUp() throws Exception { | ||
// Create server with basic authentication enabled | ||
|
||
server = createSeaTunnelContainerWithBasicAuth(); | ||
// Wait for server to be ready | ||
Awaitility.await() | ||
.atMost(2, TimeUnit.MINUTES) | ||
.until( | ||
() -> { | ||
try { | ||
// Try to access with correct credentials | ||
String credentials = USERNAME + ":" + PASSWORD; | ||
String encodedCredentials = | ||
Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
given().header( | ||
BASIC_AUTH_HEADER, | ||
BASIC_AUTH_PREFIX + encodedCredentials) | ||
.get( | ||
HTTP | ||
+ server.getHost() | ||
+ COLON | ||
+ server.getMappedPort(8080) | ||
+ "/") | ||
.then() | ||
.statusCode(200); | ||
return true; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
@AfterEach | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
/** | ||
* Test that accessing the web UI without authentication credentials returns 401 Unauthorized. | ||
*/ | ||
@Test | ||
public void testAccessWithoutCredentials() { | ||
given().get(HTTP + server.getHost() + COLON + server.getMappedPort(8080) + "/") | ||
.then() | ||
.statusCode(401); | ||
} | ||
|
||
/** Test that accessing the web UI with incorrect credentials returns 401 Unauthorized. */ | ||
@Test | ||
public void testAccessWithIncorrectCredentials() { | ||
String credentials = "wronguser:wrongpassword"; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.get(HTTP + server.getHost() + COLON + server.getMappedPort(8080) + "/") | ||
.then() | ||
.statusCode(401); | ||
} | ||
|
||
/** Test that accessing the web UI with correct credentials returns 200 OK. */ | ||
@Test | ||
public void testAccessWithCorrectCredentials() { | ||
String credentials = USERNAME + ":" + PASSWORD; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.get(HTTP + server.getHost() + COLON + server.getMappedPort(8080) + "/") | ||
.then() | ||
.statusCode(200) | ||
.contentType(containsString("text/html")) | ||
.body(containsString("<title>Seatunnel Engine UI</title>")); | ||
} | ||
|
||
/** Test that accessing the REST API with correct credentials returns 200 OK. */ | ||
@Test | ||
public void testRestApiAccessWithCorrectCredentials() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a new test case with |
||
String credentials = USERNAME + ":" + PASSWORD; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.get( | ||
HTTP | ||
+ server.getHost() | ||
+ COLON | ||
+ server.getMappedPort(8080) | ||
+ RestConstant.REST_URL_OVERVIEW) | ||
.then() | ||
.statusCode(200) | ||
.body("projectVersion", notNullValue()); | ||
} | ||
|
||
/** Test that accessing the REST API with Incorrect credentials returns 200 OK. */ | ||
@Test | ||
public void testRestApiAccessWithIncorrectCredentials() { | ||
String credentials = "wronguser:wrongpassword"; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.get( | ||
HTTP | ||
+ server.getHost() | ||
+ COLON | ||
+ server.getMappedPort(8080) | ||
+ RestConstant.REST_URL_OVERVIEW) | ||
.then() | ||
.statusCode(401); | ||
} | ||
|
||
/** Test submitting a job via REST API with correct credentials. */ | ||
@Test | ||
public void testSubmitJobWithCorrectCredentials() { | ||
String credentials = USERNAME + ":" + PASSWORD; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
// Simple batch job configuration | ||
String jobConfig = | ||
"{\n" | ||
+ " \"env\": {\n" | ||
+ " \"job.mode\": \"batch\"\n" | ||
+ " },\n" | ||
+ " \"source\": [\n" | ||
+ " {\n" | ||
+ " \"plugin_name\": \"FakeSource\",\n" | ||
+ " \"plugin_output\": \"fake\",\n" | ||
+ " \"row.num\": 100,\n" | ||
+ " \"schema\": {\n" | ||
+ " \"fields\": {\n" | ||
+ " \"name\": \"string\",\n" | ||
+ " \"age\": \"int\",\n" | ||
+ " \"card\": \"int\"\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"transform\": [\n" | ||
+ " ],\n" | ||
+ " \"sink\": [\n" | ||
+ " {\n" | ||
+ " \"plugin_name\": \"InMemory\",\n" | ||
+ " \"plugin_input\": \"fake\",\n" | ||
+ " \"throw_exception\": true\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ "}"; | ||
|
||
Response response = | ||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.contentType(ContentType.JSON) | ||
.body(jobConfig) | ||
.post( | ||
HTTP | ||
+ server.getHost() | ||
+ COLON | ||
+ server.getMappedPort(8080) | ||
+ RestConstant.REST_URL_SUBMIT_JOB); | ||
|
||
response.then().statusCode(200).body("jobId", notNullValue()); | ||
} | ||
|
||
/** Test submitting a job via REST API with incorrect credentials. */ | ||
@Test | ||
public void testSubmitJobWithIncorrectCredentials() { | ||
String credentials = "wronguser:wrongpassword"; | ||
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); | ||
|
||
// Simple batch job configuration | ||
String jobConfig = | ||
"{\n" | ||
+ " \"env\": {\n" | ||
+ " \"job.mode\": \"BATCH\"\n" | ||
+ " },\n" | ||
+ " \"source\": {\n" | ||
+ " \"FakeSource\": {\n" | ||
+ " \"plugin_output\": \"fake\",\n" | ||
+ " \"row.num\": 100,\n" | ||
+ " \"schema\": {\n" | ||
+ " \"fields\": {\n" | ||
+ " \"id\": \"int\",\n" | ||
+ " \"name\": \"string\"\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " },\n" | ||
+ " \"sink\": {\n" | ||
+ " \"Console\": {\n" | ||
+ " \"plugin_input\": \"fake\"\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ "}"; | ||
|
||
given().header(BASIC_AUTH_HEADER, BASIC_AUTH_PREFIX + encodedCredentials) | ||
.contentType(ContentType.JSON) | ||
.body(jobConfig) | ||
.post( | ||
HTTP | ||
+ server.getHost() | ||
+ COLON | ||
+ server.getMappedPort(8080) | ||
+ RestConstant.REST_URL_SUBMIT_JOB) | ||
.then() | ||
.statusCode(401); | ||
} | ||
|
||
/** Create a SeaTunnel container with basic authentication enabled. */ | ||
private GenericContainer<?> createSeaTunnelContainerWithBasicAuth() | ||
throws IOException, InterruptedException { | ||
String configPath = | ||
PROJECT_ROOT_PATH | ||
+ "/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/resources/basic-auth/seatunnel.yaml"; | ||
|
||
return createSeaTunnelContainerWithFakeSourceAndInMemorySink(configPath); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...nnel-engine-e2e/connector-seatunnel-e2e-base/src/test/resources/basic-auth/seatunnel.yaml
This file contains hidden or 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,46 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
seatunnel: | ||
engine: | ||
history-job-expire-minutes: 1 | ||
backup-count: 2 | ||
queue-type: blockingqueue | ||
print-execution-info-interval: 10 | ||
classloader-cache-mode: false | ||
slot-service: | ||
dynamic-slot: true | ||
checkpoint: | ||
interval: 300000 | ||
timeout: 100000 | ||
storage: | ||
type: localfile | ||
max-retained: 3 | ||
plugin-config: | ||
namespace: /tmp/seatunnel/checkpoint_snapshot/ | ||
http: | ||
enable-http: true | ||
port: 8080 | ||
enable-dynamic-port: false | ||
enable-basic-auth: true | ||
basic-auth-username: "testuser" | ||
basic-auth-password: "testpassword" | ||
telemetry: | ||
metric: | ||
enabled: false | ||
logs: | ||
scheduled-deletion-enable: false |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.