aws / aws/aws-sdk-java-v2

Force Refresh of credentials inside of STSCredentialProvider cache

Aperta
#5,545 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub
feature-request needs-triage
Lingua principale
Java
Stelle
2.6k
Fork
1k
Merge medio
2g 9h
PR unite (30g)
51

Descrizione

### Describe the feature

include a public method for STSCredentialProvider that will forcefully refresh the sessionCache when called

### Use Case

Credentials inside of session cache can become invalid due to a role being deleted and recreated causing `InvalidClientTokenId`, this will continue till new creds are fetched which can take up to 12 hours depending on configuration and in the mean time the client using the provider will be in-operational. Calling the new method will allow for an almost immediate recovery time after catching the error

loose example of recovery

```
try{ client call }
catch(InvalidClientTokenId e){
client.serviceClientConfiguration().credentialsProvider().asInstanceOf[StsAssumeRoleCredentialsProvider].refreshCredentials()
}
```

### Proposed Solution

### StsCredentialsProvider
```
public void refreshCredentials(){
sessionCache.forceRefreshCache();
}
```
### CachedSupplier

```
public void forceRefreshCache() {
try {
boolean lockAcquired = refreshLock.tryLock(BLOCKING_REFRESH_MAX_WAIT.getSeconds(), TimeUnit.SECONDS);

try {
log.debug(() -> "(" + cachedValueName + ") Refreshing cached value.");

// It wasn't, call the supplier to update it.

if (prefetchStrategyInitialized.compareAndSet(false, true)) {
prefetchStrategy.initializeCachedSupplier(this);
}

try {
RefreshResult cachedValue = handleFetchedSuccess(prefetchStrategy.fetch(valueSupplier));
this.cachedValue = cachedValue;
log.debug(() -> "(" + cachedValueName + ") Successfully refreshed cached value. "
+ "Next Prefetch Time: " + cachedValue.prefetchTime() + ". "
+ "Next Stale Time: " + cachedValue.staleTime());
} catch (RuntimeException t) {
cachedValue = handleFetchFailure(t);
}
} finally {
if (lockAcquired) {
refreshLock.unlock();
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted waiting to refresh a cached value.", e);
}
}
```

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [x] This feature might incur a breaking change

### AWS Java SDK version used

2.0

### JDK version used

openjdk version "1.8.0_422"

### Operating System and version

Amazon Linux 2 x86_64 5.10 Kernel

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con StsCredentialsProvider e CachedSupplier, quindi esamina il comportamento esistente di aggiornamento e blocco della cache di sessione. Aggiungi il punto di ingresso pubblico richiesto per l'aggiornamento e assicurati che la cache venga aggiornata forzatamente, gestendo errori e interruzioni in modo coerente; il lavoro è completato quando i chiamanti possono riprendersi rapidamente dopo InvalidClientTokenId.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, java
Ambito
authentication, security
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.