MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / resolve

Method resolve

crates/openshell-server/src/auth/k8s_sa.rs:221–323  ·  view source on GitHub ↗
(&self, token: &str)

Source from the content-addressed store, hash-verified

219#[async_trait]
220impl K8sIdentityResolver for LiveK8sResolver {
221 async fn resolve(&self, token: &str) -> Result<Option<ResolvedK8sIdentity>, Status> {
222 let review = TokenReview {
223 metadata: ObjectMeta::default(),
224 spec: TokenReviewSpec {
225 audiences: Some(vec![self.expected_audience.clone()]),
226 token: Some(token.to_string()),
227 },
228 status: None,
229 };
230
231 let review = self
232 .token_reviews_api
233 .create(&PostParams::default(), &review)
234 .await
235 .map_err(|e| {
236 warn!(error = %e, "K8s TokenReview failed");
237 Status::internal(format!("tokenreview failed: {e}"))
238 })?;
239 let status = review
240 .status
241 .ok_or_else(|| Status::internal("TokenReview response missing status"))?;
242 let Some(identity) = token_review_identity(
243 &status,
244 &self.expected_audience,
245 &self.sandbox_namespace,
246 &self.expected_service_account,
247 )?
248 else {
249 return Ok(None);
250 };
251
252 info!(
253 pod_name = %identity.pod_name,
254 pod_uid = %identity.pod_uid,
255 service_account = %self.expected_service_account,
256 "validated K8s SA token via TokenReview"
257 );
258
259 // Look up the pod and read its sandbox-id annotation.
260 let pod = self
261 .pods_api
262 .get_opt(&identity.pod_name)
263 .await
264 .map_err(|e| {
265 warn!(
266 pod = %identity.pod_name,
267 error = %e,
268 "failed to fetch sandbox pod for annotation lookup"
269 );
270 Status::internal(format!("pod GET failed: {e}"))
271 })?;
272 let Some(pod) = pod else {
273 warn!(
274 pod = %identity.pod_name,
275 "sandbox pod referenced by SA token not found in this namespace"
276 );
277 return Err(Status::not_found("sandbox pod not found"));
278 };

Callers 1

authenticateMethod · 0.45

Calls 9

token_review_identityFunction · 0.85
pod_sandbox_idFunction · 0.85
sandbox_owner_referenceFunction · 0.85
pushMethod · 0.80
codeMethod · 0.80
messageMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected