-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement][Registry] Add ZK authorization yaml control & add diges…
…t auth UT Update dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryProperties.java Co-authored-by: Wenjun Ruan <[email protected]>
- Loading branch information
1 parent
66548a2
commit faaac71
Showing
10 changed files
with
155 additions
and
13 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
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
98 changes: 98 additions & 0 deletions
98
...rg/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryDigestTestCase.java
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,98 @@ | ||
/* | ||
* 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.dolphinscheduler.plugin.registry.zookeeper; | ||
|
||
import org.apache.dolphinscheduler.plugin.registry.RegistryTestCase; | ||
|
||
import org.apache.zookeeper.ZooDefs; | ||
import org.apache.zookeeper.ZooKeeper; | ||
import org.apache.zookeeper.client.ZKClientConfig; | ||
import org.apache.zookeeper.data.ACL; | ||
import org.apache.zookeeper.data.Id; | ||
import org.apache.zookeeper.server.DumbWatcher; | ||
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.stream.Stream; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.lifecycle.Startables; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@ActiveProfiles("digest") | ||
@SpringBootTest(classes = ZookeeperRegistryProperties.class) | ||
@SpringBootApplication(scanBasePackageClasses = ZookeeperRegistryProperties.class) | ||
public class ZookeeperRegistryDigestTestCase extends RegistryTestCase<ZookeeperRegistry> { | ||
|
||
@Autowired | ||
private ZookeeperRegistryProperties zookeeperRegistryProperties; | ||
|
||
private static GenericContainer<?> zookeeperContainer; | ||
|
||
private static final Network NETWORK = Network.newNetwork(); | ||
|
||
private static ZooKeeper zk; | ||
|
||
private static final String ROOT_USER = "root"; | ||
|
||
private static final String ROOT_PASSWORD = "root_passwd"; | ||
|
||
private static final String ID_PASSWORD = String.format("%s:%s", ROOT_USER, ROOT_PASSWORD); | ||
|
||
private static void setupRootACLForDigest(final ZooKeeper zk) throws Exception { | ||
final String digest = DigestAuthenticationProvider.generateDigest(ID_PASSWORD); | ||
final ACL acl = new ACL(ZooDefs.Perms.ALL, new Id("digest", digest)); | ||
zk.setACL("/", Collections.singletonList(acl), -1); | ||
} | ||
|
||
@SneakyThrows | ||
@BeforeAll | ||
public static void setUpTestingServer() { | ||
zookeeperContainer = new GenericContainer<>(DockerImageName.parse("zookeeper:3.8")) | ||
.withNetwork(NETWORK) | ||
.withExposedPorts(2181); | ||
Startables.deepStart(Stream.of(zookeeperContainer)).join(); | ||
System.clearProperty("registry.zookeeper.connect-string"); | ||
System.setProperty("registry.zookeeper.connect-string", "localhost:" + zookeeperContainer.getMappedPort(2181)); | ||
zk = new ZooKeeper("localhost:" + zookeeperContainer.getMappedPort(2181), | ||
30000, new DumbWatcher(), new ZKClientConfig()); | ||
setupRootACLForDigest(zk); | ||
} | ||
|
||
@SneakyThrows | ||
@Override | ||
public ZookeeperRegistry createRegistry() { | ||
return new ZookeeperRegistry(zookeeperRegistryProperties); | ||
} | ||
|
||
@SneakyThrows | ||
@AfterAll | ||
public static void tearDownTestingServer() { | ||
zk.close(); | ||
zookeeperContainer.close(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ry-plugins/dolphinscheduler-registry-zookeeper/src/test/resources/application-digest.yaml
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,31 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
registry: | ||
type: zookeeper | ||
zookeeper: | ||
namespace: dolphinscheduler | ||
connect-string: 127.0.0.1:2181 | ||
retry-policy: | ||
base-sleep-time: 60ms | ||
max-sleep: 300ms | ||
max-retries: 5 | ||
session-timeout: 30s | ||
connection-timeout: 9s | ||
block-until-connected: 3s | ||
authorization: | ||
digest: root:root_passwd |
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