Skip to content

Commit 7296853

Browse files
authored
Print OIDC token payload (#222)
Print the JSON payload for the OIDC token for the better debuggability regarding the WIP policy. Signed-off-by: Jiankun Lu <[email protected]>
1 parent f2b7b10 commit 7296853

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

launcher/container_runner.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ func (r *ContainerRunner) refreshToken(ctx context.Context) (time.Duration, erro
349349
return 0, fmt.Errorf("failed to write token to container mount source point: %v", err)
350350
}
351351

352+
// Print out the claims in the jwt payload
353+
mapClaims := jwt.MapClaims{}
354+
_, _, err = jwt.NewParser().ParseUnverified(string(token), mapClaims)
355+
if err != nil {
356+
return 0, fmt.Errorf("failed to parse token: %w", err)
357+
}
358+
claimsString, err := json.MarshalIndent(mapClaims, "", " ")
359+
if err != nil {
360+
return 0, fmt.Errorf("failed to format claims: %w", err)
361+
}
362+
r.logger.Println(string(claimsString))
363+
352364
return time.Duration(float64(time.Until(claims.ExpiresAt.Time)) * defaultRefreshMultiplier), nil
353365
}
354366

@@ -357,7 +369,6 @@ func (r *ContainerRunner) fetchAndWriteToken(ctx context.Context) error {
357369
if err := os.MkdirAll(HostTokenPath, 0744); err != nil {
358370
return err
359371
}
360-
361372
duration, err := r.refreshToken(ctx)
362373
if err != nil {
363374
return err

0 commit comments

Comments
 (0)