Skip to content

Commit 5a4860e

Browse files
committed
split token and host endpoint
1 parent 29202b9 commit 5a4860e

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ spec:
148148
149149
Must contain the fields `clientId` and `clientSecret`.
150150
type: string
151-
hostname:
152-
default: microsoft.com
153-
description: Hostname of the identity provider, defaults to `login.microsoft.com`.
151+
hostnameGraph:
152+
default: graph.microsoft.com
153+
description: Hostname of the user info provider, defaults to `graph.microsoft.com`.
154+
type: string
155+
hostnameToken:
156+
default: login.microsoft.com
157+
description: Hostname of the token provider, defaults to `login.microsoft.com`.
154158
type: string
155159
port:
156160
default: 443

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ pub mod versioned {
120120
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
121121
#[serde(rename_all = "camelCase")]
122122
pub struct EntraBackend {
123-
/// Hostname of the identity provider, defaults to `login.microsoft.com`.
124-
#[serde(default = "entra_default_host")]
125-
pub hostname: HostName,
123+
/// Hostname of the token provider, defaults to `login.microsoft.com`.
124+
#[serde(default = "entra_default_host_token")]
125+
pub hostname_token: HostName,
126+
127+
/// Hostname of the user info provider, defaults to `graph.microsoft.com`.
128+
#[serde(default = "entra_default_host_graph")]
129+
pub hostname_graph: HostName,
126130

127131
/// Port of the identity provider. Defaults to 443.
128132
#[serde(default = "entra_default_port")]
@@ -160,8 +164,12 @@ fn default_root_path() -> String {
160164
"/".to_string()
161165
}
162166

163-
fn entra_default_host() -> HostName {
164-
HostName::from_str("microsoft.com").unwrap()
167+
fn entra_default_host_token() -> HostName {
168+
HostName::from_str("login.microsoft.com").unwrap()
169+
}
170+
171+
fn entra_default_host_graph() -> HostName {
172+
HostName::from_str("graph.microsoft.com").unwrap()
165173
}
166174

167175
fn entra_default_port() -> u16 {

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ struct GroupMembership {
6464
}
6565

6666
struct EntraEndpoint {
67-
hostname: HostName,
67+
hostname_token: HostName,
68+
hostname_graph: HostName,
6869
port: u16,
6970
tenant_id: String,
7071
protocol: String,
@@ -78,16 +79,18 @@ pub(crate) async fn get_user_info(
7879
) -> Result<UserInfo, Error> {
7980
let v1alpha1::EntraBackend {
8081
client_credentials_secret: _,
81-
hostname,
82+
hostname_token,
83+
hostname_graph,
8284
port,
8385
tenant_id,
8486
tls,
8587
} = config;
8688

8789
let entra_endpoint = EntraEndpoint::new(
88-
hostname.clone(),
90+
hostname_token.clone(),
91+
hostname_graph.clone(),
8992
*port,
90-
tenant_id.clone(),
93+
tenant_id.to_string(),
9194
&TlsClientDetails { tls: tls.clone() },
9295
);
9396
let token_url = entra_endpoint.oauth2_token();
@@ -141,9 +144,16 @@ pub(crate) async fn get_user_info(
141144
}
142145

143146
impl EntraEndpoint {
144-
pub fn new(hostname: HostName, port: u16, tenant_id: String, tls: &TlsClientDetails) -> Self {
147+
pub fn new(
148+
hostname_token: HostName,
149+
hostname_graph: HostName,
150+
port: u16,
151+
tenant_id: String,
152+
tls: &TlsClientDetails,
153+
) -> Self {
145154
Self {
146-
hostname,
155+
hostname_token,
156+
hostname_graph,
147157
port,
148158
tenant_id,
149159
protocol: if tls.uses_tls() {
@@ -157,7 +167,7 @@ impl EntraEndpoint {
157167
pub fn oauth2_token(&self) -> String {
158168
format!(
159169
"{base_url}/{tenant_id}/oauth2/v2.0/token",
160-
base_url = self.base_url("login"),
170+
base_url = self.base_url(&self.hostname_token),
161171
tenant_id = self.tenant_id
162172
)
163173
}
@@ -166,26 +176,25 @@ impl EntraEndpoint {
166176
pub fn user_info(&self, user: &str) -> String {
167177
format!(
168178
"{base_url}/v1.0/users/{user}",
169-
base_url = self.base_url("graph"),
179+
base_url = self.base_url(&self.hostname_graph),
170180
)
171181
}
172182

173183
pub fn group_info(&self, user: &str) -> String {
174184
format!(
175185
"{base_url}/v1.0/users/{user}/memberOf",
176-
base_url = self.base_url("graph"),
186+
base_url = self.base_url(&self.hostname_graph),
177187
)
178188
}
179189

180-
fn base_url(&self, prefix: &str) -> String {
190+
fn base_url(&self, hostname: &HostName) -> String {
181191
format!(
182-
"{protocol}://{prefix}.{hostname}{opt_port}",
192+
"{protocol}://{hostname}{opt_port}",
183193
opt_port = if self.port == 443 || self.port == 80 {
184194
"".to_string()
185195
} else {
186196
format!(":{port}", port = self.port)
187197
},
188-
hostname = self.hostname,
189198
protocol = self.protocol
190199
)
191200
}
@@ -204,7 +213,8 @@ mod tests {
204213
#[test]
205214
fn test_defaults() {
206215
let entra_endpoint = EntraEndpoint::new(
207-
HostName::from_str("microsoft.com").expect("Could not parse hostname"),
216+
HostName::from_str("login.microsoft.com").expect("Could not parse hostname"),
217+
HostName::from_str("graph.microsoft.com").expect("Could not parse hostname"),
208218
443,
209219
"1234-5678".to_string(),
210220
&TlsClientDetails {
@@ -233,7 +243,8 @@ mod tests {
233243
#[test]
234244
fn test_non_defaults_tls() {
235245
let entra_endpoint = EntraEndpoint::new(
236-
HostName::from_str("myentra.com").expect("Could not parse hostname"),
246+
HostName::from_str("login.myentra.com").expect("Could not parse hostname"),
247+
HostName::from_str("graph.myentra.com").expect("Could not parse hostname"),
237248
8443,
238249
"1234-5678".to_string(),
239250
&TlsClientDetails {
@@ -258,7 +269,8 @@ mod tests {
258269
#[test]
259270
fn test_non_defaults_non_tls() {
260271
let entra_endpoint = EntraEndpoint::new(
261-
HostName::from_str("myentra.com").expect("Could not parse hostname"),
272+
HostName::from_str("login.myentra.com").expect("Could not parse hostname"),
273+
HostName::from_str("graph.myentra.com").expect("Could not parse hostname"),
262274
8080,
263275
"1234-5678".to_string(),
264276
&TlsClientDetails { tls: None },

0 commit comments

Comments
 (0)