You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnfmt.Errorf("audience %q not found in pod spec volume", requestedAudience)
671
+
iffoundAudiencesInPodSpec {
672
+
returnnil
659
673
}
660
-
returnnil
674
+
675
+
userInfo:=a.GetUserInfo()
676
+
attrs:= authorizer.AttributesRecord{
677
+
User: userInfo, // this is the user info of the node requesting the token
678
+
Verb: "request-serviceaccounts-token-audience",
679
+
Namespace: a.GetNamespace(),
680
+
APIGroup: "",
681
+
APIVersion: "v1",
682
+
Resource: requestedAudience, // this gives us the audience for which node is requesting a token for; wildcard will allow all audiences
683
+
Name: a.GetName(), // this gives us the service account name for which node is requesting a token for; if not set, default will allow all service accounts
684
+
ResourceRequest: true,
685
+
}
686
+
687
+
authorized, _, err:=p.authz.Authorize(ctx, attrs)
688
+
// an authorizer like RBAC could encounter evaluation errors and still allow the request, so authorizer decision is checked before error here.
689
+
// following the same pattern as withAuthorization (ref: https://github.com/kubernetes/kubernetes/blob/2b025e645975d6d51bf38c008f972c632cf49657/staging/src/k8s.io/apiserver/pkg/endpoints/filters/authorization.go#L71-L91)
690
+
ifauthorized==authorizer.DecisionAllow {
691
+
returnnil
692
+
}
693
+
iferr!=nil {
694
+
returnfmt.Errorf("audience %q not found in pod spec volume, error authorizing %s to request tokens for this audience: %w", requestedAudience, userInfo.GetName(), err)
695
+
}
696
+
697
+
returnfmt.Errorf("audience %q not found in pod spec volume, %s is not authorized to request tokens for this audience", requestedAudience, userInfo.GetName())
err: `serviceaccounts "mysa" is forbidden: audience "foo" not found in pod spec volume`,
1320
+
err: `serviceaccounts "mysa" is forbidden: audience "foo" not found in pod spec volume, system:node:mynode is not authorized to request tokens for this audience`,
1321
+
authz: fakeAuthorizer{
1322
+
t: t,
1323
+
serviceAccountName: "mysa",
1324
+
namespace: coremypod.Namespace,
1325
+
requestAudience: "foo",
1326
+
decision: authorizer.DecisionDeny,
1327
+
},
1315
1328
},
1316
1329
{
1317
1330
name: "allow create of token when audience in pod --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled",
err: `audience "bar" not found in pod spec volume`,
1350
+
err: `audience "bar" not found in pod spec volume, system:node:mynode is not authorized to request tokens for this audience`,
1351
+
authz: fakeAuthorizer{
1352
+
t: t,
1353
+
serviceAccountName: "mysa",
1354
+
namespace: coremypod.Namespace,
1355
+
requestAudience: "bar",
1356
+
decision: authorizer.DecisionDeny,
1357
+
},
1338
1358
},
1339
1359
{
1340
1360
name: "forbid create of token when audience in pod --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled, csidriver not found",
err: `error validating audience "foo": csidriver.storage.k8s.io "com.example.csi.mydriver" not found`,
1370
+
authz: fakeAuthorizer{},
1350
1371
},
1351
1372
{
1352
1373
name: "allow create of token when audience in pod --> pvc --> pv --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled",
err: `audience "bar" not found in pod spec volume`,
1397
+
err: `audience "bar" not found in pod spec volume, system:node:mynode is not authorized to request tokens for this audience`,
1398
+
authz: fakeAuthorizer{
1399
+
t: t,
1400
+
serviceAccountName: "mysa",
1401
+
namespace: coremypod.Namespace,
1402
+
requestAudience: "bar",
1403
+
decision: authorizer.DecisionDeny,
1404
+
},
1377
1405
},
1378
1406
{
1379
1407
name: "forbid create of token when audience in pod --> pvc --> pv --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled, pvc not found",
err: `error validating audience "foo": persistentvolumeclaim "pvclaim" not found`,
1419
+
authz: fakeAuthorizer{},
1391
1420
},
1392
1421
{
1393
1422
name: "forbid create of token when audience in pod --> pvc --> pv --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled, pv not found",
err: `error validating audience "foo": persistentvolume "pvname" not found`,
1434
+
authz: fakeAuthorizer{},
1405
1435
},
1406
1436
{
1407
1437
name: "allow create of token when audience in pod --> ephemeral --> pvc --> pv --> csi --> driver --> tokenrequest with audience and ServiceAccountNodeAudienceRestriction is enabled",
err: `serviceaccounts "mysa" is forbidden: audience "foo" not found in pod spec volume, system:node:mynode is not authorized to request tokens for this audience`,
0 commit comments