Skip to content

Commit 4d10eaa

Browse files
committed
make port optional
1 parent 616b514 commit 4d10eaa

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ spec:
149149
Must contain the fields `clientId` and `clientSecret`.
150150
type: string
151151
port:
152-
default: 443
153-
description: Port of the identity provider. Defaults to 443.
152+
description: Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
154153
format: uint16
155154
minimum: 0.0
155+
nullable: true
156156
type: integer
157157
tenantId:
158158
description: The Microsoft Entra tenant ID.

rust/operator-binary/src/crd/user_info_fetcher.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ pub mod versioned {
128128
#[serde(default = "entra_default_user_info_hostname")]
129129
pub user_info_hostname: HostName,
130130

131-
/// Port of the identity provider. Defaults to 443.
132-
#[serde(default = "entra_default_port")]
133-
pub port: u16,
131+
/// Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
132+
pub port: Option<u16>,
134133

135134
/// The Microsoft Entra tenant ID.
136135
pub tenant_id: String,
@@ -139,7 +138,7 @@ pub mod versioned {
139138
// We do not use the flattened `TlsClientDetails` here since we cannot
140139
// default to WebPki using a default and flatten
141140
// https://github.com/serde-rs/serde/issues/1626
142-
// This means we have to wrap `Tls` in `TlsClientDetails` to its
141+
// This means we have to wrap `Tls` in `TlsClientDetails` to use its
143142
// method like `uses_tls()`.
144143
#[serde(default = "default_tls_web_pki")]
145144
pub tls: Option<Tls>,
@@ -178,10 +177,6 @@ fn entra_default_user_info_hostname() -> HostName {
178177
HostName::from_str("graph.microsoft.com").unwrap()
179178
}
180179

181-
fn entra_default_port() -> u16 {
182-
443
183-
}
184-
185180
fn default_tls_web_pki() -> Option<Tls> {
186181
Some(Tls {
187182
verification: TlsVerification::Server(TlsServerVerification {

rust/user-info-fetcher/src/backend/entra.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ impl EntraBackend {
166166
pub fn try_new(
167167
token_endpoint: &HostName,
168168
user_info_endpoint: &HostName,
169-
port: u16,
169+
port: Option<u16>,
170170
tenant_id: &str,
171171
uses_tls: bool,
172172
) -> Result<Self, Error> {
173173
let schema = if uses_tls { "https" } else { "http" };
174+
let port = port.unwrap_or_else(|| if uses_tls { 443 } else { 80 });
174175

175176
let token_endpoint =
176177
format!("{schema}://{token_endpoint}:{port}/{tenant_id}/oauth2/v2.0/token");
@@ -223,7 +224,7 @@ mod tests {
223224
let entra = EntraBackend::try_new(
224225
&HostName::from_str("login.microsoft.com").unwrap(),
225226
&HostName::from_str("graph.microsoft.com").unwrap(),
226-
443,
227+
None,
227228
tenant_id,
228229
true,
229230
)
@@ -248,4 +249,38 @@ mod tests {
248249
.unwrap()
249250
);
250251
}
252+
253+
#[test]
254+
fn test_entra_custom_id() {
255+
let tenant_id = "1234-5678-1234-5678";
256+
let user = "1234-5678-1234-5678";
257+
258+
let entra = EntraBackend::try_new(
259+
&HostName::from_str("login.mock.com").unwrap(),
260+
&HostName::from_str("graph.mock.com").unwrap(),
261+
Some(8080),
262+
tenant_id,
263+
false,
264+
)
265+
.unwrap();
266+
267+
assert_eq!(
268+
entra.oauth2_token(),
269+
Url::parse(&format!(
270+
"http://login.mock.com:8080/{tenant_id}/oauth2/v2.0/token"
271+
))
272+
.unwrap()
273+
);
274+
assert_eq!(
275+
entra.user_info(user),
276+
Url::parse(&format!("http://graph.mock.com:8080/v1.0/users/{user}")).unwrap()
277+
);
278+
assert_eq!(
279+
entra.group_info(user),
280+
Url::parse(&format!(
281+
"http://graph.mock.com:8080/v1.0/users/{user}/memberOf"
282+
))
283+
.unwrap()
284+
);
285+
}
251286
}

0 commit comments

Comments
 (0)