use of io.strimzi.api.kafka.model.GenericSecretSource in project strimzi by strimzi.
the class UtilTest method getHashOk.
@Test
public void getHashOk() {
String namespace = "ns";
GenericSecretSource at = new GenericSecretSourceBuilder().withSecretName("top-secret-at").withKey("key").build();
GenericSecretSource cs = new GenericSecretSourceBuilder().withSecretName("top-secret-cs").withKey("key").build();
GenericSecretSource rt = new GenericSecretSourceBuilder().withSecretName("top-secret-rt").withKey("key").build();
KafkaClientAuthentication kcu = new KafkaClientAuthenticationOAuthBuilder().withAccessToken(at).withRefreshToken(rt).withClientSecret(cs).build();
CertSecretSource css = new CertSecretSourceBuilder().withCertificate("key").withSecretName("css-secret").build();
Secret secret = new SecretBuilder().withData(Map.of("key", "value")).build();
SecretOperator secretOps = mock(SecretOperator.class);
when(secretOps.getAsync(eq(namespace), eq("top-secret-at"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-rt"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-cs"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("css-secret"))).thenReturn(Future.succeededFuture(secret));
Future<Integer> res = Util.authTlsHash(secretOps, "ns", kcu, singletonList(css));
res.onComplete(v -> {
assertThat(v.succeeded(), is(true));
// we are summing "value" hash four times
assertThat(v.result(), is("value".hashCode() * 4));
});
}
use of io.strimzi.api.kafka.model.GenericSecretSource in project strimzi by strimzi.
the class AuthenticationUtils method configureGenericSecretVolumes.
/**
* Generates volumes needed for generic secrets needed for custom authentication.
*
* @param volumeNamePrefix Prefix for naming the secret volumes
* @param genericSecretSources List of generic secrets which should be mounted
* @param isOpenShift Flag whether we are on OpenShift or not
*
* @return List of new Volumes
*/
public static List<Volume> configureGenericSecretVolumes(String volumeNamePrefix, List<GenericSecretSource> genericSecretSources, boolean isOpenShift) {
List<Volume> newVolumes = new ArrayList<>();
if (genericSecretSources != null && genericSecretSources.size() > 0) {
int i = 0;
for (GenericSecretSource genericSecretSource : genericSecretSources) {
Map<String, String> items = Collections.singletonMap(genericSecretSource.getKey(), genericSecretSource.getKey());
String volumeName = String.format("%s-%d", volumeNamePrefix, i);
Volume vol = VolumeUtils.createSecretVolume(volumeName, genericSecretSource.getSecretName(), items, isOpenShift);
newVolumes.add(vol);
i++;
}
}
return newVolumes;
}
use of io.strimzi.api.kafka.model.GenericSecretSource in project strimzi by strimzi.
the class AuthenticationUtils method configureGenericSecretVolumeMounts.
/**
* Generates volume mounts needed for generic secrets that are being mounted.
*
* @param volumeNamePrefix Prefix which was used to name the secret volumes
* @param genericSecretSources List of generic secrets that should be mounted
* @param baseVolumeMount The Base volume into which the certificates should be mounted
*
* @return List of new VolumeMounts
*/
public static List<VolumeMount> configureGenericSecretVolumeMounts(String volumeNamePrefix, List<GenericSecretSource> genericSecretSources, String baseVolumeMount) {
List<VolumeMount> newVolumeMounts = new ArrayList<>();
if (genericSecretSources != null && genericSecretSources.size() > 0) {
int i = 0;
for (GenericSecretSource genericSecretSource : genericSecretSources) {
String volumeName = String.format("%s-%d", volumeNamePrefix, i);
newVolumeMounts.add(VolumeUtils.createVolumeMount(volumeName, String.format("%s/%s", baseVolumeMount, genericSecretSource.getSecretName())));
i++;
}
}
return newVolumeMounts;
}
use of io.strimzi.api.kafka.model.GenericSecretSource in project strimzi-kafka-operator by strimzi.
the class UtilTest method getHashOk.
@Test
public void getHashOk() {
String namespace = "ns";
GenericSecretSource at = new GenericSecretSourceBuilder().withSecretName("top-secret-at").withKey("key").build();
GenericSecretSource cs = new GenericSecretSourceBuilder().withSecretName("top-secret-cs").withKey("key").build();
GenericSecretSource rt = new GenericSecretSourceBuilder().withSecretName("top-secret-rt").withKey("key").build();
KafkaClientAuthentication kcu = new KafkaClientAuthenticationOAuthBuilder().withAccessToken(at).withRefreshToken(rt).withClientSecret(cs).build();
CertSecretSource css = new CertSecretSourceBuilder().withCertificate("key").withSecretName("css-secret").build();
Secret secret = new SecretBuilder().withData(Map.of("key", "value")).build();
SecretOperator secretOps = mock(SecretOperator.class);
when(secretOps.getAsync(eq(namespace), eq("top-secret-at"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-rt"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-cs"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("css-secret"))).thenReturn(Future.succeededFuture(secret));
Future<Integer> res = Util.authTlsHash(secretOps, "ns", kcu, singletonList(css));
res.onComplete(v -> {
assertThat(v.succeeded(), is(true));
// we are summing "value" hash four times
assertThat(v.result(), is("value".hashCode() * 4));
});
}
use of io.strimzi.api.kafka.model.GenericSecretSource in project strimzi by strimzi.
the class UtilTest method getHashFailure.
@Test
public void getHashFailure() {
String namespace = "ns";
GenericSecretSource at = new GenericSecretSourceBuilder().withSecretName("top-secret-at").withKey("key").build();
GenericSecretSource cs = new GenericSecretSourceBuilder().withSecretName("top-secret-cs").withKey("key").build();
GenericSecretSource rt = new GenericSecretSourceBuilder().withSecretName("top-secret-rt").withKey("key").build();
KafkaClientAuthentication kcu = new KafkaClientAuthenticationOAuthBuilder().withAccessToken(at).withRefreshToken(rt).withClientSecret(cs).build();
CertSecretSource css = new CertSecretSourceBuilder().withCertificate("key").withSecretName("css-secret").build();
Secret secret = new SecretBuilder().withData(Map.of("key", "value")).build();
SecretOperator secretOps = mock(SecretOperator.class);
when(secretOps.getAsync(eq(namespace), eq("top-secret-at"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-rt"))).thenReturn(Future.succeededFuture(secret));
when(secretOps.getAsync(eq(namespace), eq("top-secret-cs"))).thenReturn(Future.succeededFuture(null));
when(secretOps.getAsync(eq(namespace), eq("css-secret"))).thenReturn(Future.succeededFuture(secret));
Future<Integer> res = Util.authTlsHash(secretOps, "ns", kcu, singletonList(css));
res.onComplete(v -> {
assertThat(v.succeeded(), is(false));
assertThat(v.cause().getMessage(), is("Secret top-secret-cs not found"));
});
}
Aggregations