fix: default vpc must be shared globally

1. For default vpc, prohibit private operation.
2. For default vpc, prohibit public operation without scope 'system'.
This commit is contained in:
rainzm
2020-07-18 19:37:15 +08:00
parent 0fd4a857ec
commit d3741d9a45
+6
View File
@@ -1197,6 +1197,9 @@ func (manager *SVpcManager) ListItemExportKeys(ctx context.Context,
}
func (vpc *SVpc) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
if rbacutils.String2ScopeDefault(input.Scope, rbacutils.ScopeSystem) != rbacutils.ScopeSystem {
return nil, httperrors.NewForbiddenError("For default vpc, only system level sharing can be set")
}
_, err := vpc.SEnabledStatusInfrasResourceBase.PerformPublic(ctx, userCred, query, input)
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBase.PerformPublic")
@@ -1215,6 +1218,9 @@ func (vpc *SVpc) PerformPublic(ctx context.Context, userCred mcclient.TokenCrede
}
func (vpc *SVpc) PerformPrivate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPrivateInput) (jsonutils.JSONObject, error) {
if vpc.Id == "default" {
return nil, httperrors.NewForbiddenError("Prohibit making default vpc private")
}
// perform private for all emulated wires
emptyNets := true
wires := vpc.GetWires()