mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-16 07:44:31 +08:00
This commit fixes #3369, refs #3374 It adds support for kuberenetes_users section in roles, allowing Teleport proxy to impersonate user identities. It also extends variable interpolation syntax by adding suffix and prefix to variables and function `email.local`: Example: ```yaml kind: role version: v3 metadata: name: admin spec: allow: # extract email local part from the email claim logins: ['{{email.local(external.email)}}'] # impersonate a kubernetes user with IAM prefix kubernetes_users: ['IAM#{{external.email}}'] # the deny section uses the identical format as the 'allow' section. # the deny rules always override allow rules. deny: {} ``` Some notes on email.local behavior: * This is the only function supported in the template variables for now * In case if the email.local will encounter invalid email address, it will interpolate to empty value, will be removed from resulting output. Changes in impersonation behavior: * By default, if no kubernetes_users is set, which is a majority of cases, user will impersonate themselves, which is the backwards-compatible behavior. * As long as at least one `kubernetes_users` is set, the forwarder will start limiting the list of users allowed by the client to impersonate. * If the users' role set does not include actual user name, it will be rejected, otherwise there will be no way to exclude the user from the list). * If the `kuberentes_users` role set includes only one user (quite frequently that's the real intent), teleport will default to it, otherwise it will refuse to select. This will enable the use case when `kubernetes_users` has just one field to link the user identity with the IAM role, for example `IAM#{{external.email}}` * Previous versions of the forwarding proxy were denying all external impersonation headers, this commit allows 'Impesrsonate-User' and 'Impersonate-Group' header values that are allowed by role set. * Previous versions of the forwarding proxy ignored 'Deny' section of the roles when applied to impersonation, this commit fixes that - roles with deny kubernetes_users and kubernetes_groups section will not allow impersonation of those users and groups.
132 lines
4.0 KiB
Go
132 lines
4.0 KiB
Go
/*
|
|
Copyright 2017 Gravitational, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
// package modules allows external packages override certain behavioral
|
|
// aspects of teleport
|
|
package modules
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"runtime"
|
|
"sync"
|
|
|
|
"github.com/gravitational/teleport"
|
|
)
|
|
|
|
// Modules defines interface that external libraries can implement customizing
|
|
// default teleport behavior
|
|
type Modules interface {
|
|
// EmptyRoles handler is called when a new trusted cluster with empty roles
|
|
// is being created
|
|
EmptyRolesHandler() error
|
|
// DefaultAllowedLogins returns default allowed logins for a new admin role
|
|
DefaultAllowedLogins() []string
|
|
// DefaultKubeGroups returns default kuberentes groups for a new admin role
|
|
DefaultKubeGroups() []string
|
|
// PrintVersion prints teleport version
|
|
PrintVersion()
|
|
// RolesFromLogins returns roles for external user based on the logins
|
|
// extracted from the connector
|
|
RolesFromLogins([]string) []string
|
|
// TraitsFromLogins returns traits for external user based on the logins
|
|
// and kubernetes groups extracted from the connector
|
|
TraitsFromLogins(logins []string, kubeGroups []string, kubeUsers []string) map[string][]string
|
|
// SupportsKubernetes returns true if this cluster supports kubernetes
|
|
SupportsKubernetes() bool
|
|
// IsBoringBinary checks if the binary was compiled with BoringCrypto.
|
|
IsBoringBinary() bool
|
|
}
|
|
|
|
// SetModules sets the modules interface
|
|
func SetModules(m Modules) {
|
|
mutex.Lock()
|
|
defer mutex.Unlock()
|
|
modules = m
|
|
}
|
|
|
|
// GetModules returns the modules interface
|
|
func GetModules() Modules {
|
|
mutex.Lock()
|
|
defer mutex.Unlock()
|
|
return modules
|
|
}
|
|
|
|
type defaultModules struct{}
|
|
|
|
// EmptyRolesHandler is called when a new trusted cluster with empty roles
|
|
// is created, no-op by default
|
|
func (p *defaultModules) EmptyRolesHandler() error {
|
|
return nil
|
|
}
|
|
|
|
// DefaultKubeGroups returns default kuberentes groups for a new admin role
|
|
func (p *defaultModules) DefaultKubeGroups() []string {
|
|
return []string{teleport.TraitInternalKubeGroupsVariable}
|
|
}
|
|
|
|
// DefaultAllowedLogins returns allowed logins for a new admin role
|
|
func (p *defaultModules) DefaultAllowedLogins() []string {
|
|
return []string{teleport.TraitInternalLoginsVariable}
|
|
}
|
|
|
|
// PrintVersion prints the Teleport version.
|
|
func (p *defaultModules) PrintVersion() {
|
|
var buf bytes.Buffer
|
|
|
|
buf.WriteString(fmt.Sprintf("Teleport v%s ", teleport.Version))
|
|
buf.WriteString(fmt.Sprintf("git:%s ", teleport.Gitref))
|
|
buf.WriteString(runtime.Version())
|
|
|
|
fmt.Println(buf.String())
|
|
}
|
|
|
|
// RolesFromLogins returns roles for external user based on the logins
|
|
// extracted from the connector
|
|
//
|
|
// By default there is only one role, "admin", so logins are ignored and
|
|
// instead used as allowed logins (see TraitsFromLogins below).
|
|
func (p *defaultModules) RolesFromLogins(logins []string) []string {
|
|
return []string{teleport.AdminRoleName}
|
|
}
|
|
|
|
// TraitsFromLogins returns traits for external user based on the logins
|
|
// extracted from the connector
|
|
//
|
|
// By default logins are treated as allowed logins user traits.
|
|
func (p *defaultModules) TraitsFromLogins(logins []string, kubeGroups, kubeUsers []string) map[string][]string {
|
|
return map[string][]string{
|
|
teleport.TraitLogins: logins,
|
|
teleport.TraitKubeGroups: kubeGroups,
|
|
teleport.TraitKubeUsers: kubeUsers,
|
|
}
|
|
}
|
|
|
|
// SupportsKubernetes returns true if this cluster supports kubernetes
|
|
func (p *defaultModules) SupportsKubernetes() bool {
|
|
return true
|
|
}
|
|
|
|
// IsBoringBinary checks if the binary was compiled with BoringCrypto.
|
|
func (p *defaultModules) IsBoringBinary() bool {
|
|
return false
|
|
}
|
|
|
|
var (
|
|
mutex = &sync.Mutex{}
|
|
modules Modules = &defaultModules{}
|
|
)
|