opa

package
v1.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ClientKindHTTP ClientKind = "http"
	ClientKindNop  ClientKind = "nop"
	ClientKindMock ClientKind = "mock"

	DefaultClientKind           = ClientKindNop
	DefaultRequestTimeOut       = 10
	DefaultPermissionQueryPath  = "/v1/data/iguazio/authz/allow"
	DefaultPermissionFilterPath = "/v1/data/iguazio/authz/filter_allowed"
)
View Source
const (
	OverrideHeader string = "x-projects-role"
)

Variables

This section is empty.

Functions

func GenerateFunctionEventResourceString

func GenerateFunctionEventResourceString(projectName, functionName, functionEventName string) string

func GenerateFunctionRedeployResourceString

func GenerateFunctionRedeployResourceString(projectName, functionName string) string

func GenerateFunctionResourceString

func GenerateFunctionResourceString(projectName, functionName string) string

func GenerateProjectResourceString

func GenerateProjectResourceString(projectName string) string

func GetUserAndGroupIdsFromAuthSession

func GetUserAndGroupIdsFromAuthSession(session auth.Session) []string

func GetUserAndGroupIdsFromHeaders

func GetUserAndGroupIdsFromHeaders(request *http.Request) []string

Types

type Action

type Action string
const (
	ActionRead   Action = "read"
	ActionCreate Action = "create"
	ActionUpdate Action = "update"
	ActionDelete Action = "delete"
)

type Client

type Client interface {
	QueryPermissions(string, Action, *PermissionOptions) (bool, error)
	QueryPermissionsMultiResources(context.Context, []string, Action, *PermissionOptions) ([]bool, error)
}

func CreateOpaClient

func CreateOpaClient(parentLogger logger.Logger, opaConfiguration *Config) Client

CreateOpaClient creates an OPA client by a given configuration

type ClientKind

type ClientKind string

type Config

type Config struct {

	// OPA server address
	Address string `json:"address,omitempty"`

	// client kind to use (nop | http | mock)
	ClientKind ClientKind `json:"clientKind,omitempty"`

	// timeout period when querying opa server
	RequestTimeout int `json:"requestTimeout,omitempty"`

	// the path used when querying single resource against opa server (e.g.: /v1/data/somewhere/authz/allow)
	PermissionQueryPath string `json:"permissionQueryPath,omitempty"`

	// the path used when querying multiple resources against opa server (e.g.: /v1/data/somewhere/authz/filter_allowed)
	PermissionFilterPath string `json:"permissionFilterPath,omitempty"`

	// for extra verbosity on top of nuclio logger
	LogLevel int `json:"logLevel,omitempty"`

	// the header value for bypassing OPA if needed
	OverrideHeaderValue string `json:"overrideHeaderValue,omitempty"`
}

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(parentLogger logger.Logger,
	address string,
	permissionQueryPath string,
	permissionFilterPath string,
	requestTimeout time.Duration,
	logLevel int,
	overrideHeaderValue string) *HTTPClient

func (*HTTPClient) QueryPermissions

func (c *HTTPClient) QueryPermissions(resource string,
	action Action,
	permissionOptions *PermissionOptions) (bool, error)

func (*HTTPClient) QueryPermissionsMultiResources

func (c *HTTPClient) QueryPermissionsMultiResources(ctx context.Context,
	resources []string,
	action Action,
	permissionOptions *PermissionOptions) ([]bool, error)

QueryPermissionsMultiResources query permissions for multiple resources at once. The response is a list of booleans indicating for each resource if the action against such resource is allowed or not. Therefore, it is guaranteed that len(resources) and len(results) are equal and resources[i] query permission is at results[i]

type MockClient

type MockClient struct {
	mock.Mock
}

func (*MockClient) QueryPermissions

func (mc *MockClient) QueryPermissions(resource string,
	action Action,
	permissionOptions *PermissionOptions) (bool, error)

func (*MockClient) QueryPermissionsMultiResources

func (mc *MockClient) QueryPermissionsMultiResources(ctx context.Context,
	resources []string,
	action Action,
	permissionOptions *PermissionOptions) ([]bool, error)

type NopClient

type NopClient struct {
	// contains filtered or unexported fields
}

func NewNopClient

func NewNopClient(parentLogger logger.Logger, logLevel int) *NopClient

func (*NopClient) QueryPermissions

func (c *NopClient) QueryPermissions(resource string, action Action, permissionOptions *PermissionOptions) (bool, error)

func (*NopClient) QueryPermissionsMultiResources

func (c *NopClient) QueryPermissionsMultiResources(ctx context.Context,
	resources []string, action Action, permissionOptions *PermissionOptions) ([]bool, error)

type PermissionFilterRequest

type PermissionFilterRequest struct {
	Input PermissionFilterRequestInput `json:"input,omitempty"`
}

type PermissionFilterRequestInput

type PermissionFilterRequestInput struct {
	Resources []string `json:"resources,omitempty"`
	Action    string   `json:"action,omitempty"`
	Ids       []string `json:"ids,omitempty"`
}

type PermissionFilterResponse

type PermissionFilterResponse struct {
	Result []string `json:"result,omitempty"`
}

type PermissionOptions

type PermissionOptions struct {
	MemberIds           []string
	RaiseForbidden      bool
	OverrideHeaderValue string
}

type PermissionQueryRequest

type PermissionQueryRequest struct {
	Input PermissionQueryRequestInput `json:"input,omitempty"`
}

type PermissionQueryRequestInput

type PermissionQueryRequestInput struct {
	Resource string   `json:"resource,omitempty"`
	Action   string   `json:"action,omitempty"`
	Ids      []string `json:"ids,omitempty"`
}

type PermissionQueryResponse

type PermissionQueryResponse struct {
	Result bool `json:"result,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL