Skip to content

Commit b6bc3ee

Browse files
committed
Upstream Hostname validation to operator-rs
1 parent 9bba989 commit b6bc3ee

File tree

7 files changed

+25
-67
lines changed

7 files changed

+25
-67
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ serde_json = "1.0"
3434
serde_yaml = "0.9"
3535
snafu = "0.8"
3636
socket2 = { version = "0.5", features = ["all"] }
37-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.73.0", features = ["time"] }
37+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.74.0", features = ["time"] }
3838
strum = { version = "0.26", features = ["derive"] }
3939
sys-mount = { version = "3.0", default-features = false }
4040
tempfile = "3.12"
@@ -54,5 +54,6 @@ yasna = "0.5"
5454
h2 = { git = "https://github.com/stackabletech/h2.git", branch = "feature/grpc-uds-/0.4.5" }
5555

5656
[patch."https://github.com/stackabletech/operator-rs.git"]
57-
# stackable-operator = { path = "../operator-rs" }
57+
# stackable-operator = { path = "../operator-rs/crates/stackable-operator" }
5858
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }
59+
stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "feature/validation-hostname" }

crate-hashes.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ spec:
134134
type: object
135135
ldapServer:
136136
description: An AD LDAP server, such as the AD Domain Controller. This must match the server’s FQDN, or GSSAPI authentication will fail.
137+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
137138
type: string
138139
ldapTlsCaSecret:
139140
description: Reference (name and namespace) to a Kubernetes Secret object containing the TLS CA (in `ca.crt`) that the LDAP server’s certificate should be authenticated against.
@@ -179,6 +180,7 @@ spec:
179180
properties:
180181
kadminServer:
181182
description: The hostname of the Kerberos Admin Server. This should be provided by the Kerberos administrator.
183+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
182184
type: string
183185
required:
184186
- kadminServer
@@ -202,9 +204,11 @@ spec:
202204
type: string
203205
kdc:
204206
description: The hostname of the Kerberos Key Distribution Center (KDC). This should be provided by the Kerberos administrator.
207+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
205208
type: string
206209
realmName:
207210
description: The name of the Kerberos realm. This should be provided by the Kerberos administrator.
211+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
208212
type: string
209213
required:
210214
- admin

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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::{commons::networking::{Hostname, KerberosRealmName}, k8s_openapi::api::core::v1::Secret, kube::runtime::reflector::ObjectRef};
99
use stackable_secret_operator_crd_utils::SecretReference;
1010
use tempfile::tempdir;
1111
use tokio::{
@@ -15,8 +15,8 @@ use tokio::{
1515

1616
use crate::{
1717
crd::{
18-
ActiveDirectorySamAccountNameRules, Hostname, InvalidKerberosPrincipal,
19-
KerberosKeytabBackendAdmin, KerberosPrincipal,
18+
ActiveDirectorySamAccountNameRules, InvalidKerberosPrincipal, KerberosKeytabBackendAdmin,
19+
KerberosPrincipal,
2020
},
2121
format::{well_known, SecretData, WellKnownSecretData},
2222
utils::Unloggable,
@@ -82,7 +82,7 @@ impl SecretBackendError for Error {
8282

8383
#[derive(Debug)]
8484
pub struct KerberosProfile {
85-
pub realm_name: Hostname,
85+
pub realm_name: KerberosRealmName,
8686
pub kdc: Hostname,
8787
pub admin: KerberosKeytabBackendAdmin,
8888
}

rust/operator-binary/src/crd.rs

Lines changed: 2 additions & 44 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, JsonSchema},
89
time::Duration,
@@ -125,7 +126,7 @@ impl AutoTlsCa {
125126
#[serde(rename_all = "camelCase")]
126127
pub struct KerberosKeytabBackend {
127128
/// The name of the Kerberos realm. This should be provided by the Kerberos administrator.
128-
pub realm_name: Hostname,
129+
pub realm_name: KerberosRealmName,
129130

130131
/// The hostname of the Kerberos Key Distribution Center (KDC).
131132
/// This should be provided by the Kerberos administrator.
@@ -205,49 +206,6 @@ impl ActiveDirectorySamAccountNameRules {
205206
}
206207
}
207208

208-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
209-
#[serde(try_from = "String", into = "String")]
210-
pub struct Hostname(String);
211-
#[derive(Debug, Snafu)]
212-
#[snafu(module)]
213-
pub enum InvalidHostname {
214-
#[snafu(display("hostname contains illegal characters (allowed: alphanumeric, -, and .)"))]
215-
IllegalCharacter,
216-
217-
#[snafu(display("hostname may not start with a dash"))]
218-
StartWithDash,
219-
}
220-
impl TryFrom<String> for Hostname {
221-
type Error = InvalidHostname;
222-
223-
fn try_from(value: String) -> Result<Self, Self::Error> {
224-
if value.starts_with('-') {
225-
invalid_hostname::StartWithDashSnafu.fail()
226-
} else if value.contains(|chr: char| !chr.is_alphanumeric() && chr != '.' && chr != '-') {
227-
invalid_hostname::IllegalCharacterSnafu.fail()
228-
} else {
229-
Ok(Hostname(value))
230-
}
231-
}
232-
}
233-
impl From<Hostname> for String {
234-
fn from(value: Hostname) -> Self {
235-
value.0
236-
}
237-
}
238-
impl Display for Hostname {
239-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
240-
f.write_str(&self.0)
241-
}
242-
}
243-
impl Deref for Hostname {
244-
type Target = str;
245-
246-
fn deref(&self) -> &Self::Target {
247-
&self.0
248-
}
249-
}
250-
251209
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
252210
#[serde(try_from = "String", into = "String")]
253211
pub struct KerberosPrincipal(String);

0 commit comments

Comments
 (0)