Skip to content

Commit 9a1575b

Browse files
authored
Upstream Hostname into operator-rs (#494)
* Upstream Hostname validation to operator-rs * Update op-rs * Changelog * Update crate hashes * fmt * make crds * make crds * Fix markdownlint errors
1 parent 8ae61c0 commit 9a1575b

File tree

5 files changed

+24
-57
lines changed

5 files changed

+24
-57
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ All notable changes to this project will be documented in this file.
1010
- Added experimental cert-manager backend ([#482]).
1111
- Make RSA key length configurable ([#506]).
1212

13+
### Changed
14+
15+
- Refactored hostname validation ([#494]).
16+
- BREAKING: Hostname validation is now somewhat stricter.
17+
- BREAKING: Hostname validation is now enforced in CRD.
18+
- Remove custom `h2` patch, as Kubernetes 1.26 has fixed the invalid data from Kubernetes' side. Starting with 24.11 we only support at least 1.27 (as it's needed by OpenShift 4.14) ([#495]).
19+
1320
### Fixed
1421

1522
- Fixed Kerberos keytab provisioning reusing its credential cache ([#490]).
1623
- Fixed listener volumes missing a required permission to inspect manually provisioned listeners ([#497]).
1724
- test: Fixed cert-manager tests by installing cert-manager if it doesn't exist ([#505]).
1825

19-
### Changed
20-
21-
- Remove custom `h2` patch, as Kubernetes 1.26 has fixed the invalid data from Kubernetes' side. Starting with 24.11 we only support at least 1.27 (as it's needed by OpenShift 4.14) ([#495]).
22-
2326
[#454]: https://github.com/stackabletech/secret-operator/pull/454
2427
[#482]: https://github.com/stackabletech/secret-operator/pull/482
2528
[#490]: https://github.com/stackabletech/secret-operator/pull/490
29+
[#494]: https://github.com/stackabletech/secret-operator/pull/494
2630
[#495]: https://github.com/stackabletech/secret-operator/pull/495
2731
[#497]: https://github.com/stackabletech/secret-operator/pull/497
2832
[#505]: https://github.com/stackabletech/secret-operator/pull/505

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ uuid = { version = "1.10.0", features = ["v4"] }
5050
yasna = "0.5"
5151

5252
[patch."https://github.com/stackabletech/operator-rs.git"]
53-
# stackable-operator = { path = "../operator-rs" }
53+
# stackable-operator = { path = "../operator-rs/crates/stackable-operator" }
5454
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }

deploy/helm/secret-operator/crds/crds.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ spec:
266266
type: string
267267
realmName:
268268
description: The name of the Kerberos realm. This should be provided by the Kerberos administrator.
269+
pattern: ^[-.a-zA-Z0-9]+$
269270
type: string
270271
required:
271272
- admin

rust/operator-binary/src/backend/kerberos_keytab.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use stackable_krb5_provision_keytab::{
55
self as provision,
66
provision_keytab,
77
};
8-
use stackable_operator::{k8s_openapi::api::core::v1::Secret, kube::runtime::reflector::ObjectRef};
8+
use stackable_operator::{
9+
commons::networking::{HostName, KerberosRealmName},
10+
k8s_openapi::api::core::v1::Secret,
11+
kube::runtime::reflector::ObjectRef,
12+
};
913
use stackable_secret_operator_crd_utils::SecretReference;
1014
use tempfile::tempdir;
1115
use tokio::{
@@ -15,8 +19,8 @@ use tokio::{
1519

1620
use crate::{
1721
crd::{
18-
ActiveDirectorySamAccountNameRules, Hostname, InvalidKerberosPrincipal,
19-
KerberosKeytabBackendAdmin, KerberosPrincipal,
22+
ActiveDirectorySamAccountNameRules, InvalidKerberosPrincipal, KerberosKeytabBackendAdmin,
23+
KerberosPrincipal,
2024
},
2125
format::{well_known, SecretData, WellKnownSecretData},
2226
utils::Unloggable,
@@ -82,8 +86,8 @@ impl SecretBackendError for Error {
8286

8387
#[derive(Debug)]
8488
pub struct KerberosProfile {
85-
pub realm_name: Hostname,
86-
pub kdc: Hostname,
89+
pub realm_name: KerberosRealmName,
90+
pub kdc: HostName,
8791
pub admin: KerberosKeytabBackendAdmin,
8892
}
8993

rust/operator-binary/src/crd.rs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{fmt::Display, ops::Deref};
33
use serde::{Deserialize, Serialize};
44
use snafu::Snafu;
55
use stackable_operator::{
6+
commons::networking::{HostName, KerberosRealmName},
67
kube::CustomResource,
78
schemars::{self, schema::Schema, JsonSchema},
89
time::Duration,
@@ -235,11 +236,11 @@ pub enum CertManagerIssuerKind {
235236
#[serde(rename_all = "camelCase")]
236237
pub struct KerberosKeytabBackend {
237238
/// The name of the Kerberos realm. This should be provided by the Kerberos administrator.
238-
pub realm_name: Hostname,
239+
pub realm_name: KerberosRealmName,
239240

240241
/// The hostname of the Kerberos Key Distribution Center (KDC).
241242
/// This should be provided by the Kerberos administrator.
242-
pub kdc: Hostname,
243+
pub kdc: HostName,
243244

244245
/// Kerberos admin configuration settings.
245246
pub admin: KerberosKeytabBackendAdmin,
@@ -260,15 +261,15 @@ pub enum KerberosKeytabBackendAdmin {
260261
Mit {
261262
/// The hostname of the Kerberos Admin Server.
262263
/// This should be provided by the Kerberos administrator.
263-
kadmin_server: Hostname,
264+
kadmin_server: HostName,
264265
},
265266

266267
/// Credentials should be provisioned in a Microsoft Active Directory domain.
267268
#[serde(rename_all = "camelCase")]
268269
ActiveDirectory {
269270
/// An AD LDAP server, such as the AD Domain Controller.
270271
/// This must match the server’s FQDN, or GSSAPI authentication will fail.
271-
ldap_server: Hostname,
272+
ldap_server: HostName,
272273

273274
/// Reference (name and namespace) to a Kubernetes Secret object containing
274275
/// the TLS CA (in `ca.crt`) that the LDAP server’s certificate should be authenticated against.
@@ -315,49 +316,6 @@ impl ActiveDirectorySamAccountNameRules {
315316
}
316317
}
317318

318-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
319-
#[serde(try_from = "String", into = "String")]
320-
pub struct Hostname(String);
321-
#[derive(Debug, Snafu)]
322-
#[snafu(module)]
323-
pub enum InvalidHostname {
324-
#[snafu(display("hostname contains illegal characters (allowed: alphanumeric, -, and .)"))]
325-
IllegalCharacter,
326-
327-
#[snafu(display("hostname may not start with a dash"))]
328-
StartWithDash,
329-
}
330-
impl TryFrom<String> for Hostname {
331-
type Error = InvalidHostname;
332-
333-
fn try_from(value: String) -> Result<Self, Self::Error> {
334-
if value.starts_with('-') {
335-
invalid_hostname::StartWithDashSnafu.fail()
336-
} else if value.contains(|chr: char| !chr.is_alphanumeric() && chr != '.' && chr != '-') {
337-
invalid_hostname::IllegalCharacterSnafu.fail()
338-
} else {
339-
Ok(Hostname(value))
340-
}
341-
}
342-
}
343-
impl From<Hostname> for String {
344-
fn from(value: Hostname) -> Self {
345-
value.0
346-
}
347-
}
348-
impl Display for Hostname {
349-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
350-
f.write_str(&self.0)
351-
}
352-
}
353-
impl Deref for Hostname {
354-
type Target = str;
355-
356-
fn deref(&self) -> &Self::Target {
357-
&self.0
358-
}
359-
}
360-
361319
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
362320
#[serde(try_from = "String", into = "String")]
363321
pub struct KerberosPrincipal(String);

0 commit comments

Comments
 (0)