Skip to content

Commit 961a433

Browse files
authored
[INLONG-5283][Manager] Add OpenAPI authentication option (default off) (apache#5284)
1 parent 2bcd555 commit 961a433

File tree

9 files changed

+30
-15
lines changed

9 files changed

+30
-15
lines changed

inlong-agent/agent-core/src/test/resources/agent.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ job.thread.running.core=10
2626
############################
2727
agent.manager.vip.http.host=127.0.0.1
2828
agent.manager.vip.http.port=8083
29-
agent.manager.auth.secretId=test
30-
agent.manager.auth.secretKey=123456
29+
agent.manager.auth.secretId=
30+
agent.manager.auth.secretKey=

inlong-agent/agent-plugins/src/test/resources/agent.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ job.thread.running.core=10
2323
agent.manager.vip.http.host=127.0.0.1
2424
agent.manager.vip.http.port=8083
2525
agent.fetcher.classname=org.apache.inlong.agent.plugin.fetcher.ManagerFetcher
26-
agent.manager.auth.secretId=test
27-
agent.manager.auth.secretKey=123456
26+
agent.manager.auth.secretId=
27+
agent.manager.auth.secretKey=

inlong-agent/conf/agent.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ agent.scheduled.snapshotreport=0 0/1 * * * ? *
106106
############################
107107
agent.manager.vip.http.host=127.0.0.1
108108
agent.manager.vip.http.port=8083
109-
agent.manager.auth.secretId=admin
110-
agent.manager.auth.secretKey=87haw3VYTPqK5fK0
109+
agent.manager.auth.secretId=
110+
agent.manager.auth.secretKey=
111111

112112

113113

inlong-common/src/main/java/org/apache/inlong/common/util/BasicAuth.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.inlong.common.util;
1919

20+
import org.apache.commons.lang3.StringUtils;
21+
2022
import java.nio.charset.StandardCharsets;
2123
import java.util.Base64;
2224

@@ -29,11 +31,15 @@ public class BasicAuth {
2931
public static final String BASIC_AUTH_PREFIX = "Basic";
3032
public static final String BASIC_AUTH_SEPARATOR = " ";
3133
public static final String BASIC_AUTH_JOINER = ":";
34+
public static final String BASIC_AUTH_EMPTY = "";
3235

3336
/**
3437
* Generate http basic auth credential from configured secretId and secretKey
3538
*/
3639
public static String genBasicAuthCredential(String secretId, String secretKey) {
40+
if (StringUtils.isBlank(secretId) || StringUtils.isBlank(secretKey)) {
41+
return BASIC_AUTH_EMPTY;
42+
}
3743
String credential = String.join(BASIC_AUTH_JOINER, secretId, secretKey);
3844
return BASIC_AUTH_PREFIX + BASIC_AUTH_SEPARATOR + Base64.getEncoder()
3945
.encodeToString(credential.getBytes(StandardCharsets.UTF_8));

inlong-dataproxy/conf/common.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
cluster.id=1
2121
# manager open api address and auth key
2222
manager.hosts=127.0.0.1:8083
23-
manager.auth.secretId=admin
24-
manager.auth.secretKey=87haw3VYTPqK5fK0
23+
manager.auth.secretId=
24+
manager.auth.secretKey=
2525
# proxy cluster name
2626
proxy.cluster.name=default_dataproxy
2727
# check interval of local config (millisecond)

inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/AuthUtils.java

-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.inlong.dataproxy.config;
1919

20-
import org.apache.commons.lang3.StringUtils;
2120
import org.apache.inlong.common.util.BasicAuth;
2221
import org.apache.inlong.dataproxy.consts.ConfigConstants;
2322
import org.slf4j.Logger;
@@ -36,10 +35,6 @@ public static String genBasicAuth() {
3635
Map<String, String> properties = ConfigManager.getInstance().getCommonProperties();
3736
String secretId = properties.get(ConfigConstants.MANAGER_AUTH_SECRET_ID);
3837
String secretKey = properties.get(ConfigConstants.MANAGER_AUTH_SECRET_KEY);
39-
if (StringUtils.isBlank(secretId) || StringUtils.isBlank(secretKey)) {
40-
LOG.error("secretId or secretKey missing");
41-
return null;
42-
}
4338
return BasicAuth.genBasicAuthCredential(secretId, secretKey);
4439
}
4540

inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/auth/impl/InlongShiroImpl.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
3737
import org.apache.shiro.web.session.mgt.WebSessionManager;
3838
import org.springframework.beans.factory.annotation.Autowired;
39+
import org.springframework.beans.factory.annotation.Value;
3940
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4041
import org.springframework.stereotype.Component;
4142

@@ -59,6 +60,9 @@ public class InlongShiroImpl implements InlongShiro {
5960
@Autowired
6061
private UserService userService;
6162

63+
@Value("${openapi.auth.enabled:false}")
64+
private Boolean openAPIAuthEnabled;
65+
6266
@Override
6367
public WebSecurityManager getWebSecurityManager() {
6468
return new DefaultWebSecurityManager();
@@ -93,7 +97,6 @@ public ShiroFilterFactoryBean getShiroFilter(SecurityManager securityManager) {
9397
// anon: can be accessed by anyone, authc: only authentication is successful can be accessed
9498
Map<String, Filter> filters = new LinkedHashMap<>();
9599
filters.put(FILTER_NAME_WEB, new AuthenticationFilter());
96-
filters.put(FILTER_NAME_API, new OpenAPIFilter());
97100
shiroFilterFactoryBean.setFilters(filters);
98101
Map<String, String> pathDefinitions = new LinkedHashMap<>();
99102
// login, register request
@@ -107,7 +110,12 @@ public ShiroFilterFactoryBean getShiroFilter(SecurityManager securityManager) {
107110
pathDefinitions.put("/swagger-resources", "anon");
108111

109112
// openapi
110-
pathDefinitions.put("/openapi/**/*", FILTER_NAME_API);
113+
if (openAPIAuthEnabled) {
114+
filters.put(FILTER_NAME_API, new OpenAPIFilter());
115+
pathDefinitions.put("/openapi/**/*", FILTER_NAME_API);
116+
} else {
117+
pathDefinitions.put("/openapi/**/*", "anon");
118+
}
111119

112120
// other web
113121
pathDefinitions.put("/**", FILTER_NAME_WEB);

inlong-manager/manager-web/src/main/resources/application.properties

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ inlong.auth.type=default
5858
# Encryption config, the suffix of value must be the same as the version.
5959
inlong.encrypt.version=1
6060
inlong.encrypt.key.value1="I!N@L#O$N%G^"
61+
62+
# clients (e.g. agent and dataproxy) must be authenticated by secretId and secretKey if turned on
63+
openapi.auth.enabled=false

inlong-manager/manager-web/src/test/resources/application.properties

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ inlong.auth.type=default
5858
# Encryption config, the suffix of value must be the same as the version.
5959
inlong.encrypt.version=1
6060
inlong.encrypt.key.value1="I!N@L#O$N%G^"
61+
62+
# clients (e.g. agent and dataproxy) must be authenticated by secretId and secretKey if turned on
63+
openapi.auth.enabled=false

0 commit comments

Comments
 (0)