Savonitar commented on code in PR #30043:
URL: https://github.com/apache/flink/pull/30043#discussion_r4700351741
##########
flink-runtime/src/main/java/org/apache/flink/runtime/security/token/DefaultDelegationTokenManager.java:
##########
@@ -222,171 +194,195 @@ static void checkProviderAndReceiverConsistency(
LOG.info("Provider and receiver instances are consistent");
}
- @VisibleForTesting
- static void checkSamePrefixedProviders(
- Map<String, DelegationTokenProvider> providers, Set<String>
warnings) {
- Set<String> providerPrefixes = new HashSet<>();
- for (String name : providers.keySet()) {
- String[] split = name.split("-");
- if (!providerPrefixes.add(split[0])) {
- String msg =
- String.format(
- "Multiple providers loaded with the same
prefix: %s. This might lead to unintended consequences, please consider using
only one of them.",
- split[0]);
- warnings.add(msg);
- }
- }
- }
-
/**
* Obtains new tokens in a one-time fashion and leaves it up to the caller
to distribute them.
*/
@Override
public void obtainDelegationTokens(DelegationTokenContainer container)
throws Exception {
LOG.info("Obtaining delegation tokens");
- obtainDelegationTokensAndGetNextRenewal(container);
+ obtainDelegationTokensAndGetExpiry(container);
LOG.info("Delegation tokens obtained successfully");
}
+ /**
+ * Obtains the tokens of the providers which require them, adds them to
the container and
+ * returns their expiry: the earliest {@code validUntil} of the obtained
tokens, empty if no
+ * provider reports one.
+ */
+ protected Optional<Long> obtainDelegationTokensAndGetExpiry(
+ DelegationTokenContainer container) {
+ return
delegationTokenProviderRepository.obtainDelegationTokensAndGetExpiry(container);
+ }
+
+ /**
+ * Starts obtaining tokens for the lifetime of the process: obtains tokens
inline, propagates
+ * them to the local JVM receivers and schedules the next obtain. A
failure of the first obtain
+ * is not retried but thrown, because the process may need the tokens
right away (e.g.
+ * BlobServer).
+ */
@Override
- public void obtainDelegationTokens() throws Exception {
- LOG.info("Obtaining delegation tokens");
+ public void start() throws Exception {
+ checkNotNull(scheduledExecutor, "Scheduled executor must not be null");
+ checkNotNull(ioExecutor, "IO executor must not be null");
+ synchronized (stateLock) {
+ checkState(
+ state == State.CREATED,
+ "The delegation token manager can only be started once,
current state: %s",
+ state);
+ state = State.RUNNING;
+ }
+
+ try {
+ obtainDistributeAndScheduleNext();
+ } catch (Throwable t) {
+ stop();
+ throw t;
+ }
+ }
+
+ @Override
+ public void attachListener(Listener listener) throws Exception {
+ checkNotNull(listener, "Listener must not be null");
+ synchronized (stateLock) {
+ checkState(
+ state == State.RUNNING,
+ "The delegation token manager must be running to attach a
listener, current state: %s",
+ state);
+ if (this.listener != null && this.listener != listener) {
+ LOG.warn("Replacing the attached delegation token listener");
+ }
+ this.listener = listener;
+ LOG.info("Delegation token listener attached");
+ }
+ deliverLatestTokens();
Review Comment:
Should the replay be skipped once the tokens are past `lastKnownExpiry`?
If standby obtains have been failing, a reconnecting TaskManager can
overwrite still-valid credentials from the previous leader. Previously a failed
obtaining on handover left those credentials active.
E.g. we have 2 JMs A and B:
- A gave a worker an S3 token valid until 10:30.
- B own S3 token expired at 10:00. B tried to obtain a new one, but the
token service was unavailable.
- At 10:05 A fails. The worker reconnects to B. The worker still has 25
minutes of valid S3 access.
Before the PR, B would try to fetch a token. If that failed, B would send no
token, so the worker would keep its working one. With the PR, B sends its
cached 10:00 token. The worker installs it over its 10:30 token and immediately
loses S3 access.
Or am I missing something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]