Skip to content

Commit

Permalink
Cadence authorization (cadence-workflow#2903)
Browse files Browse the repository at this point in the history
As a multi-tendency platform, Cadence wants to provide authN and authZ for domain owner to protect their workflows from being start/describe/terminate by unauthorized person/services.

Assuming authN is taken care already and all requests to Cadence server contains identity information (say this info lives in request context).
AuthZ needs to check: is actor X allow to perform action Y on resource Z.
  • Loading branch information
vancexu authored Dec 13, 2019
1 parent 1c6aa68 commit 8f4ed1c
Show file tree
Hide file tree
Showing 9 changed files with 845 additions and 17 deletions.
4 changes: 4 additions & 0 deletions cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"log"
"time"

"github.com/uber/cadence/common/authorization"

"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
"go.uber.org/zap"

Expand Down Expand Up @@ -204,6 +206,8 @@ func (s *server) startService() common.Daemon {

params.PersistenceConfig.TransactionSizeLimit = dc.GetIntProperty(dynamicconfig.TransactionSizeLimit, common.DefaultTransactionSizeLimit)

params.Authorizer = authorization.NewNopAuthorizer()

params.Logger.Info("Starting service " + s.name)

var daemon common.Daemon
Expand Down
55 changes: 55 additions & 0 deletions common/authorization/authorizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination authority_mock.go

package authorization

import "context"

const (
// DecisionDeny means auth decision is deny
DecisionDeny Decision = iota + 1
// DecisionAllow means auth decision is allow
DecisionAllow
)

type (
// Attributes is input for authority to make decision.
// It can be extended in future if required auth on resources like WorkflowType and TaskList
Attributes struct {
Actor string
APIName string
DomainName string
}

// Result is result from authority.
Result struct {
Decision Decision
}

// Decision is enum type for auth decision
Decision int
)

// Authorizer is an interface for authorization
type Authorizer interface {
Authorize(ctx context.Context, attributes *Attributes) (Result, error)
}
37 changes: 37 additions & 0 deletions common/authorization/nopAuthorizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package authorization

import "context"

type nopAuthority struct{}

// NewNopAuthorizer creates a no-op authority
func NewNopAuthorizer() Authorizer {
return &nopAuthority{}
}

func (a *nopAuthority) Authorize(
ctx context.Context,
attributes *Attributes,
) (Result, error) {
return Result{Decision: DecisionAllow}, nil
}
3 changes: 3 additions & 0 deletions common/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"sync/atomic"
"time"

"github.com/uber/cadence/common/authorization"

"github.com/uber-go/tally"
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
"go.uber.org/yarpc"
Expand Down Expand Up @@ -80,6 +82,7 @@ type (
PublicClient workflowserviceclient.Interface
ArchivalMetadata archiver.ArchivalMetadata
ArchiverProvider provider.ArchiverProvider
Authorizer authorization.Authorizer
}

// MembershipMonitorFactory provides a bootstrapped membership monitor
Expand Down
3 changes: 3 additions & 0 deletions host/onebox.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"fmt"
"sync"

"github.com/uber/cadence/common/authorization"

"github.com/pborman/uuid"
"github.com/uber-go/tally"

Expand Down Expand Up @@ -407,6 +409,7 @@ func (c *cadenceImpl) startFrontend(hosts map[string][]string, startWG *sync.Wai
params.ArchiverProvider = c.archiverProvider
params.ESConfig = c.esConfig
params.ESClient = c.esClient
params.Authorizer = authorization.NewNopAuthorizer()

var err error
params.PersistenceConfig, err = copyPersistenceConfig(c.persistenceConfig)
Expand Down
Loading

0 comments on commit 8f4ed1c

Please sign in to comment.