Skip to content

Commit

Permalink
Added remove from redis in invalidateAuthorization (#591)
Browse files Browse the repository at this point in the history

Signed-off-by: munishchouhan <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
munishchouhan and pditommaso authored Aug 5, 2024
1 parent e3b3d02 commit c34a462
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RegistryAuthServiceImpl implements RegistryAuthService {
protected String getToken(CacheKey key){
// check if there's a record in the store cache (redis)
// since the key is shared across replicas, it should be stable (java hashCode is not good)
final stableKey = "key-" + key.stableKey()
final stableKey = getStableKey(key)
def result = tokenStore.get(stableKey)
if( result ) {
log.debug "Registry auth token for cachekey: '$key' [$stableKey] => $result [from store]"
Expand Down Expand Up @@ -282,7 +282,13 @@ class RegistryAuthServiceImpl implements RegistryAuthService {
void invalidateAuthorization(String image, RegistryAuth auth, RegistryCredentials creds) {
final key = new CacheKey(image, auth, creds)
cacheTokens.invalidate(key)
tokenStore.remove(getStableKey(key))
}


/**
* Invalidate all cached authorization tokens
*/
private static String getStableKey(CacheKey key) {
return "key-" + key.stableKey()
}
}
14 changes: 14 additions & 0 deletions src/test/groovy/io/seqera/wave/auth/RegistryAuthServiceTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,18 @@ class RegistryAuthServiceTest extends Specification implements SecureDockerRegis
c1.stableKey() != c5.stableKey()
}

void 'invalidateAuthorization should remove token from cache'() {
given:
RegistryAuthServiceImpl impl = loginService as RegistryAuthServiceImpl
def key = new RegistryAuthServiceImpl.CacheKey("image", Mock(RegistryAuth), Mock(RegistryCredentials))
def stableKey = "key-" + key.stableKey()
tokenStore.put(stableKey, "token")

when:
impl.invalidateAuthorization("image", key.auth, key.creds)

then:
!tokenStore.get(stableKey)
}

}

0 comments on commit c34a462

Please sign in to comment.