Skip to content

Commit

Permalink
Verify subscription id matches (#51085)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardjkim authored Jan 22, 2025
1 parent a2438f3 commit a749106
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/auth/join_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func parseAndVerifyAttestedData(ctx context.Context, adBytes []byte, challenge s
}

// verifyVMIdentity verifies that the provided access token came from the
// correct Azure VM. Returns the Aure join attributes
// correct Azure VM. Returns the Azure join attributes
func verifyVMIdentity(
ctx context.Context,
cfg *azureRegisterConfig,
Expand Down Expand Up @@ -291,6 +291,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
}
logger.WarnContext(ctx, "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 a749106

Please sign in to comment.