-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f29977
commit 7fadf42
Showing
10 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
operator/controller/src/main/java/io/apicurio/registry/operator/feat/security/AuthTLS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.apicurio.registry.operator.feat.security; | ||
|
||
import io.apicurio.registry.operator.EnvironmentVariables; | ||
import io.apicurio.registry.operator.api.v1.spec.auth.AuthSpec; | ||
import io.apicurio.registry.operator.api.v1.spec.auth.AuthTLSSpec; | ||
import io.apicurio.registry.operator.utils.SecretKeyRefTool; | ||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static io.apicurio.registry.operator.EnvironmentVariables.*; | ||
import static io.apicurio.registry.operator.api.v1.ContainerNames.REGISTRY_APP_CONTAINER_NAME; | ||
import static io.apicurio.registry.operator.resource.app.AppDeploymentResource.addEnvVar; | ||
import static io.apicurio.registry.operator.utils.Utils.putIfNotBlank; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class AuthTLS { | ||
|
||
/** | ||
* Configure TLS for OIDC authentication | ||
*/ | ||
public static void configureAuthTLS(AuthSpec authSpec, Deployment deployment, Map<String, EnvVar> env) { | ||
|
||
putIfNotBlank(env, EnvironmentVariables.OIDC_TLS_VERIFICATION, | ||
authSpec.getTls().getTlsVerificationType()); | ||
|
||
// spotless:off | ||
var truststore = new SecretKeyRefTool(getAuthTLSSpec(authSpec) | ||
.map(AuthTLSSpec::getTruststoreSecretRef) | ||
.orElse(null), "ca.p12"); | ||
|
||
var truststorePassword = new SecretKeyRefTool(getAuthTLSSpec(authSpec) | ||
.map(AuthTLSSpec::getTruststorePasswordSecretRef) | ||
.orElse(null), "ca.password"); | ||
// spotless:on | ||
if (truststore.isValid() && truststorePassword.isValid()) { | ||
truststore.applySecretVolume(deployment, REGISTRY_APP_CONTAINER_NAME); | ||
addEnvVar(env, OIDC_TLS_TRUSTSTORE_LOCATION, truststore.getSecretVolumeKeyPath()); | ||
truststorePassword.applySecretEnvVar(env, OIDC_TLS_TRUSTSTORE_PASSWORD); | ||
} | ||
} | ||
|
||
private static Optional<AuthTLSSpec> getAuthTLSSpec(AuthSpec primary) { | ||
// spotless:off | ||
return ofNullable(primary) | ||
.map(AuthSpec::getTls); | ||
// spotless:on | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
operator/model/src/main/java/io/apicurio/registry/operator/api/v1/spec/auth/AuthTLSSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.apicurio.registry.operator.api.v1.spec.auth; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.databind.JsonDeserializer.None; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import io.apicurio.registry.operator.api.v1.spec.SecretKeyRef; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
@JsonDeserialize(using = None.class) | ||
@JsonInclude(Include.NON_NULL) | ||
@JsonPropertyOrder({ "tlsVerificationType", "truststoreSecretRef", "truststorePasswordSecretRef" }) | ||
@NoArgsConstructor | ||
@AllArgsConstructor(access = PRIVATE) | ||
@SuperBuilder(toBuilder = true) | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class AuthTLSSpec { | ||
|
||
/** | ||
* Type of TLS verification. | ||
*/ | ||
@JsonProperty("tlsVerificationType") | ||
@JsonPropertyDescription(""" | ||
Verify the identity server certificate.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private String tlsVerificationType; | ||
|
||
/** | ||
* Name of a Secret that contains the TLS truststore (in PKCS12 format). Key <code>ca.p12</code> is | ||
* assumed by default. | ||
*/ | ||
@JsonProperty("truststoreSecretRef") | ||
@JsonPropertyDescription(""" | ||
Name of a Secret that contains the TLS truststore (in PKCS12 format). \ | ||
Key `ca.p12` is assumed by default.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private SecretKeyRef truststoreSecretRef; | ||
|
||
/** | ||
* Name of a Secret that contains the TLS truststore password. Key <code>ca.password</code> is assumed by | ||
* default. | ||
*/ | ||
@JsonProperty("truststorePasswordSecretRef") | ||
@JsonPropertyDescription(""" | ||
Name of a Secret that contains the TLS truststore password. \ | ||
Key `ca.password` is assumed by default.""") | ||
@JsonSetter(nulls = Nulls.SKIP) | ||
private SecretKeyRef truststorePasswordSecretRef; | ||
} |