Skip to content

Commit

Permalink
Remove resource caching from PCF and Kubernetes authentication methods
Browse files Browse the repository at this point in the history
Since AuthenticationStepsOperator is now able to use non-blocking I/O for resource access, there's no need to cache the instance keys/tokens.

See gh-586.
  • Loading branch information
mp911de committed Sep 24, 2020
1 parent 672fb86 commit e00a271
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static Node<Map<String, String>> getAuthenticationSteps(AppRoleAuthentic
private static Node<String> getRoleIdSteps(AppRoleAuthenticationOptions options, RoleId roleId) {

if (roleId instanceof Provided) {
return AuthenticationSteps.fromSupplier(((Provided) roleId)::getValue);
return AuthenticationSteps.fromValue(((Provided) roleId).getValue());
}

if (roleId instanceof Pull) {
Expand All @@ -138,7 +138,7 @@ private static Node<String> getRoleIdSteps(AppRoleAuthenticationOptions options,
private static Node<String> getSecretIdSteps(AppRoleAuthenticationOptions options, SecretId secretId) {

if (secretId instanceof Provided) {
return AuthenticationSteps.fromSupplier(((Provided) secretId)::getValue);
return AuthenticationSteps.fromValue(((Provided) secretId).getValue());
}

if (secretId instanceof Pull) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected static AuthenticationSteps createAuthenticationSteps(AzureMsiAuthentic
.map(AzureMsiAuthentication::toAzureVmEnvironment);
}
else {
environmentSteps = AuthenticationSteps.fromSupplier(() -> environment);
environmentSteps = AuthenticationSteps.fromValue(environment);
}

return environmentSteps.zipWith(msiToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static AuthenticationSteps createAuthenticationSteps(KubernetesAuthentica

Assert.notNull(options, "KubernetesAuthenticationOptions must not be null");

String token = options.getJwtSupplier().get();
return AuthenticationSteps.fromSupplier(() -> getKubernetesLogin(options.getRole(), token))
return AuthenticationSteps.fromSupplier(options.getJwtSupplier())
.map(token -> getKubernetesLogin(options.getRole(), token))
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* {@link KubernetesAuthentication} can be constructed using {@link #builder()}. Instances
* of this class are immutable once constructed.
* <p>
* Default to obtain a cached token from
* {@code /var/run/secrets/kubernetes.io/serviceaccount/token}.
* Defaults to obtain the token from
* {@code /var/run/secrets/kubernetes.io/serviceaccount/token} on each login.
*
* @author Michal Budzyn
* @author Mark Paluch
Expand Down Expand Up @@ -155,7 +155,7 @@ public KubernetesAuthenticationOptions build() {
Assert.notNull(this.role, "Role must not be null");

return new KubernetesAuthenticationOptions(this.path, this.role,
this.jwtSupplier == null ? new KubernetesServiceAccountTokenFile().cached() : this.jwtSupplier);
this.jwtSupplier == null ? new KubernetesServiceAccountTokenFile() : this.jwtSupplier);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ public static AuthenticationSteps createAuthenticationSteps(PcfAuthenticationOpt

Assert.notNull(options, "PcfAuthenticationOptions must not be null");

String instanceCert = options.getInstanceCertSupplier().get();
String instanceKey = options.getInstanceKeySupplier().get();
return AuthenticationSteps
.fromSupplier(() -> getPcfLogin(options.getRole(), options.getClock(), instanceCert, instanceKey)) //
AuthenticationSteps.Node<String> cert = AuthenticationSteps.fromSupplier(options.getInstanceCertSupplier());
AuthenticationSteps.Node<String> key = AuthenticationSteps.fromSupplier(options.getInstanceKeySupplier());

return cert
.zipWith(key).map(credentials -> getPcfLogin(options.getRole(), options.getClock(),
credentials.getLeft(), credentials.getRight()))
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* certificate {@link Supplier}s. {@link PcfAuthenticationOptions} can be constructed
* using {@link #builder()}. Instances of this class are immutable once constructed.
* <p>
* Defaults to a cached instance certificate/key by resolving {@code CF_INSTANCE_CERT} and
* {@code CF_INSTANCE_KEY} env variables.
* Defaults to platform-default instance certificate/key by resolving
* {@code CF_INSTANCE_CERT} and {@code CF_INSTANCE_KEY} env variables.
*
* @author Mark Paluch
* @see CredentialSupplier
Expand Down Expand Up @@ -223,12 +223,12 @@ public PcfAuthenticationOptions build() {
Supplier<String> instanceCertSupplier = this.instanceCertSupplier;

if (instanceCertSupplier == null) {
instanceCertSupplier = new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_CERT")).cached();
instanceCertSupplier = new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_CERT"));
}

Supplier<String> instanceKeySupplier = this.instanceKeySupplier;
if (instanceKeySupplier == null) {
instanceKeySupplier = new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_KEY")).cached();
instanceKeySupplier = new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_KEY"));
}

return new PcfAuthenticationOptions(this.path, this.role, this.clock, instanceCertSupplier,
Expand Down

0 comments on commit e00a271

Please sign in to comment.