proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPolicy is the default value for the config oidc.policy field.
	// It assumes the user is using keycloak in a default configuration and checks if the requested tenant ID appears in the users realm roles
	DefaultPolicy = `
{{- if not (has .Tenant.ID .Token.Claims.realm_access.roles) }}
Forbidden: You are not part of this tenant
{{- end }}
`
	DefaultGetSubject = `{{ .Token.Claims.preferred_username }}`

	// DefaultAddress is the default value of the config http.address field.
	// It listens on localhost only on port 8088.
	DefaultAddress = "127.0.0.1:8088"
	// DefaultTenantsPath is the default value of the config http.tenantsPath field.
	// It assuems tenant servers have --static-prefix=tenants/${tenant_id}
	DefaultTenantsPath = "/tenants/"
	// DefaultAccessTokenHeader is the default value of the config oidc.tokenHeader.
	// It assumes the server is being proxied by the OAuth2Proxy (https://github.com/oauth2-proxy/oauth2-proxy/) with --pass-access-token
	DefaultTokenHeader = "X-Forwarded-Access-Token"
	// DefaulTokenMode is the default value of the config oidc.tokenMode.
	DefaultTokenMode = gotoken.TokenModeRaw
	// DefaultCerificate header is the default value of the config robots.certificateHeader
	DefaultCertificateHeader = "Ssl-Client-Cert"
)
View Source
const (
	MLFlowUserTag     = "mlflow.user"
	MLFlowUserIDField = "user_id"
	MLFlowTagsField   = "tags"

	MLFlowCreateExperimentPath      = "2.0/mlflow/experiments/create"
	MLFlowCreateRunPath             = "2.0/mlflow/runs/create"
	MLFlowCreateRegisteredModelPath = "2.0/mlflow/registered-models/create"
	MLFlowCreateModelVersionPath    = "2.0/mlflow/model-versions/create"

	MLFlowSetTagExperimentPath      = "2.0/mlflow/experiments/set-experiment-tag"
	MLFlowSetTagRunPath             = "2.0/mlflow/runs/set-tag"
	MLFlowSetTagRegisteredModelPath = "2.0/mlflow/registered-models/set-tag"
	MLFlowSetTagModelVersionPath    = "2.0/mlflow/model-versions/set-tag"

	MLFlowDeleteTagRunPath             = "2.0/mlflow/runs/delete-tag"
	MLFlowDeleteTagRegisteredModelPath = "2.0/mlflow/registered-models/delete-tag"
	MLFlowDeleteTagModelVersionPath    = "2.0/mlflow/model-versions/delete-tag"

	MLFlowAPIPrefix  = "api/"
	MLFlowAJAXPrefix = "ajax-api/"
)

Variables

View Source
var (
	ParsedDefaultPolicy     Template
	ParsedDefaultGetSubject Template
	ParsedDefaultAddress    Address
)
View Source
var (
	HomePage *template.Template
)

Functions

func FuncMap

func FuncMap() template.FuncMap

func JoinPaths

func JoinPaths(p1 string, ps ...string) string

func TplHasIntersection

func TplHasIntersection(lists ...interface{}) bool

func TplIntersection

func TplIntersection(lists ...interface{}) interface{}

func WithTrailingSlash

func WithTrailingSlash(p string) string

func WithoutTrailingSlash

func WithoutTrailingSlash(p string) string

Types

type Address

type Address struct {
	URL
}

func (*Address) Parse

func (a *Address) Parse(s string) (*Address, error)

func (*Address) String

func (a *Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(bytes []byte) error

type CertificateFromPath

type CertificateFromPath struct {
	Raw   string
	PEM   string
	Inner *x509.Certificate
}

func (*CertificateFromPath) UnmarshalJSON

func (c *CertificateFromPath) UnmarshalJSON(bytes []byte) error

type PolicyContext

type PolicyContext struct {
	Tenant         *ProxyMLFlowTenant
	Token          *jwt.Token
	Request        *http.Request
	ExtraVariables interface{}
}

type ProxyConfig

type ProxyConfig struct {
	OIDC   ProxyOIDCConfig   `json:"oidc"`
	MLFlow ProxyMLFlowConfig `json:"mlflow"`
	HTTP   ProxyHTTPConfig   `json:"http"`
	TLS    ProxyTLSConfig    `json:"tls"`
	Robots ProxyRobotConfig  `json:"robots"`
}

func (*ProxyConfig) ApplyDefaults

func (p *ProxyConfig) ApplyDefaults() (err error)

func (*ProxyConfig) Init

func (p *ProxyConfig) Init() *ProxyConfig

type ProxyHTTPConfig

type ProxyHTTPConfig struct {
	Address     Address `json:"address"`
	ExternalURL URL     `json:"externalURL"`
	TenantsPath string  `json:"tenantsPath"`
}

type ProxyMLFlowConfig

type ProxyMLFlowConfig struct {
	Tenants []ProxyMLFlowTenant `json:"tenants"`
}

type ProxyMLFlowTenant

type ProxyMLFlowTenant struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Upstream URL    `json:"upstream"`
}

type ProxyOIDCConfig

type ProxyOIDCConfig struct {
	TokenHeader    string            `json:"tokenHeader"`
	TokenMode      gotoken.TokenMode `json:"tokenMode"`
	WellKnownURL   URL               `json:"wellKnownURL"`
	Policy         Template          `json:"policy"`
	GetSubject     Template          `json:"getSubject"`
	ExtraVariables interface{}       `json:"extraVariables"`
}

type ProxyOptions

type ProxyOptions struct {
	Log *log.Logger
}

type ProxyRobotConfig

type ProxyRobotConfig struct {
	CertificateHeader string  `json:"certificateHeader"`
	Robots            []Robot `json:"robots"`
}

type ProxyState

type ProxyState struct {
	Config  *ProxyConfig
	Tenants map[string]*ProxyTenantState
	BaseURL *url.URL
	*http.ServeMux
	Log      *log.Logger
	GetToken gotoken.TokenGetter

	HomeURL        string
	BasePath       string
	TenantsPath    string
	LongHealthPath string
}

func NewProxy

func NewProxy(config ProxyConfig, opts ProxyOptions) (*ProxyState, error)

func (*ProxyState) Authorize

func (p *ProxyState) Authorize(req *http.Request, tenant *ProxyMLFlowTenant, token *jwt.Token) (string, error)

func (*ProxyState) EnforceUserTagsAndFields

func (p *ProxyState) EnforceUserTagsAndFields(w http.ResponseWriter, req *http.Request, path string, requestID string, subject string, token *jwt.Token) (rejectMsg string, err error)

func (*ProxyState) EnsureRequestID

func (p *ProxyState) EnsureRequestID(w http.ResponseWriter, req *http.Request) string

func (*ProxyState) EnsureToken

func (p *ProxyState) EnsureToken(w http.ResponseWriter, req *http.Request, requestID string) *jwt.Token

func (*ProxyState) GetSubject

func (p *ProxyState) GetSubject(token *jwt.Token) (string, error)

func (*ProxyState) Home

func (p *ProxyState) Home(w http.ResponseWriter, req *http.Request, requestID string, token *jwt.Token)

func (*ProxyState) InternalError

func (p *ProxyState) InternalError(w http.ResponseWriter, req *http.Request, requestID string, msg string, err error)

func (*ProxyState) ListenAndServe

func (p *ProxyState) ListenAndServe() error

func (*ProxyState) MergeURLs

func (p *ProxyState) MergeURLs(dest, src *url.URL)

func (*ProxyState) MutateRequest

func (p *ProxyState) MutateRequest(w http.ResponseWriter, req *http.Request, path string, requestID string, subject string, token *jwt.Token) (rejectMsg string, err error)

func (*ProxyState) Proxy

func (p *ProxyState) Proxy(w http.ResponseWriter, r *http.Request, requestID string, token *jwt.Token)

func (*ProxyState) ServeHTTP

func (p *ProxyState) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ProxyState) ValidateRequest

func (p *ProxyState) ValidateRequest(w http.ResponseWriter, req *http.Request, requestID string, token *jwt.Token) (tenant *ProxyTenantState, path string, err error)

type ProxyTLSConfig

type ProxyTLSConfig struct {
	Enabled    bool   `json:"enabled"`
	CertFile   string `json:"certFile"`
	KeyFile    string `json:"keyFile"`
	Terminated bool   `json:"terminated"`
}

type ProxyTenantState

type ProxyTenantState struct {
	*ProxyMLFlowTenant
	Proxy *ProxyState
	httputil.ReverseProxy
}

type Robot

type Robot struct {
	Name        string              `json:"name"`
	Cert        CertificateFromPath `json:"certPath"`
	SecretToken SecretTokenFromPath `json:"secretTokenPath"`
	Token       TokenFromClaims     `json:"token"`
}

type SecretTokenFromPath added in v0.2.0

type SecretTokenFromPath struct {
	Token string
}

func (*SecretTokenFromPath) UnmarshalJSON added in v0.2.0

func (c *SecretTokenFromPath) UnmarshalJSON(bytes []byte) error

type Template

type Template struct {
	Inner *template.Template
	Raw   string
}

func (*Template) UnmarshalJSON

func (t *Template) UnmarshalJSON(bytes []byte) error

type TokenFromClaims

type TokenFromClaims struct {
	Raw   map[string]interface{}
	Inner jwt.Token
}

func (*TokenFromClaims) UnmarshalJSON

func (t *TokenFromClaims) UnmarshalJSON(bytes []byte) error

type URL

type URL struct {
	Inner *url.URL
	Raw   string
}

func (*URL) Parse

func (u *URL) Parse(s string) (*URL, error)

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(bytes []byte) error

Jump to

Keyboard shortcuts

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