-
Notifications
You must be signed in to change notification settings - Fork 154
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
don't add bind and dial permissions to services for admins #1782
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e4ef2b
respect service policies for admin identities. fixes #1781.
scareything 512be08
fix service tests
scareything ba995a6
combine ReadForNonAdminIdentityInTx into ReadForIdentityInTx
scareything ecce28c
more tests fixes
scareything 0c628ae
update changelog
scareything 4bd062b
update versions in changelog
scareything 797fd79
update versions in changelog
scareything 6ed63f4
Merge remote-tracking branch 'origin/fix.1781' into fix.1781
scareything File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,21 +119,11 @@ func (self *EdgeServiceManager) ReadForIdentity(id string, identityId string, co | |
} | ||
|
||
func (self *EdgeServiceManager) ReadForIdentityInTx(tx *bbolt.Tx, id string, identityId string, configTypes map[string]struct{}) (*ServiceDetail, error) { | ||
identity, err := self.GetEnv().GetManagers().Identity.readInTx(tx, identityId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var err error | ||
var service *ServiceDetail | ||
|
||
if identity.IsAdmin { | ||
service, err = self.readInTx(tx, id) | ||
if err == nil && service != nil { | ||
service.Permissions = []string{db.PolicyTypeBindName, db.PolicyTypeDialName} | ||
} | ||
} else { | ||
service, err = self.ReadForNonAdminIdentityInTx(tx, id, identityId) | ||
} | ||
// service permissions for admin & non-admin identities will be set according to policies | ||
service, err = self.ReadForNonAdminIdentityInTx(tx, id, identityId) | ||
if err == nil && len(configTypes) > 0 { | ||
identityServiceConfigs := self.env.GetStores().Identity.LoadServiceConfigsByServiceAndType(tx, identityId, configTypes) | ||
self.mergeConfigs(tx, configTypes, service, identityServiceConfigs) | ||
|
@@ -143,10 +133,14 @@ func (self *EdgeServiceManager) ReadForIdentityInTx(tx *bbolt.Tx, id string, ide | |
|
||
func (self *EdgeServiceManager) ReadForNonAdminIdentityInTx(tx *bbolt.Tx, id string, identityId string) (*ServiceDetail, error) { | ||
edgeServiceStore := self.env.GetStores().EdgeService | ||
identity, err := self.GetEnv().GetManagers().Identity.readInTx(tx, identityId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
isBindable := edgeServiceStore.IsBindableByIdentity(tx, id, identityId) | ||
isDialable := edgeServiceStore.IsDialableByIdentity(tx, id, identityId) | ||
|
||
if !isBindable && !isDialable { | ||
if !isBindable && !isDialable && !identity.IsAdmin { // admin can view services even if policies don't permit bind/dial | ||
return nil, boltz.NewNotFoundError(self.GetStore().GetSingularEntityType(), "id", id) | ||
} | ||
|
||
|
@@ -163,6 +157,10 @@ func (self *EdgeServiceManager) ReadForNonAdminIdentityInTx(tx *bbolt.Tx, id str | |
if isDialable { | ||
result.Permissions = append(result.Permissions, db.PolicyTypeDialName) | ||
} | ||
if result.Permissions == nil { | ||
// don't return results with no permissions, since some SDKs assume non-nil permissions | ||
result.Permissions = []string{db.PolicyTypeInvalidName} | ||
} | ||
return result, nil | ||
} | ||
|
||
|
@@ -259,14 +257,8 @@ func (result *ServiceListResult) collect(tx *bbolt.Tx, ids []string, queryMetaDa | |
identityServiceConfigs := result.manager.env.GetStores().Identity.LoadServiceConfigsByServiceAndType(tx, result.identityId, result.configTypes) | ||
|
||
for _, key := range ids { | ||
if !result.isAdmin && result.identityId != "" { | ||
service, err = result.manager.ReadForNonAdminIdentityInTx(tx, key, result.identityId) | ||
} else { | ||
service, err = result.manager.readInTx(tx, key) | ||
if service != nil && result.isAdmin { | ||
service.Permissions = []string{db.PolicyTypeBindName, db.PolicyTypeDialName} | ||
} | ||
} | ||
// service permissions for admin & non-admin identities will be set according to policies | ||
service, err = result.manager.ReadForNonAdminIdentityInTx(tx, key, result.identityId) | ||
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. I'm not sure if this is valid when |
||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we merge ReadForNonAdminIdentityInTx into ReadForIdentityInTx, as the 'NonAdmin' name is no longer accurate and the first method is now pretty short?