-
Notifications
You must be signed in to change notification settings - Fork 203
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
Add guards against using distinct subscriptions between owner and child resources #3546
Changes from 1 commit
8c2497a
d2d494c
4b61406
89c2901
aa1687a
b3d9ce9
2c19518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,22 @@ func (h ResourceHierarchy) fullyQualifiedARMIDImpl(subscriptionID string, origin | |
return "", err | ||
} | ||
|
||
root := h[0] | ||
|
||
err = genruntime.VerifyResourceOwnerARMID(root) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
armID, err := genruntime.GetAndParseResourceID(root) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if err = h.matchOwnerSubscription(subscriptionID, armID); err != nil { | ||
return "", err | ||
} | ||
|
||
// Ensure that we have the same number of names and types | ||
if len(remainingNames) != len(resourceTypes) { | ||
return "", errors.Errorf( | ||
|
@@ -202,13 +218,9 @@ func (h ResourceHierarchy) fullyQualifiedARMIDImpl(subscriptionID string, origin | |
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you take the |
||
return "", err | ||
} | ||
// armIDSub may be empty if there is no subscription in the user specified ARM ID (for example because the resource roots | ||
// at the tenant level) | ||
if armID.SubscriptionID != "" { | ||
// Confirm that the subscription ID the user specified matches the subscription ID we're using from our credential | ||
if !strings.EqualFold(armID.SubscriptionID, subscriptionID) { | ||
return "", core.NewSubscriptionMismatchError(armID.SubscriptionID, subscriptionID) | ||
} | ||
|
||
if err = h.matchOwnerSubscription(subscriptionID, armID); err != nil { | ||
return "", err | ||
} | ||
|
||
// Rooting to an ARM ID means that some of the resourceTypes may not actually be included explicitly in our | ||
|
@@ -261,6 +273,18 @@ func (h ResourceHierarchy) fullyQualifiedARMIDImpl(subscriptionID string, origin | |
} | ||
} | ||
|
||
func (h ResourceHierarchy) matchOwnerSubscription(subscriptionID string, ownerRID *arm.ResourceID) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I like it. Considering to move the method into |
||
// armIDSub may be empty if there is no subscription in the user specified ARM ID (for example because the resource roots | ||
// at the tenant level) | ||
if ownerRID.SubscriptionID != "" { | ||
// Confirm that the subscription ID the user specified matches the subscription ID we're using from our credential | ||
if !strings.EqualFold(ownerRID.SubscriptionID, subscriptionID) { | ||
return core.NewSubscriptionMismatchError(ownerRID.SubscriptionID, subscriptionID) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// rootKind returns the ResourceHierarchyRoot type of the hierarchy. | ||
// There are 6 cases here: | ||
// 1. The hierarchy is comprised solely of a resource group. This is subscription rooted. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: Probably can remove this TODO? I am not sure what it was referencing but the code seems OK to me now