Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Use URN for resource, e.g. cherami:dst:zone1_prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Yang committed Apr 26, 2017
1 parent ddad921 commit ba6a818
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions common/auth_util.go
Expand Up @@ -26,10 +26,12 @@ import (
)

const (
resourceUriTemplateCreateDestination = "dst://%v"
resourceURNTemplateCreateDestination = "cherami:dst:%v"
)

func GetResourceRootUri(scommon SCommon) string {
// GetResourceRootURN returns the root resource URN, e.g. cherami:dst:zone1_prod
// We use URN (Uniform Resource Name) like this: https://www.ietf.org/rfc/rfc2141.txt
func GetResourceRootURN(scommon SCommon) string {
deploymentName := scommon.GetConfig().GetDeploymentName()
return fmt.Sprintf(resourceUriTemplateCreateDestination, strings.ToLower(deploymentName))
return fmt.Sprintf(resourceURNTemplateCreateDestination, strings.ToLower(deploymentName))
}
5 changes: 3 additions & 2 deletions services/frontendhost/frontend.go
Expand Up @@ -588,13 +588,14 @@ func (h *Frontend) CreateDestination(ctx thrift.Context, createRequest *c.Create

authSubject, err := h.GetAuthManager().Authenticate(ctx)
if err != nil {
// TODO add metrics
return nil, err
}

authResource := common.GetResourceRootUri(h.SCommon)
authResource := common.GetResourceRootURN(h.SCommon)
err = h.GetAuthManager().Authorize(authSubject, common.OperationCreate, common.Resource(authResource))
if err != nil {
lclLg.WithField(common.TagSubject, authSubject).WithField(common.TagResource, authResource).Warn("Not allowed to create destination")
lclLg.WithField(common.TagSubject, authSubject).WithField(common.TagResource, authResource).Info("Not allowed to create destination")
// TODO add metrics
return nil, err
}
Expand Down

0 comments on commit ba6a818

Please sign in to comment.