repo stringlengths 5 67 | sha stringlengths 40 40 | path stringlengths 4 234 | url stringlengths 85 339 | language stringclasses 6 values | split stringclasses 3 values | doc stringlengths 3 51.2k | sign stringlengths 5 8.01k | problem stringlengths 13 51.2k | output stringlengths 0 3.87M |
|---|---|---|---|---|---|---|---|---|---|
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/sanitize.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/sanitize.go#L117-L122 | go | train | // Delete deletes item by key | func (s *Sanitizer) Delete(ctx context.Context, key []byte) error | // Delete deletes item by key
func (s *Sanitizer) Delete(ctx context.Context, key []byte) error | {
if !isKeySafe(key) {
return trace.BadParameter(errorMessage)
}
return s.backend.Delete(ctx, key)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/sanitize.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/sanitize.go#L125-L133 | go | train | // DeleteRange deletes range of items | func (s *Sanitizer) DeleteRange(ctx context.Context, startKey []byte, endKey []byte) error | // DeleteRange deletes range of items
func (s *Sanitizer) DeleteRange(ctx context.Context, startKey []byte, endKey []byte) error | {
if !isKeySafe(startKey) {
return trace.BadParameter(errorMessage)
}
if !isKeySafe(endKey) {
return trace.BadParameter(errorMessage)
}
return s.backend.DeleteRange(ctx, startKey, endKey)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/sanitize.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/sanitize.go#L139-L144 | go | train | // KeepAlive keeps object from expiring, updates lease on the existing object,
// expires contains the new expiry to set on the lease,
// some backends may ignore expires based on the implementation
// in case if the lease managed server side | func (s *Sanitizer) KeepAlive(ctx context.Context, lease Lease, expires time.Time) error | // KeepAlive keeps object from expiring, updates lease on the existing object,
// expires contains the new expiry to set on the lease,
// some backends may ignore expires based on the implementation
// in case if the lease managed server side
func (s *Sanitizer) KeepAlive(ctx context.Context, lease Lease, expires time.Time) error | {
if !isKeySafe(lease.Key) {
return trace.BadParameter(errorMessage)
}
return s.backend.KeepAlive(ctx, lease, expires)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/sanitize.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/sanitize.go#L147-L154 | go | train | // NewWatcher returns a new event watcher | func (s *Sanitizer) NewWatcher(ctx context.Context, watch Watch) (Watcher, error) | // NewWatcher returns a new event watcher
func (s *Sanitizer) NewWatcher(ctx context.Context, watch Watch) (Watcher, error) | {
for _, prefix := range watch.Prefixes {
if !isKeySafe(prefix) {
return nil, trace.BadParameter(errorMessage)
}
}
return s.backend.NewWatcher(ctx, watch)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L60-L71 | go | train | // Check makes sure that the request is valid | func (r SSOLoginConsoleReq) Check() error | // Check makes sure that the request is valid
func (r SSOLoginConsoleReq) Check() error | {
if r.RedirectURL == "" {
return trace.BadParameter("missing RedirectURL")
}
if len(r.PublicKey) == 0 {
return trace.BadParameter("missing PublicKey")
}
if r.ConnectorID == "" {
return trace.BadParameter("missing ConnectorID")
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L253-L294 | go | train | // NewCredentialsClient creates a new client to the HTTPS web proxy. | func NewCredentialsClient(proxyAddr string, insecure bool, pool *x509.CertPool) (*CredentialsClient, error) | // NewCredentialsClient creates a new client to the HTTPS web proxy.
func NewCredentialsClient(proxyAddr string, insecure bool, pool *x509.CertPool) (*CredentialsClient, error) | {
log := logrus.WithFields(logrus.Fields{
trace.Component: teleport.ComponentClient,
})
log.Debugf("HTTPS client init(proxyAddr=%v, insecure=%v)", proxyAddr, insecure)
// validate proxyAddr:
host, port, err := net.SplitHostPort(proxyAddr)
if err != nil || host == "" || port == "" {
if err != nil {
log.Error(err)
}
return nil, trace.BadParameter("'%v' is not a valid proxy address", proxyAddr)
}
proxyAddr = "https://" + net.JoinHostPort(host, port)
u, err := url.Parse(proxyAddr)
if err != nil {
return nil, trace.BadParameter("'%v' is not a valid proxy address", proxyAddr)
}
var opts []roundtrip.ClientParam
if insecure {
// Skip https cert verification, print a warning that this is insecure.
fmt.Printf("WARNING: You are using insecure connection to SSH proxy %v\n", proxyAddr)
opts = append(opts, roundtrip.HTTPClient(NewInsecureWebClient()))
} else if pool != nil {
// use custom set of trusted CAs
opts = append(opts, roundtrip.HTTPClient(newClientWithPool(pool)))
}
clt, err := NewWebClient(proxyAddr, opts...)
if err != nil {
return nil, trace.Wrap(err)
}
return &CredentialsClient{
log: log,
clt: clt,
url: u,
}, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L301-L319 | go | train | // Ping serves two purposes. The first is to validate the HTTP endpoint of a
// Teleport proxy. This leads to better user experience: users get connection
// errors before being asked for passwords. The second is to return the form
// of authentication that the server supports. This also leads to better user
// experience: users only get prompted for the type of authentication the server supports. | func (c *CredentialsClient) Ping(ctx context.Context, connectorName string) (*PingResponse, error) | // Ping serves two purposes. The first is to validate the HTTP endpoint of a
// Teleport proxy. This leads to better user experience: users get connection
// errors before being asked for passwords. The second is to return the form
// of authentication that the server supports. This also leads to better user
// experience: users only get prompted for the type of authentication the server supports.
func (c *CredentialsClient) Ping(ctx context.Context, connectorName string) (*PingResponse, error) | {
endpoint := c.clt.Endpoint("webapi", "ping")
if connectorName != "" {
endpoint = c.clt.Endpoint("webapi", "ping", connectorName)
}
response, err := c.clt.Get(ctx, endpoint, url.Values{})
if err != nil {
return nil, trace.Wrap(err)
}
var pr *PingResponse
err = json.Unmarshal(response.Bytes(), &pr)
if err != nil {
return nil, trace.Wrap(err)
}
return pr, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L340-L397 | go | train | // SSHAgentSSOLogin is used by tsh to fetch user credentials using OpenID Connect (OIDC) or SAML. | func (c *CredentialsClient) SSHAgentSSOLogin(login SSHLogin) (*auth.SSHLoginResponse, error) | // SSHAgentSSOLogin is used by tsh to fetch user credentials using OpenID Connect (OIDC) or SAML.
func (c *CredentialsClient) SSHAgentSSOLogin(login SSHLogin) (*auth.SSHLoginResponse, error) | {
rd, err := NewRedirector(login)
if err != nil {
return nil, trace.Wrap(err)
}
if err := rd.Start(); err != nil {
return nil, trace.Wrap(err)
}
defer rd.Close()
clickableURL := rd.ClickableURL()
// If a command was found to launch the browser, create and start it.
var execCmd *exec.Cmd
switch runtime.GOOS {
// macOS.
case teleport.DarwinOS:
path, err := exec.LookPath(teleport.OpenBrowserDarwin)
if err == nil {
execCmd = exec.Command(path, clickableURL)
}
// Windows.
case teleport.WindowsOS:
path, err := exec.LookPath(teleport.OpenBrowserWindows)
if err == nil {
execCmd = exec.Command(path, "url.dll,FileProtocolHandler", clickableURL)
}
// Linux or any other operating system.
default:
path, err := exec.LookPath(teleport.OpenBrowserLinux)
if err == nil {
execCmd = exec.Command(path, clickableURL)
}
}
if execCmd != nil {
execCmd.Start()
}
// Print to screen in-case the command that launches the browser did not run.
fmt.Printf("If browser window does not open automatically, open it by ")
fmt.Printf("clicking on the link:\n %v\n", clickableURL)
select {
case err := <-rd.ErrorC():
log.Debugf("Got an error: %v.", err)
return nil, trace.Wrap(err)
case response := <-rd.ResponseC():
log.Debugf("Got response from browser.")
return response, nil
case <-time.After(defaults.CallbackTimeout):
log.Debugf("Timed out waiting for callback after %v.", defaults.CallbackTimeout)
return nil, trace.Wrap(trace.Errorf("timed out waiting for callback"))
case <-rd.Done():
log.Debugf("Canceled by user.")
return nil, trace.Wrap(login.Context.Err(), "cancelled by user")
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L400-L420 | go | train | // SSHAgentLogin is used by tsh to fetch local user credentials. | func (c *CredentialsClient) SSHAgentLogin(ctx context.Context, user string, password string, otpToken string, pubKey []byte, ttl time.Duration, compatibility string) (*auth.SSHLoginResponse, error) | // SSHAgentLogin is used by tsh to fetch local user credentials.
func (c *CredentialsClient) SSHAgentLogin(ctx context.Context, user string, password string, otpToken string, pubKey []byte, ttl time.Duration, compatibility string) (*auth.SSHLoginResponse, error) | {
re, err := c.clt.PostJSON(ctx, c.clt.Endpoint("webapi", "ssh", "certs"), CreateSSHCertReq{
User: user,
Password: password,
OTPToken: otpToken,
PubKey: pubKey,
TTL: ttl,
Compatibility: compatibility,
})
if err != nil {
return nil, trace.Wrap(err)
}
var out *auth.SSHLoginResponse
err = json.Unmarshal(re.Bytes(), &out)
if err != nil {
return nil, trace.Wrap(err)
}
return out, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L427-L505 | go | train | // SSHAgentU2FLogin requests a U2F sign request (authentication challenge) via
// the proxy. If the credentials are valid, the proxy wiil return a challenge.
// We then call the official u2f-host binary to perform the signing and pass
// the signature to the proxy. If the authentication succeeds, we will get a
// temporary certificate back. | func (c *CredentialsClient) SSHAgentU2FLogin(ctx context.Context, user string, password string, pubKey []byte, ttl time.Duration, compatibility string) (*auth.SSHLoginResponse, error) | // SSHAgentU2FLogin requests a U2F sign request (authentication challenge) via
// the proxy. If the credentials are valid, the proxy wiil return a challenge.
// We then call the official u2f-host binary to perform the signing and pass
// the signature to the proxy. If the authentication succeeds, we will get a
// temporary certificate back.
func (c *CredentialsClient) SSHAgentU2FLogin(ctx context.Context, user string, password string, pubKey []byte, ttl time.Duration, compatibility string) (*auth.SSHLoginResponse, error) | {
u2fSignRequest, err := c.clt.PostJSON(ctx, c.clt.Endpoint("webapi", "u2f", "signrequest"), U2fSignRequestReq{
User: user,
Pass: password,
})
if err != nil {
return nil, trace.Wrap(err)
}
// Pass the JSON-encoded data undecoded to the u2f-host binary
facet := "https://" + strings.ToLower(c.url.String())
cmd := exec.Command("u2f-host", "-aauthenticate", "-o", facet)
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, trace.Wrap(err)
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, trace.Wrap(err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, trace.Wrap(err)
}
cmd.Start()
stdin.Write(u2fSignRequest.Bytes())
stdin.Close()
fmt.Println("Please press the button on your U2F key")
// The origin URL is passed back base64-encoded and the keyHandle is passed back as is.
// A very long proxy hostname or keyHandle can overflow a fixed-size buffer.
signResponseLen := 500 + len(u2fSignRequest.Bytes()) + len(c.url.String())*4/3
signResponseBuf := make([]byte, signResponseLen)
signResponseLen, err = io.ReadFull(stdout, signResponseBuf)
// unexpected EOF means we have read the data completely.
if err == nil {
return nil, trace.LimitExceeded("u2f sign response exceeded buffer size")
}
// Read error message (if any). 100 bytes is more than enough for any error message u2f-host outputs
errMsgBuf := make([]byte, 100)
errMsgLen, err := io.ReadFull(stderr, errMsgBuf)
if err == nil {
return nil, trace.LimitExceeded("u2f error message exceeded buffer size")
}
err = cmd.Wait()
if err != nil {
return nil, trace.AccessDenied("u2f-host returned error: " + string(errMsgBuf[:errMsgLen]))
} else if signResponseLen == 0 {
return nil, trace.NotFound("u2f-host returned no error and no sign response")
}
var u2fSignResponse *u2f.SignResponse
err = json.Unmarshal(signResponseBuf[:signResponseLen], &u2fSignResponse)
if err != nil {
return nil, trace.Wrap(err)
}
re, err := c.clt.PostJSON(ctx, c.clt.Endpoint("webapi", "u2f", "certs"), CreateSSHCertWithU2FReq{
User: user,
U2FSignResponse: *u2fSignResponse,
PubKey: pubKey,
TTL: ttl,
Compatibility: compatibility,
})
if err != nil {
return nil, trace.Wrap(err)
}
var out *auth.SSHLoginResponse
err = json.Unmarshal(re.Bytes(), &out)
if err != nil {
return nil, trace.Wrap(err)
}
return out, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/client/weblogin.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/client/weblogin.go#L508-L521 | go | train | // HostCredentials is used to fetch host credentials for a node. | func (c *CredentialsClient) HostCredentials(ctx context.Context, req auth.RegisterUsingTokenRequest) (*auth.PackedKeys, error) | // HostCredentials is used to fetch host credentials for a node.
func (c *CredentialsClient) HostCredentials(ctx context.Context, req auth.RegisterUsingTokenRequest) (*auth.PackedKeys, error) | {
resp, err := c.clt.PostJSON(ctx, c.clt.Endpoint("webapi", "host", "credentials"), req)
if err != nil {
return nil, trace.Wrap(err)
}
var packedKeys *auth.PackedKeys
err = json.Unmarshal(resp.Bytes(), &packedKeys)
if err != nil {
return nil, trace.Wrap(err)
}
return packedKeys, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/services/local/access.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/access.go#L40-L42 | go | train | // DeleteAllRoles deletes all roles | func (s *AccessService) DeleteAllRoles() error | // DeleteAllRoles deletes all roles
func (s *AccessService) DeleteAllRoles() error | {
return s.DeleteRange(context.TODO(), backend.Key(rolesPrefix), backend.RangeEnd(backend.Key(rolesPrefix)))
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/services/local/access.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/access.go#L45-L61 | go | train | // GetRoles returns a list of roles registered with the local auth server | func (s *AccessService) GetRoles() ([]services.Role, error) | // GetRoles returns a list of roles registered with the local auth server
func (s *AccessService) GetRoles() ([]services.Role, error) | {
result, err := s.GetRange(context.TODO(), backend.Key(rolesPrefix), backend.RangeEnd(backend.Key(rolesPrefix)), backend.NoLimit)
if err != nil {
return nil, trace.Wrap(err)
}
out := make([]services.Role, 0, len(result.Items))
for _, item := range result.Items {
role, err := services.GetRoleMarshaler().UnmarshalRole(item.Value,
services.WithResourceID(item.ID), services.WithExpires(item.Expires))
if err != nil {
return nil, trace.Wrap(err)
}
out = append(out, role)
}
sort.Sort(services.SortedRoles(out))
return out, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/services/local/access.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/access.go#L64-L81 | go | train | // CreateRole creates a role on the backend. | func (s *AccessService) CreateRole(role services.Role) error | // CreateRole creates a role on the backend.
func (s *AccessService) CreateRole(role services.Role) error | {
value, err := services.GetRoleMarshaler().MarshalRole(role)
if err != nil {
return trace.Wrap(err)
}
item := backend.Item{
Key: backend.Key(rolesPrefix, role.GetName(), paramsPrefix),
Value: value,
Expires: role.Expiry(),
}
_, err = s.Create(context.TODO(), item)
if err != nil {
return trace.Wrap(err)
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/services/local/access.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/access.go#L105-L118 | go | train | // GetRole returns a role by name | func (s *AccessService) GetRole(name string) (services.Role, error) | // GetRole returns a role by name
func (s *AccessService) GetRole(name string) (services.Role, error) | {
if name == "" {
return nil, trace.BadParameter("missing role name")
}
item, err := s.Get(context.TODO(), backend.Key(rolesPrefix, name, paramsPrefix))
if err != nil {
if trace.IsNotFound(err) {
return nil, trace.NotFound("role %v is not found", name)
}
return nil, trace.Wrap(err)
}
return services.GetRoleMarshaler().UnmarshalRole(item.Value,
services.WithResourceID(item.ID), services.WithExpires(item.Expires))
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/services/local/access.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/access.go#L121-L132 | go | train | // DeleteRole deletes a role from the backend | func (s *AccessService) DeleteRole(name string) error | // DeleteRole deletes a role from the backend
func (s *AccessService) DeleteRole(name string) error | {
if name == "" {
return trace.BadParameter("missing role name")
}
err := s.Delete(context.TODO(), backend.Key(rolesPrefix, name, paramsPrefix))
if err != nil {
if trace.IsNotFound(err) {
return trace.NotFound("role %q is not found", name)
}
}
return trace.Wrap(err)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L56-L62 | go | train | // currentUserAction is a special checker that allows certain actions for users
// even if they are not admins, e.g. update their own passwords,
// or generate certificates, otherwise it will require admin privileges | func (a *AuthWithRoles) currentUserAction(username string) error | // currentUserAction is a special checker that allows certain actions for users
// even if they are not admins, e.g. update their own passwords,
// or generate certificates, otherwise it will require admin privileges
func (a *AuthWithRoles) currentUserAction(username string) error | {
if username == a.user.GetName() {
return nil
}
return a.checker.CheckAccessToRule(&services.Context{User: a.user},
defaults.Namespace, services.KindUser, services.VerbCreate, false)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L68-L75 | go | train | // authConnectorAction is a special checker that grants access to auth
// connectors. It first checks if you have access to the specific connector.
// If not, it checks if the requester has the meta KindAuthConnector access
// (which grants access to all connectors). | func (a *AuthWithRoles) authConnectorAction(namespace string, resource string, verb string) error | // authConnectorAction is a special checker that grants access to auth
// connectors. It first checks if you have access to the specific connector.
// If not, it checks if the requester has the meta KindAuthConnector access
// (which grants access to all connectors).
func (a *AuthWithRoles) authConnectorAction(namespace string, resource string, verb string) error | {
if err := a.checker.CheckAccessToRule(&services.Context{User: a.user}, namespace, resource, verb, false); err != nil {
if err := a.checker.CheckAccessToRule(&services.Context{User: a.user}, namespace, services.KindAuthConnector, verb, false); err != nil {
return trace.Wrap(err)
}
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L79-L81 | go | train | // hasBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is builtin and the name matches. | func (a *AuthWithRoles) hasBuiltinRole(name string) bool | // hasBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is builtin and the name matches.
func (a *AuthWithRoles) hasBuiltinRole(name string) bool | {
return hasBuiltinRole(a.checker, name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L85-L94 | go | train | // hasBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is builtin and the name matches. | func hasBuiltinRole(checker services.AccessChecker, name string) bool | // hasBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is builtin and the name matches.
func hasBuiltinRole(checker services.AccessChecker, name string) bool | {
if _, ok := checker.(BuiltinRoleSet); !ok {
return false
}
if !checker.HasRole(name) {
return false
}
return true
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L98-L107 | go | train | // hasRemoteBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is remote builtin and the name matches. | func (a *AuthWithRoles) hasRemoteBuiltinRole(name string) bool | // hasRemoteBuiltinRole checks the type of the role set returned and the name.
// Returns true if role set is remote builtin and the name matches.
func (a *AuthWithRoles) hasRemoteBuiltinRole(name string) bool | {
if _, ok := a.checker.(RemoteBuiltinRoleSet); !ok {
return false
}
if !a.checker.HasRole(name) {
return false
}
return true
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L111-L118 | go | train | // AuthenticateWebUser authenticates web user, creates and returns web session
// in case if authentication is successful | func (a *AuthWithRoles) AuthenticateWebUser(req AuthenticateUserRequest) (services.WebSession, error) | // AuthenticateWebUser authenticates web user, creates and returns web session
// in case if authentication is successful
func (a *AuthWithRoles) AuthenticateWebUser(req AuthenticateUserRequest) (services.WebSession, error) | {
// authentication request has it's own authentication, however this limits the requests
// types to proxies to make it harder to break
if !a.hasBuiltinRole(string(teleport.RoleProxy)) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}
return a.authServer.AuthenticateWebUser(req)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L122-L129 | go | train | // AuthenticateSSHUser authenticates SSH console user, creates and returns a pair of signed TLS and SSH
// short lived certificates as a result | func (a *AuthWithRoles) AuthenticateSSHUser(req AuthenticateSSHRequest) (*SSHLoginResponse, error) | // AuthenticateSSHUser authenticates SSH console user, creates and returns a pair of signed TLS and SSH
// short lived certificates as a result
func (a *AuthWithRoles) AuthenticateSSHUser(req AuthenticateSSHRequest) (*SSHLoginResponse, error) | {
// authentication request has it's own authentication, however this limits the requests
// types to proxies to make it harder to break
if !a.hasBuiltinRole(string(teleport.RoleProxy)) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}
return a.authServer.AuthenticateSSHUser(req)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L165-L176 | go | train | // RotateCertAuthority starts or restarts certificate authority rotation process. | func (a *AuthWithRoles) RotateCertAuthority(req RotateRequest) error | // RotateCertAuthority starts or restarts certificate authority rotation process.
func (a *AuthWithRoles) RotateCertAuthority(req RotateRequest) error | {
if err := req.CheckAndSetDefaults(a.authServer.clock); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.RotateCertAuthority(req)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L181-L190 | go | train | // RotateExternalCertAuthority rotates external certificate authority,
// this method is called by a remote trusted cluster and is used to update
// only public keys and certificates of the certificate authority. | func (a *AuthWithRoles) RotateExternalCertAuthority(ca services.CertAuthority) error | // RotateExternalCertAuthority rotates external certificate authority,
// this method is called by a remote trusted cluster and is used to update
// only public keys and certificates of the certificate authority.
func (a *AuthWithRoles) RotateExternalCertAuthority(ca services.CertAuthority) error | {
if ca == nil {
return trace.BadParameter("missing certificate authority")
}
ctx := &services.Context{User: a.user, Resource: ca}
if err := a.actionWithContext(ctx, defaults.Namespace, services.KindCertAuthority, services.VerbRotate); err != nil {
return trace.Wrap(err)
}
return a.authServer.RotateExternalCertAuthority(ca)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L193-L205 | go | train | // UpsertCertAuthority updates existing cert authority or updates the existing one. | func (a *AuthWithRoles) UpsertCertAuthority(ca services.CertAuthority) error | // UpsertCertAuthority updates existing cert authority or updates the existing one.
func (a *AuthWithRoles) UpsertCertAuthority(ca services.CertAuthority) error | {
if ca == nil {
return trace.BadParameter("missing certificate authority")
}
ctx := &services.Context{User: a.user, Resource: ca}
if err := a.actionWithContext(ctx, defaults.Namespace, services.KindCertAuthority, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.actionWithContext(ctx, defaults.Namespace, services.KindCertAuthority, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.UpsertCertAuthority(ca)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L209-L217 | go | train | // CompareAndSwapCertAuthority updates existing cert authority if the existing cert authority
// value matches the value stored in the backend. | func (a *AuthWithRoles) CompareAndSwapCertAuthority(new, existing services.CertAuthority) error | // CompareAndSwapCertAuthority updates existing cert authority if the existing cert authority
// value matches the value stored in the backend.
func (a *AuthWithRoles) CompareAndSwapCertAuthority(new, existing services.CertAuthority) error | {
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.CompareAndSwapCertAuthority(new, existing)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L306-L324 | go | train | // GenerateServerKeys generates new host private keys and certificates (signed
// by the host certificate authority) for a node. | func (a *AuthWithRoles) GenerateServerKeys(req GenerateServerKeysRequest) (*PackedKeys, error) | // GenerateServerKeys generates new host private keys and certificates (signed
// by the host certificate authority) for a node.
func (a *AuthWithRoles) GenerateServerKeys(req GenerateServerKeysRequest) (*PackedKeys, error) | {
clusterName, err := a.authServer.GetDomainName()
if err != nil {
return nil, trace.Wrap(err)
}
// username is hostID + cluster name, so make sure server requests new keys for itself
if a.user.GetName() != HostFQDN(req.HostID, clusterName) {
return nil, trace.AccessDenied("username mismatch %q and %q", a.user.GetName(), HostFQDN(req.HostID, clusterName))
}
existingRoles, err := teleport.NewRoles(a.user.GetRoles())
if err != nil {
return nil, trace.Wrap(err)
}
// prohibit privilege escalations through role changes
if !existingRoles.Equals(req.Roles) {
return nil, trace.AccessDenied("roles do not match: %v and %v", existingRoles, req.Roles)
}
return a.authServer.GenerateServerKeys(req)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L327-L335 | go | train | // UpsertNodes bulk upserts nodes into the backend. | func (a *AuthWithRoles) UpsertNodes(namespace string, servers []services.Server) error | // UpsertNodes bulk upserts nodes into the backend.
func (a *AuthWithRoles) UpsertNodes(namespace string, servers []services.Server) error | {
if err := a.action(namespace, services.KindNode, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(namespace, services.KindNode, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.UpsertNodes(namespace, servers)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L369-L445 | go | train | // NewWatcher returns a new event watcher | func (a *AuthWithRoles) NewWatcher(ctx context.Context, watch services.Watch) (services.Watcher, error) | // NewWatcher returns a new event watcher
func (a *AuthWithRoles) NewWatcher(ctx context.Context, watch services.Watch) (services.Watcher, error) | {
if len(watch.Kinds) == 0 {
return nil, trace.AccessDenied("can't setup global watch")
}
for _, kind := range watch.Kinds {
switch kind.Kind {
case services.KindNamespace:
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindUser:
if err := a.action(defaults.Namespace, services.KindUser, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindRole:
if err := a.action(defaults.Namespace, services.KindRole, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindNode:
if err := a.action(defaults.Namespace, services.KindNode, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindProxy:
if err := a.action(defaults.Namespace, services.KindProxy, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindAuthServer:
if err := a.action(defaults.Namespace, services.KindAuthServer, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindTunnelConnection:
if err := a.action(defaults.Namespace, services.KindTunnelConnection, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindReverseTunnel:
if err := a.action(defaults.Namespace, services.KindReverseTunnel, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindClusterConfig:
if err := a.action(defaults.Namespace, services.KindClusterConfig, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindClusterName:
if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindToken:
if err := a.action(defaults.Namespace, services.KindToken, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindStaticTokens:
if err := a.action(defaults.Namespace, services.KindStaticTokens, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
case services.KindCertAuthority:
if kind.LoadSecrets {
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
} else {
if err := a.action(defaults.Namespace, services.KindCertAuthority, services.VerbReadNoSecrets); err != nil {
return nil, trace.Wrap(err)
}
}
default:
return nil, trace.AccessDenied("not authorized to watch %v events", kind.Kind)
}
}
switch {
case a.hasBuiltinRole(string(teleport.RoleProxy)):
watch.QueueSize = defaults.ProxyQueueSize
case a.hasBuiltinRole(string(teleport.RoleNode)):
watch.QueueSize = defaults.NodeQueueSize
}
return a.authServer.NewWatcher(ctx, watch)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L448-L489 | go | train | // filterNodes filters nodes based off the role of the logged in user. | func (a *AuthWithRoles) filterNodes(nodes []services.Server) ([]services.Server, error) | // filterNodes filters nodes based off the role of the logged in user.
func (a *AuthWithRoles) filterNodes(nodes []services.Server) ([]services.Server, error) | {
// For certain built-in roles, continue to allow full access and return
// the full set of nodes to not break existing clusters during migration.
//
// In addition, allow proxy (and remote proxy) to access all nodes for it's
// smart resolution address resolution. Once the smart resolution logic is
// moved to the auth server, this logic can be removed.
if a.hasBuiltinRole(string(teleport.RoleAdmin)) ||
a.hasBuiltinRole(string(teleport.RoleProxy)) ||
a.hasRemoteBuiltinRole(string(teleport.RoleRemoteProxy)) {
return nodes, nil
}
// Fetch services.RoleSet for the identity of the logged in user.
roles, err := services.FetchRoles(a.user.GetRoles(), a.authServer, a.user.GetTraits())
if err != nil {
return nil, trace.Wrap(err)
}
// Extract all unique allowed logins across all roles.
allowedLogins := make(map[string]bool)
for _, role := range roles {
for _, login := range role.GetLogins(services.Allow) {
allowedLogins[login] = true
}
}
// Loop over all nodes and check if the caller has access.
filteredNodes := make([]services.Server, 0, len(nodes))
NextNode:
for _, node := range nodes {
for login, _ := range allowedLogins {
err := roles.CheckAccessToServer(login, node)
if err == nil {
filteredNodes = append(filteredNodes, node)
continue NextNode
}
}
}
return filteredNodes, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L492-L497 | go | train | // DeleteAllNodes deletes all nodes in a given namespace | func (a *AuthWithRoles) DeleteAllNodes(namespace string) error | // DeleteAllNodes deletes all nodes in a given namespace
func (a *AuthWithRoles) DeleteAllNodes(namespace string) error | {
if err := a.action(namespace, services.KindNode, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteAllNodes(namespace)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L560-L565 | go | train | // DeleteAllAuthServers deletes all auth servers | func (a *AuthWithRoles) DeleteAllAuthServers() error | // DeleteAllAuthServers deletes all auth servers
func (a *AuthWithRoles) DeleteAllAuthServers() error | {
if err := a.action(defaults.Namespace, services.KindAuthServer, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteAllAuthServers()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L568-L573 | go | train | // DeleteAuthServer deletes auth server by name | func (a *AuthWithRoles) DeleteAuthServer(name string) error | // DeleteAuthServer deletes auth server by name
func (a *AuthWithRoles) DeleteAuthServer(name string) error | {
if err := a.action(defaults.Namespace, services.KindAuthServer, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteAuthServer(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L596-L601 | go | train | // DeleteAllProxies deletes all proxies | func (a *AuthWithRoles) DeleteAllProxies() error | // DeleteAllProxies deletes all proxies
func (a *AuthWithRoles) DeleteAllProxies() error | {
if err := a.action(defaults.Namespace, services.KindProxy, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteAllProxies()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L604-L609 | go | train | // DeleteProxy deletes proxy by name | func (a *AuthWithRoles) DeleteProxy(name string) error | // DeleteProxy deletes proxy by name
func (a *AuthWithRoles) DeleteProxy(name string) error | {
if err := a.action(defaults.Namespace, services.KindProxy, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteProxy(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L798-L800 | go | train | // NewKeepAliver returns a new instance of keep aliver | func (a *AuthWithRoles) NewKeepAliver(ctx context.Context) (services.KeepAliver, error) | // NewKeepAliver returns a new instance of keep aliver
func (a *AuthWithRoles) NewKeepAliver(ctx context.Context) (services.KeepAliver, error) | {
return nil, trace.NotImplemented("not implemented")
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1133-L1141 | go | train | // GetNamespaces returns a list of namespaces | func (a *AuthWithRoles) GetNamespaces() ([]services.Namespace, error) | // GetNamespaces returns a list of namespaces
func (a *AuthWithRoles) GetNamespaces() ([]services.Namespace, error) | {
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbList); err != nil {
return nil, trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetNamespaces()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1144-L1149 | go | train | // GetNamespace returns namespace by name | func (a *AuthWithRoles) GetNamespace(name string) (*services.Namespace, error) | // GetNamespace returns namespace by name
func (a *AuthWithRoles) GetNamespace(name string) (*services.Namespace, error) | {
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetNamespace(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1152-L1160 | go | train | // UpsertNamespace upserts namespace | func (a *AuthWithRoles) UpsertNamespace(ns services.Namespace) error | // UpsertNamespace upserts namespace
func (a *AuthWithRoles) UpsertNamespace(ns services.Namespace) error | {
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.UpsertNamespace(ns)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1163-L1168 | go | train | // DeleteNamespace deletes namespace by name | func (a *AuthWithRoles) DeleteNamespace(name string) error | // DeleteNamespace deletes namespace by name
func (a *AuthWithRoles) DeleteNamespace(name string) error | {
if err := a.action(defaults.Namespace, services.KindNamespace, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteNamespace(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1171-L1179 | go | train | // GetRoles returns a list of roles | func (a *AuthWithRoles) GetRoles() ([]services.Role, error) | // GetRoles returns a list of roles
func (a *AuthWithRoles) GetRoles() ([]services.Role, error) | {
if err := a.action(defaults.Namespace, services.KindRole, services.VerbList); err != nil {
return nil, trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindRole, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetRoles()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1187-L1195 | go | train | // UpsertRole creates or updates role | func (a *AuthWithRoles) UpsertRole(role services.Role) error | // UpsertRole creates or updates role
func (a *AuthWithRoles) UpsertRole(role services.Role) error | {
if err := a.action(defaults.Namespace, services.KindRole, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindRole, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.UpsertRole(role)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1198-L1207 | go | train | // GetRole returns role by name | func (a *AuthWithRoles) GetRole(name string) (services.Role, error) | // GetRole returns role by name
func (a *AuthWithRoles) GetRole(name string) (services.Role, error) | {
if err := a.action(defaults.Namespace, services.KindRole, services.VerbRead); err != nil {
// allow user to read roles assigned to them
log.Infof("%v %v %v", a.user, a.user.GetRoles(), name)
if !utils.SliceContainsStr(a.user.GetRoles(), name) {
return nil, trace.Wrap(err)
}
}
return a.authServer.GetRole(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1210-L1215 | go | train | // DeleteRole deletes role by name | func (a *AuthWithRoles) DeleteRole(name string) error | // DeleteRole deletes role by name
func (a *AuthWithRoles) DeleteRole(name string) error | {
if err := a.action(defaults.Namespace, services.KindRole, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteRole(name)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1218-L1223 | go | train | // GetClusterConfig gets cluster level configuration. | func (a *AuthWithRoles) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error) | // GetClusterConfig gets cluster level configuration.
func (a *AuthWithRoles) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error) | {
if err := a.action(defaults.Namespace, services.KindClusterConfig, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetClusterConfig(opts...)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1226-L1231 | go | train | // DeleteClusterConfig deletes cluster config | func (a *AuthWithRoles) DeleteClusterConfig() error | // DeleteClusterConfig deletes cluster config
func (a *AuthWithRoles) DeleteClusterConfig() error | {
if err := a.action(defaults.Namespace, services.KindClusterConfig, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteClusterConfig()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1234-L1239 | go | train | // DeleteClusterName deletes cluster name | func (a *AuthWithRoles) DeleteClusterName() error | // DeleteClusterName deletes cluster name
func (a *AuthWithRoles) DeleteClusterName() error | {
if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteClusterName()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1242-L1247 | go | train | // DeleteStaticTokens deletes static tokens | func (a *AuthWithRoles) DeleteStaticTokens() error | // DeleteStaticTokens deletes static tokens
func (a *AuthWithRoles) DeleteStaticTokens() error | {
if err := a.action(defaults.Namespace, services.KindStaticTokens, services.VerbDelete); err != nil {
return trace.Wrap(err)
}
return a.authServer.DeleteStaticTokens()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1250-L1258 | go | train | // SetClusterConfig sets cluster level configuration. | func (a *AuthWithRoles) SetClusterConfig(c services.ClusterConfig) error | // SetClusterConfig sets cluster level configuration.
func (a *AuthWithRoles) SetClusterConfig(c services.ClusterConfig) error | {
if err := a.action(defaults.Namespace, services.KindClusterConfig, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindClusterConfig, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.SetClusterConfig(c)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1261-L1266 | go | train | // GetClusterName gets the name of the cluster. | func (a *AuthWithRoles) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error) | // GetClusterName gets the name of the cluster.
func (a *AuthWithRoles) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error) | {
if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetClusterName()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1269-L1277 | go | train | // SetClusterName sets the name of the cluster. SetClusterName can only be called once. | func (a *AuthWithRoles) SetClusterName(c services.ClusterName) error | // SetClusterName sets the name of the cluster. SetClusterName can only be called once.
func (a *AuthWithRoles) SetClusterName(c services.ClusterName) error | {
if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.SetClusterName(c)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1291-L1296 | go | train | // GetStaticTokens gets the list of static tokens used to provision nodes. | func (a *AuthWithRoles) GetStaticTokens() (services.StaticTokens, error) | // GetStaticTokens gets the list of static tokens used to provision nodes.
func (a *AuthWithRoles) GetStaticTokens() (services.StaticTokens, error) | {
if err := a.action(defaults.Namespace, services.KindStaticTokens, services.VerbRead); err != nil {
return nil, trace.Wrap(err)
}
return a.authServer.GetStaticTokens()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1299-L1307 | go | train | // SetStaticTokens sets the list of static tokens used to provision nodes. | func (a *AuthWithRoles) SetStaticTokens(s services.StaticTokens) error | // SetStaticTokens sets the list of static tokens used to provision nodes.
func (a *AuthWithRoles) SetStaticTokens(s services.StaticTokens) error | {
if err := a.action(defaults.Namespace, services.KindStaticTokens, services.VerbCreate); err != nil {
return trace.Wrap(err)
}
if err := a.action(defaults.Namespace, services.KindStaticTokens, services.VerbUpdate); err != nil {
return trace.Wrap(err)
}
return a.authServer.SetStaticTokens(s)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1492-L1498 | go | train | // ProcessKubeCSR processes CSR request against Kubernetes CA, returns
// signed certificate if sucessful. | func (a *AuthWithRoles) ProcessKubeCSR(req KubeCSR) (*KubeCSRResponse, error) | // ProcessKubeCSR processes CSR request against Kubernetes CA, returns
// signed certificate if sucessful.
func (a *AuthWithRoles) ProcessKubeCSR(req KubeCSR) (*KubeCSRResponse, error) | {
// limits the requests types to proxies to make it harder to break
if !a.hasBuiltinRole(string(teleport.RoleProxy)) {
return nil, trace.AccessDenied("this request can be only executed by a proxy")
}
return a.authServer.ProcessKubeCSR(req)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1510-L1522 | go | train | // NewAdminAuthServer returns auth server authorized as admin,
// used for auth server cached access | func NewAdminAuthServer(authServer *AuthServer, sessions session.Service, alog events.IAuditLog) (ClientI, error) | // NewAdminAuthServer returns auth server authorized as admin,
// used for auth server cached access
func NewAdminAuthServer(authServer *AuthServer, sessions session.Service, alog events.IAuditLog) (ClientI, error) | {
ctx, err := NewAdminContext()
if err != nil {
return nil, trace.Wrap(err)
}
return &AuthWithRoles{
authServer: authServer,
checker: ctx.Checker,
user: ctx.User,
alog: alog,
sessions: sessions,
}, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/auth/auth_with_roles.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/auth_with_roles.go#L1525-L1537 | go | train | // NewAuthWithRoles creates new auth server with access control | func NewAuthWithRoles(authServer *AuthServer,
checker services.AccessChecker,
user services.User,
sessions session.Service,
alog events.IAuditLog) *AuthWithRoles | // NewAuthWithRoles creates new auth server with access control
func NewAuthWithRoles(authServer *AuthServer,
checker services.AccessChecker,
user services.User,
sessions session.Service,
alog events.IAuditLog) *AuthWithRoles | {
return &AuthWithRoles{
authServer: authServer,
checker: checker,
sessions: sessions,
user: user,
alog: alog,
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L34-L41 | go | train | // SetChmod sets file permissions | func (l *localFileSystem) SetChmod(path string, mode int) error | // SetChmod sets file permissions
func (l *localFileSystem) SetChmod(path string, mode int) error | {
chmode := os.FileMode(mode & int(os.ModePerm))
if err := os.Chmod(path, chmode); err != nil {
return trace.Wrap(err)
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L44-L52 | go | train | // MkDir creates a directory | func (l *localFileSystem) MkDir(path string, mode int) error | // MkDir creates a directory
func (l *localFileSystem) MkDir(path string, mode int) error | {
fileMode := os.FileMode(mode & int(os.ModePerm))
err := os.MkdirAll(path, fileMode)
if err != nil && !os.IsExist(err) {
return trace.ConvertSystemError(err)
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L60-L67 | go | train | // OpenFile opens a file for read operations and returns a Reader | func (l *localFileSystem) OpenFile(filePath string) (io.ReadCloser, error) | // OpenFile opens a file for read operations and returns a Reader
func (l *localFileSystem) OpenFile(filePath string) (io.ReadCloser, error) | {
f, err := os.Open(filePath)
if err != nil {
return nil, trace.Wrap(err)
}
return f, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L70-L77 | go | train | // GetFileInfo returns FileInfo for a given file path | func (l *localFileSystem) GetFileInfo(filePath string) (FileInfo, error) | // GetFileInfo returns FileInfo for a given file path
func (l *localFileSystem) GetFileInfo(filePath string) (FileInfo, error) | {
info, err := makeFileInfo(filePath)
if err != nil {
return nil, trace.Wrap(err)
}
return info, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L80-L87 | go | train | // CreateFile creates a new file and returns a Writer | func (l *localFileSystem) CreateFile(filePath string, length uint64) (io.WriteCloser, error) | // CreateFile creates a new file and returns a Writer
func (l *localFileSystem) CreateFile(filePath string, length uint64) (io.WriteCloser, error) | {
f, err := os.Create(filePath)
if err != nil {
return nil, trace.Wrap(err)
}
return f, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L128-L150 | go | train | // ReadDir returns all files in this directory | func (l *localFileInfo) ReadDir() ([]FileInfo, error) | // ReadDir returns all files in this directory
func (l *localFileInfo) ReadDir() ([]FileInfo, error) | {
f, err := os.Open(l.filePath)
if err != nil {
return nil, trace.Wrap(err)
}
fis, err := f.Readdir(0)
if err != nil {
return nil, trace.Wrap(err)
}
infos := make([]FileInfo, len(fis))
for i := range fis {
fi := fis[i]
info, err := makeFileInfo(filepath.Join(l.GetPath(), fi.Name()))
if err != nil {
return nil, trace.Wrap(err)
}
infos[i] = info
}
return infos, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/sshutils/scp/local.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/local.go#L153-L155 | go | train | // GetModePerm returns file permissions | func (l *localFileInfo) GetModePerm() os.FileMode | // GetModePerm returns file permissions
func (l *localFileInfo) GetModePerm() os.FileMode | {
return l.fileInfo.Mode() & os.ModePerm
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L158-L168 | go | train | // Clos closes remote cluster connections | func (s *remoteSite) Close() error | // Clos closes remote cluster connections
func (s *remoteSite) Close() error | {
s.Lock()
defer s.Unlock()
s.cancel()
for i := range s.connections {
s.connections[i].Close()
}
s.connections = []*remoteConn{}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L173-L196 | go | train | // nextConn returns next connection that is ready
// and has not been marked as invalid
// it will close connections marked as invalid | func (s *remoteSite) nextConn() (*remoteConn, error) | // nextConn returns next connection that is ready
// and has not been marked as invalid
// it will close connections marked as invalid
func (s *remoteSite) nextConn() (*remoteConn, error) | {
s.Lock()
defer s.Unlock()
s.removeInvalidConns()
for i := 0; i < len(s.connections); i++ {
s.lastUsed = (s.lastUsed + 1) % len(s.connections)
remoteConn := s.connections[s.lastUsed]
// connection could have been initated, but agent
// on the other side is not ready yet.
// Proxy assumes that connection is ready to serve when
// it has received a first heartbeat, otherwise
// it could attempt to use it before the agent
// had a chance to start handling connection requests,
// what could lead to proxy marking the connection
// as invalid without a good reason.
if remoteConn.isReady() {
return remoteConn, nil
}
}
return nil, trace.NotFound("%v is offline: no active tunnels to %v found", s.GetName(), s.srv.ClusterName)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L200-L221 | go | train | // removeInvalidConns removes connections marked as invalid,
// it should be called only under write lock | func (s *remoteSite) removeInvalidConns() | // removeInvalidConns removes connections marked as invalid,
// it should be called only under write lock
func (s *remoteSite) removeInvalidConns() | {
// for first pass, do nothing if no connections are marked
count := 0
for _, conn := range s.connections {
if conn.isInvalid() {
count++
}
}
if count == 0 {
return
}
s.lastUsed = 0
conns := make([]*remoteConn, 0, len(s.connections)-count)
for i := range s.connections {
if !s.connections[i].isInvalid() {
conns = append(conns, s.connections[i])
} else {
go s.connections[i].Close()
}
}
s.connections = conns
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L225-L247 | go | train | // addConn helper adds a new active remote cluster connection to the list
// of such connections | func (s *remoteSite) addConn(conn net.Conn, sconn ssh.Conn) (*remoteConn, error) | // addConn helper adds a new active remote cluster connection to the list
// of such connections
func (s *remoteSite) addConn(conn net.Conn, sconn ssh.Conn) (*remoteConn, error) | {
s.Lock()
defer s.Unlock()
cn, err := s.localAccessPoint.GetClusterName()
if err != nil {
return nil, trace.Wrap(err)
}
rconn := newRemoteConn(&connConfig{
conn: conn,
sconn: sconn,
accessPoint: s.localAccessPoint,
tunnelID: cn.GetClusterName(),
tunnelType: string(services.ProxyTunnel),
proxyName: s.connInfo.GetProxyName(),
clusterName: s.domainName,
})
s.connections = append(s.connections, rconn)
s.lastUsed = 0
return rconn, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L291-L293 | go | train | // deleteConnectionRecord deletes connection record to let know peer proxies
// that this node lost the connection and needs to be discovered | func (s *remoteSite) deleteConnectionRecord() | // deleteConnectionRecord deletes connection record to let know peer proxies
// that this node lost the connection and needs to be discovered
func (s *remoteSite) deleteConnectionRecord() | {
s.localAccessPoint.DeleteTunnelConnection(s.connInfo.GetClusterName(), s.connInfo.GetName())
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L298-L338 | go | train | // handleHearbeat receives heartbeat messages from the connected agent
// if the agent has missed several heartbeats in a row, Proxy marks
// the connection as invalid. | func (s *remoteSite) handleHeartbeat(conn *remoteConn, ch ssh.Channel, reqC <-chan *ssh.Request) | // handleHearbeat receives heartbeat messages from the connected agent
// if the agent has missed several heartbeats in a row, Proxy marks
// the connection as invalid.
func (s *remoteSite) handleHeartbeat(conn *remoteConn, ch ssh.Channel, reqC <-chan *ssh.Request) | {
defer func() {
s.Infof("Cluster connection closed.")
conn.Close()
}()
for {
select {
case <-s.ctx.Done():
s.Infof("closing")
return
case req := <-reqC:
if req == nil {
s.Infof("Cluster agent disconnected.")
conn.markInvalid(trace.ConnectionProblem(nil, "agent disconnected"))
if !s.hasValidConnections() {
s.Debugf("Deleting connection record.")
s.deleteConnectionRecord()
}
return
}
var timeSent time.Time
var roundtrip time.Duration
if req.Payload != nil {
if err := timeSent.UnmarshalText(req.Payload); err == nil {
roundtrip = s.srv.Clock.Now().Sub(timeSent)
}
}
if roundtrip != 0 {
s.WithFields(log.Fields{"latency": roundtrip}).Debugf("ping <- %v", conn.conn.RemoteAddr())
} else {
s.Debugf("Ping <- %v.", conn.conn.RemoteAddr())
}
tm := time.Now().UTC()
conn.setLastHeartbeat(tm)
go s.registerHeartbeat(tm)
// since we block on select, time.After is re-created everytime we process a request.
case <-time.After(defaults.ReverseTunnelOfflineThreshold):
conn.markInvalid(trace.ConnectionProblem(nil, "no heartbeats for %v", defaults.ReverseTunnelOfflineThreshold))
}
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L371-L421 | go | train | // updateCertAuthorities updates local and remote cert authorities | func (s *remoteSite) updateCertAuthorities() error | // updateCertAuthorities updates local and remote cert authorities
func (s *remoteSite) updateCertAuthorities() error | {
// update main cluster cert authorities on the remote side
// remote side makes sure that only relevant fields
// are updated
hostCA, err := s.localClient.GetCertAuthority(services.CertAuthID{
Type: services.HostCA,
DomainName: s.srv.ClusterName,
}, false)
if err != nil {
return trace.Wrap(err)
}
err = s.remoteClient.RotateExternalCertAuthority(hostCA)
if err != nil {
return trace.Wrap(err)
}
userCA, err := s.localClient.GetCertAuthority(services.CertAuthID{
Type: services.UserCA,
DomainName: s.srv.ClusterName,
}, false)
if err != nil {
return trace.Wrap(err)
}
err = s.remoteClient.RotateExternalCertAuthority(userCA)
if err != nil {
return trace.Wrap(err)
}
// update remote cluster's host cert authoritiy on a local cluster
// local proxy is authorized to perform this operation only for
// host authorities of remote clusters.
remoteCA, err := s.remoteClient.GetCertAuthority(services.CertAuthID{
Type: services.HostCA,
DomainName: s.domainName,
}, false)
if err != nil {
return trace.Wrap(err)
}
if remoteCA.GetClusterName() != s.domainName {
return trace.BadParameter(
"remote cluster sent different cluster name %v instead of expected one %v",
remoteCA.GetClusterName(), s.domainName)
}
err = s.localClient.UpsertCertAuthority(remoteCA)
if err != nil {
return trace.Wrap(err)
}
return s.compareAndSwapCertAuthority(remoteCA)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/reversetunnel/remotesite.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/remotesite.go#L460-L480 | go | train | // Dial is used to connect a requesting client (say, tsh) to an SSH server
// located in a remote connected site, the connection goes through the
// reverse proxy tunnel. | func (s *remoteSite) Dial(params DialParams) (net.Conn, error) | // Dial is used to connect a requesting client (say, tsh) to an SSH server
// located in a remote connected site, the connection goes through the
// reverse proxy tunnel.
func (s *remoteSite) Dial(params DialParams) (net.Conn, error) | {
err := params.CheckAndSetDefaults()
if err != nil {
return nil, trace.Wrap(err)
}
clusterConfig, err := s.localAccessPoint.GetClusterConfig()
if err != nil {
return nil, trace.Wrap(err)
}
// if the proxy is in recording mode use the agent to dial and build a
// in-memory forwarding server
if clusterConfig.GetSessionRecording() == services.RecordAtProxy {
if params.UserAgent == nil {
return nil, trace.BadParameter("user agent missing")
}
return s.dialWithAgent(params)
}
return s.DialTCP(params.From, params.To)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L44-L52 | go | train | // CheckAndSetDefaults checks and sets | func (r *ReporterConfig) CheckAndSetDefaults() error | // CheckAndSetDefaults checks and sets
func (r *ReporterConfig) CheckAndSetDefaults() error | {
if r.Backend == nil {
return trace.BadParameter("missing parameter Backend")
}
if r.Component == "" {
r.Component = teleport.ComponentBackend
}
return nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L62-L70 | go | train | // NewReporter returns a new Reporter. | func NewReporter(cfg ReporterConfig) (*Reporter, error) | // NewReporter returns a new Reporter.
func NewReporter(cfg ReporterConfig) (*Reporter, error) | {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
r := &Reporter{
ReporterConfig: cfg,
}
return r, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L73-L83 | go | train | // GetRange returns query range | func (s *Reporter) GetRange(ctx context.Context, startKey []byte, endKey []byte, limit int) (*GetResult, error) | // GetRange returns query range
func (s *Reporter) GetRange(ctx context.Context, startKey []byte, endKey []byte, limit int) (*GetResult, error) | {
start := s.Clock().Now()
res, err := s.Backend.GetRange(ctx, startKey, endKey, limit)
batchReadLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
batchReadRequests.WithLabelValues(s.Component).Inc()
if err != nil {
batchReadRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpGet, startKey, endKey)
return res, err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L86-L96 | go | train | // Create creates item if it does not exist | func (s *Reporter) Create(ctx context.Context, i Item) (*Lease, error) | // Create creates item if it does not exist
func (s *Reporter) Create(ctx context.Context, i Item) (*Lease, error) | {
start := s.Clock().Now()
lease, err := s.Backend.Create(ctx, i)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpPut, i.Key, nil)
return lease, err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L126-L136 | go | train | // Get returns a single item or not found error | func (s *Reporter) Get(ctx context.Context, key []byte) (*Item, error) | // Get returns a single item or not found error
func (s *Reporter) Get(ctx context.Context, key []byte) (*Item, error) | {
start := s.Clock().Now()
readLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
readRequests.WithLabelValues(s.Component).Inc()
item, err := s.Backend.Get(ctx, key)
if err != nil && !trace.IsNotFound(err) {
readRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpGet, key, nil)
return item, err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L140-L150 | go | train | // CompareAndSwap compares item with existing item
// and replaces is with replaceWith item | func (s *Reporter) CompareAndSwap(ctx context.Context, expected Item, replaceWith Item) (*Lease, error) | // CompareAndSwap compares item with existing item
// and replaces is with replaceWith item
func (s *Reporter) CompareAndSwap(ctx context.Context, expected Item, replaceWith Item) (*Lease, error) | {
start := s.Clock().Now()
lease, err := s.Backend.CompareAndSwap(ctx, expected, replaceWith)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) && !trace.IsCompareFailed(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpPut, expected.Key, nil)
return lease, err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L153-L163 | go | train | // Delete deletes item by key | func (s *Reporter) Delete(ctx context.Context, key []byte) error | // Delete deletes item by key
func (s *Reporter) Delete(ctx context.Context, key []byte) error | {
start := s.Clock().Now()
err := s.Backend.Delete(ctx, key)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpDelete, key, nil)
return err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L166-L176 | go | train | // DeleteRange deletes range of items | func (s *Reporter) DeleteRange(ctx context.Context, startKey []byte, endKey []byte) error | // DeleteRange deletes range of items
func (s *Reporter) DeleteRange(ctx context.Context, startKey []byte, endKey []byte) error | {
start := s.Clock().Now()
err := s.Backend.DeleteRange(ctx, startKey, endKey)
batchWriteLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
batchWriteRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
batchWriteRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpDelete, startKey, endKey)
return err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L182-L192 | go | train | // KeepAlive keeps object from expiring, updates lease on the existing object,
// expires contains the new expiry to set on the lease,
// some backends may ignore expires based on the implementation
// in case if the lease managed server side | func (s *Reporter) KeepAlive(ctx context.Context, lease Lease, expires time.Time) error | // KeepAlive keeps object from expiring, updates lease on the existing object,
// expires contains the new expiry to set on the lease,
// some backends may ignore expires based on the implementation
// in case if the lease managed server side
func (s *Reporter) KeepAlive(ctx context.Context, lease Lease, expires time.Time) error | {
start := s.Clock().Now()
err := s.Backend.KeepAlive(ctx, lease, expires)
writeLatencies.WithLabelValues(s.Component).Observe(time.Since(start).Seconds())
writeRequests.WithLabelValues(s.Component).Inc()
if err != nil && !trace.IsNotFound(err) {
writeRequestsFailed.WithLabelValues(s.Component).Inc()
}
s.trackRequest(OpPut, lease.Key, nil)
return err
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L195-L201 | go | train | // NewWatcher returns a new event watcher | func (s *Reporter) NewWatcher(ctx context.Context, watch Watch) (Watcher, error) | // NewWatcher returns a new event watcher
func (s *Reporter) NewWatcher(ctx context.Context, watch Watch) (Watcher, error) | {
w, err := s.Backend.NewWatcher(ctx, watch)
if err != nil {
return nil, trace.Wrap(err)
}
return NewReporterWatcher(ctx, s.Component, w), nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L220-L244 | go | train | // trackRequests tracks top requests, endKey is supplied for ranges | func (s *Reporter) trackRequest(opType OpType, key []byte, endKey []byte) | // trackRequests tracks top requests, endKey is supplied for ranges
func (s *Reporter) trackRequest(opType OpType, key []byte, endKey []byte) | {
if !s.TrackTopRequests {
return
}
if len(key) == 0 {
return
}
// take just the first two parts, otherwise too many distinct requests
// can end up in the map
parts := bytes.Split(key, []byte{Separator})
if len(parts) > 3 {
parts = parts[:3]
}
rangeSuffix := teleport.TagFalse
if len(endKey) != 0 {
// Range denotes range queries in stat entry
rangeSuffix = teleport.TagTrue
}
counter, err := requests.GetMetricWithLabelValues(s.Component, string(bytes.Join(parts, []byte{Separator})), rangeSuffix)
if err != nil {
log.Warningf("Failed to get counter: %v", err)
return
}
counter.Inc()
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/backend/report.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/report.go#L254-L261 | go | train | // NewReporterWatcher creates new reporter watcher instance | func NewReporterWatcher(ctx context.Context, component string, w Watcher) *ReporterWatcher | // NewReporterWatcher creates new reporter watcher instance
func NewReporterWatcher(ctx context.Context, component string, w Watcher) *ReporterWatcher | {
rw := &ReporterWatcher{
Watcher: w,
Component: component,
}
go rw.watch(ctx)
return rw
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/asciitable/table.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/asciitable/table.go#L42-L49 | go | train | // MakeTable creates a new instance of the table with given column names. | func MakeTable(headers []string) Table | // MakeTable creates a new instance of the table with given column names.
func MakeTable(headers []string) Table | {
t := MakeHeadlessTable(len(headers))
for i := range t.columns {
t.columns[i].title = headers[i]
t.columns[i].width = len(headers[i])
}
return t
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/asciitable/table.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/asciitable/table.go#L53-L58 | go | train | // MakeTable creates a new instance of the table without any column names.
// The number of columns is required. | func MakeHeadlessTable(columnCount int) Table | // MakeTable creates a new instance of the table without any column names.
// The number of columns is required.
func MakeHeadlessTable(columnCount int) Table | {
return Table{
columns: make([]column, columnCount),
rows: make([][]string, 0),
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/asciitable/table.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/asciitable/table.go#L61-L68 | go | train | // AddRow adds a row of cells to the table. | func (t *Table) AddRow(row []string) | // AddRow adds a row of cells to the table.
func (t *Table) AddRow(row []string) | {
limit := min(len(row), len(t.columns))
for i := 0; i < limit; i++ {
cellWidth := len(row[i])
t.columns[i].width = max(cellWidth, t.columns[i].width)
}
t.rows = append(t.rows, row[:limit])
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/asciitable/table.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/asciitable/table.go#L71-L101 | go | train | // AsBuffer returns a *bytes.Buffer with the printed output of the table. | func (t *Table) AsBuffer() *bytes.Buffer | // AsBuffer returns a *bytes.Buffer with the printed output of the table.
func (t *Table) AsBuffer() *bytes.Buffer | {
var buffer bytes.Buffer
writer := tabwriter.NewWriter(&buffer, 5, 0, 1, ' ', 0)
template := strings.Repeat("%v\t", len(t.columns))
// Header and separator.
if !t.IsHeadless() {
var colh []interface{}
var cols []interface{}
for _, col := range t.columns {
colh = append(colh, col.title)
cols = append(cols, strings.Repeat("-", col.width))
}
fmt.Fprintf(writer, template+"\n", colh...)
fmt.Fprintf(writer, template+"\n", cols...)
}
// Body.
for _, row := range t.rows {
var rowi []interface{}
for _, cell := range row {
rowi = append(rowi, cell)
}
fmt.Fprintf(writer, template+"\n", rowi...)
}
writer.Flush()
return &buffer
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/asciitable/table.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/asciitable/table.go#L104-L110 | go | train | // IsHeadless returns true if none of the table title cells contains any text. | func (t *Table) IsHeadless() bool | // IsHeadless returns true if none of the table title cells contains any text.
func (t *Table) IsHeadless() bool | {
total := 0
for i := range t.columns {
total += len(t.columns[i].title)
}
return total == 0
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/uri.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/uri.go#L28-L40 | go | train | // ParseSessionsURI parses uri per convention of session upload URIs
// file is a default scheme | func ParseSessionsURI(in string) (*url.URL, error) | // ParseSessionsURI parses uri per convention of session upload URIs
// file is a default scheme
func ParseSessionsURI(in string) (*url.URL, error) | {
if in == "" {
return nil, trace.BadParameter("uri is empty")
}
u, err := url.Parse(in)
if err != nil {
return nil, trace.BadParameter("failed to parse URI %q: %v", in, err)
}
if u.Scheme == "" {
u.Scheme = teleport.SchemeFile
}
return u, nil
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L44-L88 | go | train | // InitLogger configures the global logger for a given purpose / verbosity level | func InitLogger(purpose LoggingPurpose, level log.Level, verbose ...bool) | // InitLogger configures the global logger for a given purpose / verbosity level
func InitLogger(purpose LoggingPurpose, level log.Level, verbose ...bool) | {
log.StandardLogger().SetHooks(make(log.LevelHooks))
log.SetLevel(level)
switch purpose {
case LoggingForCLI:
// If debug logging was asked for on the CLI, then write logs to stderr.
// Otherwise discard all logs.
if level == log.DebugLevel {
log.SetFormatter(&trace.TextFormatter{
DisableTimestamp: true,
EnableColors: trace.IsTerminal(os.Stderr),
})
log.SetOutput(os.Stderr)
} else {
log.SetOutput(ioutil.Discard)
}
case LoggingForDaemon:
log.SetFormatter(&trace.TextFormatter{
DisableTimestamp: true,
EnableColors: trace.IsTerminal(os.Stderr),
})
log.SetOutput(os.Stderr)
case LoggingForTests:
log.SetFormatter(&trace.TextFormatter{
DisableTimestamp: true,
EnableColors: true,
})
log.SetLevel(level)
log.SetOutput(os.Stderr)
if len(verbose) != 0 && verbose[0] {
return
}
val, _ := strconv.ParseBool(os.Getenv(teleport.VerboseLogsEnvVar))
if val {
return
}
val, _ = strconv.ParseBool(os.Getenv(teleport.DebugEnvVar))
if val {
return
}
log.SetLevel(log.WarnLevel)
log.SetOutput(ioutil.Discard)
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L96-L99 | go | train | // FatalError is for CLI front-ends: it detects gravitational/trace debugging
// information, sends it to the logger, strips it off and prints a clean message to stderr | func FatalError(err error) | // FatalError is for CLI front-ends: it detects gravitational/trace debugging
// information, sends it to the logger, strips it off and prints a clean message to stderr
func FatalError(err error) | {
fmt.Fprintln(os.Stderr, UserMessageFromError(err))
os.Exit(1)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L103-L114 | go | train | // GetIterations provides a simple way to add iterations to the test
// by setting environment variable "ITERATIONS", by default it returns 1 | func GetIterations() int | // GetIterations provides a simple way to add iterations to the test
// by setting environment variable "ITERATIONS", by default it returns 1
func GetIterations() int | {
out := os.Getenv(teleport.IterationsEnvVar)
if out == "" {
return 1
}
iter, err := strconv.Atoi(out)
if err != nil {
panic(err)
}
log.Debugf("Starting tests with %v iterations.", iter)
return iter
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L117-L167 | go | train | // UserMessageFromError returns user friendly error message from error | func UserMessageFromError(err error) string | // UserMessageFromError returns user friendly error message from error
func UserMessageFromError(err error) string | {
// untrusted cert?
switch innerError := trace.Unwrap(err).(type) {
case x509.HostnameError:
return fmt.Sprintf("Cannot establish https connection to %s:\n%s\n%s\n",
innerError.Host,
innerError.Error(),
"try a different hostname for --proxy or specify --insecure flag if you know what you're doing.")
case x509.UnknownAuthorityError:
return `WARNING:
The proxy you are connecting to has presented a certificate signed by a
unknown authority. This is most likely due to either being presented
with a self-signed certificate or the certificate was truly signed by an
authority not known to the client.
If you know the certificate is self-signed and would like to ignore this
error use the --insecure flag.
If you have your own certificate authority that you would like to use to
validate the certificate chain presented by the proxy, set the
SSL_CERT_FILE and SSL_CERT_DIR environment variables respectively and try
again.
If you think something malicious may be occurring, contact your Teleport
system administrator to resolve this issue.
`
case x509.CertificateInvalidError:
return fmt.Sprintf(`WARNING:
The certificate presented by the proxy is invalid: %v.
Contact your Teleport system administrator to resolve this issue.`, innerError)
}
if log.GetLevel() == log.DebugLevel {
return trace.DebugReport(err)
}
if err != nil {
// If the error is a trace error, check if it has a user message embedded in
// it. If a user message is embedded in it, print the user message and the
// original error. Otherwise return the original with a generic "A fatal
// error occurred" message.
if er, ok := err.(*trace.TraceErr); ok {
if er.Message != "" {
return fmt.Sprintf("error: %v", EscapeControl(er.Message))
}
}
return fmt.Sprintf("error: %v", EscapeControl(err.Error()))
}
return ""
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L171-L181 | go | train | // Consolef prints the same message to a 'ui console' (if defined) and also to
// the logger with INFO priority | func Consolef(w io.Writer, component string, msg string, params ...interface{}) | // Consolef prints the same message to a 'ui console' (if defined) and also to
// the logger with INFO priority
func Consolef(w io.Writer, component string, msg string, params ...interface{}) | {
entry := log.WithFields(log.Fields{
trace.Component: component,
})
msg = fmt.Sprintf(msg, params...)
entry.Info(msg)
if w != nil {
component := strings.ToUpper(component)
fmt.Fprintf(w, "[%v]%v%v\n", strings.ToUpper(component), strings.Repeat(" ", 8-len(component)), msg)
}
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L185-L194 | go | train | // InitCLIParser configures kingpin command line args parser with
// some defaults common for all Teleport CLI tools | func InitCLIParser(appName, appHelp string) (app *kingpin.Application) | // InitCLIParser configures kingpin command line args parser with
// some defaults common for all Teleport CLI tools
func InitCLIParser(appName, appHelp string) (app *kingpin.Application) | {
app = kingpin.New(appName, appHelp)
// hide "--help" flag
app.HelpFlag.Hidden()
app.HelpFlag.NoEnvar()
// set our own help template
return app.UsageTemplate(defaultUsageTemplate)
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L200-L205 | go | train | // EscapeControl escapes all ANSI escape sequences from string and returns a
// string that is safe to print on the CLI. This is to ensure that malicious
// servers can not hide output. For more details, see:
// * https://sintonen.fi/advisories/scp-client-multiple-vulnerabilities.txt | func EscapeControl(s string) string | // EscapeControl escapes all ANSI escape sequences from string and returns a
// string that is safe to print on the CLI. This is to ensure that malicious
// servers can not hide output. For more details, see:
// * https://sintonen.fi/advisories/scp-client-multiple-vulnerabilities.txt
func EscapeControl(s string) string | {
if needsQuoting(s) {
return fmt.Sprintf("%q", s)
}
return s
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/utils/cli.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/cli.go#L208-L215 | go | train | // needsQuoting returns true if any non-printable characters are found. | func needsQuoting(text string) bool | // needsQuoting returns true if any non-printable characters are found.
func needsQuoting(text string) bool | {
for _, r := range text {
if !strconv.IsPrint(r) {
return true
}
}
return false
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/web/ui/server.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/web/ui/server.go#L63-L95 | go | train | // MakeServers creates server objects for webapp | func MakeServers(clusterName string, servers []services.Server) []Server | // MakeServers creates server objects for webapp
func MakeServers(clusterName string, servers []services.Server) []Server | {
uiServers := []Server{}
for _, server := range servers {
uiLabels := []Label{}
serverLabels := server.GetLabels()
for name, value := range serverLabels {
uiLabels = append(uiLabels, Label{
Name: name,
Value: value,
})
}
serverCmdLabels := server.GetCmdLabels()
for name, cmd := range serverCmdLabels {
uiLabels = append(uiLabels, Label{
Name: name,
Value: cmd.GetResult(),
})
}
sort.Sort(sortedLabels(uiLabels))
uiServers = append(uiServers, Server{
ClusterName: clusterName,
Name: server.GetName(),
Hostname: server.GetHostname(),
Addr: server.GetAddr(),
Labels: uiLabels,
})
}
return uiServers
} |
gravitational/teleport | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | lib/service/signals.go | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/signals.go#L38-L49 | go | train | // printShutdownStatus prints running services until shut down | func (process *TeleportProcess) printShutdownStatus(ctx context.Context) | // printShutdownStatus prints running services until shut down
func (process *TeleportProcess) printShutdownStatus(ctx context.Context) | {
t := time.NewTicker(defaults.HighResReportingPeriod)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
log.Infof("Waiting for services: %v to finish.", process.Supervisor.Services())
}
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.