Skip to content

Commit

Permalink
Verify subscription id matches (#51085) (#51329)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardjkim authored Jan 22, 2025
1 parent 548a7d1 commit 201535d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/auth/join_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ func verifyVMIdentity(
// from the VM resource.
vmSubscription, vmResourceGroup, err := claimsToIdentifiers(tokenClaims)
if err == nil {
if subscriptionID != vmSubscription {
return nil, trace.AccessDenied("subscription ID mismatch between attested data and access token")
}
return azureJoinToAttrs(vmSubscription, vmResourceGroup), nil
}
log.WithError(err).Warn("Failed to parse VM identifiers from claims. Retrying with Azure VM API.")
Expand Down
22 changes: 22 additions & 0 deletions lib/auth/join_azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,28 @@ func TestAuth_RegisterUsingAzureClaims(t *testing.T) {
certs: []*x509.Certificate{tlsConfig.Certificate},
assertError: require.NoError,
},
{
name: "subscription mismatch between attestation and token",
requestTokenName: "test-token",
tokenSubscription: "attested-subscription",
tokenVMID: defaultVMID,
tokenManagedIdentityResourceID: vmResourceID("token-subscription", defaultResourceGroup, defaultVMName),
tokenSpec: types.ProvisionTokenSpecV2{
Roles: []types.SystemRole{types.RoleNode},
Azure: &types.ProvisionTokenSpecV2Azure{
Allow: []*types.ProvisionTokenSpecV2Azure_Rule{
{
Subscription: "token-subscription",
ResourceGroups: []string{defaultResourceGroup},
},
},
},
JoinMethod: types.JoinMethodAzure,
},
verify: mockVerifyToken(nil),
certs: []*x509.Certificate{tlsConfig.Certificate},
assertError: isAccessDenied,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 201535d

Please sign in to comment.