-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for http mw in v2 version (#30)
- reorganize code for grpc and http mw in v2 folder - NOVER-5:add refactoring and http mw changes in v2 version - NOVER-5: update go mod and path to v2 - NOVER-5: remove grpc_opa package in v2 version - NOVER-5: update documentation for authorizer - NOVER-5: remove external dependencies - NOVER-5: update go version
- Loading branch information
1 parent
d191e93
commit 515846d
Showing
46 changed files
with
1,287 additions
and
2,853 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package authorizer | ||
|
||
import "context" | ||
|
||
// OpaEvaluator implements calling OPA with a request and receiving the raw response | ||
type OpaEvaluator func(ctx context.Context, decisionDocument string, opaReq, opaResp interface{}) error | ||
|
||
type ClaimsVerifier func([]string, []string) (string, []error) | ||
|
||
// Authorizer interface is implemented for making arbitrary requests to Opa. | ||
type Authorizer interface { | ||
// Evaluate evaluates the authorization policy for the given request. | ||
// It takes the context, full method name, request object, and an OpaEvaluator as input. | ||
// It returns a boolean indicating whether the request is authorized, a modified context, | ||
// and an error if any. | ||
Evaluate(ctx context.Context, fullMethod string, req interface{}, opaEvaluator OpaEvaluator) (bool, context.Context, error) | ||
|
||
// OpaQuery executes a query against the OPA (Open Policy Agent) with the specified decision document. | ||
// If the decision document is an empty string, the query is executed against the default decision document | ||
// configured in OPA. | ||
// It takes the context, decision document name, OPA request object, and OPA response object as input. | ||
// It returns an error if any. | ||
OpaQuery(ctx context.Context, decisionDocument string, opaReq, opaResp interface{}) error | ||
|
||
AffirmAuthorization(ctx context.Context, fullMethod string, eq interface{}) (context.Context, error) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package authorizer | ||
|
||
import "context" | ||
|
||
// DecisionInput is app/service-specific data supplied by app/service ABAC requests | ||
type DecisionInput struct { | ||
Type string `json:"type"` // Object/resource-type to match | ||
Verb string `json:"verb"` // Verb to match | ||
SealCtx []interface{} `json:"ctx"` // Array of app/service-specific context data to match | ||
DecisionDocument string `json:"-"` // OPA decision document to query, by default "", | ||
// which is default decision document configured in OPA | ||
} | ||
|
||
// fullMethod is of the form "Service.FullMethod" | ||
type DecisionInputHandler interface { | ||
// GetDecisionInput returns an app/service-specific DecisionInput. | ||
// A nil DecisionInput should NOT be returned unless error. | ||
GetDecisionInput(ctx context.Context, fullMethod string, req interface{}) (*DecisionInput, error) | ||
} | ||
|
||
// DefaultDecisionInputer is an example DecisionInputHandler that is used as default | ||
type DefaultDecisionInputer struct{} | ||
|
||
func (m DefaultDecisionInputer) String() string { | ||
return "authorizer.DefaultDecisionInputer{}" | ||
} | ||
|
||
// GetDecisionInput is an example DecisionInputHandler that returns some decision input | ||
// based on some incoming Context values. App/services will most likely supply their | ||
// own DecisionInputHandler using WithDecisionInputHandler option. | ||
func (m *DefaultDecisionInputer) GetDecisionInput(ctx context.Context, fullMethod string, grpcReq interface{}) (*DecisionInput, error) { | ||
var abacType string | ||
if v, ok := ctx.Value(TypeKey).(string); ok { | ||
abacType = v | ||
} | ||
|
||
var abacVerb string | ||
if v, ok := ctx.Value(VerbKey).(string); ok { | ||
abacVerb = v | ||
} | ||
|
||
decInp := DecisionInput{ | ||
Type: abacType, | ||
Verb: abacVerb, | ||
} | ||
return &decInp, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package authorizer | ||
|
||
// ABACKey is a context.Context key type | ||
type ABACKey string | ||
type ObligationKey string | ||
|
||
const ( | ||
// DefaultValidatePath is default OPA path to perform authz validation | ||
DefaultValidatePath = "v1/data/authz/rbac/validate_v1" | ||
|
||
REDACTED = "redacted" | ||
TypeKey = ABACKey("ABACType") | ||
VerbKey = ABACKey("ABACVerb") | ||
ObKey = ObligationKey("obligations") | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package grpc_opa_middleware | ||
package claim | ||
|
||
import ( | ||
atlas_claims "github.com/infobloxopen/atlas-claims" | ||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package common | ||
|
||
const ( | ||
// DefaultAcctEntitlementsApiPath is default OPA path to fetch acct entitlements | ||
DefaultAcctEntitlementsApiPath = "v1/data/authz/rbac/acct_entitlements_api" | ||
) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package grpc_opa_middleware | ||
package common | ||
|
||
import ( | ||
"reflect" | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package opautil | ||
|
||
import "context" | ||
|
||
// EntitledFeaturesKeyType is the type of the entitled_features key stored in the caller's context | ||
type EntitledFeaturesKeyType string | ||
|
||
// EntitledFeaturesKey is the entitled_features key stored in the caller's context. | ||
// It is also the entitled_features key in the OPA response. | ||
const EntitledFeaturesKey = EntitledFeaturesKeyType("entitled_features") | ||
|
||
// AddRawEntitledFeatures adds raw entitled_features (if they exist) from OPAResponse to context | ||
// The raw JSON-unmarshaled entitled_features is of the form: | ||
// | ||
// map[string]interface {}{"lic":[]interface {}{"dhcp", "ipam"}, "rpz":[]interface {}{"bogon", "malware"}}} | ||
func (o OPAResponse) AddRawEntitledFeatures(ctx context.Context) context.Context { | ||
efIfc, ok := o[string(EntitledFeaturesKey)] | ||
if ok { | ||
ctx = context.WithValue(ctx, EntitledFeaturesKey, efIfc) | ||
} | ||
return ctx | ||
} |
Oops, something went wrong.