Skip to content

Commit feb03e5

Browse files
remove default token (#5265)
* fix compile error * fix token security * fix token security --------- Co-authored-by: aiceflower <kinsanities@sina.com>
1 parent 59c29d7 commit feb03e5

File tree

18 files changed

+308
-244
lines changed

18 files changed

+308
-244
lines changed

linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/Configuration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object Configuration extends Logging {
8181
"The request interface %s is abnormal. You can try to troubleshoot common problems in the knowledge base document"
8282
)
8383

84-
val LINKIS_TOKEN = CommonVars("wds.linkis.token", "LINKIS-AUTH")
84+
val LINKIS_TOKEN = CommonVars("wds.linkis.token", "")
8585

8686
val GLOBAL_CONF_CHN_NAME = "全局设置"
8787

linkis-computation-governance/linkis-client/linkis-cli/src/test/resources/conf/linkis-cli.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ wds.linkis.client.common.creator=LINKISCLI
1717
wds.linkis.client.common.gatewayUrl=http://127.0.0.1:9001
1818
wds.linkis.client.common.authStrategy=token
1919
wds.linkis.client.common.tokenKey=Validation-Code
20-
wds.linkis.client.common.tokenValue=LINKIS-AUTH
20+
wds.linkis.client.common.tokenValue=LINKIS-UNAVAILABLE-TOKEN
2121
wds.linkis.client.noncustomizable.enable.user.specification=true
2222
#wds.linkis.client.noncustomizable.enable.proxy.user=true
2323
#wds.linkis.client.common.submitUser

linkis-computation-governance/linkis-client/linkis-cli/src/test/resources/linkis-cli.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
wds.linkis.client.common.gatewayUrl=http://127.0.0.1:9001
1818
wds.linkis.client.common.authStrategy=token
1919
wds.linkis.client.common.tokenKey=Validation-Code
20-
wds.linkis.client.common.tokenValue=LINKIS-AUTH
20+
wds.linkis.client.common.tokenValue=LINKIS-UNAVAILABLE-TOKEN
2121
#
2222
#wds.linkis.client.common.submitUser
2323
#wds.linkis.client.common.submitPassword

linkis-computation-governance/linkis-client/linkis-computation-client/src/test/java/org/apache/linkis/ujes/client/JobObserveActionTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.linkis.ujes.client
1919

2020
import org.apache.commons.io.IOUtils
21-
import org.apache.linkis.common.conf.CommonVars
21+
import org.apache.linkis.common.conf.{CommonVars, Configuration}
2222
import org.apache.linkis.httpclient.dws.authentication.{StaticAuthenticationStrategy, TokenAuthenticationStrategy}
2323
import org.apache.linkis.httpclient.dws.config.{DWSClientConfig, DWSClientConfigBuilder}
2424
import org.apache.linkis.ujes.client.request.{EmsListAction, JobExecuteAction, JobObserveAction, ResultSetAction}
@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit
2929
@Deprecated
3030
object JobObserveActionTest extends App {
3131

32-
val bmlToken = CommonVars("wds.linkis.bml.auth.token.value", "LINKIS-AUTH").getValue
32+
val bmlToken = CommonVars("wds.linkis.bml.auth.token.value", Configuration.LINKIS_TOKEN.getValue).getValue
3333

3434
val clientConfig = DWSClientConfigBuilder.newBuilder()
3535
.addServerUrl("127.0.0.1:9001") // Change to test gateway address

linkis-dist/bin/install.sh

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,34 @@ cp ${LINKIS_DB_CONFIG_PATH} $LINKIS_HOME/conf
124124

125125
common_conf=$LINKIS_HOME/conf/linkis.properties
126126

127-
RANDOM_BML_TOKEN="LINKIS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
128-
RANDOM_WS_TOKEN="WS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
129-
RANDOM_DSM_TOKEN="DSM-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
130-
RANDOM_DSS_TOKEN="DSS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
131-
RANDOM_QUALITIS_TOKEN="QUALITIS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
132-
RANDOM_VALIDATOR_TOKEN="VALIDATOR-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
133-
if [ $DEBUG_MODE != "true" ];then
134-
sed -i ${txt} "s#LINKIS-AUTH#$RANDOM_BML_TOKEN#g" $LINKIS_HOME/conf/linkis-cli/linkis-cli.properties
135-
sed -i ${txt} "s#LINKIS-AUTH#$RANDOM_BML_TOKEN#g" $common_conf
136-
sed -i ${txt} "s#LINKIS-AUTH#$RANDOM_BML_TOKEN#g" $LINKIS_HOME/admin/configuration_helper.sh
137-
fi
127+
echo "======= SECURITY: Generating secure random tokens =========="
128+
129+
# SECURITY: Generate secure random tokens for all services using new secure placeholders
130+
LINKIS_GATEWAY_TOKEN="LINKIS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
131+
WS_SERVICE_TOKEN="WS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
132+
DSM_SERVICE_TOKEN="DSM-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
133+
DSS_SERVICE_TOKEN="DSS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
134+
QUALITIS_SERVICE_TOKEN="QUALITIS-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
135+
VALIDATOR_SERVICE_TOKEN="VALIDATOR-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
136+
CLI_SERVICE_TOKEN="CLI-`cat /proc/sys/kernel/random/uuid | awk -F- '{print $1$2$3$4$5}'`"
137+
138+
# SECURITY: Set secure user and host restrictions (no wildcards)
139+
echo "Generated secure tokens:"
140+
echo "- LINKIS Gateway Token: $LINKIS_GATEWAY_TOKEN"
141+
echo "- WS Service Token: $WS_SERVICE_TOKEN"
142+
echo "- DSM Service Token: $DSM_SERVICE_TOKEN"
143+
echo "- DSS Service Token: $DSS_SERVICE_TOKEN"
144+
echo "- QUALITIS Service Token: $QUALITIS_SERVICE_TOKEN"
145+
echo "- VALIDATOR Service Token: $VALIDATOR_SERVICE_TOKEN"
146+
echo "- CLI Service Token: $CLI_SERVICE_TOKEN"
147+
148+
# SECURITY: Replace secure placeholders in all configuration files
149+
echo "Replacing secure placeholders in configuration files..."
150+
sed -i ${txt} "s#LINKIS-UNAVAILABLE-TOKEN#$LINKIS_GATEWAY_TOKEN#g" $LINKIS_HOME/conf/linkis-cli/linkis-cli.properties 2>/dev/null || true
151+
sed -i ${txt} "s#CLI-UNAVAILABLE-TOKEN#$CLI_SERVICE_TOKEN#g" $LINKIS_HOME/conf/linkis-cli/linkis-cli.properties 2>/dev/null || true
152+
sed -i ${txt} "s#LINKIS-UNAVAILABLE-TOKEN#$LINKIS_GATEWAY_TOKEN#g" $common_conf 2>/dev/null || true
153+
sed -i ${txt} "s#DSM-UNAVAILABLE-TOKEN#$DSM_SERVICE_TOKEN#g" $common_conf 2>/dev/null || true
154+
sed -i ${txt} "s#LINKIS-UNAVAILABLE-TOKEN#$LINKIS_GATEWAY_TOKEN#g" $LINKIS_HOME/admin/configuration_helper.sh 2>/dev/null || true
138155

139156
echo "======= Step 3: Create necessary directory =========="
140157

@@ -219,13 +236,60 @@ dml_file_name=linkis_dml.sql
219236
if [[ 'postgresql' = "$dbType" ]];then
220237
dml_file_name=linkis_dml_pg.sql
221238
fi
222-
if [ $DEBUG_MODE != "true" ];then
223-
sed -i ${txt} "s#LINKIS-AUTH#$RANDOM_BML_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
224-
sed -i ${txt} "s#WS-AUTH#$RANDOM_WS_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
225-
sed -i ${txt} "s#DSM-AUTH#$RANDOM_DSM_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
226-
sed -i ${txt} "s#DSS-AUTH#$RANDOM_DSS_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
227-
sed -i ${txt} "s#QUALITIS-AUTH#$RANDOM_QUALITIS_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
228-
sed -i ${txt} "s#VALIDATOR-AUTH#$RANDOM_VALIDATOR_TOKEN#g" $LINKIS_HOME/db/${dml_file_name}
239+
echo "======= SECURITY: Replacing database placeholders with secure tokens =========="
240+
241+
# SECURITY: Replace secure placeholders in database initialization file
242+
echo "Replacing secure placeholders in database file: $LINKIS_HOME/db/${dml_file_name}"
243+
sed -i ${txt} "s#{{LINKIS_GATEWAY_TOKEN}}#$LINKIS_GATEWAY_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
244+
sed -i ${txt} "s#{{WS_SERVICE_TOKEN}}#$WS_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
245+
sed -i ${txt} "s#{{DSM_SERVICE_TOKEN}}#$DSM_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
246+
sed -i ${txt} "s#{{DSS_SERVICE_TOKEN}}#$DSS_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
247+
sed -i ${txt} "s#{{QUALITIS_SERVICE_TOKEN}}#$QUALITIS_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
248+
sed -i ${txt} "s#{{VALIDATOR_SERVICE_TOKEN}}#$VALIDATOR_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
249+
sed -i ${txt} "s#{{CLI_SERVICE_TOKEN}}#$CLI_SERVICE_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
250+
# Replace old insecure placeholder token with secure gateway token
251+
sed -i ${txt} "s#LINKIS-UNAVAILABLE-TOKEN#$LINKIS_GATEWAY_TOKEN#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
252+
253+
# SECURITY: Replace user and host placeholders with secure values
254+
sed -i ${txt} "s#{{LINKIS_GATEWAY_USER}}#$LINKIS_GATEWAY_USER#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
255+
sed -i ${txt} "s#{{LINKIS_GATEWAY_HOST}}#$LINKIS_GATEWAY_HOST#g" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
256+
257+
echo "Database placeholder replacement completed."
258+
259+
# SECURITY: Final verification - check for unreplaced placeholders
260+
remaining_placeholders=$(grep -o "{{[^}]*}}" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null | wc -l)
261+
if [ $remaining_placeholders -gt 0 ]; then
262+
echo "WARNING: Found $remaining_placeholders unreplaced placeholders in database file!"
263+
echo "SECURITY RISK: Please review $LINKIS_HOME/db/${dml_file_name} manually."
264+
grep "{{[^}]*}}" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
265+
else
266+
echo "SUCCESS: All security placeholders in database file have been replaced with secure tokens."
267+
fi
268+
269+
# SECURITY: Check for any remaining old insecure tokens
270+
old_tokens=$(grep -o "LINKIS-AUTH\|WS-AUTH\|DSS-AUTH\|QUALITIS-AUTH\|VALIDATOR-AUTH\|LINKISCLI-AUTH\|DSM-AUTH\|LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null | wc -l)
271+
if [ $old_tokens -gt 0 ]; then
272+
echo "CRITICAL: Found $old_tokens old insecure tokens still in database file!"
273+
echo "These should have been replaced with secure placeholders. Please check the file manually."
274+
grep -o "LINKIS-AUTH\|WS-AUTH\|DSS-AUTH\|QUALITIS-AUTH\|VALIDATOR-AUTH\|LINKISCLI-AUTH\|DSM-AUTH\|LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/db/${dml_file_name} 2>/dev/null || true
275+
else
276+
echo "SUCCESS: No old insecure tokens found in database file."
277+
fi
278+
279+
# SECURITY: Final verification - check for unreplaced LINKIS-UNAVAILABLE-TOKEN in all configuration files
280+
echo "======= SECURITY: Final verification for remaining insecure tokens =========="
281+
remaining_insecure_config=$(grep -r "LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/conf/ 2>/dev/null | wc -l)
282+
remaining_insecure_admin=$(grep -o "LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/admin/configuration_helper.sh 2>/dev/null | wc -l)
283+
284+
if [ $remaining_insecure_config -gt 0 ] || [ $remaining_insecure_admin -gt 0 ]; then
285+
echo "WARNING: Found remaining LINKIS-UNAVAILABLE-TOKEN in configuration files!"
286+
echo "Configuration files: $remaining_insecure_config occurrences"
287+
echo "Admin scripts: $remaining_insecure_admin occurrences"
288+
echo "SECURITY RISK: Please review these files manually:"
289+
grep -r "LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/conf/ 2>/dev/null || true
290+
grep -n "LINKIS-UNAVAILABLE-TOKEN" $LINKIS_HOME/admin/configuration_helper.sh 2>/dev/null || true
291+
else
292+
echo "SUCCESS: All LINKIS-UNAVAILABLE-TOKEN placeholders have been replaced with secure tokens."
229293
fi
230294

231295

linkis-dist/helm/charts/linkis/templates/configmap-init-sql.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,9 +1426,9 @@ data:
14261426
INSERT INTO linkis_ps_error_code (error_code,error_desc,error_regex,error_type) VALUES ('91007','JobServer中不存在您的脚本文件,请将你的脚本文件放入对应的JobServer路径中', 'Could not open input file for reading%does not exist',0);
14271427
14281428
-- ----------------------------
1429-
-- Default Tokens
1429+
-- Default Tokens
14301430
-- ----------------------------
1431-
REPLACE INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('LINKIS-AUTH','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
1431+
REPLACE INTO `linkis_mg_gateway_auth_token`(`token_name`,`legal_users`,`legal_hosts`,`business_owner`,`create_time`,`update_time`,`elapse_day`,`update_by`) VALUES ('LINKIS-UNAVAILABLE-TOKEN','*','*','BDP',curdate(),curdate(),-1,'LINKIS');
14321432
14331433
INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('mysql', 'mysql数据库', 'mysql数据库', '关系型数据库', '', 3);
14341434
INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('kafka', 'kafka', 'kafka', '消息队列', '', 2);

linkis-dist/helm/charts/linkis/templates/configmap-linkis-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ data:
6969
## Token-Code=Token-User
7070
## eg:TEST-AUTH=hadoop,root,user01
7171
### http request with header { Token-Code:TEST-AUTH,Token-User:user01 }
72-
LINKIS-AUTH=*
72+
LINKIS-UNAVAILABLE-TOKEN=*
7373
7474
application-linkis.yml: |
7575
debug: {{ .Values.linkis.featureGates.testMode }}
@@ -212,7 +212,7 @@ data:
212212
wds.linkis.client.common.gatewayUrl={{- include "linkis.gateway.url" . }}
213213
wds.linkis.client.common.authStrategy=token
214214
wds.linkis.client.common.tokenKey=Validation-Code
215-
wds.linkis.client.common.tokenValue=LINKIS-AUTH
215+
wds.linkis.client.common.tokenValue=LINKIS-UNAVAILABLE-TOKE
216216
spring.spring.mvc.pathmatch.matching-strategy=ant_path_matcher
217217
spring.spring.cloud.loadbalancer.cache.enabled=false
218218
springfox.documentation.enabled=false

linkis-dist/package/admin/configuration_helper.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ fi
6161
get()
6262
{
6363
requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue?creator=$creator&engineType=$engineType&version=$version&configKey=$configKey"
64-
curl --location --request GET $requestUrl -H "Token-Code:LINKIS-AUTH" -H "Token-User:$user"
64+
curl --location --request GET $requestUrl -H "Token-Code:LINKIS-UNAVAILABLE-TOKEN" -H "Token-User:$user"
6565
}
6666

6767
delete()
6868
{
6969
requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue"
7070
requestBody="{\"engineType\":\"$engineType\",\"version\":\"$version\",\"creator\":\"$creator\",\"configKey\":\"$configKey\"}"
71-
curl -i -X DELETE $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:LINKIS-AUTH" -H "Token-User:$user" -d "$requestBody"
71+
curl -i -X DELETE $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:LINKIS-UNAVAILABLE-TOKEN" -H "Token-User:$user" -d "$requestBody"
7272
}
7373

7474
add()
7575
{
7676
requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue"
7777
requestBody="{\"engineType\":\"$engineType\",\"version\":\"$version\",\"creator\":\"$creator\",\"configKey\":\"$configKey\",\"configValue\":\"$configValue\",\"force\":\"$force\",\"user\":\"$user\"}"
78-
curl -i -X POST $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:LINKIS-AUTH" -H "Token-User:hadoop" -d "$requestBody"
78+
curl -i -X POST $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:LINKIS-UNAVAILABLE-TOKEN" -H "Token-User:hadoop" -d "$requestBody"
7979
}
8080

8181
case $COMMAND in

linkis-dist/package/conf/linkis-cli/linkis-cli.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
wds.linkis.client.common.gatewayUrl=http://127.0.0.1:9001
1818
wds.linkis.client.common.authStrategy=token
1919
wds.linkis.client.common.tokenKey=Validation-Code
20-
wds.linkis.client.common.tokenValue=LINKIS-AUTH
20+
wds.linkis.client.common.tokenValue=LINKIS-UNAVAILABLE-TOKEN
2121
wds.linkis.client.noncustomizable.enable.user.specification=true
2222
wds.linkis.client.noncustomizable.enable.proxy.user=true

linkis-dist/package/conf/linkis.properties

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ wds.linkis.workspace.filesystem.owner.check=true
104104
wds.linkis.workspace.filesystem.path.check=true
105105

106106
#linkis token
107-
linkis.configuration.linkisclient.auth.token.value=LINKIS-AUTH
108-
wds.linkis.client.common.tokenValue=LINKIS-AUTH
109-
wds.linkis.bml.auth.token.value=LINKIS-AUTH
110-
wds.linkis.context.client.auth.value=LINKIS-AUTH
111-
wds.linkis.errorcode.auth.token=LINKIS-AUTH
112-
wds.linkis.client.test.common.tokenValue=LINKIS-AUTH
113-
wds.linkis.filesystem.token.value=LINKIS-AUTH
114-
wds.linkis.gateway.access.token=LINKIS-AUTH
115-
wds.linkis.server.dsm.auth.token.value=LINKIS-AUTH
107+
linkis.configuration.linkisclient.auth.token.value=LINKIS-UNAVAILABLE-TOKEN
108+
wds.linkis.client.common.tokenValue=LINKIS-UNAVAILABLE-TOKEN
109+
wds.linkis.bml.auth.token.value=LINKIS-UNAVAILABLE-TOKEN
110+
wds.linkis.context.client.auth.value=LINKIS-UNAVAILABLE-TOKEN
111+
wds.linkis.errorcode.auth.token=LINKIS-UNAVAILABLE-TOKEN
112+
wds.linkis.client.test.common.tokenValue=LINKIS-UNAVAILABLE-TOKEN
113+
wds.linkis.filesystem.token.value=LINKIS-UNAVAILABLE-TOKEN
114+
wds.linkis.gateway.access.token=LINKIS-UNAVAILABLE-TOKEN
115+
wds.linkis.server.dsm.auth.token.value=LINKIS-UNAVAILABLE-TOKEN
116116

117117

118118
# s3 file system

0 commit comments

Comments
 (0)