Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v16] Verify subscription id matches #51329

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading