Skip to content

Commit

Permalink
fix: domain resource domain share to system when non_default_domain_p…
Browse files Browse the repository at this point in the history
…rojects off
  • Loading branch information
Qiu Jian committed Jul 23, 2020
1 parent 7e629b3 commit 671d202
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/cloudcommon/db/infraresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"yunion.io/x/sqlchemy"

"yunion.io/x/onecloud/pkg/apis"
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/rbacutils"
Expand Down Expand Up @@ -248,6 +249,15 @@ func (model *SInfrasResourceBase) SaveSharedInfo(src apis.TOwnerSource, ctx cont
}

func (model *SInfrasResourceBase) SyncShareState(ctx context.Context, userCred mcclient.TokenCredential, shareInfo apis.SAccountShareInfo) {
if !consts.GetNonDefaultDomainProjects() {
if model.PublicSrc != string(apis.OWNER_SOURCE_LOCAL) {
model.SaveSharedInfo(apis.OWNER_SOURCE_CLOUD, ctx, userCred, apis.SShareInfo{
IsPublic: true,
PublicScope: rbacutils.ScopeSystem,
})
}
return
}
si := shareInfo.GetDomainShareInfo()
if model.PublicSrc != string(apis.OWNER_SOURCE_LOCAL) {
model.SaveSharedInfo(apis.OWNER_SOURCE_CLOUD, ctx, userCred, si)
Expand Down
11 changes: 9 additions & 2 deletions pkg/cloudcommon/db/sharablebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ func SharableManagerValidateCreateData(
input.PublicScope = "" // string(rbacutils.ScopeNone)
}
} else {
input.IsPublic = nil
input.PublicScope = string(rbacutils.ScopeNone)
// if non_default_domain_projects turned off, all domain resources shared to system
input.IsPublic = &isPublic
input.PublicScope = string(rbacutils.ScopeSystem)
reqScope = rbacutils.ScopeSystem
}
default:
return input, errors.Wrap(httperrors.ErrInputParameter, "the resource is not sharable")
Expand Down Expand Up @@ -494,6 +496,11 @@ func SharablePerformPrivate(model ISharableBaseModel, ctx context.Context, userC
return nil
}

resourceScope := model.GetModelManager().ResourceScope()
if resourceScope == rbacutils.ScopeDomain && !consts.GetNonDefaultDomainProjects() {
return errors.Wrap(httperrors.ErrForbidden, "not allow to private domain resource")
}

requireIds := model.GetRequiredSharedDomainIds()
if len(requireIds) == 0 {
return errors.Wrap(httperrors.ErrForbidden, "require to be shared to system")
Expand Down

0 comments on commit 671d202

Please sign in to comment.