Documentation ¶
Index ¶
- Variables
- func CheckIPPinning(ctx context.Context, identity tlsca.Identity, pinSourceIP bool, ...) error
- func ClientAddrsFromContext(ctx context.Context) (src net.Addr, dst net.Addr)
- func ClientImpersonator(ctx context.Context) string
- func ClientSrcAddrFromContext(ctx context.Context) (net.Addr, error)
- func ClientUserMetadata(ctx context.Context) apievents.UserMetadata
- func ClientUserMetadataWithUser(ctx context.Context, user string) apievents.UserMetadata
- func ClientUsername(ctx context.Context) string
- func ConnFromContext(ctx context.Context) (net.Conn, error)
- func ConnectionMetadata(ctx context.Context) apievents.ConnectionMetadata
- func ContextWithClientAddrs(ctx context.Context, src, dst net.Addr) context.Context
- func ContextWithClientSrcAddr(ctx context.Context, addr net.Addr) context.Context
- func ContextWithConn(ctx context.Context, conn net.Conn) context.Context
- func ContextWithUser(ctx context.Context, user IdentityGetter) context.Context
- func ContextWithUserCertificate(ctx context.Context, cert *x509.Certificate) context.Context
- func GetClientUserIsSSO(ctx context.Context) (bool, error)
- func GetClientUsername(ctx context.Context) (string, error)
- func HasBuiltinRole(authContext Context, name string) bool
- func IsCurrentUser(authContext Context, username string) bool
- func IsLocalOrRemoteService(authContext Context) bool
- func IsLocalOrRemoteUser(authContext Context) bool
- func IsLocalUser(authContext Context) bool
- func IsRemoteUser(authContext Context) bool
- func RoleSetForBuiltinRoles(clusterName string, recConfig types.SessionRecordingConfig, ...) (services.RoleSet, error)
- func UserCertificateFromContext(ctx context.Context) (*x509.Certificate, error)
- type AdminActionAuthState
- type Authorizer
- type AuthorizerAccessPoint
- type AuthorizerFunc
- type AuthorizerOpts
- type BuiltinRole
- type Context
- func ContextForBuiltinRole(r BuiltinRole, recConfig types.SessionRecordingConfig) (*Context, error)
- func ContextForLocalUser(ctx context.Context, u LocalUser, accessPoint AuthorizerAccessPoint, ...) (*Context, error)
- func NewAdminContext() (*Context, error)
- func NewBuiltinRoleContext(role types.SystemRole) (*Context, error)
- func (c *Context) AuthorizeAdminAction() error
- func (c *Context) AuthorizeAdminActionAllowReusedMFA() error
- func (c *Context) CheckAccessToKind(kind string, verb string, additionalVerbs ...string) error
- func (c *Context) CheckAccessToResource(resource types.Resource, verb string, additionalVerbs ...string) error
- func (c *Context) CheckAccessToRule(ruleCtx *services.Context, kind string, verb string, additionalVerbs ...string) error
- func (c *Context) GetAccessState(authPref types.AuthPreference) services.AccessState
- func (c *Context) GetUserMetadata() apievents.UserMetadata
- func (c *Context) LockTargets() []types.LockTarget
- func (c *Context) WithExtraRoles(access services.RoleGetter, clusterName string, roles []string) (*Context, error)
- type DeviceAuthorizationOpts
- type IdentityGetter
- type LocalUser
- type MFAAuthData
- type MFAAuthenticator
- type RemoteBuiltinRole
- type RemoteUser
- type WrapIdentity
Constants ¶
This section is empty.
Variables ¶
var ErrIPPinningMismatch = trace.AccessDenied("pinned IP doesn't match observed client IP")
ErrIPPinningMismatch is returned when user's pinned IP doesn't match observed IP.
var ErrIPPinningMissing = trace.AccessDenied("pinned IP is required for the user, but is not present on identity")
ErrIPPinningMissing is returned when user cert should be pinned but isn't.
var ErrIPPinningNotAllowed = trace.AccessDenied("IP pinning is not allowed for connections behind L4 load balancers with " +
"PROXY protocol enabled without explicitly setting 'proxy_protocol: on' in the proxy_service and/or auth_service config.")
ErrIPPinningNotAllowed is returned when user's pinned IP doesn't match observed IP.
var WithDelegator = utils.WithDelegator
WithDelegator alias for backwards compatibility
Functions ¶
func CheckIPPinning ¶
func CheckIPPinning(ctx context.Context, identity tlsca.Identity, pinSourceIP bool, log logrus.FieldLogger) error
CheckIPPinning verifies IP pinning for the identity, using the client IP taken from context. Check is considered successful if no error is returned.
func ClientAddrsFromContext ¶
ClientAddrsFromContext returns the client address from the context.
func ClientImpersonator ¶
ClientImpersonator returns the impersonator username of a remote client making the call. If not present, returns an empty string
func ClientSrcAddrFromContext ¶
ClientSrcAddrFromContext returns the client address from the context.
func ClientUserMetadata ¶
func ClientUserMetadata(ctx context.Context) apievents.UserMetadata
ClientUserMetadata returns a UserMetadata suitable for events caused by a remote client making a call. If ctx didn't pass through auth middleware or did not come from an HTTP request, metadata for teleport.UserSystem is returned.
func ClientUserMetadataWithUser ¶
func ClientUserMetadataWithUser(ctx context.Context, user string) apievents.UserMetadata
ClientUserMetadataWithUser returns a UserMetadata suitable for events caused by a remote client making a call, with the specified username overriding the one from the remote client.
func ClientUsername ¶
ClientUsername returns the username of a remote HTTP client making the call. If ctx didn't pass through auth middleware or did not come from an HTTP request, teleport.UserSystem is returned.
func ConnectionMetadata ¶
func ConnectionMetadata(ctx context.Context) apievents.ConnectionMetadata
ConnectionMetadata returns a ConnectionMetadata suitable for events caused by a remote client making a call. If ctx didn't pass through auth middleware or did not come from an HTTP request, empty metadata is returned.
func ContextWithClientAddrs ¶
ContextWithClientAddrs returns the context with the client source and destination addresses embedded.
func ContextWithClientSrcAddr ¶
ContextWithClientSrcAddr returns the context with the address embedded.
func ContextWithUser ¶
func ContextWithUser(ctx context.Context, user IdentityGetter) context.Context
ContextWithUser returns the context with the user embedded.
func ContextWithUserCertificate ¶
ContextWithUserCertificate returns the context with the user certificate embedded.
func GetClientUserIsSSO ¶
GetClientUserIsSSO extracts the identity of a remote HTTP client and indicates whether that is an SSO user. If ctx didn't pass through auth middleware or did not come from an HTTP request, returns an error.
func GetClientUsername ¶
GetClientUsername returns the username of a remote HTTP client making the call. If ctx didn't pass through auth middleware or did not come from an HTTP request, returns an error.
func HasBuiltinRole ¶
HasBuiltinRole checks if the identity is a builtin role with the matching name.
func IsCurrentUser ¶
IsCurrentUser checks if the identity is a local user matching the given username
func IsLocalOrRemoteService ¶
IsLocalOrRemoteService checks if the identity is either a local or remote service.
func IsLocalOrRemoteUser ¶
IsLocalOrRemoteUser checks if the identity is either a local or remote user.
func IsLocalUser ¶
IsLocalUser checks if the identity is a local user.
func IsRemoteUser ¶
IsRemoteUser checks if the identity is a remote user.
func RoleSetForBuiltinRoles ¶
func RoleSetForBuiltinRoles(clusterName string, recConfig types.SessionRecordingConfig, roles ...types.SystemRole) (services.RoleSet, error)
RoleSetForBuiltinRoles returns RoleSet for embedded builtin role
func UserCertificateFromContext ¶
func UserCertificateFromContext(ctx context.Context) (*x509.Certificate, error)
UserCertificateFromContext returns the user certificate from the context.
Types ¶
type AdminActionAuthState ¶
type AdminActionAuthState int
AdminActionAuthState is an admin action authorization state.
const ( AdminActionAuthState = iota // AdminActionAuthNotRequired admin action authorization is not authorized. // This state is used for non-user cases, like internal service roles or Machine ID. AdminActionAuthNotRequired // AdminActionAuthMFAVerified admin action is authorized with MFA verification. AdminActionAuthMFAVerified // AdminActionAuthMFAVerifiedWithReuse admin action is authorized with MFA verification. // The MFA challenged used for verification allows reuse, which may be denied by some // admin actions. AdminActionAuthMFAVerifiedWithReuse )AdminActionAuthUnauthorized
type Authorizer ¶
type Authorizer interface { // Authorize authorizes user based on identity supplied via context Authorize(ctx context.Context) (*Context, error) }
Authorizer authorizes identity and returns auth context
func NewAuthorizer ¶
func NewAuthorizer(opts AuthorizerOpts) (Authorizer, error)
NewAuthorizer returns new authorizer using backends
type AuthorizerAccessPoint ¶
type AuthorizerAccessPoint interface { // GetAuthPreference returns the cluster authentication configuration. GetAuthPreference(ctx context.Context) (types.AuthPreference, error) // GetRole returns role by name. GetRole(ctx context.Context, name string) (types.Role, error) // GetUser returns user by name. GetUser(ctx context.Context, name string, withSecrets bool) (types.User, error) // GetCertAuthority returns cert authority by id. GetCertAuthority(ctx context.Context, id types.CertAuthID, loadKeys bool) (types.CertAuthority, error) // GetCertAuthorities returns a list of cert authorities. GetCertAuthorities(ctx context.Context, caType types.CertAuthType, loadKeys bool) ([]types.CertAuthority, error) // GetClusterAuditConfig returns cluster audit configuration. GetClusterAuditConfig(ctx context.Context, opts ...services.MarshalOption) (types.ClusterAuditConfig, error) // GetClusterNetworkingConfig returns cluster networking configuration. GetClusterNetworkingConfig(ctx context.Context, opts ...services.MarshalOption) (types.ClusterNetworkingConfig, error) // GetSessionRecordingConfig returns session recording configuration. GetSessionRecordingConfig(ctx context.Context, opts ...services.MarshalOption) (types.SessionRecordingConfig, error) }
AuthorizerAccessPoint is the access point contract required by an Authorizer
type AuthorizerFunc ¶
The AuthorizerFunc type is an adapter to allow the use of ordinary functions as an Authorizer. If f is a function with the appropriate signature, AuthorizerFunc(f) is a Authorizer that calls f.
type AuthorizerOpts ¶
type AuthorizerOpts struct { ClusterName string AccessPoint AuthorizerAccessPoint MFAAuthenticator MFAAuthenticator LockWatcher *services.LockWatcher Logger logrus.FieldLogger // DeviceAuthorization holds Device Trust authorization options. // // Allows services that either do explicit device authorization or don't (yet) // support device trust to disable it. // Most services should not set this field. DeviceAuthorization DeviceAuthorizationOpts }
AuthorizerOpts holds creation options for NewAuthorizer.
type BuiltinRole ¶
type BuiltinRole struct { // Role is the primary builtin role this username is associated with Role types.SystemRole // AdditionalSystemRoles is a collection of additional system roles held by // this identity (only currently used by identities with RoleInstance as their // primary role). AdditionalSystemRoles types.SystemRoles // Username is for authentication tracking purposes Username string // ClusterName is the name of the local cluster ClusterName string // Identity is source x509 used to build this role Identity tlsca.Identity }
BuiltinRole is the role of the Teleport service.
func (BuiltinRole) GetIdentity ¶
func (r BuiltinRole) GetIdentity() tlsca.Identity
GetIdentity returns client identity
func (BuiltinRole) GetServerID ¶
func (r BuiltinRole) GetServerID() string
GetServerID extracts the identity from the full name. The username extracted from the node's identity (x.509 certificate) is expected to consist of "<server-id>.<cluster-name>" so strip the cluster name suffix to get the server id.
Note that as of right now Teleport expects server id to be a UUID4 but older Gravity clusters used to override it with strings like "192_168_1_1.<cluster-name>" so this code can't rely on it being UUID4 to account for clusters upgraded from older versions.
func (BuiltinRole) IsServer ¶
func (r BuiltinRole) IsServer() bool
IsServer returns true if the primary role is either RoleInstance, or one of the local service roles (e.g. proxy).
type Context ¶
type Context struct { // User is the username User types.User // Checker is access checker Checker services.AccessChecker // Identity holds the caller identity: // 1. If caller is a user // a. local user identity // b. remote user identity remapped to local identity based on trusted // cluster role mapping. // 2. If caller is a teleport instance, Identity holds their identity as-is // (because there's no role mapping for non-human roles) Identity IdentityGetter // UnmappedIdentity holds the original caller identity. If this is a remote // user, UnmappedIdentity holds the data before role mapping. Otherwise, // it's identical to Identity. UnmappedIdentity IdentityGetter // AdminActionAuthState is the state of admin action authorization for this auth context. AdminActionAuthState AdminActionAuthState // contains filtered or unexported fields }
Context is authorization context
func ContextForBuiltinRole ¶
func ContextForBuiltinRole(r BuiltinRole, recConfig types.SessionRecordingConfig) (*Context, error)
ContextForBuiltinRole returns a context with the builtin role information embedded.
func ContextForLocalUser ¶
func ContextForLocalUser(ctx context.Context, u LocalUser, accessPoint AuthorizerAccessPoint, clusterName string, disableDeviceRoleMode bool) (*Context, error)
ContextForLocalUser returns a context with the local user info embedded.
func NewAdminContext ¶
NewAdminContext returns new admin auth context
func NewBuiltinRoleContext ¶
func NewBuiltinRoleContext(role types.SystemRole) (*Context, error)
NewBuiltinRoleContext create auth context for the provided builtin role.
func (*Context) AuthorizeAdminAction ¶
AuthorizeAdminAction will ensure that the user is authorized to perform admin actions.
func (*Context) AuthorizeAdminActionAllowReusedMFA ¶
AuthorizeAdminActionAllowReusedMFA will ensure that the user is authorized to perform admin actions. Additionally, MFA challenges that allow reuse will be accepted.
func (*Context) CheckAccessToKind ¶
CheckAccessToKind will ensure that the user has access to the given verbs for the given kind.
func (*Context) CheckAccessToResource ¶
func (c *Context) CheckAccessToResource(resource types.Resource, verb string, additionalVerbs ...string) error
CheckAccessToResource will ensure that the user has access to the given verbs for the given resource.
func (*Context) CheckAccessToRule ¶
func (c *Context) CheckAccessToRule(ruleCtx *services.Context, kind string, verb string, additionalVerbs ...string) error
CheckAccessToRule will ensure that the user has access to the given verbs for the given services.Context and kind. Prefer to use Context.CheckAccessToKind or Context.CheckAccessToResource for common checks.
func (*Context) GetAccessState ¶
func (c *Context) GetAccessState(authPref types.AuthPreference) services.AccessState
GetAccessState returns the AccessState based on the underlying services.AccessChecker and tlsca.Identity.
func (*Context) GetUserMetadata ¶
func (c *Context) GetUserMetadata() apievents.UserMetadata
GetUserMetadata returns information about the authenticated identity to be included in audit events.
func (*Context) LockTargets ¶
func (c *Context) LockTargets() []types.LockTarget
LockTargets returns a list of LockTargets inferred from the context's Identity and UnmappedIdentity.
func (*Context) WithExtraRoles ¶
func (c *Context) WithExtraRoles(access services.RoleGetter, clusterName string, roles []string) (*Context, error)
WithExtraRoles returns a shallow copy of [c], where the users roles have been extended with [roles]. It may return [c] unmodified.
type DeviceAuthorizationOpts ¶
type DeviceAuthorizationOpts struct { // DisableGlobalMode disables the global device_trust.mode toggle. // See [types.DeviceTrust.Mode]. DisableGlobalMode bool // DisableRoleMode disables the role-based device trust toggle. // See [types.RoleOption.DeviceTrustMode]. DisableRoleMode bool }
DeviceAuthorizationOpts captures Device Trust options for AuthorizerOpts.
type IdentityGetter ¶
type IdentityGetter interface { // GetIdentity returns x509-derived identity of the user GetIdentity() tlsca.Identity }
IdentityGetter returns the unmapped client identity.
Unmapped means that if the client is a remote cluster user, the returned tlsca.Identity contains data from the remote cluster before role mapping is applied.
func UserFromContext ¶
func UserFromContext(ctx context.Context) (IdentityGetter, error)
UserFromContext returns the user from the context.
type LocalUser ¶
type LocalUser struct { // Username is local username Username string // Identity is x509-derived identity used to build this user Identity tlsca.Identity }
LocalUser is a local user
func (LocalUser) GetIdentity ¶
GetIdentity returns client identity
type MFAAuthData ¶
type MFAAuthData struct { // User is the authenticated Teleport User. User string // Device is the user's MFA device used to authenticate. Device *types.MFADevice // AllowReuse determines whether the MFA challenge response used to authenticate // can be reused. AllowReuse MFAAuthData may be denied for specific actions. AllowReuse mfav1.ChallengeAllowReuse }
MFAAuthData contains a user's MFA authentication data for a validated MFA response.
type MFAAuthenticator ¶
type MFAAuthenticator interface { // ValidateMFAAuthResponse validates an MFA challenge response. ValidateMFAAuthResponse(ctx context.Context, resp *proto.MFAAuthenticateResponse, user string, requiredExtensions *mfav1.ChallengeExtensions) (*MFAAuthData, error) }
MFAAuthenticator authenticates MFA responses.
type RemoteBuiltinRole ¶
type RemoteBuiltinRole struct { // Role is the builtin role of the user Role types.SystemRole // Username is for authentication tracking purposes Username string // ClusterName is the name of the remote cluster. ClusterName string // Identity is source x509 used to build this role Identity tlsca.Identity }
RemoteBuiltinRole is the role of the remote (service connecting via trusted cluster link) Teleport service.
func (RemoteBuiltinRole) GetIdentity ¶
func (r RemoteBuiltinRole) GetIdentity() tlsca.Identity
GetIdentity returns client identity
func (RemoteBuiltinRole) IsRemoteServer ¶
func (r RemoteBuiltinRole) IsRemoteServer() bool
IsRemoteServer returns true if the primary role is either RoleRemoteProxy, or one of the local service roles (e.g. proxy) from the remote cluster.
type RemoteUser ¶
type RemoteUser struct { // Username is a name of the remote user Username string `json:"username"` // ClusterName is the name of the remote cluster // of the user. ClusterName string `json:"cluster_name"` // RemoteRoles is optional list of remote roles RemoteRoles []string `json:"remote_roles"` // Principals is a list of Unix logins. Principals []string `json:"principals"` // KubernetesGroups is a list of Kubernetes groups KubernetesGroups []string `json:"kubernetes_groups"` // KubernetesUsers is a list of Kubernetes users KubernetesUsers []string `json:"kubernetes_users"` // DatabaseNames is a list of database names a user can connect to. DatabaseNames []string `json:"database_names"` // DatabaseUsers is a list of database users a user can connect as. DatabaseUsers []string `json:"database_users"` // Identity is source x509 used to build this role Identity tlsca.Identity }
RemoteUser defines encoded remote user.
func (RemoteUser) GetIdentity ¶
func (r RemoteUser) GetIdentity() tlsca.Identity
GetIdentity returns client identity
type WrapIdentity ¶
WrapIdentity wraps identity to return identity getter function
func (WrapIdentity) GetIdentity ¶
func (i WrapIdentity) GetIdentity() tlsca.Identity
GetIdentity returns identity