Skip to content

Commit 556d9e4

Browse files
committed
fix: #241 Decode secret service account and credentials for connecting to Keycloak
Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
1 parent 9e8f10d commit 556d9e4

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

documentation/microcks-dependent-cr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ This secrete will need to have -at least- two keys:
8484
* `service-account-name` will hold the value of the Service Account name to use,
8585
* `service-account-credentials` will hold the corresponding credentials to authenticate on your target Keycloak instance and realm.
8686

87-
The last thing is how to tell the Microcks operator the secret to be used for Service Account retrievel? Well this
87+
The last thing is how to tell the Microcks operator the secret to be used for Service Account retrieval? Well this
8888
is done using an additional annotation on your Microcks-dependent resource: the `microcks.io/service-account-secret`
8989
annotation allows you to specify the name of secret to consider:
9090

operator/src/main/java/io/github/microcks/operator/KeycloakHelper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,19 @@ private ServiceAccountAndCredentials getServiceAccountAndCredentials(ObjectMeta
154154
Secret saSecret = client.secrets().inNamespace(resourceMetadata.getNamespace())
155155
.withName(serviceAccountSecret).get();
156156

157-
serviceAccountName = saSecret.getStringData().get("service-account-name");
158-
serviceAccountCredentials = saSecret.getStringData().get("service-account-credentials");
157+
if (saSecret == null) {
158+
logger.errorf("Could not find secret '%s' in namespace '%s'", serviceAccountSecret, resourceMetadata.getNamespace());
159+
logger.errorf("Please check that the secret exists and is in the same namespace as the Microcks instance '%s'", resourceMetadata.getName());
160+
} else {
161+
String encodedServiceAccountName = saSecret.getData().get("service-account-name");
162+
String encodedServiceAccountCredentials = saSecret.getData().get("service-account-credentials");
163+
if (encodedServiceAccountName != null && encodedServiceAccountCredentials != null) {
164+
serviceAccountName = new String(Base64.getDecoder().decode(encodedServiceAccountName));
165+
serviceAccountCredentials = new String(Base64.getDecoder().decode(encodedServiceAccountCredentials));
166+
} else {
167+
logger.errorf("Could not find service account name or credentials in secret '%s'", serviceAccountSecret);
168+
}
169+
}
159170
}
160171

161172
return new ServiceAccountAndCredentials(serviceAccountName, serviceAccountCredentials);

0 commit comments

Comments
 (0)