Skip to content
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

bugfix: fix access key loss after server restart #5097

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a09ddd
bugfix:fix access key loss after server restart
renliangyu857 Nov 22, 2022
2cb9648
Merge branch 'develop' into bugfix_accesskey_loss_afterserverrestart
slievrly Nov 22, 2022
0ab7064
Merge branch 'develop' into bugfix_accesskey_loss_afterserverrestart
funky-eyes Nov 22, 2022
f1810b9
reconstruct
renliangyu857 Nov 22, 2022
c2aae48
throw exception when TmNettyRemotingClient#getInstance() returns null
renliangyu857 Nov 23, 2022
5b9a0ac
resolve test failure
renliangyu857 Nov 23, 2022
d61b8f5
Merge branch 'develop' into bugfix_accesskey_loss_afterserverrestart
renliangyu857 Nov 23, 2022
3a8354f
Merge branch 'develop' into bugfix_accesskey_loss_afterserverrestart
funky-eyes Nov 24, 2022
115ec7d
Update TmNettyRemotingClient.java
renliangyu857 Nov 24, 2022
68d45d5
Update TmNettyClientTest.java
renliangyu857 Nov 24, 2022
fa4ad71
Update TmNettyClientTest.java
renliangyu857 Nov 24, 2022
4de0017
Update DefaultSagaTransactionalTemplate.java
renliangyu857 Nov 24, 2022
c4c8411
Update TMClient.java
renliangyu857 Nov 24, 2022
54eae20
Merge branch 'develop' into bugfix_accesskey_loss_afterserverrestart
xingfudeshi Nov 24, 2022
62fe80d
retain ak/sk get/set method
renliangyu857 Nov 25, 2022
a624eea
Merge branch 'bugfix_accesskey_loss_afterserverrestart' of https://gi…
renliangyu857 Nov 25, 2022
ae94944
resolve test failure
renliangyu857 Nov 25, 2022
8b7197e
retain set/get accessKey
renliangyu857 Nov 27, 2022
d2dbbf1
Update TmNettyRemotingClient.java
renliangyu857 Nov 27, 2022
b045b28
Update TmNettyRemotingClient.java
renliangyu857 Nov 27, 2022
648eeeb
Update develop.md
renliangyu857 Nov 27, 2022
9f569ae
Update GlobalTransactionScanner.java
renliangyu857 Nov 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5052](https://github.com/seata/seata/pull/5052)] fix update join condition placeholder param error
- [[#5031](https://github.com/seata/seata/pull/5031)] fix mysql InsertOnDuplicateUpdate should not use null index value as image sql query condition
- [[#5075](https://github.com/seata/seata/pull/5075)] fix InsertOnDuplicateUpdateExecutor could not intercept the sql which has no primary and unique key

- [[#5093](https://github.com/seata/seata/pull/5093)] fix access key loss after seata server restart

### optimize:
- [[#4774](https://github.com/seata/seata/pull/4774)] optimize mysql8 dependencies for seataio/seata-server image
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [[#5052](https://github.com/seata/seata/pull/5052)] 修复update join条件中占位符参数问题
- [[#5031](https://github.com/seata/seata/pull/5031)] 修复InsertOnDuplicateUpdate中不应该使用null值索引作为查询条件
- [[#5075](https://github.com/seata/seata/pull/5075)] 修复InsertOnDuplicateUpdate无法拦截无主键和唯一索引的SQL
- [[#5093](https://github.com/seata/seata/pull/5093)] 修复seata server重启后access key丢失问题

### optimize:
- [[#4774](https://github.com/seata/seata/pull/4774)] 优化 seataio/seata-server 镜像中的 mysql8 依赖
Expand Down
14 changes: 12 additions & 2 deletions common/src/main/java/io/seata/common/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,25 @@ public interface ConfigurationKeys {
*/
String TM_INTERCEPTOR_ORDER = CLIENT_TM_PREFIX + "interceptorOrder";

/**
* The constant ACCESS_KEY.
*/
String ACCESS_KEY = "accesskey";

/**
* The constant SECRET_KEY.
*/
String SECRET_KEY = "secretkey";

/**
* The constant SEATA_ACCESS_KEY.
*/
String SEATA_ACCESS_KEY = SEATA_PREFIX + "accesskey";
String SEATA_ACCESS_KEY = SEATA_PREFIX + ACCESS_KEY;

/**
* The constant SEATA_SECRET_KEY.
*/
String SEATA_SECRET_KEY = SEATA_PREFIX + "secretkey";
String SEATA_SECRET_KEY = SEATA_PREFIX + SECRET_KEY;

/**
* The constant EXTRA_DATA_SPLIT_CHAR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@

import static io.seata.core.constants.ConfigurationKeys.EXTRA_DATA_KV_CHAR;
import static io.seata.core.constants.ConfigurationKeys.EXTRA_DATA_SPLIT_CHAR;
import static io.seata.core.constants.ConfigurationKeys.SEATA_ACCESS_KEY;
import static io.seata.core.constants.ConfigurationKeys.SEATA_SECRET_KEY;

/**
* The rm netty client.
Expand All @@ -67,8 +65,8 @@ public final class TmNettyRemotingClient extends AbstractNettyRemotingClient {
private String applicationId;
private String transactionServiceGroup;
private final AuthSigner signer;
private String accessKey;
private String secretKey;
private final String accessKey = ConfigurationFactory.getInstance().getConfig(ConfigurationKeys.ACCESS_KEY,null);
private final String secretKey = ConfigurationFactory.getInstance().getConfig(ConfigurationKeys.SECRET_KEY,null);


private TmNettyRemotingClient(NettyClientConfig nettyClientConfig,
Expand Down Expand Up @@ -99,24 +97,9 @@ public void onChangeEvent(ConfigurationChangeEvent event) {
* @return the instance
*/
public static TmNettyRemotingClient getInstance(String applicationId, String transactionServiceGroup) {
return getInstance(applicationId, transactionServiceGroup, null, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to retain the method without the ak/sk parameter.


建议保留无ak/sk 参数的方法。

}

/**
* Gets instance.
*
* @param applicationId the application id
* @param transactionServiceGroup the transaction service group
* @param accessKey the access key
* @param secretKey the secret key
* @return the instance
*/
public static TmNettyRemotingClient getInstance(String applicationId, String transactionServiceGroup, String accessKey, String secretKey) {
TmNettyRemotingClient tmRpcClient = getInstance();
tmRpcClient.setApplicationId(applicationId);
tmRpcClient.setTransactionServiceGroup(transactionServiceGroup);
tmRpcClient.setAccessKey(accessKey);
tmRpcClient.setSecretKey(secretKey);
return tmRpcClient;
}

Expand Down Expand Up @@ -162,32 +145,6 @@ public void setTransactionServiceGroup(String transactionServiceGroup) {
this.transactionServiceGroup = transactionServiceGroup;
}

/**
* Sets access key.
*
* @param accessKey the access key
*/
protected void setAccessKey(String accessKey) {
if (null != accessKey) {
this.accessKey = accessKey;
return;
}
this.accessKey = System.getProperty(SEATA_ACCESS_KEY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to keep this part, but also to determine if it is null.


建议保留,但同样需要判空。

}

/**
* Sets secret key.
*
* @param secretKey the secret key
*/
protected void setSecretKey(String secretKey) {
if (null != secretKey) {
this.secretKey = secretKey;
return;
}
this.secretKey = System.getProperty(SEATA_SECRET_KEY);
}

@Override
public void init() {
// registry processor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public GlobalTransactionScanner globalTransactionScanner(SeataProperties seataPr
GlobalTransactionScanner.addScannablePackages(seataProperties.getScanPackages());
// add excludeBeanNames
GlobalTransactionScanner.addScannerExcludeBeanNames(seataProperties.getExcludesForScanning());
//set accessKey and secretKey
GlobalTransactionScanner.setAccessKey(seataProperties.getAccessKey());
GlobalTransactionScanner.setSecretKey(seataProperties.getSecretKey());
// create global transaction scanner
return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup(), failureHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator
private final String applicationId;
private final String txServiceGroup;
private final int mode;
private static String accessKey;
private static String secretKey;
private volatile boolean disableGlobalTransaction = ConfigurationFactory.getInstance().getBoolean(
ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, DEFAULT_DISABLE_GLOBAL_TRANSACTION);
private final AtomicBoolean initialized = new AtomicBoolean(false);
Expand Down Expand Up @@ -180,24 +178,6 @@ public GlobalTransactionScanner(String applicationId, String txServiceGroup, int
this.failureHandlerHook = failureHandlerHook;
}

/**
* Sets access key.
*
* @param accessKey the access key
*/
public static void setAccessKey(String accessKey) {
GlobalTransactionScanner.accessKey = accessKey;
}

/**
* Sets secret key.
*
* @param secretKey the secret key
*/
public static void setSecretKey(String secretKey) {
GlobalTransactionScanner.secretKey = secretKey;
}

@Override
public void destroy() {
ShutdownHook.getInstance().destroyAll();
Expand All @@ -217,7 +197,7 @@ private void initClient() {
throw new IllegalArgumentException(String.format("applicationId: %s, txServiceGroup: %s", applicationId, txServiceGroup));
}
//init TM
TMClient.init(applicationId, txServiceGroup, accessKey, secretKey);
TMClient.init(applicationId, txServiceGroup);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Transaction Manager Client is initialized. applicationId[{}] txServiceGroup[{}]", applicationId, txServiceGroup);
}
Expand Down
14 changes: 1 addition & 13 deletions tm/src/main/java/io/seata/tm/TMClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@ public class TMClient {
* @param transactionServiceGroup the transaction service group
*/
public static void init(String applicationId, String transactionServiceGroup) {
init(applicationId, transactionServiceGroup, null, null);
}

/**
* Init.
*
* @param applicationId the application id
* @param transactionServiceGroup the transaction service group
* @param accessKey the access key
* @param secretKey the secret key
*/
public static void init(String applicationId, String transactionServiceGroup, String accessKey, String secretKey) {
TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance(applicationId, transactionServiceGroup, accessKey, secretKey);
TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance(applicationId,transactionServiceGroup);
tmNettyRemotingClient.init();
}

Expand Down