repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
gravitational/teleport
lib/web/static.go
NewStaticFileSystem
func NewStaticFileSystem(debugMode bool) (http.FileSystem, error) { if debugMode { assetsToCheck := []string{"index.html", "/app"} if debugAssetsPath == "" { exePath, err := osext.ExecutableFolder() if err != nil { return nil, trace.Wrap(err) } debugAssetsPath = path.Join(exePath, "../web/dist") } for _, af := range assetsToCheck { _, err := os.Stat(filepath.Join(debugAssetsPath, af)) if err != nil { return nil, trace.Wrap(err) } } log.Infof("[Web] Using filesystem for serving web assets: %s", debugAssetsPath) return http.Dir(debugAssetsPath), nil } // otherwise, lets use the zip archive attached to the executable: return loadZippedExeAssets() }
go
func NewStaticFileSystem(debugMode bool) (http.FileSystem, error) { if debugMode { assetsToCheck := []string{"index.html", "/app"} if debugAssetsPath == "" { exePath, err := osext.ExecutableFolder() if err != nil { return nil, trace.Wrap(err) } debugAssetsPath = path.Join(exePath, "../web/dist") } for _, af := range assetsToCheck { _, err := os.Stat(filepath.Join(debugAssetsPath, af)) if err != nil { return nil, trace.Wrap(err) } } log.Infof("[Web] Using filesystem for serving web assets: %s", debugAssetsPath) return http.Dir(debugAssetsPath), nil } // otherwise, lets use the zip archive attached to the executable: return loadZippedExeAssets() }
[ "func", "NewStaticFileSystem", "(", "debugMode", "bool", ")", "(", "http", ".", "FileSystem", ",", "error", ")", "{", "if", "debugMode", "{", "assetsToCheck", ":=", "[", "]", "string", "{", "\"index.html\"", ",", "\"/app\"", "}", "\n", "if", "debugAssetsPath", "==", "\"\"", "{", "exePath", ",", "err", ":=", "osext", ".", "ExecutableFolder", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "debugAssetsPath", "=", "path", ".", "Join", "(", "exePath", ",", "\"../web/dist\"", ")", "\n", "}", "\n", "for", "_", ",", "af", ":=", "range", "assetsToCheck", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "filepath", ".", "Join", "(", "debugAssetsPath", ",", "af", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "}", "\n", "log", ".", "Infof", "(", "\"[Web] Using filesystem for serving web assets: %s\"", ",", "debugAssetsPath", ")", "\n", "return", "http", ".", "Dir", "(", "debugAssetsPath", ")", ",", "nil", "\n", "}", "\n", "return", "loadZippedExeAssets", "(", ")", "\n", "}" ]
// NewStaticFileSystem returns the initialized implementation of http.FileSystem // interface which can be used to serve Teleport Proxy Web UI // // If 'debugMode' is true, it will load the web assets from the same git repo // directory where the executable is, otherwise it will load them from the embedded // zip archive. //
[ "NewStaticFileSystem", "returns", "the", "initialized", "implementation", "of", "http", ".", "FileSystem", "interface", "which", "can", "be", "used", "to", "serve", "Teleport", "Proxy", "Web", "UI", "If", "debugMode", "is", "true", "it", "will", "load", "the", "web", "assets", "from", "the", "same", "git", "repo", "directory", "where", "the", "executable", "is", "otherwise", "it", "will", "load", "them", "from", "the", "embedded", "zip", "archive", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/web/static.go#L53-L77
train
gravitational/teleport
lib/web/static.go
isDebugMode
func isDebugMode() bool { v, _ := strconv.ParseBool(os.Getenv(teleport.DebugEnvVar)) return v }
go
func isDebugMode() bool { v, _ := strconv.ParseBool(os.Getenv(teleport.DebugEnvVar)) return v }
[ "func", "isDebugMode", "(", ")", "bool", "{", "v", ",", "_", ":=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "teleport", ".", "DebugEnvVar", ")", ")", "\n", "return", "v", "\n", "}" ]
// isDebugMode determines if teleport is running in a "debug" mode. // It looks at DEBUG environment variable
[ "isDebugMode", "determines", "if", "teleport", "is", "running", "in", "a", "debug", "mode", ".", "It", "looks", "at", "DEBUG", "environment", "variable" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/web/static.go#L81-L84
train
gravitational/teleport
lib/web/static.go
loadZippedExeAssets
func loadZippedExeAssets() (ResourceMap, error) { // open ourselves (teleport binary) for reading: // NOTE: the file stays open to serve future Read() requests myExe, err := osext.Executable() if err != nil { return nil, trace.Wrap(err) } return readZipArchive(myExe) }
go
func loadZippedExeAssets() (ResourceMap, error) { // open ourselves (teleport binary) for reading: // NOTE: the file stays open to serve future Read() requests myExe, err := osext.Executable() if err != nil { return nil, trace.Wrap(err) } return readZipArchive(myExe) }
[ "func", "loadZippedExeAssets", "(", ")", "(", "ResourceMap", ",", "error", ")", "{", "myExe", ",", "err", ":=", "osext", ".", "Executable", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "readZipArchive", "(", "myExe", ")", "\n", "}" ]
// LoadWebResources returns a filesystem implementation compatible // with http.Serve. // // The "filesystem" is served from a zip file attached at the end of // the executable //
[ "LoadWebResources", "returns", "a", "filesystem", "implementation", "compatible", "with", "http", ".", "Serve", ".", "The", "filesystem", "is", "served", "from", "a", "zip", "file", "attached", "at", "the", "end", "of", "the", "executable" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/web/static.go#L92-L100
train
gravitational/teleport
lib/auth/register.go
LocalRegister
func LocalRegister(id IdentityID, authServer *AuthServer, additionalPrincipals, dnsNames []string, remoteAddr string) (*Identity, error) { // If local registration is happening and no remote address was passed in // (which means no advertise IP was set), use localhost. if remoteAddr == "" { remoteAddr = defaults.Localhost } keys, err := authServer.GenerateServerKeys(GenerateServerKeysRequest{ HostID: id.HostUUID, NodeName: id.NodeName, Roles: teleport.Roles{id.Role}, AdditionalPrincipals: additionalPrincipals, RemoteAddr: remoteAddr, DNSNames: dnsNames, NoCache: true, }) if err != nil { return nil, trace.Wrap(err) } identity, err := ReadIdentityFromKeyPair(keys) if err != nil { return nil, trace.Wrap(err) } return identity, nil }
go
func LocalRegister(id IdentityID, authServer *AuthServer, additionalPrincipals, dnsNames []string, remoteAddr string) (*Identity, error) { // If local registration is happening and no remote address was passed in // (which means no advertise IP was set), use localhost. if remoteAddr == "" { remoteAddr = defaults.Localhost } keys, err := authServer.GenerateServerKeys(GenerateServerKeysRequest{ HostID: id.HostUUID, NodeName: id.NodeName, Roles: teleport.Roles{id.Role}, AdditionalPrincipals: additionalPrincipals, RemoteAddr: remoteAddr, DNSNames: dnsNames, NoCache: true, }) if err != nil { return nil, trace.Wrap(err) } identity, err := ReadIdentityFromKeyPair(keys) if err != nil { return nil, trace.Wrap(err) } return identity, nil }
[ "func", "LocalRegister", "(", "id", "IdentityID", ",", "authServer", "*", "AuthServer", ",", "additionalPrincipals", ",", "dnsNames", "[", "]", "string", ",", "remoteAddr", "string", ")", "(", "*", "Identity", ",", "error", ")", "{", "if", "remoteAddr", "==", "\"\"", "{", "remoteAddr", "=", "defaults", ".", "Localhost", "\n", "}", "\n", "keys", ",", "err", ":=", "authServer", ".", "GenerateServerKeys", "(", "GenerateServerKeysRequest", "{", "HostID", ":", "id", ".", "HostUUID", ",", "NodeName", ":", "id", ".", "NodeName", ",", "Roles", ":", "teleport", ".", "Roles", "{", "id", ".", "Role", "}", ",", "AdditionalPrincipals", ":", "additionalPrincipals", ",", "RemoteAddr", ":", "remoteAddr", ",", "DNSNames", ":", "dnsNames", ",", "NoCache", ":", "true", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "identity", ",", "err", ":=", "ReadIdentityFromKeyPair", "(", "keys", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "identity", ",", "nil", "\n", "}" ]
// LocalRegister is used to generate host keys when a node or proxy is running // within the same process as the Auth Server and as such, does not need to // use provisioning tokens.
[ "LocalRegister", "is", "used", "to", "generate", "host", "keys", "when", "a", "node", "or", "proxy", "is", "running", "within", "the", "same", "process", "as", "the", "Auth", "Server", "and", "as", "such", "does", "not", "need", "to", "use", "provisioning", "tokens", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L37-L62
train
gravitational/teleport
lib/auth/register.go
Register
func Register(params RegisterParams) (*Identity, error) { // Read in the token. The token can either be passed in or come from a file // on disk. token, err := readToken(params.Token) if err != nil { return nil, trace.Wrap(err) } // Attempt to register through the auth server, if it fails, try and // register through the proxy server. ident, err := registerThroughAuth(token, params) if err != nil { // If no params client was set this is a proxy and fail right away. if params.CredsClient == nil { log.Debugf("Missing client, failing with error from Auth Server: %v.", err) return nil, trace.Wrap(err) } ident, er := registerThroughProxy(token, params) if er != nil { return nil, trace.NewAggregate(err, er) } log.Debugf("Successfully registered through proxy server.") return ident, nil } log.Debugf("Successfully registered through auth server.") return ident, nil }
go
func Register(params RegisterParams) (*Identity, error) { // Read in the token. The token can either be passed in or come from a file // on disk. token, err := readToken(params.Token) if err != nil { return nil, trace.Wrap(err) } // Attempt to register through the auth server, if it fails, try and // register through the proxy server. ident, err := registerThroughAuth(token, params) if err != nil { // If no params client was set this is a proxy and fail right away. if params.CredsClient == nil { log.Debugf("Missing client, failing with error from Auth Server: %v.", err) return nil, trace.Wrap(err) } ident, er := registerThroughProxy(token, params) if er != nil { return nil, trace.NewAggregate(err, er) } log.Debugf("Successfully registered through proxy server.") return ident, nil } log.Debugf("Successfully registered through auth server.") return ident, nil }
[ "func", "Register", "(", "params", "RegisterParams", ")", "(", "*", "Identity", ",", "error", ")", "{", "token", ",", "err", ":=", "readToken", "(", "params", ".", "Token", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "ident", ",", "err", ":=", "registerThroughAuth", "(", "token", ",", "params", ")", "\n", "if", "err", "!=", "nil", "{", "if", "params", ".", "CredsClient", "==", "nil", "{", "log", ".", "Debugf", "(", "\"Missing client, failing with error from Auth Server: %v.\"", ",", "err", ")", "\n", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "ident", ",", "er", ":=", "registerThroughProxy", "(", "token", ",", "params", ")", "\n", "if", "er", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "NewAggregate", "(", "err", ",", "er", ")", "\n", "}", "\n", "log", ".", "Debugf", "(", "\"Successfully registered through proxy server.\"", ")", "\n", "return", "ident", ",", "nil", "\n", "}", "\n", "log", ".", "Debugf", "(", "\"Successfully registered through auth server.\"", ")", "\n", "return", "ident", ",", "nil", "\n", "}" ]
// Register is used to generate host keys when a node or proxy are running on // different hosts than the auth server. This method requires provisioning // tokens to prove a valid auth server was used to issue the joining request // as well as a method for the node to validate the auth server.
[ "Register", "is", "used", "to", "generate", "host", "keys", "when", "a", "node", "or", "proxy", "are", "running", "on", "different", "hosts", "than", "the", "auth", "server", ".", "This", "method", "requires", "provisioning", "tokens", "to", "prove", "a", "valid", "auth", "server", "was", "used", "to", "issue", "the", "joining", "request", "as", "well", "as", "a", "method", "for", "the", "node", "to", "validate", "the", "auth", "server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L108-L137
train
gravitational/teleport
lib/auth/register.go
registerThroughProxy
func registerThroughProxy(token string, params RegisterParams) (*Identity, error) { log.Debugf("Attempting to register through proxy server.") keys, err := params.CredsClient.HostCredentials(context.Background(), RegisterUsingTokenRequest{ Token: token, HostID: params.ID.HostUUID, NodeName: params.ID.NodeName, Role: params.ID.Role, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
go
func registerThroughProxy(token string, params RegisterParams) (*Identity, error) { log.Debugf("Attempting to register through proxy server.") keys, err := params.CredsClient.HostCredentials(context.Background(), RegisterUsingTokenRequest{ Token: token, HostID: params.ID.HostUUID, NodeName: params.ID.NodeName, Role: params.ID.Role, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
[ "func", "registerThroughProxy", "(", "token", "string", ",", "params", "RegisterParams", ")", "(", "*", "Identity", ",", "error", ")", "{", "log", ".", "Debugf", "(", "\"Attempting to register through proxy server.\"", ")", "\n", "keys", ",", "err", ":=", "params", ".", "CredsClient", ".", "HostCredentials", "(", "context", ".", "Background", "(", ")", ",", "RegisterUsingTokenRequest", "{", "Token", ":", "token", ",", "HostID", ":", "params", ".", "ID", ".", "HostUUID", ",", "NodeName", ":", "params", ".", "ID", ".", "NodeName", ",", "Role", ":", "params", ".", "ID", ".", "Role", ",", "AdditionalPrincipals", ":", "params", ".", "AdditionalPrincipals", ",", "DNSNames", ":", "params", ".", "DNSNames", ",", "PublicTLSKey", ":", "params", ".", "PublicTLSKey", ",", "PublicSSHKey", ":", "params", ".", "PublicSSHKey", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "keys", ".", "Key", "=", "params", ".", "PrivateKey", "\n", "return", "ReadIdentityFromKeyPair", "(", "keys", ")", "\n", "}" ]
// registerThroughProxy is used to register through the proxy server.
[ "registerThroughProxy", "is", "used", "to", "register", "through", "the", "proxy", "server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L140-L160
train
gravitational/teleport
lib/auth/register.go
registerThroughAuth
func registerThroughAuth(token string, params RegisterParams) (*Identity, error) { log.Debugf("Attempting to register through auth server.") var client *Client var err error // Build a client to the Auth Server. If a CA pin is specified require the // Auth Server is validated. Otherwise attempt to use the CA file on disk // but if it's not available connect without validating the Auth Server CA. switch { case params.CAPin != "": client, err = pinRegisterClient(params) default: client, err = insecureRegisterClient(params) } if err != nil { return nil, trace.Wrap(err) } defer client.Close() // Get the SSH and X509 certificates for a node. keys, err := client.RegisterUsingToken(RegisterUsingTokenRequest{ Token: token, HostID: params.ID.HostUUID, NodeName: params.ID.NodeName, Role: params.ID.Role, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
go
func registerThroughAuth(token string, params RegisterParams) (*Identity, error) { log.Debugf("Attempting to register through auth server.") var client *Client var err error // Build a client to the Auth Server. If a CA pin is specified require the // Auth Server is validated. Otherwise attempt to use the CA file on disk // but if it's not available connect without validating the Auth Server CA. switch { case params.CAPin != "": client, err = pinRegisterClient(params) default: client, err = insecureRegisterClient(params) } if err != nil { return nil, trace.Wrap(err) } defer client.Close() // Get the SSH and X509 certificates for a node. keys, err := client.RegisterUsingToken(RegisterUsingTokenRequest{ Token: token, HostID: params.ID.HostUUID, NodeName: params.ID.NodeName, Role: params.ID.Role, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
[ "func", "registerThroughAuth", "(", "token", "string", ",", "params", "RegisterParams", ")", "(", "*", "Identity", ",", "error", ")", "{", "log", ".", "Debugf", "(", "\"Attempting to register through auth server.\"", ")", "\n", "var", "client", "*", "Client", "\n", "var", "err", "error", "\n", "switch", "{", "case", "params", ".", "CAPin", "!=", "\"\"", ":", "client", ",", "err", "=", "pinRegisterClient", "(", "params", ")", "\n", "default", ":", "client", ",", "err", "=", "insecureRegisterClient", "(", "params", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "keys", ",", "err", ":=", "client", ".", "RegisterUsingToken", "(", "RegisterUsingTokenRequest", "{", "Token", ":", "token", ",", "HostID", ":", "params", ".", "ID", ".", "HostUUID", ",", "NodeName", ":", "params", ".", "ID", ".", "NodeName", ",", "Role", ":", "params", ".", "ID", ".", "Role", ",", "AdditionalPrincipals", ":", "params", ".", "AdditionalPrincipals", ",", "DNSNames", ":", "params", ".", "DNSNames", ",", "PublicTLSKey", ":", "params", ".", "PublicTLSKey", ",", "PublicSSHKey", ":", "params", ".", "PublicSSHKey", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "keys", ".", "Key", "=", "params", ".", "PrivateKey", "\n", "return", "ReadIdentityFromKeyPair", "(", "keys", ")", "\n", "}" ]
// registerThroughAuth is used to register through the auth server.
[ "registerThroughAuth", "is", "used", "to", "register", "through", "the", "auth", "server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L163-L200
train
gravitational/teleport
lib/auth/register.go
insecureRegisterClient
func insecureRegisterClient(params RegisterParams) (*Client, error) { tlsConfig := utils.TLSConfig(params.CipherSuites) cert, err := readCA(params) if err != nil && !trace.IsNotFound(err) { return nil, trace.Wrap(err) } // If no CA was found, then create a insecure connection to the Auth Server, // otherwise use the CA on disk to validate the Auth Server. if trace.IsNotFound(err) { tlsConfig.InsecureSkipVerify = true log.Warnf("Joining cluster without validating the identity of the Auth " + "Server. This may open you up to a Man-In-The-Middle (MITM) attack if an " + "attacker can gain privileged network access. To remedy this, use the CA pin " + "value provided when join token was generated to validate the identity of " + "the Auth Server.") } else { certPool := x509.NewCertPool() certPool.AddCert(cert) tlsConfig.RootCAs = certPool log.Infof("Joining remote cluster %v, validating connection with certificate on disk.", cert.Subject.CommonName) } client, err := NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } return client, nil }
go
func insecureRegisterClient(params RegisterParams) (*Client, error) { tlsConfig := utils.TLSConfig(params.CipherSuites) cert, err := readCA(params) if err != nil && !trace.IsNotFound(err) { return nil, trace.Wrap(err) } // If no CA was found, then create a insecure connection to the Auth Server, // otherwise use the CA on disk to validate the Auth Server. if trace.IsNotFound(err) { tlsConfig.InsecureSkipVerify = true log.Warnf("Joining cluster without validating the identity of the Auth " + "Server. This may open you up to a Man-In-The-Middle (MITM) attack if an " + "attacker can gain privileged network access. To remedy this, use the CA pin " + "value provided when join token was generated to validate the identity of " + "the Auth Server.") } else { certPool := x509.NewCertPool() certPool.AddCert(cert) tlsConfig.RootCAs = certPool log.Infof("Joining remote cluster %v, validating connection with certificate on disk.", cert.Subject.CommonName) } client, err := NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } return client, nil }
[ "func", "insecureRegisterClient", "(", "params", "RegisterParams", ")", "(", "*", "Client", ",", "error", ")", "{", "tlsConfig", ":=", "utils", ".", "TLSConfig", "(", "params", ".", "CipherSuites", ")", "\n", "cert", ",", "err", ":=", "readCA", "(", "params", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "trace", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "if", "trace", ".", "IsNotFound", "(", "err", ")", "{", "tlsConfig", ".", "InsecureSkipVerify", "=", "true", "\n", "log", ".", "Warnf", "(", "\"Joining cluster without validating the identity of the Auth \"", "+", "\"Server. This may open you up to a Man-In-The-Middle (MITM) attack if an \"", "+", "\"attacker can gain privileged network access. To remedy this, use the CA pin \"", "+", "\"value provided when join token was generated to validate the identity of \"", "+", "\"the Auth Server.\"", ")", "\n", "}", "else", "{", "certPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "certPool", ".", "AddCert", "(", "cert", ")", "\n", "tlsConfig", ".", "RootCAs", "=", "certPool", "\n", "log", ".", "Infof", "(", "\"Joining remote cluster %v, validating connection with certificate on disk.\"", ",", "cert", ".", "Subject", ".", "CommonName", ")", "\n", "}", "\n", "client", ",", "err", ":=", "NewTLSClient", "(", "ClientConfig", "{", "Addrs", ":", "params", ".", "Servers", ",", "TLS", ":", "tlsConfig", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "client", ",", "nil", "\n", "}" ]
// insecureRegisterClient attempts to connects to the Auth Server using the // CA on disk. If no CA is found on disk, Teleport will not verify the Auth // Server it is connecting to.
[ "insecureRegisterClient", "attempts", "to", "connects", "to", "the", "Auth", "Server", "using", "the", "CA", "on", "disk", ".", "If", "no", "CA", "is", "found", "on", "disk", "Teleport", "will", "not", "verify", "the", "Auth", "Server", "it", "is", "connecting", "to", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L205-L237
train
gravitational/teleport
lib/auth/register.go
readCA
func readCA(params RegisterParams) (*x509.Certificate, error) { certBytes, err := utils.ReadPath(params.CAPath) if err != nil { return nil, trace.Wrap(err) } cert, err := tlsca.ParseCertificatePEM(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse certificate at %v", params.CAPath) } return cert, nil }
go
func readCA(params RegisterParams) (*x509.Certificate, error) { certBytes, err := utils.ReadPath(params.CAPath) if err != nil { return nil, trace.Wrap(err) } cert, err := tlsca.ParseCertificatePEM(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse certificate at %v", params.CAPath) } return cert, nil }
[ "func", "readCA", "(", "params", "RegisterParams", ")", "(", "*", "x509", ".", "Certificate", ",", "error", ")", "{", "certBytes", ",", "err", ":=", "utils", ".", "ReadPath", "(", "params", ".", "CAPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "cert", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "certBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to parse certificate at %v\"", ",", "params", ".", "CAPath", ")", "\n", "}", "\n", "return", "cert", ",", "nil", "\n", "}" ]
// readCA will read in CA that will be used to validate the certificate that // the Auth Server presents.
[ "readCA", "will", "read", "in", "CA", "that", "will", "be", "used", "to", "validate", "the", "certificate", "that", "the", "Auth", "Server", "presents", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L241-L251
train
gravitational/teleport
lib/auth/register.go
pinRegisterClient
func pinRegisterClient(params RegisterParams) (*Client, error) { // Build a insecure client to the Auth Server. This is safe because even if // an attacker were to MITM this connection the CA pin will not match below. tlsConfig := utils.TLSConfig(params.CipherSuites) tlsConfig.InsecureSkipVerify = true client, err := NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } defer client.Close() // Fetch the root CA from the Auth Server. The NOP role has access to the // GetClusterCACert endpoint. localCA, err := client.GetClusterCACert() if err != nil { return nil, trace.Wrap(err) } tlsCA, err := tlsca.ParseCertificatePEM(localCA.TLSCA) if err != nil { return nil, trace.Wrap(err) } // Check that the SPKI pin matches the CA we fetched over a insecure // connection. This makes sure the CA fetched over a insecure connection is // in-fact the expected CA. err = utils.CheckSPKI(params.CAPin, tlsCA) if err != nil { return nil, trace.Wrap(err) } log.Infof("Joining remote cluster %v with CA pin.", tlsCA.Subject.CommonName) // Create another client, but this time with the CA provided to validate // that the Auth Server was issued a certificate by the same CA. tlsConfig = utils.TLSConfig(params.CipherSuites) certPool := x509.NewCertPool() certPool.AddCert(tlsCA) tlsConfig.RootCAs = certPool client, err = NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } return client, nil }
go
func pinRegisterClient(params RegisterParams) (*Client, error) { // Build a insecure client to the Auth Server. This is safe because even if // an attacker were to MITM this connection the CA pin will not match below. tlsConfig := utils.TLSConfig(params.CipherSuites) tlsConfig.InsecureSkipVerify = true client, err := NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } defer client.Close() // Fetch the root CA from the Auth Server. The NOP role has access to the // GetClusterCACert endpoint. localCA, err := client.GetClusterCACert() if err != nil { return nil, trace.Wrap(err) } tlsCA, err := tlsca.ParseCertificatePEM(localCA.TLSCA) if err != nil { return nil, trace.Wrap(err) } // Check that the SPKI pin matches the CA we fetched over a insecure // connection. This makes sure the CA fetched over a insecure connection is // in-fact the expected CA. err = utils.CheckSPKI(params.CAPin, tlsCA) if err != nil { return nil, trace.Wrap(err) } log.Infof("Joining remote cluster %v with CA pin.", tlsCA.Subject.CommonName) // Create another client, but this time with the CA provided to validate // that the Auth Server was issued a certificate by the same CA. tlsConfig = utils.TLSConfig(params.CipherSuites) certPool := x509.NewCertPool() certPool.AddCert(tlsCA) tlsConfig.RootCAs = certPool client, err = NewTLSClient(ClientConfig{Addrs: params.Servers, TLS: tlsConfig}) if err != nil { return nil, trace.Wrap(err) } return client, nil }
[ "func", "pinRegisterClient", "(", "params", "RegisterParams", ")", "(", "*", "Client", ",", "error", ")", "{", "tlsConfig", ":=", "utils", ".", "TLSConfig", "(", "params", ".", "CipherSuites", ")", "\n", "tlsConfig", ".", "InsecureSkipVerify", "=", "true", "\n", "client", ",", "err", ":=", "NewTLSClient", "(", "ClientConfig", "{", "Addrs", ":", "params", ".", "Servers", ",", "TLS", ":", "tlsConfig", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "localCA", ",", "err", ":=", "client", ".", "GetClusterCACert", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "tlsCA", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "localCA", ".", "TLSCA", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "err", "=", "utils", ".", "CheckSPKI", "(", "params", ".", "CAPin", ",", "tlsCA", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "log", ".", "Infof", "(", "\"Joining remote cluster %v with CA pin.\"", ",", "tlsCA", ".", "Subject", ".", "CommonName", ")", "\n", "tlsConfig", "=", "utils", ".", "TLSConfig", "(", "params", ".", "CipherSuites", ")", "\n", "certPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "certPool", ".", "AddCert", "(", "tlsCA", ")", "\n", "tlsConfig", ".", "RootCAs", "=", "certPool", "\n", "client", ",", "err", "=", "NewTLSClient", "(", "ClientConfig", "{", "Addrs", ":", "params", ".", "Servers", ",", "TLS", ":", "tlsConfig", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "client", ",", "nil", "\n", "}" ]
// pinRegisterClient first connects to the Auth Server using a insecure // connection to fetch the root CA. If the root CA matches the provided CA // pin, a connection will be re-established and the root CA will be used to // validate the certificate presented. If both conditions hold true, then we // know we are connecting to the expected Auth Server.
[ "pinRegisterClient", "first", "connects", "to", "the", "Auth", "Server", "using", "a", "insecure", "connection", "to", "fetch", "the", "root", "CA", ".", "If", "the", "root", "CA", "matches", "the", "provided", "CA", "pin", "a", "connection", "will", "be", "re", "-", "established", "and", "the", "root", "CA", "will", "be", "used", "to", "validate", "the", "certificate", "presented", ".", "If", "both", "conditions", "hold", "true", "then", "we", "know", "we", "are", "connecting", "to", "the", "expected", "Auth", "Server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L258-L303
train
gravitational/teleport
lib/auth/register.go
ReRegister
func ReRegister(params ReRegisterParams) (*Identity, error) { hostID, err := params.ID.HostID() if err != nil { return nil, trace.Wrap(err) } keys, err := params.Client.GenerateServerKeys(GenerateServerKeysRequest{ HostID: hostID, NodeName: params.ID.NodeName, Roles: teleport.Roles{params.ID.Role}, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, Rotation: &params.Rotation, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
go
func ReRegister(params ReRegisterParams) (*Identity, error) { hostID, err := params.ID.HostID() if err != nil { return nil, trace.Wrap(err) } keys, err := params.Client.GenerateServerKeys(GenerateServerKeysRequest{ HostID: hostID, NodeName: params.ID.NodeName, Roles: teleport.Roles{params.ID.Role}, AdditionalPrincipals: params.AdditionalPrincipals, DNSNames: params.DNSNames, PublicTLSKey: params.PublicTLSKey, PublicSSHKey: params.PublicSSHKey, Rotation: &params.Rotation, }) if err != nil { return nil, trace.Wrap(err) } keys.Key = params.PrivateKey return ReadIdentityFromKeyPair(keys) }
[ "func", "ReRegister", "(", "params", "ReRegisterParams", ")", "(", "*", "Identity", ",", "error", ")", "{", "hostID", ",", "err", ":=", "params", ".", "ID", ".", "HostID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "keys", ",", "err", ":=", "params", ".", "Client", ".", "GenerateServerKeys", "(", "GenerateServerKeysRequest", "{", "HostID", ":", "hostID", ",", "NodeName", ":", "params", ".", "ID", ".", "NodeName", ",", "Roles", ":", "teleport", ".", "Roles", "{", "params", ".", "ID", ".", "Role", "}", ",", "AdditionalPrincipals", ":", "params", ".", "AdditionalPrincipals", ",", "DNSNames", ":", "params", ".", "DNSNames", ",", "PublicTLSKey", ":", "params", ".", "PublicTLSKey", ",", "PublicSSHKey", ":", "params", ".", "PublicSSHKey", ",", "Rotation", ":", "&", "params", ".", "Rotation", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "keys", ".", "Key", "=", "params", ".", "PrivateKey", "\n", "return", "ReadIdentityFromKeyPair", "(", "keys", ")", "\n", "}" ]
// ReRegister renews the certificates and private keys based on the client's existing identity.
[ "ReRegister", "renews", "the", "certificates", "and", "private", "keys", "based", "on", "the", "client", "s", "existing", "identity", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/register.go#L327-L348
train
gravitational/teleport
lib/config/fileconf.go
ReadFromFile
func ReadFromFile(filePath string) (*FileConfig, error) { f, err := os.Open(filePath) if err != nil { return nil, trace.Wrap(err, fmt.Sprintf("failed to open file: %v", filePath)) } defer f.Close() return ReadConfig(f) }
go
func ReadFromFile(filePath string) (*FileConfig, error) { f, err := os.Open(filePath) if err != nil { return nil, trace.Wrap(err, fmt.Sprintf("failed to open file: %v", filePath)) } defer f.Close() return ReadConfig(f) }
[ "func", "ReadFromFile", "(", "filePath", "string", ")", "(", "*", "FileConfig", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "filePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "fmt", ".", "Sprintf", "(", "\"failed to open file: %v\"", ",", "filePath", ")", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "return", "ReadConfig", "(", "f", ")", "\n", "}" ]
// ReadFromFile reads Teleport configuration from a file. Currently only YAML // format is supported
[ "ReadFromFile", "reads", "Teleport", "configuration", "from", "a", "file", ".", "Currently", "only", "YAML", "format", "is", "supported" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L170-L177
train
gravitational/teleport
lib/config/fileconf.go
ReadFromString
func ReadFromString(configString string) (*FileConfig, error) { data, err := base64.StdEncoding.DecodeString(configString) if err != nil { return nil, trace.BadParameter( "confiugraion should be base64 encoded: %v", err) } return ReadConfig(bytes.NewBuffer(data)) }
go
func ReadFromString(configString string) (*FileConfig, error) { data, err := base64.StdEncoding.DecodeString(configString) if err != nil { return nil, trace.BadParameter( "confiugraion should be base64 encoded: %v", err) } return ReadConfig(bytes.NewBuffer(data)) }
[ "func", "ReadFromString", "(", "configString", "string", ")", "(", "*", "FileConfig", ",", "error", ")", "{", "data", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "configString", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"confiugraion should be base64 encoded: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "ReadConfig", "(", "bytes", ".", "NewBuffer", "(", "data", ")", ")", "\n", "}" ]
// ReadFromString reads values from base64 encoded byte string
[ "ReadFromString", "reads", "values", "from", "base64", "encoded", "byte", "string" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L180-L187
train
gravitational/teleport
lib/config/fileconf.go
ReadConfig
func ReadConfig(reader io.Reader) (*FileConfig, error) { // read & parse YAML config: bytes, err := ioutil.ReadAll(reader) if err != nil { return nil, trace.Wrap(err, "failed reading Teleport configuration") } var fc FileConfig if err = yaml.Unmarshal(bytes, &fc); err != nil { return nil, trace.BadParameter("failed to parse Teleport configuration: %v", err) } // don't start Teleport with invalid ciphers, kex algorithms, or mac algorithms. err = fc.Check() if err != nil { return nil, trace.BadParameter("failed to parse Teleport configuration: %v", err) } // now check for unknown (misspelled) config keys: var validateKeys func(m YAMLMap) error validateKeys = func(m YAMLMap) error { var recursive, ok bool var key string for k, v := range m { if key, ok = k.(string); ok { if recursive, ok = validKeys[key]; !ok { return trace.BadParameter("unrecognized configuration key: '%v'", key) } if recursive { if m2, ok := v.(YAMLMap); ok { if err := validateKeys(m2); err != nil { return err } } } } } return nil } // validate configuration keys: var tmp YAMLMap if err = yaml.Unmarshal(bytes, &tmp); err != nil { return nil, trace.BadParameter("error parsing YAML config") } if err = validateKeys(tmp); err != nil { return nil, trace.Wrap(err) } return &fc, nil }
go
func ReadConfig(reader io.Reader) (*FileConfig, error) { // read & parse YAML config: bytes, err := ioutil.ReadAll(reader) if err != nil { return nil, trace.Wrap(err, "failed reading Teleport configuration") } var fc FileConfig if err = yaml.Unmarshal(bytes, &fc); err != nil { return nil, trace.BadParameter("failed to parse Teleport configuration: %v", err) } // don't start Teleport with invalid ciphers, kex algorithms, or mac algorithms. err = fc.Check() if err != nil { return nil, trace.BadParameter("failed to parse Teleport configuration: %v", err) } // now check for unknown (misspelled) config keys: var validateKeys func(m YAMLMap) error validateKeys = func(m YAMLMap) error { var recursive, ok bool var key string for k, v := range m { if key, ok = k.(string); ok { if recursive, ok = validKeys[key]; !ok { return trace.BadParameter("unrecognized configuration key: '%v'", key) } if recursive { if m2, ok := v.(YAMLMap); ok { if err := validateKeys(m2); err != nil { return err } } } } } return nil } // validate configuration keys: var tmp YAMLMap if err = yaml.Unmarshal(bytes, &tmp); err != nil { return nil, trace.BadParameter("error parsing YAML config") } if err = validateKeys(tmp); err != nil { return nil, trace.Wrap(err) } return &fc, nil }
[ "func", "ReadConfig", "(", "reader", "io", ".", "Reader", ")", "(", "*", "FileConfig", ",", "error", ")", "{", "bytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed reading Teleport configuration\"", ")", "\n", "}", "\n", "var", "fc", "FileConfig", "\n", "if", "err", "=", "yaml", ".", "Unmarshal", "(", "bytes", ",", "&", "fc", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"failed to parse Teleport configuration: %v\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "fc", ".", "Check", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"failed to parse Teleport configuration: %v\"", ",", "err", ")", "\n", "}", "\n", "var", "validateKeys", "func", "(", "m", "YAMLMap", ")", "error", "\n", "validateKeys", "=", "func", "(", "m", "YAMLMap", ")", "error", "{", "var", "recursive", ",", "ok", "bool", "\n", "var", "key", "string", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "if", "key", ",", "ok", "=", "k", ".", "(", "string", ")", ";", "ok", "{", "if", "recursive", ",", "ok", "=", "validKeys", "[", "key", "]", ";", "!", "ok", "{", "return", "trace", ".", "BadParameter", "(", "\"unrecognized configuration key: '%v'\"", ",", "key", ")", "\n", "}", "\n", "if", "recursive", "{", "if", "m2", ",", "ok", ":=", "v", ".", "(", "YAMLMap", ")", ";", "ok", "{", "if", "err", ":=", "validateKeys", "(", "m2", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "var", "tmp", "YAMLMap", "\n", "if", "err", "=", "yaml", ".", "Unmarshal", "(", "bytes", ",", "&", "tmp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"error parsing YAML config\"", ")", "\n", "}", "\n", "if", "err", "=", "validateKeys", "(", "tmp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "&", "fc", ",", "nil", "\n", "}" ]
// ReadConfig reads Teleport configuration from reader in YAML format
[ "ReadConfig", "reads", "Teleport", "configuration", "from", "reader", "in", "YAML", "format" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L190-L235
train
gravitational/teleport
lib/config/fileconf.go
MakeSampleFileConfig
func MakeSampleFileConfig() (fc *FileConfig) { conf := service.MakeDefaultConfig() // sample global config: var g Global g.NodeName = conf.Hostname g.AuthToken = "cluster-join-token" g.Logger.Output = "stderr" g.Logger.Severity = "INFO" g.AuthServers = []string{defaults.AuthListenAddr().Addr} g.Limits.MaxConnections = defaults.LimiterMaxConnections g.Limits.MaxUsers = defaults.LimiterMaxConcurrentUsers g.DataDir = defaults.DataDir g.PIDFile = "/var/run/teleport.pid" // sample SSH config: var s SSH s.EnabledFlag = "yes" s.ListenAddress = conf.SSH.Addr.Addr s.Commands = []CommandLabel{ { Name: "hostname", Command: []string{"/usr/bin/hostname"}, Period: time.Minute, }, { Name: "arch", Command: []string{"/usr/bin/uname", "-p"}, Period: time.Hour, }, } s.Labels = map[string]string{ "db_type": "postgres", "db_role": "master", } // sample Auth config: var a Auth a.ListenAddress = conf.Auth.SSHAddr.Addr a.EnabledFlag = "yes" a.StaticTokens = []StaticToken{"proxy,node:cluster-join-token"} // sample proxy config: var p Proxy p.EnabledFlag = "yes" p.ListenAddress = conf.Proxy.SSHAddr.Addr p.WebAddr = conf.Proxy.WebAddr.Addr p.TunAddr = conf.Proxy.ReverseTunnelListenAddr.Addr p.CertFile = "/var/lib/teleport/webproxy_cert.pem" p.KeyFile = "/var/lib/teleport/webproxy_key.pem" fc = &FileConfig{ Global: g, Proxy: p, SSH: s, Auth: a, } return fc }
go
func MakeSampleFileConfig() (fc *FileConfig) { conf := service.MakeDefaultConfig() // sample global config: var g Global g.NodeName = conf.Hostname g.AuthToken = "cluster-join-token" g.Logger.Output = "stderr" g.Logger.Severity = "INFO" g.AuthServers = []string{defaults.AuthListenAddr().Addr} g.Limits.MaxConnections = defaults.LimiterMaxConnections g.Limits.MaxUsers = defaults.LimiterMaxConcurrentUsers g.DataDir = defaults.DataDir g.PIDFile = "/var/run/teleport.pid" // sample SSH config: var s SSH s.EnabledFlag = "yes" s.ListenAddress = conf.SSH.Addr.Addr s.Commands = []CommandLabel{ { Name: "hostname", Command: []string{"/usr/bin/hostname"}, Period: time.Minute, }, { Name: "arch", Command: []string{"/usr/bin/uname", "-p"}, Period: time.Hour, }, } s.Labels = map[string]string{ "db_type": "postgres", "db_role": "master", } // sample Auth config: var a Auth a.ListenAddress = conf.Auth.SSHAddr.Addr a.EnabledFlag = "yes" a.StaticTokens = []StaticToken{"proxy,node:cluster-join-token"} // sample proxy config: var p Proxy p.EnabledFlag = "yes" p.ListenAddress = conf.Proxy.SSHAddr.Addr p.WebAddr = conf.Proxy.WebAddr.Addr p.TunAddr = conf.Proxy.ReverseTunnelListenAddr.Addr p.CertFile = "/var/lib/teleport/webproxy_cert.pem" p.KeyFile = "/var/lib/teleport/webproxy_key.pem" fc = &FileConfig{ Global: g, Proxy: p, SSH: s, Auth: a, } return fc }
[ "func", "MakeSampleFileConfig", "(", ")", "(", "fc", "*", "FileConfig", ")", "{", "conf", ":=", "service", ".", "MakeDefaultConfig", "(", ")", "\n", "var", "g", "Global", "\n", "g", ".", "NodeName", "=", "conf", ".", "Hostname", "\n", "g", ".", "AuthToken", "=", "\"cluster-join-token\"", "\n", "g", ".", "Logger", ".", "Output", "=", "\"stderr\"", "\n", "g", ".", "Logger", ".", "Severity", "=", "\"INFO\"", "\n", "g", ".", "AuthServers", "=", "[", "]", "string", "{", "defaults", ".", "AuthListenAddr", "(", ")", ".", "Addr", "}", "\n", "g", ".", "Limits", ".", "MaxConnections", "=", "defaults", ".", "LimiterMaxConnections", "\n", "g", ".", "Limits", ".", "MaxUsers", "=", "defaults", ".", "LimiterMaxConcurrentUsers", "\n", "g", ".", "DataDir", "=", "defaults", ".", "DataDir", "\n", "g", ".", "PIDFile", "=", "\"/var/run/teleport.pid\"", "\n", "var", "s", "SSH", "\n", "s", ".", "EnabledFlag", "=", "\"yes\"", "\n", "s", ".", "ListenAddress", "=", "conf", ".", "SSH", ".", "Addr", ".", "Addr", "\n", "s", ".", "Commands", "=", "[", "]", "CommandLabel", "{", "{", "Name", ":", "\"hostname\"", ",", "Command", ":", "[", "]", "string", "{", "\"/usr/bin/hostname\"", "}", ",", "Period", ":", "time", ".", "Minute", ",", "}", ",", "{", "Name", ":", "\"arch\"", ",", "Command", ":", "[", "]", "string", "{", "\"/usr/bin/uname\"", ",", "\"-p\"", "}", ",", "Period", ":", "time", ".", "Hour", ",", "}", ",", "}", "\n", "s", ".", "Labels", "=", "map", "[", "string", "]", "string", "{", "\"db_type\"", ":", "\"postgres\"", ",", "\"db_role\"", ":", "\"master\"", ",", "}", "\n", "var", "a", "Auth", "\n", "a", ".", "ListenAddress", "=", "conf", ".", "Auth", ".", "SSHAddr", ".", "Addr", "\n", "a", ".", "EnabledFlag", "=", "\"yes\"", "\n", "a", ".", "StaticTokens", "=", "[", "]", "StaticToken", "{", "\"proxy,node:cluster-join-token\"", "}", "\n", "var", "p", "Proxy", "\n", "p", ".", "EnabledFlag", "=", "\"yes\"", "\n", "p", ".", "ListenAddress", "=", "conf", ".", "Proxy", ".", "SSHAddr", ".", "Addr", "\n", "p", ".", "WebAddr", "=", "conf", ".", "Proxy", ".", "WebAddr", ".", "Addr", "\n", "p", ".", "TunAddr", "=", "conf", ".", "Proxy", ".", "ReverseTunnelListenAddr", ".", "Addr", "\n", "p", ".", "CertFile", "=", "\"/var/lib/teleport/webproxy_cert.pem\"", "\n", "p", ".", "KeyFile", "=", "\"/var/lib/teleport/webproxy_key.pem\"", "\n", "fc", "=", "&", "FileConfig", "{", "Global", ":", "g", ",", "Proxy", ":", "p", ",", "SSH", ":", "s", ",", "Auth", ":", "a", ",", "}", "\n", "return", "fc", "\n", "}" ]
// MakeSampleFileConfig returns a sample config structure populated by defaults, // useful to generate sample configuration files
[ "MakeSampleFileConfig", "returns", "a", "sample", "config", "structure", "populated", "by", "defaults", "useful", "to", "generate", "sample", "configuration", "files" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L239-L297
train
gravitational/teleport
lib/config/fileconf.go
DebugDumpToYAML
func (conf *FileConfig) DebugDumpToYAML() string { bytes, err := yaml.Marshal(&conf) if err != nil { panic(err) } return string(bytes) }
go
func (conf *FileConfig) DebugDumpToYAML() string { bytes, err := yaml.Marshal(&conf) if err != nil { panic(err) } return string(bytes) }
[ "func", "(", "conf", "*", "FileConfig", ")", "DebugDumpToYAML", "(", ")", "string", "{", "bytes", ",", "err", ":=", "yaml", ".", "Marshal", "(", "&", "conf", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "string", "(", "bytes", ")", "\n", "}" ]
// DebugDumpToYAML allows for quick YAML dumping of the config
[ "DebugDumpToYAML", "allows", "for", "quick", "YAML", "dumping", "of", "the", "config" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L300-L306
train
gravitational/teleport
lib/config/fileconf.go
Parse
func (c *CachePolicy) Parse() (*service.CachePolicy, error) { out := service.CachePolicy{ Enabled: c.Enabled(), NeverExpires: c.NeverExpires(), } if out.NeverExpires { return &out, nil } var err error if c.TTL != "" { out.TTL, err = time.ParseDuration(c.TTL) if err != nil { return nil, trace.BadParameter("cache.ttl invalid duration: %v, accepted format '10h'", c.TTL) } } return &out, nil }
go
func (c *CachePolicy) Parse() (*service.CachePolicy, error) { out := service.CachePolicy{ Enabled: c.Enabled(), NeverExpires: c.NeverExpires(), } if out.NeverExpires { return &out, nil } var err error if c.TTL != "" { out.TTL, err = time.ParseDuration(c.TTL) if err != nil { return nil, trace.BadParameter("cache.ttl invalid duration: %v, accepted format '10h'", c.TTL) } } return &out, nil }
[ "func", "(", "c", "*", "CachePolicy", ")", "Parse", "(", ")", "(", "*", "service", ".", "CachePolicy", ",", "error", ")", "{", "out", ":=", "service", ".", "CachePolicy", "{", "Enabled", ":", "c", ".", "Enabled", "(", ")", ",", "NeverExpires", ":", "c", ".", "NeverExpires", "(", ")", ",", "}", "\n", "if", "out", ".", "NeverExpires", "{", "return", "&", "out", ",", "nil", "\n", "}", "\n", "var", "err", "error", "\n", "if", "c", ".", "TTL", "!=", "\"\"", "{", "out", ".", "TTL", ",", "err", "=", "time", ".", "ParseDuration", "(", "c", ".", "TTL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"cache.ttl invalid duration: %v, accepted format '10h'\"", ",", "c", ".", "TTL", ")", "\n", "}", "\n", "}", "\n", "return", "&", "out", ",", "nil", "\n", "}" ]
// Parse parses cache policy from Teleport config
[ "Parse", "parses", "cache", "policy", "from", "Teleport", "config" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L425-L441
train
gravitational/teleport
lib/config/fileconf.go
Parse
func (p *PAM) Parse() *pam.Config { serviceName := p.ServiceName if serviceName == "" { serviceName = defaults.ServiceName } enabled, _ := utils.ParseBool(p.Enabled) return &pam.Config{ Enabled: enabled, ServiceName: serviceName, } }
go
func (p *PAM) Parse() *pam.Config { serviceName := p.ServiceName if serviceName == "" { serviceName = defaults.ServiceName } enabled, _ := utils.ParseBool(p.Enabled) return &pam.Config{ Enabled: enabled, ServiceName: serviceName, } }
[ "func", "(", "p", "*", "PAM", ")", "Parse", "(", ")", "*", "pam", ".", "Config", "{", "serviceName", ":=", "p", ".", "ServiceName", "\n", "if", "serviceName", "==", "\"\"", "{", "serviceName", "=", "defaults", ".", "ServiceName", "\n", "}", "\n", "enabled", ",", "_", ":=", "utils", ".", "ParseBool", "(", "p", ".", "Enabled", ")", "\n", "return", "&", "pam", ".", "Config", "{", "Enabled", ":", "enabled", ",", "ServiceName", ":", "serviceName", ",", "}", "\n", "}" ]
// Parse returns a parsed pam.Config.
[ "Parse", "returns", "a", "parsed", "pam", ".", "Config", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L710-L720
train
gravitational/teleport
lib/config/fileconf.go
ConvertAndValidate
func (t *ReverseTunnel) ConvertAndValidate() (services.ReverseTunnel, error) { for i := range t.Addresses { addr, err := utils.ParseHostPortAddr(t.Addresses[i], defaults.SSHProxyTunnelListenPort) if err != nil { return nil, trace.Wrap(err, "Invalid address for tunnel %v", t.DomainName) } t.Addresses[i] = addr.String() } out := services.NewReverseTunnel(t.DomainName, t.Addresses) if err := out.Check(); err != nil { return nil, trace.Wrap(err) } return out, nil }
go
func (t *ReverseTunnel) ConvertAndValidate() (services.ReverseTunnel, error) { for i := range t.Addresses { addr, err := utils.ParseHostPortAddr(t.Addresses[i], defaults.SSHProxyTunnelListenPort) if err != nil { return nil, trace.Wrap(err, "Invalid address for tunnel %v", t.DomainName) } t.Addresses[i] = addr.String() } out := services.NewReverseTunnel(t.DomainName, t.Addresses) if err := out.Check(); err != nil { return nil, trace.Wrap(err) } return out, nil }
[ "func", "(", "t", "*", "ReverseTunnel", ")", "ConvertAndValidate", "(", ")", "(", "services", ".", "ReverseTunnel", ",", "error", ")", "{", "for", "i", ":=", "range", "t", ".", "Addresses", "{", "addr", ",", "err", ":=", "utils", ".", "ParseHostPortAddr", "(", "t", ".", "Addresses", "[", "i", "]", ",", "defaults", ".", "SSHProxyTunnelListenPort", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"Invalid address for tunnel %v\"", ",", "t", ".", "DomainName", ")", "\n", "}", "\n", "t", ".", "Addresses", "[", "i", "]", "=", "addr", ".", "String", "(", ")", "\n", "}", "\n", "out", ":=", "services", ".", "NewReverseTunnel", "(", "t", ".", "DomainName", ",", "t", ".", "Addresses", ")", "\n", "if", "err", ":=", "out", ".", "Check", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// ConvertAndValidate returns validated services.ReverseTunnel or nil and error otherwize
[ "ConvertAndValidate", "returns", "validated", "services", ".", "ReverseTunnel", "or", "nil", "and", "error", "otherwize" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L778-L792
train
gravitational/teleport
lib/config/fileconf.go
Parse
func (a *Authority) Parse() (services.CertAuthority, services.Role, error) { ca := &services.CertAuthorityV1{ AllowedLogins: a.AllowedLogins, DomainName: a.DomainName, Type: a.Type, } for _, path := range a.CheckingKeyFiles { keyBytes, err := utils.ReadPath(path) if err != nil { return nil, nil, trace.Wrap(err) } ca.CheckingKeys = append(ca.CheckingKeys, keyBytes) } for _, val := range a.CheckingKeys { ca.CheckingKeys = append(ca.CheckingKeys, []byte(val)) } for _, path := range a.SigningKeyFiles { keyBytes, err := utils.ReadPath(path) if err != nil { return nil, nil, trace.Wrap(err) } ca.SigningKeys = append(ca.SigningKeys, keyBytes) } for _, val := range a.SigningKeys { ca.SigningKeys = append(ca.SigningKeys, []byte(val)) } new, role := services.ConvertV1CertAuthority(ca) return new, role, nil }
go
func (a *Authority) Parse() (services.CertAuthority, services.Role, error) { ca := &services.CertAuthorityV1{ AllowedLogins: a.AllowedLogins, DomainName: a.DomainName, Type: a.Type, } for _, path := range a.CheckingKeyFiles { keyBytes, err := utils.ReadPath(path) if err != nil { return nil, nil, trace.Wrap(err) } ca.CheckingKeys = append(ca.CheckingKeys, keyBytes) } for _, val := range a.CheckingKeys { ca.CheckingKeys = append(ca.CheckingKeys, []byte(val)) } for _, path := range a.SigningKeyFiles { keyBytes, err := utils.ReadPath(path) if err != nil { return nil, nil, trace.Wrap(err) } ca.SigningKeys = append(ca.SigningKeys, keyBytes) } for _, val := range a.SigningKeys { ca.SigningKeys = append(ca.SigningKeys, []byte(val)) } new, role := services.ConvertV1CertAuthority(ca) return new, role, nil }
[ "func", "(", "a", "*", "Authority", ")", "Parse", "(", ")", "(", "services", ".", "CertAuthority", ",", "services", ".", "Role", ",", "error", ")", "{", "ca", ":=", "&", "services", ".", "CertAuthorityV1", "{", "AllowedLogins", ":", "a", ".", "AllowedLogins", ",", "DomainName", ":", "a", ".", "DomainName", ",", "Type", ":", "a", ".", "Type", ",", "}", "\n", "for", "_", ",", "path", ":=", "range", "a", ".", "CheckingKeyFiles", "{", "keyBytes", ",", "err", ":=", "utils", ".", "ReadPath", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "ca", ".", "CheckingKeys", "=", "append", "(", "ca", ".", "CheckingKeys", ",", "keyBytes", ")", "\n", "}", "\n", "for", "_", ",", "val", ":=", "range", "a", ".", "CheckingKeys", "{", "ca", ".", "CheckingKeys", "=", "append", "(", "ca", ".", "CheckingKeys", ",", "[", "]", "byte", "(", "val", ")", ")", "\n", "}", "\n", "for", "_", ",", "path", ":=", "range", "a", ".", "SigningKeyFiles", "{", "keyBytes", ",", "err", ":=", "utils", ".", "ReadPath", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "ca", ".", "SigningKeys", "=", "append", "(", "ca", ".", "SigningKeys", ",", "keyBytes", ")", "\n", "}", "\n", "for", "_", ",", "val", ":=", "range", "a", ".", "SigningKeys", "{", "ca", ".", "SigningKeys", "=", "append", "(", "ca", ".", "SigningKeys", ",", "[", "]", "byte", "(", "val", ")", ")", "\n", "}", "\n", "new", ",", "role", ":=", "services", ".", "ConvertV1CertAuthority", "(", "ca", ")", "\n", "return", "new", ",", "role", ",", "nil", "\n", "}" ]
// Parse reads values and returns parsed CertAuthority
[ "Parse", "reads", "values", "and", "returns", "parsed", "CertAuthority" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L818-L851
train
gravitational/teleport
lib/config/fileconf.go
Parse
func (o *OIDCConnector) Parse() (services.OIDCConnector, error) { if o.Display == "" { o.Display = o.ID } var mappings []services.ClaimMapping for _, c := range o.ClaimsToRoles { var roles []string if len(c.Roles) > 0 { roles = append(roles, c.Roles...) } mappings = append(mappings, services.ClaimMapping{ Claim: c.Claim, Value: c.Value, Roles: roles, RoleTemplate: c.RoleTemplate, }) } other := &services.OIDCConnectorV1{ ID: o.ID, Display: o.Display, IssuerURL: o.IssuerURL, ClientID: o.ClientID, ClientSecret: o.ClientSecret, RedirectURL: o.RedirectURL, Scope: o.Scope, ClaimsToRoles: mappings, } v2 := other.V2() v2.SetACR(o.ACR) v2.SetProvider(o.Provider) if err := v2.Check(); err != nil { return nil, trace.Wrap(err) } return v2, nil }
go
func (o *OIDCConnector) Parse() (services.OIDCConnector, error) { if o.Display == "" { o.Display = o.ID } var mappings []services.ClaimMapping for _, c := range o.ClaimsToRoles { var roles []string if len(c.Roles) > 0 { roles = append(roles, c.Roles...) } mappings = append(mappings, services.ClaimMapping{ Claim: c.Claim, Value: c.Value, Roles: roles, RoleTemplate: c.RoleTemplate, }) } other := &services.OIDCConnectorV1{ ID: o.ID, Display: o.Display, IssuerURL: o.IssuerURL, ClientID: o.ClientID, ClientSecret: o.ClientSecret, RedirectURL: o.RedirectURL, Scope: o.Scope, ClaimsToRoles: mappings, } v2 := other.V2() v2.SetACR(o.ACR) v2.SetProvider(o.Provider) if err := v2.Check(); err != nil { return nil, trace.Wrap(err) } return v2, nil }
[ "func", "(", "o", "*", "OIDCConnector", ")", "Parse", "(", ")", "(", "services", ".", "OIDCConnector", ",", "error", ")", "{", "if", "o", ".", "Display", "==", "\"\"", "{", "o", ".", "Display", "=", "o", ".", "ID", "\n", "}", "\n", "var", "mappings", "[", "]", "services", ".", "ClaimMapping", "\n", "for", "_", ",", "c", ":=", "range", "o", ".", "ClaimsToRoles", "{", "var", "roles", "[", "]", "string", "\n", "if", "len", "(", "c", ".", "Roles", ")", ">", "0", "{", "roles", "=", "append", "(", "roles", ",", "c", ".", "Roles", "...", ")", "\n", "}", "\n", "mappings", "=", "append", "(", "mappings", ",", "services", ".", "ClaimMapping", "{", "Claim", ":", "c", ".", "Claim", ",", "Value", ":", "c", ".", "Value", ",", "Roles", ":", "roles", ",", "RoleTemplate", ":", "c", ".", "RoleTemplate", ",", "}", ")", "\n", "}", "\n", "other", ":=", "&", "services", ".", "OIDCConnectorV1", "{", "ID", ":", "o", ".", "ID", ",", "Display", ":", "o", ".", "Display", ",", "IssuerURL", ":", "o", ".", "IssuerURL", ",", "ClientID", ":", "o", ".", "ClientID", ",", "ClientSecret", ":", "o", ".", "ClientSecret", ",", "RedirectURL", ":", "o", ".", "RedirectURL", ",", "Scope", ":", "o", ".", "Scope", ",", "ClaimsToRoles", ":", "mappings", ",", "}", "\n", "v2", ":=", "other", ".", "V2", "(", ")", "\n", "v2", ".", "SetACR", "(", "o", ".", "ACR", ")", "\n", "v2", ".", "SetProvider", "(", "o", ".", "Provider", ")", "\n", "if", "err", ":=", "v2", ".", "Check", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "v2", ",", "nil", "\n", "}" ]
// Parse parses config struct into services connector and checks if it's valid
[ "Parse", "parses", "config", "struct", "into", "services", "connector", "and", "checks", "if", "it", "s", "valid" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L898-L935
train
gravitational/teleport
lib/config/fileconf.go
Parse
func (u *U2F) Parse() (*services.U2F, error) { // If no appID specified, default to hostname appID := u.AppID if appID == "" { hostname, err := os.Hostname() if err != nil { return nil, trace.Wrap(err, "failed to automatically determine U2F AppID from hostname") } appID = fmt.Sprintf("https://%s:%d", strings.ToLower(hostname), defaults.HTTPListenPort) } // If no facets specified, default to AppID facets := u.Facets if len(facets) == 0 { facets = []string{appID} } return &services.U2F{ AppID: appID, Facets: facets, }, nil }
go
func (u *U2F) Parse() (*services.U2F, error) { // If no appID specified, default to hostname appID := u.AppID if appID == "" { hostname, err := os.Hostname() if err != nil { return nil, trace.Wrap(err, "failed to automatically determine U2F AppID from hostname") } appID = fmt.Sprintf("https://%s:%d", strings.ToLower(hostname), defaults.HTTPListenPort) } // If no facets specified, default to AppID facets := u.Facets if len(facets) == 0 { facets = []string{appID} } return &services.U2F{ AppID: appID, Facets: facets, }, nil }
[ "func", "(", "u", "*", "U2F", ")", "Parse", "(", ")", "(", "*", "services", ".", "U2F", ",", "error", ")", "{", "appID", ":=", "u", ".", "AppID", "\n", "if", "appID", "==", "\"\"", "{", "hostname", ",", "err", ":=", "os", ".", "Hostname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to automatically determine U2F AppID from hostname\"", ")", "\n", "}", "\n", "appID", "=", "fmt", ".", "Sprintf", "(", "\"https://%s:%d\"", ",", "strings", ".", "ToLower", "(", "hostname", ")", ",", "defaults", ".", "HTTPListenPort", ")", "\n", "}", "\n", "facets", ":=", "u", ".", "Facets", "\n", "if", "len", "(", "facets", ")", "==", "0", "{", "facets", "=", "[", "]", "string", "{", "appID", "}", "\n", "}", "\n", "return", "&", "services", ".", "U2F", "{", "AppID", ":", "appID", ",", "Facets", ":", "facets", ",", "}", ",", "nil", "\n", "}" ]
// Parse parses values in the U2F configuration section and validates its content.
[ "Parse", "parses", "values", "in", "the", "U2F", "configuration", "section", "and", "validates", "its", "content", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/config/fileconf.go#L943-L964
train
gravitational/teleport
lib/sshutils/signer.go
NewSigner
func NewSigner(keyBytes, certBytes []byte) (ssh.Signer, error) { keySigner, err := ssh.ParsePrivateKey(keyBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse SSH private key") } pubkey, _, _, _, err := ssh.ParseAuthorizedKey(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse SSH certificate") } cert, ok := pubkey.(*ssh.Certificate) if !ok { return nil, trace.BadParameter("expected SSH certificate, got %T ", pubkey) } return ssh.NewCertSigner(cert, keySigner) }
go
func NewSigner(keyBytes, certBytes []byte) (ssh.Signer, error) { keySigner, err := ssh.ParsePrivateKey(keyBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse SSH private key") } pubkey, _, _, _, err := ssh.ParseAuthorizedKey(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse SSH certificate") } cert, ok := pubkey.(*ssh.Certificate) if !ok { return nil, trace.BadParameter("expected SSH certificate, got %T ", pubkey) } return ssh.NewCertSigner(cert, keySigner) }
[ "func", "NewSigner", "(", "keyBytes", ",", "certBytes", "[", "]", "byte", ")", "(", "ssh", ".", "Signer", ",", "error", ")", "{", "keySigner", ",", "err", ":=", "ssh", ".", "ParsePrivateKey", "(", "keyBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to parse SSH private key\"", ")", "\n", "}", "\n", "pubkey", ",", "_", ",", "_", ",", "_", ",", "err", ":=", "ssh", ".", "ParseAuthorizedKey", "(", "certBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to parse SSH certificate\"", ")", "\n", "}", "\n", "cert", ",", "ok", ":=", "pubkey", ".", "(", "*", "ssh", ".", "Certificate", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"expected SSH certificate, got %T \"", ",", "pubkey", ")", "\n", "}", "\n", "return", "ssh", ".", "NewCertSigner", "(", "cert", ",", "keySigner", ")", "\n", "}" ]
// NewSigner returns new ssh Signer from private key + certificate pair. The // signer can be used to create "auth methods" i.e. login into Teleport SSH // servers.
[ "NewSigner", "returns", "new", "ssh", "Signer", "from", "private", "key", "+", "certificate", "pair", ".", "The", "signer", "can", "be", "used", "to", "create", "auth", "methods", "i", ".", "e", ".", "login", "into", "Teleport", "SSH", "servers", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/signer.go#L29-L46
train
gravitational/teleport
lib/sshutils/signer.go
CryptoPublicKey
func CryptoPublicKey(publicKey []byte) (crypto.PublicKey, error) { // reuse the same RSA keys for SSH and TLS keys pubKey, _, _, _, err := ssh.ParseAuthorizedKey(publicKey) if err != nil { return nil, trace.Wrap(err) } cryptoPubKey, ok := pubKey.(ssh.CryptoPublicKey) if !ok { return nil, trace.BadParameter("expected ssh.CryptoPublicKey, got %T", pubKey) } return cryptoPubKey.CryptoPublicKey(), nil }
go
func CryptoPublicKey(publicKey []byte) (crypto.PublicKey, error) { // reuse the same RSA keys for SSH and TLS keys pubKey, _, _, _, err := ssh.ParseAuthorizedKey(publicKey) if err != nil { return nil, trace.Wrap(err) } cryptoPubKey, ok := pubKey.(ssh.CryptoPublicKey) if !ok { return nil, trace.BadParameter("expected ssh.CryptoPublicKey, got %T", pubKey) } return cryptoPubKey.CryptoPublicKey(), nil }
[ "func", "CryptoPublicKey", "(", "publicKey", "[", "]", "byte", ")", "(", "crypto", ".", "PublicKey", ",", "error", ")", "{", "pubKey", ",", "_", ",", "_", ",", "_", ",", "err", ":=", "ssh", ".", "ParseAuthorizedKey", "(", "publicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "cryptoPubKey", ",", "ok", ":=", "pubKey", ".", "(", "ssh", ".", "CryptoPublicKey", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"expected ssh.CryptoPublicKey, got %T\"", ",", "pubKey", ")", "\n", "}", "\n", "return", "cryptoPubKey", ".", "CryptoPublicKey", "(", ")", ",", "nil", "\n", "}" ]
// CryptoPublicKey extracts public key from RSA public key in authorized_keys format
[ "CryptoPublicKey", "extracts", "public", "key", "from", "RSA", "public", "key", "in", "authorized_keys", "format" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/signer.go#L49-L60
train
gravitational/teleport
lib/tlsca/parsegen.go
ClusterName
func ClusterName(subject pkix.Name) (string, error) { if len(subject.Organization) == 0 { return "", trace.BadParameter("missing subject organization") } return subject.Organization[0], nil }
go
func ClusterName(subject pkix.Name) (string, error) { if len(subject.Organization) == 0 { return "", trace.BadParameter("missing subject organization") } return subject.Organization[0], nil }
[ "func", "ClusterName", "(", "subject", "pkix", ".", "Name", ")", "(", "string", ",", "error", ")", "{", "if", "len", "(", "subject", ".", "Organization", ")", "==", "0", "{", "return", "\"\"", ",", "trace", ".", "BadParameter", "(", "\"missing subject organization\"", ")", "\n", "}", "\n", "return", "subject", ".", "Organization", "[", "0", "]", ",", "nil", "\n", "}" ]
// ClusterName returns cluster name from organization
[ "ClusterName", "returns", "cluster", "name", "from", "organization" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/parsegen.go#L36-L41
train
gravitational/teleport
lib/tlsca/parsegen.go
GenerateRSAPrivateKeyPEM
func GenerateRSAPrivateKeyPEM() ([]byte, error) { priv, err := rsa.GenerateKey(rand.Reader, teleport.RSAKeySize) if err != nil { return nil, trace.Wrap(err) } return pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}), nil }
go
func GenerateRSAPrivateKeyPEM() ([]byte, error) { priv, err := rsa.GenerateKey(rand.Reader, teleport.RSAKeySize) if err != nil { return nil, trace.Wrap(err) } return pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}), nil }
[ "func", "GenerateRSAPrivateKeyPEM", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "priv", ",", "err", ":=", "rsa", ".", "GenerateKey", "(", "rand", ".", "Reader", ",", "teleport", ".", "RSAKeySize", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"RSA PRIVATE KEY\"", ",", "Bytes", ":", "x509", ".", "MarshalPKCS1PrivateKey", "(", "priv", ")", "}", ")", ",", "nil", "\n", "}" ]
// GenerateRSAPrivateKeyPEM generates new RSA private key and returns PEM encoded bytes
[ "GenerateRSAPrivateKeyPEM", "generates", "new", "RSA", "private", "key", "and", "returns", "PEM", "encoded", "bytes" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/parsegen.go#L44-L50
train
gravitational/teleport
lib/tlsca/parsegen.go
ParsePublicKeyPEM
func ParsePublicKeyPEM(bytes []byte) (interface{}, error) { block, _ := pem.Decode(bytes) if block == nil { return nil, trace.BadParameter("expected PEM-encoded block") } return ParsePublicKeyDER(block.Bytes) }
go
func ParsePublicKeyPEM(bytes []byte) (interface{}, error) { block, _ := pem.Decode(bytes) if block == nil { return nil, trace.BadParameter("expected PEM-encoded block") } return ParsePublicKeyDER(block.Bytes) }
[ "func", "ParsePublicKeyPEM", "(", "bytes", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "block", ",", "_", ":=", "pem", ".", "Decode", "(", "bytes", ")", "\n", "if", "block", "==", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"expected PEM-encoded block\"", ")", "\n", "}", "\n", "return", "ParsePublicKeyDER", "(", "block", ".", "Bytes", ")", "\n", "}" ]
// ParsePublicKeyPEM parses public key PEM
[ "ParsePublicKeyPEM", "parses", "public", "key", "PEM" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/parsegen.go#L160-L166
train
gravitational/teleport
lib/tlsca/parsegen.go
ParsePublicKeyDER
func ParsePublicKeyDER(der []byte) (crypto.PublicKey, error) { generalKey, err := x509.ParsePKIXPublicKey(der) if err != nil { return nil, trace.Wrap(err) } return generalKey, nil }
go
func ParsePublicKeyDER(der []byte) (crypto.PublicKey, error) { generalKey, err := x509.ParsePKIXPublicKey(der) if err != nil { return nil, trace.Wrap(err) } return generalKey, nil }
[ "func", "ParsePublicKeyDER", "(", "der", "[", "]", "byte", ")", "(", "crypto", ".", "PublicKey", ",", "error", ")", "{", "generalKey", ",", "err", ":=", "x509", ".", "ParsePKIXPublicKey", "(", "der", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "generalKey", ",", "nil", "\n", "}" ]
// ParsePublicKeyDER parses unencrypted DER-encoded publice key
[ "ParsePublicKeyDER", "parses", "unencrypted", "DER", "-", "encoded", "publice", "key" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/parsegen.go#L169-L175
train
gravitational/teleport
lib/tlsca/parsegen.go
MarshalPublicKeyFromPrivateKeyPEM
func MarshalPublicKeyFromPrivateKeyPEM(privateKey crypto.PrivateKey) ([]byte, error) { rsaPrivateKey, ok := privateKey.(*rsa.PrivateKey) if !ok { return nil, trace.BadParameter("expected RSA key") } rsaPublicKey := rsaPrivateKey.Public() derBytes, err := x509.MarshalPKIXPublicKey(rsaPublicKey) if err != nil { return nil, trace.Wrap(err) } return pem.EncodeToMemory(&pem.Block{Type: "RSA PUBLIC KEY", Bytes: derBytes}), nil }
go
func MarshalPublicKeyFromPrivateKeyPEM(privateKey crypto.PrivateKey) ([]byte, error) { rsaPrivateKey, ok := privateKey.(*rsa.PrivateKey) if !ok { return nil, trace.BadParameter("expected RSA key") } rsaPublicKey := rsaPrivateKey.Public() derBytes, err := x509.MarshalPKIXPublicKey(rsaPublicKey) if err != nil { return nil, trace.Wrap(err) } return pem.EncodeToMemory(&pem.Block{Type: "RSA PUBLIC KEY", Bytes: derBytes}), nil }
[ "func", "MarshalPublicKeyFromPrivateKeyPEM", "(", "privateKey", "crypto", ".", "PrivateKey", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "rsaPrivateKey", ",", "ok", ":=", "privateKey", ".", "(", "*", "rsa", ".", "PrivateKey", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"expected RSA key\"", ")", "\n", "}", "\n", "rsaPublicKey", ":=", "rsaPrivateKey", ".", "Public", "(", ")", "\n", "derBytes", ",", "err", ":=", "x509", ".", "MarshalPKIXPublicKey", "(", "rsaPublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"RSA PUBLIC KEY\"", ",", "Bytes", ":", "derBytes", "}", ")", ",", "nil", "\n", "}" ]
// MarshalPublicKeyFromPrivateKeyPEM extracts public key from private key // and returns PEM marshalled key
[ "MarshalPublicKeyFromPrivateKeyPEM", "extracts", "public", "key", "from", "private", "key", "and", "returns", "PEM", "marshalled", "key" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/parsegen.go#L179-L190
train
gravitational/teleport
lib/auth/init.go
isFirstStart
func isFirstStart(authServer *AuthServer, cfg InitConfig) (bool, error) { // check if the CA exists? _, err := authServer.GetCertAuthority( services.CertAuthID{ DomainName: cfg.ClusterName.GetClusterName(), Type: services.HostCA, }, false) if err != nil { if !trace.IsNotFound(err) { return false, trace.Wrap(err) } // CA not found? --> first start! return true, nil } return false, nil }
go
func isFirstStart(authServer *AuthServer, cfg InitConfig) (bool, error) { // check if the CA exists? _, err := authServer.GetCertAuthority( services.CertAuthID{ DomainName: cfg.ClusterName.GetClusterName(), Type: services.HostCA, }, false) if err != nil { if !trace.IsNotFound(err) { return false, trace.Wrap(err) } // CA not found? --> first start! return true, nil } return false, nil }
[ "func", "isFirstStart", "(", "authServer", "*", "AuthServer", ",", "cfg", "InitConfig", ")", "(", "bool", ",", "error", ")", "{", "_", ",", "err", ":=", "authServer", ".", "GetCertAuthority", "(", "services", ".", "CertAuthID", "{", "DomainName", ":", "cfg", ".", "ClusterName", ".", "GetClusterName", "(", ")", ",", "Type", ":", "services", ".", "HostCA", ",", "}", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "trace", ".", "IsNotFound", "(", "err", ")", "{", "return", "false", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// isFirstStart returns 'true' if the auth server is starting for the 1st time // on this server.
[ "isFirstStart", "returns", "true", "if", "the", "auth", "server", "is", "starting", "for", "the", "1st", "time", "on", "this", "server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L476-L491
train
gravitational/teleport
lib/auth/init.go
GenerateIdentity
func GenerateIdentity(a *AuthServer, id IdentityID, additionalPrincipals, dnsNames []string) (*Identity, error) { keys, err := a.GenerateServerKeys(GenerateServerKeysRequest{ HostID: id.HostUUID, NodeName: id.NodeName, Roles: teleport.Roles{id.Role}, AdditionalPrincipals: additionalPrincipals, DNSNames: dnsNames, }) if err != nil { return nil, trace.Wrap(err) } return ReadIdentityFromKeyPair(keys) }
go
func GenerateIdentity(a *AuthServer, id IdentityID, additionalPrincipals, dnsNames []string) (*Identity, error) { keys, err := a.GenerateServerKeys(GenerateServerKeysRequest{ HostID: id.HostUUID, NodeName: id.NodeName, Roles: teleport.Roles{id.Role}, AdditionalPrincipals: additionalPrincipals, DNSNames: dnsNames, }) if err != nil { return nil, trace.Wrap(err) } return ReadIdentityFromKeyPair(keys) }
[ "func", "GenerateIdentity", "(", "a", "*", "AuthServer", ",", "id", "IdentityID", ",", "additionalPrincipals", ",", "dnsNames", "[", "]", "string", ")", "(", "*", "Identity", ",", "error", ")", "{", "keys", ",", "err", ":=", "a", ".", "GenerateServerKeys", "(", "GenerateServerKeysRequest", "{", "HostID", ":", "id", ".", "HostUUID", ",", "NodeName", ":", "id", ".", "NodeName", ",", "Roles", ":", "teleport", ".", "Roles", "{", "id", ".", "Role", "}", ",", "AdditionalPrincipals", ":", "additionalPrincipals", ",", "DNSNames", ":", "dnsNames", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "ReadIdentityFromKeyPair", "(", "keys", ")", "\n", "}" ]
// GenerateIdentity generates identity for the auth server
[ "GenerateIdentity", "generates", "identity", "for", "the", "auth", "server" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L494-L506
train
gravitational/teleport
lib/auth/init.go
String
func (i *Identity) String() string { var out []string if i.XCert != nil { out = append(out, fmt.Sprintf("cert(%v issued by %v:%v)", i.XCert.Subject.CommonName, i.XCert.Issuer.CommonName, i.XCert.Issuer.SerialNumber)) } for j := range i.TLSCACertsBytes { cert, err := tlsca.ParseCertificatePEM(i.TLSCACertsBytes[j]) if err != nil { out = append(out, err.Error()) } else { out = append(out, fmt.Sprintf("trust root(%v:%v)", cert.Subject.CommonName, cert.Subject.SerialNumber)) } } return fmt.Sprintf("Identity(%v, %v)", i.ID.Role, strings.Join(out, ",")) }
go
func (i *Identity) String() string { var out []string if i.XCert != nil { out = append(out, fmt.Sprintf("cert(%v issued by %v:%v)", i.XCert.Subject.CommonName, i.XCert.Issuer.CommonName, i.XCert.Issuer.SerialNumber)) } for j := range i.TLSCACertsBytes { cert, err := tlsca.ParseCertificatePEM(i.TLSCACertsBytes[j]) if err != nil { out = append(out, err.Error()) } else { out = append(out, fmt.Sprintf("trust root(%v:%v)", cert.Subject.CommonName, cert.Subject.SerialNumber)) } } return fmt.Sprintf("Identity(%v, %v)", i.ID.Role, strings.Join(out, ",")) }
[ "func", "(", "i", "*", "Identity", ")", "String", "(", ")", "string", "{", "var", "out", "[", "]", "string", "\n", "if", "i", ".", "XCert", "!=", "nil", "{", "out", "=", "append", "(", "out", ",", "fmt", ".", "Sprintf", "(", "\"cert(%v issued by %v:%v)\"", ",", "i", ".", "XCert", ".", "Subject", ".", "CommonName", ",", "i", ".", "XCert", ".", "Issuer", ".", "CommonName", ",", "i", ".", "XCert", ".", "Issuer", ".", "SerialNumber", ")", ")", "\n", "}", "\n", "for", "j", ":=", "range", "i", ".", "TLSCACertsBytes", "{", "cert", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "i", ".", "TLSCACertsBytes", "[", "j", "]", ")", "\n", "if", "err", "!=", "nil", "{", "out", "=", "append", "(", "out", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "else", "{", "out", "=", "append", "(", "out", ",", "fmt", ".", "Sprintf", "(", "\"trust root(%v:%v)\"", ",", "cert", ".", "Subject", ".", "CommonName", ",", "cert", ".", "Subject", ".", "SerialNumber", ")", ")", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"Identity(%v, %v)\"", ",", "i", ".", "ID", ".", "Role", ",", "strings", ".", "Join", "(", "out", ",", "\",\"", ")", ")", "\n", "}" ]
// String returns user-friendly representation of the identity.
[ "String", "returns", "user", "-", "friendly", "representation", "of", "the", "identity", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L534-L548
train
gravitational/teleport
lib/auth/init.go
CertInfo
func CertInfo(cert *x509.Certificate) string { return fmt.Sprintf("cert(%v issued by %v:%v)", cert.Subject.CommonName, cert.Issuer.CommonName, cert.Issuer.SerialNumber) }
go
func CertInfo(cert *x509.Certificate) string { return fmt.Sprintf("cert(%v issued by %v:%v)", cert.Subject.CommonName, cert.Issuer.CommonName, cert.Issuer.SerialNumber) }
[ "func", "CertInfo", "(", "cert", "*", "x509", ".", "Certificate", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"cert(%v issued by %v:%v)\"", ",", "cert", ".", "Subject", ".", "CommonName", ",", "cert", ".", "Issuer", ".", "CommonName", ",", "cert", ".", "Issuer", ".", "SerialNumber", ")", "\n", "}" ]
// CertInfo returns diagnostic information about certificate
[ "CertInfo", "returns", "diagnostic", "information", "about", "certificate" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L551-L553
train
gravitational/teleport
lib/auth/init.go
TLSCertInfo
func TLSCertInfo(cert *tls.Certificate) string { x509cert, err := x509.ParseCertificate(cert.Certificate[0]) if err != nil { return err.Error() } return CertInfo(x509cert) }
go
func TLSCertInfo(cert *tls.Certificate) string { x509cert, err := x509.ParseCertificate(cert.Certificate[0]) if err != nil { return err.Error() } return CertInfo(x509cert) }
[ "func", "TLSCertInfo", "(", "cert", "*", "tls", ".", "Certificate", ")", "string", "{", "x509cert", ",", "err", ":=", "x509", ".", "ParseCertificate", "(", "cert", ".", "Certificate", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", ".", "Error", "(", ")", "\n", "}", "\n", "return", "CertInfo", "(", "x509cert", ")", "\n", "}" ]
// TLSCertInfo returns diagnostic information about certificate
[ "TLSCertInfo", "returns", "diagnostic", "information", "about", "certificate" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L556-L562
train
gravitational/teleport
lib/auth/init.go
CertAuthorityInfo
func CertAuthorityInfo(ca services.CertAuthority) string { var out []string for _, keyPair := range ca.GetTLSKeyPairs() { cert, err := tlsca.ParseCertificatePEM(keyPair.Cert) if err != nil { out = append(out, err.Error()) } else { out = append(out, fmt.Sprintf("trust root(%v:%v)", cert.Subject.CommonName, cert.Subject.SerialNumber)) } } return fmt.Sprintf("cert authority(state: %v, phase: %v, roots: %v)", ca.GetRotation().State, ca.GetRotation().Phase, strings.Join(out, ", ")) }
go
func CertAuthorityInfo(ca services.CertAuthority) string { var out []string for _, keyPair := range ca.GetTLSKeyPairs() { cert, err := tlsca.ParseCertificatePEM(keyPair.Cert) if err != nil { out = append(out, err.Error()) } else { out = append(out, fmt.Sprintf("trust root(%v:%v)", cert.Subject.CommonName, cert.Subject.SerialNumber)) } } return fmt.Sprintf("cert authority(state: %v, phase: %v, roots: %v)", ca.GetRotation().State, ca.GetRotation().Phase, strings.Join(out, ", ")) }
[ "func", "CertAuthorityInfo", "(", "ca", "services", ".", "CertAuthority", ")", "string", "{", "var", "out", "[", "]", "string", "\n", "for", "_", ",", "keyPair", ":=", "range", "ca", ".", "GetTLSKeyPairs", "(", ")", "{", "cert", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "keyPair", ".", "Cert", ")", "\n", "if", "err", "!=", "nil", "{", "out", "=", "append", "(", "out", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "else", "{", "out", "=", "append", "(", "out", ",", "fmt", ".", "Sprintf", "(", "\"trust root(%v:%v)\"", ",", "cert", ".", "Subject", ".", "CommonName", ",", "cert", ".", "Subject", ".", "SerialNumber", ")", ")", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"cert authority(state: %v, phase: %v, roots: %v)\"", ",", "ca", ".", "GetRotation", "(", ")", ".", "State", ",", "ca", ".", "GetRotation", "(", ")", ".", "Phase", ",", "strings", ".", "Join", "(", "out", ",", "\", \"", ")", ")", "\n", "}" ]
// CertAuthorityInfo returns debugging information about certificate authority
[ "CertAuthorityInfo", "returns", "debugging", "information", "about", "certificate", "authority" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L565-L576
train
gravitational/teleport
lib/auth/init.go
HasTLSConfig
func (i *Identity) HasTLSConfig() bool { return len(i.TLSCACertsBytes) != 0 && len(i.TLSCertBytes) != 0 }
go
func (i *Identity) HasTLSConfig() bool { return len(i.TLSCACertsBytes) != 0 && len(i.TLSCertBytes) != 0 }
[ "func", "(", "i", "*", "Identity", ")", "HasTLSConfig", "(", ")", "bool", "{", "return", "len", "(", "i", ".", "TLSCACertsBytes", ")", "!=", "0", "&&", "len", "(", "i", ".", "TLSCertBytes", ")", "!=", "0", "\n", "}" ]
// HasTSLConfig returns true if this identity has TLS certificate and private key
[ "HasTSLConfig", "returns", "true", "if", "this", "identity", "has", "TLS", "certificate", "and", "private", "key" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L579-L581
train
gravitational/teleport
lib/auth/init.go
HasPrincipals
func (i *Identity) HasPrincipals(additionalPrincipals []string) bool { set := utils.StringsSet(i.Cert.ValidPrincipals) for _, principal := range additionalPrincipals { if _, ok := set[principal]; !ok { return false } } return true }
go
func (i *Identity) HasPrincipals(additionalPrincipals []string) bool { set := utils.StringsSet(i.Cert.ValidPrincipals) for _, principal := range additionalPrincipals { if _, ok := set[principal]; !ok { return false } } return true }
[ "func", "(", "i", "*", "Identity", ")", "HasPrincipals", "(", "additionalPrincipals", "[", "]", "string", ")", "bool", "{", "set", ":=", "utils", ".", "StringsSet", "(", "i", ".", "Cert", ".", "ValidPrincipals", ")", "\n", "for", "_", ",", "principal", ":=", "range", "additionalPrincipals", "{", "if", "_", ",", "ok", ":=", "set", "[", "principal", "]", ";", "!", "ok", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasPrincipals returns whether identity has principals
[ "HasPrincipals", "returns", "whether", "identity", "has", "principals" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L584-L592
train
gravitational/teleport
lib/auth/init.go
HasDNSNames
func (i *Identity) HasDNSNames(dnsNames []string) bool { if i.XCert == nil { return false } set := utils.StringsSet(i.XCert.DNSNames) for _, dnsName := range dnsNames { if _, ok := set[dnsName]; !ok { return false } } return true }
go
func (i *Identity) HasDNSNames(dnsNames []string) bool { if i.XCert == nil { return false } set := utils.StringsSet(i.XCert.DNSNames) for _, dnsName := range dnsNames { if _, ok := set[dnsName]; !ok { return false } } return true }
[ "func", "(", "i", "*", "Identity", ")", "HasDNSNames", "(", "dnsNames", "[", "]", "string", ")", "bool", "{", "if", "i", ".", "XCert", "==", "nil", "{", "return", "false", "\n", "}", "\n", "set", ":=", "utils", ".", "StringsSet", "(", "i", ".", "XCert", ".", "DNSNames", ")", "\n", "for", "_", ",", "dnsName", ":=", "range", "dnsNames", "{", "if", "_", ",", "ok", ":=", "set", "[", "dnsName", "]", ";", "!", "ok", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasDNSNames returns true if TLS certificate has required DNS names
[ "HasDNSNames", "returns", "true", "if", "TLS", "certificate", "has", "required", "DNS", "names" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L595-L606
train
gravitational/teleport
lib/auth/init.go
TLSConfig
func (i *Identity) TLSConfig(cipherSuites []uint16) (*tls.Config, error) { tlsConfig := utils.TLSConfig(cipherSuites) if !i.HasTLSConfig() { return nil, trace.NotFound("no TLS credentials setup for this identity") } tlsCert, err := tls.X509KeyPair(i.TLSCertBytes, i.KeyBytes) if err != nil { return nil, trace.BadParameter("failed to parse private key: %v", err) } certPool := x509.NewCertPool() for j := range i.TLSCACertsBytes { parsedCert, err := tlsca.ParseCertificatePEM(i.TLSCACertsBytes[j]) if err != nil { return nil, trace.Wrap(err, "failed to parse CA certificate") } certPool.AddCert(parsedCert) } tlsConfig.Certificates = []tls.Certificate{tlsCert} tlsConfig.RootCAs = certPool tlsConfig.ClientCAs = certPool tlsConfig.ServerName = EncodeClusterName(i.ClusterName) return tlsConfig, nil }
go
func (i *Identity) TLSConfig(cipherSuites []uint16) (*tls.Config, error) { tlsConfig := utils.TLSConfig(cipherSuites) if !i.HasTLSConfig() { return nil, trace.NotFound("no TLS credentials setup for this identity") } tlsCert, err := tls.X509KeyPair(i.TLSCertBytes, i.KeyBytes) if err != nil { return nil, trace.BadParameter("failed to parse private key: %v", err) } certPool := x509.NewCertPool() for j := range i.TLSCACertsBytes { parsedCert, err := tlsca.ParseCertificatePEM(i.TLSCACertsBytes[j]) if err != nil { return nil, trace.Wrap(err, "failed to parse CA certificate") } certPool.AddCert(parsedCert) } tlsConfig.Certificates = []tls.Certificate{tlsCert} tlsConfig.RootCAs = certPool tlsConfig.ClientCAs = certPool tlsConfig.ServerName = EncodeClusterName(i.ClusterName) return tlsConfig, nil }
[ "func", "(", "i", "*", "Identity", ")", "TLSConfig", "(", "cipherSuites", "[", "]", "uint16", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "tlsConfig", ":=", "utils", ".", "TLSConfig", "(", "cipherSuites", ")", "\n", "if", "!", "i", ".", "HasTLSConfig", "(", ")", "{", "return", "nil", ",", "trace", ".", "NotFound", "(", "\"no TLS credentials setup for this identity\"", ")", "\n", "}", "\n", "tlsCert", ",", "err", ":=", "tls", ".", "X509KeyPair", "(", "i", ".", "TLSCertBytes", ",", "i", ".", "KeyBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"failed to parse private key: %v\"", ",", "err", ")", "\n", "}", "\n", "certPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "for", "j", ":=", "range", "i", ".", "TLSCACertsBytes", "{", "parsedCert", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "i", ".", "TLSCACertsBytes", "[", "j", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to parse CA certificate\"", ")", "\n", "}", "\n", "certPool", ".", "AddCert", "(", "parsedCert", ")", "\n", "}", "\n", "tlsConfig", ".", "Certificates", "=", "[", "]", "tls", ".", "Certificate", "{", "tlsCert", "}", "\n", "tlsConfig", ".", "RootCAs", "=", "certPool", "\n", "tlsConfig", ".", "ClientCAs", "=", "certPool", "\n", "tlsConfig", ".", "ServerName", "=", "EncodeClusterName", "(", "i", ".", "ClusterName", ")", "\n", "return", "tlsConfig", ",", "nil", "\n", "}" ]
// TLSConfig returns TLS config for mutual TLS authentication // can return NotFound error if there are no TLS credentials setup for identity
[ "TLSConfig", "returns", "TLS", "config", "for", "mutual", "TLS", "authentication", "can", "return", "NotFound", "error", "if", "there", "are", "no", "TLS", "credentials", "setup", "for", "identity" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L610-L632
train
gravitational/teleport
lib/auth/init.go
SSHClientConfig
func (i *Identity) SSHClientConfig() *ssh.ClientConfig { return &ssh.ClientConfig{ User: i.ID.HostUUID, Auth: []ssh.AuthMethod{ ssh.PublicKeys(i.KeySigner), }, HostKeyCallback: i.hostKeyCallback, Timeout: defaults.DefaultDialTimeout, } }
go
func (i *Identity) SSHClientConfig() *ssh.ClientConfig { return &ssh.ClientConfig{ User: i.ID.HostUUID, Auth: []ssh.AuthMethod{ ssh.PublicKeys(i.KeySigner), }, HostKeyCallback: i.hostKeyCallback, Timeout: defaults.DefaultDialTimeout, } }
[ "func", "(", "i", "*", "Identity", ")", "SSHClientConfig", "(", ")", "*", "ssh", ".", "ClientConfig", "{", "return", "&", "ssh", ".", "ClientConfig", "{", "User", ":", "i", ".", "ID", ".", "HostUUID", ",", "Auth", ":", "[", "]", "ssh", ".", "AuthMethod", "{", "ssh", ".", "PublicKeys", "(", "i", ".", "KeySigner", ")", ",", "}", ",", "HostKeyCallback", ":", "i", ".", "hostKeyCallback", ",", "Timeout", ":", "defaults", ".", "DefaultDialTimeout", ",", "}", "\n", "}" ]
// SSHClientConfig returns a ssh.ClientConfig used by nodes to connect to // the reverse tunnel server.
[ "SSHClientConfig", "returns", "a", "ssh", ".", "ClientConfig", "used", "by", "nodes", "to", "connect", "to", "the", "reverse", "tunnel", "server", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L636-L645
train
gravitational/teleport
lib/auth/init.go
hostKeyCallback
func (i *Identity) hostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error { cert, ok := key.(*ssh.Certificate) if !ok { return trace.BadParameter("only host certificates supported") } // Loop over all CAs and see if any of them signed the certificate. for _, k := range i.SSHCACertBytes { pubkey, _, _, _, err := ssh.ParseAuthorizedKey(k) if err != nil { return trace.Wrap(err) } if sshutils.KeysEqual(cert.SignatureKey, pubkey) { return nil } } return trace.BadParameter("no matching keys found") }
go
func (i *Identity) hostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error { cert, ok := key.(*ssh.Certificate) if !ok { return trace.BadParameter("only host certificates supported") } // Loop over all CAs and see if any of them signed the certificate. for _, k := range i.SSHCACertBytes { pubkey, _, _, _, err := ssh.ParseAuthorizedKey(k) if err != nil { return trace.Wrap(err) } if sshutils.KeysEqual(cert.SignatureKey, pubkey) { return nil } } return trace.BadParameter("no matching keys found") }
[ "func", "(", "i", "*", "Identity", ")", "hostKeyCallback", "(", "hostname", "string", ",", "remote", "net", ".", "Addr", ",", "key", "ssh", ".", "PublicKey", ")", "error", "{", "cert", ",", "ok", ":=", "key", ".", "(", "*", "ssh", ".", "Certificate", ")", "\n", "if", "!", "ok", "{", "return", "trace", ".", "BadParameter", "(", "\"only host certificates supported\"", ")", "\n", "}", "\n", "for", "_", ",", "k", ":=", "range", "i", ".", "SSHCACertBytes", "{", "pubkey", ",", "_", ",", "_", ",", "_", ",", "err", ":=", "ssh", ".", "ParseAuthorizedKey", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "if", "sshutils", ".", "KeysEqual", "(", "cert", ".", "SignatureKey", ",", "pubkey", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "trace", ".", "BadParameter", "(", "\"no matching keys found\"", ")", "\n", "}" ]
// hostKeyCallback checks if the host certificate was signed by any of the // known CAs.
[ "hostKeyCallback", "checks", "if", "the", "host", "certificate", "was", "signed", "by", "any", "of", "the", "known", "CAs", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L649-L667
train
gravitational/teleport
lib/auth/init.go
HostID
func (id *IdentityID) HostID() (string, error) { parts := strings.Split(id.HostUUID, ".") if len(parts) < 2 { return "", trace.BadParameter("expected 2 parts in %q", id.HostUUID) } return parts[0], nil }
go
func (id *IdentityID) HostID() (string, error) { parts := strings.Split(id.HostUUID, ".") if len(parts) < 2 { return "", trace.BadParameter("expected 2 parts in %q", id.HostUUID) } return parts[0], nil }
[ "func", "(", "id", "*", "IdentityID", ")", "HostID", "(", ")", "(", "string", ",", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "id", ".", "HostUUID", ",", "\".\"", ")", "\n", "if", "len", "(", "parts", ")", "<", "2", "{", "return", "\"\"", ",", "trace", ".", "BadParameter", "(", "\"expected 2 parts in %q\"", ",", "id", ".", "HostUUID", ")", "\n", "}", "\n", "return", "parts", "[", "0", "]", ",", "nil", "\n", "}" ]
// HostID is host ID part of the host UUID that consists cluster name
[ "HostID", "is", "host", "ID", "part", "of", "the", "host", "UUID", "that", "consists", "cluster", "name" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L677-L683
train
gravitational/teleport
lib/auth/init.go
Equals
func (id *IdentityID) Equals(other IdentityID) bool { return id.Role == other.Role && id.HostUUID == other.HostUUID }
go
func (id *IdentityID) Equals(other IdentityID) bool { return id.Role == other.Role && id.HostUUID == other.HostUUID }
[ "func", "(", "id", "*", "IdentityID", ")", "Equals", "(", "other", "IdentityID", ")", "bool", "{", "return", "id", ".", "Role", "==", "other", ".", "Role", "&&", "id", ".", "HostUUID", "==", "other", ".", "HostUUID", "\n", "}" ]
// Equals returns true if two identities are equal
[ "Equals", "returns", "true", "if", "two", "identities", "are", "equal" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L686-L688
train
gravitational/teleport
lib/auth/init.go
ReadIdentityFromKeyPair
func ReadIdentityFromKeyPair(keys *PackedKeys) (*Identity, error) { identity, err := ReadSSHIdentityFromKeyPair(keys.Key, keys.Cert) if err != nil { return nil, trace.Wrap(err) } if len(keys.SSHCACerts) != 0 { identity.SSHCACertBytes = keys.SSHCACerts } if len(keys.TLSCACerts) != 0 { // Parse the key pair to verify that identity parses properly for future use. i, err := ReadTLSIdentityFromKeyPair(keys.Key, keys.TLSCert, keys.TLSCACerts) if err != nil { return nil, trace.Wrap(err) } identity.XCert = i.XCert identity.TLSCertBytes = keys.TLSCert identity.TLSCACertsBytes = keys.TLSCACerts } return identity, nil }
go
func ReadIdentityFromKeyPair(keys *PackedKeys) (*Identity, error) { identity, err := ReadSSHIdentityFromKeyPair(keys.Key, keys.Cert) if err != nil { return nil, trace.Wrap(err) } if len(keys.SSHCACerts) != 0 { identity.SSHCACertBytes = keys.SSHCACerts } if len(keys.TLSCACerts) != 0 { // Parse the key pair to verify that identity parses properly for future use. i, err := ReadTLSIdentityFromKeyPair(keys.Key, keys.TLSCert, keys.TLSCACerts) if err != nil { return nil, trace.Wrap(err) } identity.XCert = i.XCert identity.TLSCertBytes = keys.TLSCert identity.TLSCACertsBytes = keys.TLSCACerts } return identity, nil }
[ "func", "ReadIdentityFromKeyPair", "(", "keys", "*", "PackedKeys", ")", "(", "*", "Identity", ",", "error", ")", "{", "identity", ",", "err", ":=", "ReadSSHIdentityFromKeyPair", "(", "keys", ".", "Key", ",", "keys", ".", "Cert", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "keys", ".", "SSHCACerts", ")", "!=", "0", "{", "identity", ".", "SSHCACertBytes", "=", "keys", ".", "SSHCACerts", "\n", "}", "\n", "if", "len", "(", "keys", ".", "TLSCACerts", ")", "!=", "0", "{", "i", ",", "err", ":=", "ReadTLSIdentityFromKeyPair", "(", "keys", ".", "Key", ",", "keys", ".", "TLSCert", ",", "keys", ".", "TLSCACerts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "identity", ".", "XCert", "=", "i", ".", "XCert", "\n", "identity", ".", "TLSCertBytes", "=", "keys", ".", "TLSCert", "\n", "identity", ".", "TLSCACertsBytes", "=", "keys", ".", "TLSCACerts", "\n", "}", "\n", "return", "identity", ",", "nil", "\n", "}" ]
// ReadIdentityFromKeyPair reads SSH and TLS identity from key pair.
[ "ReadIdentityFromKeyPair", "reads", "SSH", "and", "TLS", "identity", "from", "key", "pair", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L696-L718
train
gravitational/teleport
lib/auth/init.go
ReadTLSIdentityFromKeyPair
func ReadTLSIdentityFromKeyPair(keyBytes, certBytes []byte, caCertsBytes [][]byte) (*Identity, error) { if len(keyBytes) == 0 { return nil, trace.BadParameter("missing private key") } if len(certBytes) == 0 { return nil, trace.BadParameter("missing certificate") } cert, err := tlsca.ParseCertificatePEM(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse TLS certificate") } id, err := tlsca.FromSubject(cert.Subject) if err != nil { return nil, trace.Wrap(err) } if len(cert.Issuer.Organization) == 0 { return nil, trace.BadParameter("missing CA organization") } clusterName := cert.Issuer.Organization[0] if clusterName == "" { return nil, trace.BadParameter("misssing cluster name") } identity := &Identity{ ID: IdentityID{HostUUID: id.Username, Role: teleport.Role(id.Groups[0])}, ClusterName: clusterName, KeyBytes: keyBytes, TLSCertBytes: certBytes, TLSCACertsBytes: caCertsBytes, XCert: cert, } // The passed in ciphersuites don't appear to matter here since the returned // *tls.Config is never actually used? _, err = identity.TLSConfig(utils.DefaultCipherSuites()) if err != nil { return nil, trace.Wrap(err) } return identity, nil }
go
func ReadTLSIdentityFromKeyPair(keyBytes, certBytes []byte, caCertsBytes [][]byte) (*Identity, error) { if len(keyBytes) == 0 { return nil, trace.BadParameter("missing private key") } if len(certBytes) == 0 { return nil, trace.BadParameter("missing certificate") } cert, err := tlsca.ParseCertificatePEM(certBytes) if err != nil { return nil, trace.Wrap(err, "failed to parse TLS certificate") } id, err := tlsca.FromSubject(cert.Subject) if err != nil { return nil, trace.Wrap(err) } if len(cert.Issuer.Organization) == 0 { return nil, trace.BadParameter("missing CA organization") } clusterName := cert.Issuer.Organization[0] if clusterName == "" { return nil, trace.BadParameter("misssing cluster name") } identity := &Identity{ ID: IdentityID{HostUUID: id.Username, Role: teleport.Role(id.Groups[0])}, ClusterName: clusterName, KeyBytes: keyBytes, TLSCertBytes: certBytes, TLSCACertsBytes: caCertsBytes, XCert: cert, } // The passed in ciphersuites don't appear to matter here since the returned // *tls.Config is never actually used? _, err = identity.TLSConfig(utils.DefaultCipherSuites()) if err != nil { return nil, trace.Wrap(err) } return identity, nil }
[ "func", "ReadTLSIdentityFromKeyPair", "(", "keyBytes", ",", "certBytes", "[", "]", "byte", ",", "caCertsBytes", "[", "]", "[", "]", "byte", ")", "(", "*", "Identity", ",", "error", ")", "{", "if", "len", "(", "keyBytes", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"missing private key\"", ")", "\n", "}", "\n", "if", "len", "(", "certBytes", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"missing certificate\"", ")", "\n", "}", "\n", "cert", ",", "err", ":=", "tlsca", ".", "ParseCertificatePEM", "(", "certBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ",", "\"failed to parse TLS certificate\"", ")", "\n", "}", "\n", "id", ",", "err", ":=", "tlsca", ".", "FromSubject", "(", "cert", ".", "Subject", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "cert", ".", "Issuer", ".", "Organization", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"missing CA organization\"", ")", "\n", "}", "\n", "clusterName", ":=", "cert", ".", "Issuer", ".", "Organization", "[", "0", "]", "\n", "if", "clusterName", "==", "\"\"", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"misssing cluster name\"", ")", "\n", "}", "\n", "identity", ":=", "&", "Identity", "{", "ID", ":", "IdentityID", "{", "HostUUID", ":", "id", ".", "Username", ",", "Role", ":", "teleport", ".", "Role", "(", "id", ".", "Groups", "[", "0", "]", ")", "}", ",", "ClusterName", ":", "clusterName", ",", "KeyBytes", ":", "keyBytes", ",", "TLSCertBytes", ":", "certBytes", ",", "TLSCACertsBytes", ":", "caCertsBytes", ",", "XCert", ":", "cert", ",", "}", "\n", "_", ",", "err", "=", "identity", ".", "TLSConfig", "(", "utils", ".", "DefaultCipherSuites", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "identity", ",", "nil", "\n", "}" ]
// ReadTLSIdentityFromKeyPair reads TLS identity from key pair
[ "ReadTLSIdentityFromKeyPair", "reads", "TLS", "identity", "from", "key", "pair" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L721-L763
train
gravitational/teleport
lib/auth/init.go
ReadSSHIdentityFromKeyPair
func ReadSSHIdentityFromKeyPair(keyBytes, certBytes []byte) (*Identity, error) { if len(keyBytes) == 0 { return nil, trace.BadParameter("PrivateKey: missing private key") } if len(certBytes) == 0 { return nil, trace.BadParameter("Cert: missing parameter") } pubKey, _, _, _, err := ssh.ParseAuthorizedKey(certBytes) if err != nil { return nil, trace.BadParameter("failed to parse server certificate: %v", err) } cert, ok := pubKey.(*ssh.Certificate) if !ok { return nil, trace.BadParameter("expected ssh.Certificate, got %v", pubKey) } signer, err := ssh.ParsePrivateKey(keyBytes) if err != nil { return nil, trace.BadParameter("failed to parse private key: %v", err) } // this signer authenticates using certificate signed by the cert authority // not only by the public key certSigner, err := ssh.NewCertSigner(cert, signer) if err != nil { return nil, trace.BadParameter("unsupported private key: %v", err) } // check principals on certificate if len(cert.ValidPrincipals) < 1 { return nil, trace.BadParameter("valid principals: at least one valid principal is required") } for _, validPrincipal := range cert.ValidPrincipals { if validPrincipal == "" { return nil, trace.BadParameter("valid principal can not be empty: %q", cert.ValidPrincipals) } } // check permissions on certificate if len(cert.Permissions.Extensions) == 0 { return nil, trace.BadParameter("extensions: misssing needed extensions for host roles") } roleString := cert.Permissions.Extensions[utils.CertExtensionRole] if roleString == "" { return nil, trace.BadParameter("misssing cert extension %v", utils.CertExtensionRole) } roles, err := teleport.ParseRoles(roleString) if err != nil { return nil, trace.Wrap(err) } foundRoles := len(roles) if foundRoles != 1 { return nil, trace.Errorf("expected one role per certificate. found %d: '%s'", foundRoles, roles.String()) } role := roles[0] clusterName := cert.Permissions.Extensions[utils.CertExtensionAuthority] if clusterName == "" { return nil, trace.BadParameter("missing cert extension %v", utils.CertExtensionAuthority) } return &Identity{ ID: IdentityID{HostUUID: cert.ValidPrincipals[0], Role: role}, ClusterName: clusterName, KeyBytes: keyBytes, CertBytes: certBytes, KeySigner: certSigner, Cert: cert, }, nil }
go
func ReadSSHIdentityFromKeyPair(keyBytes, certBytes []byte) (*Identity, error) { if len(keyBytes) == 0 { return nil, trace.BadParameter("PrivateKey: missing private key") } if len(certBytes) == 0 { return nil, trace.BadParameter("Cert: missing parameter") } pubKey, _, _, _, err := ssh.ParseAuthorizedKey(certBytes) if err != nil { return nil, trace.BadParameter("failed to parse server certificate: %v", err) } cert, ok := pubKey.(*ssh.Certificate) if !ok { return nil, trace.BadParameter("expected ssh.Certificate, got %v", pubKey) } signer, err := ssh.ParsePrivateKey(keyBytes) if err != nil { return nil, trace.BadParameter("failed to parse private key: %v", err) } // this signer authenticates using certificate signed by the cert authority // not only by the public key certSigner, err := ssh.NewCertSigner(cert, signer) if err != nil { return nil, trace.BadParameter("unsupported private key: %v", err) } // check principals on certificate if len(cert.ValidPrincipals) < 1 { return nil, trace.BadParameter("valid principals: at least one valid principal is required") } for _, validPrincipal := range cert.ValidPrincipals { if validPrincipal == "" { return nil, trace.BadParameter("valid principal can not be empty: %q", cert.ValidPrincipals) } } // check permissions on certificate if len(cert.Permissions.Extensions) == 0 { return nil, trace.BadParameter("extensions: misssing needed extensions for host roles") } roleString := cert.Permissions.Extensions[utils.CertExtensionRole] if roleString == "" { return nil, trace.BadParameter("misssing cert extension %v", utils.CertExtensionRole) } roles, err := teleport.ParseRoles(roleString) if err != nil { return nil, trace.Wrap(err) } foundRoles := len(roles) if foundRoles != 1 { return nil, trace.Errorf("expected one role per certificate. found %d: '%s'", foundRoles, roles.String()) } role := roles[0] clusterName := cert.Permissions.Extensions[utils.CertExtensionAuthority] if clusterName == "" { return nil, trace.BadParameter("missing cert extension %v", utils.CertExtensionAuthority) } return &Identity{ ID: IdentityID{HostUUID: cert.ValidPrincipals[0], Role: role}, ClusterName: clusterName, KeyBytes: keyBytes, CertBytes: certBytes, KeySigner: certSigner, Cert: cert, }, nil }
[ "func", "ReadSSHIdentityFromKeyPair", "(", "keyBytes", ",", "certBytes", "[", "]", "byte", ")", "(", "*", "Identity", ",", "error", ")", "{", "if", "len", "(", "keyBytes", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"PrivateKey: missing private key\"", ")", "\n", "}", "\n", "if", "len", "(", "certBytes", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"Cert: missing parameter\"", ")", "\n", "}", "\n", "pubKey", ",", "_", ",", "_", ",", "_", ",", "err", ":=", "ssh", ".", "ParseAuthorizedKey", "(", "certBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"failed to parse server certificate: %v\"", ",", "err", ")", "\n", "}", "\n", "cert", ",", "ok", ":=", "pubKey", ".", "(", "*", "ssh", ".", "Certificate", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"expected ssh.Certificate, got %v\"", ",", "pubKey", ")", "\n", "}", "\n", "signer", ",", "err", ":=", "ssh", ".", "ParsePrivateKey", "(", "keyBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"failed to parse private key: %v\"", ",", "err", ")", "\n", "}", "\n", "certSigner", ",", "err", ":=", "ssh", ".", "NewCertSigner", "(", "cert", ",", "signer", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"unsupported private key: %v\"", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "cert", ".", "ValidPrincipals", ")", "<", "1", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"valid principals: at least one valid principal is required\"", ")", "\n", "}", "\n", "for", "_", ",", "validPrincipal", ":=", "range", "cert", ".", "ValidPrincipals", "{", "if", "validPrincipal", "==", "\"\"", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"valid principal can not be empty: %q\"", ",", "cert", ".", "ValidPrincipals", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "cert", ".", "Permissions", ".", "Extensions", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"extensions: misssing needed extensions for host roles\"", ")", "\n", "}", "\n", "roleString", ":=", "cert", ".", "Permissions", ".", "Extensions", "[", "utils", ".", "CertExtensionRole", "]", "\n", "if", "roleString", "==", "\"\"", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"misssing cert extension %v\"", ",", "utils", ".", "CertExtensionRole", ")", "\n", "}", "\n", "roles", ",", "err", ":=", "teleport", ".", "ParseRoles", "(", "roleString", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "foundRoles", ":=", "len", "(", "roles", ")", "\n", "if", "foundRoles", "!=", "1", "{", "return", "nil", ",", "trace", ".", "Errorf", "(", "\"expected one role per certificate. found %d: '%s'\"", ",", "foundRoles", ",", "roles", ".", "String", "(", ")", ")", "\n", "}", "\n", "role", ":=", "roles", "[", "0", "]", "\n", "clusterName", ":=", "cert", ".", "Permissions", ".", "Extensions", "[", "utils", ".", "CertExtensionAuthority", "]", "\n", "if", "clusterName", "==", "\"\"", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"missing cert extension %v\"", ",", "utils", ".", "CertExtensionAuthority", ")", "\n", "}", "\n", "return", "&", "Identity", "{", "ID", ":", "IdentityID", "{", "HostUUID", ":", "cert", ".", "ValidPrincipals", "[", "0", "]", ",", "Role", ":", "role", "}", ",", "ClusterName", ":", "clusterName", ",", "KeyBytes", ":", "keyBytes", ",", "CertBytes", ":", "certBytes", ",", "KeySigner", ":", "certSigner", ",", "Cert", ":", "cert", ",", "}", ",", "nil", "\n", "}" ]
// ReadSSHIdentityFromKeyPair reads identity from initialized keypair
[ "ReadSSHIdentityFromKeyPair", "reads", "identity", "from", "initialized", "keypair" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/init.go#L766-L837
train
gravitational/teleport
lib/services/role.go
NewImplicitRole
func NewImplicitRole() Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: teleport.DefaultImplicitRole, Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ MaxSessionTTL: MaxDuration(), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, Rules: CopyRulesSlice(DefaultImplicitRules), }, }, } }
go
func NewImplicitRole() Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: teleport.DefaultImplicitRole, Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ MaxSessionTTL: MaxDuration(), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, Rules: CopyRulesSlice(DefaultImplicitRules), }, }, } }
[ "func", "NewImplicitRole", "(", ")", "Role", "{", "return", "&", "RoleV3", "{", "Kind", ":", "KindRole", ",", "Version", ":", "V3", ",", "Metadata", ":", "Metadata", "{", "Name", ":", "teleport", ".", "DefaultImplicitRole", ",", "Namespace", ":", "defaults", ".", "Namespace", ",", "}", ",", "Spec", ":", "RoleSpecV3", "{", "Options", ":", "RoleOptions", "{", "MaxSessionTTL", ":", "MaxDuration", "(", ")", ",", "}", ",", "Allow", ":", "RoleConditions", "{", "Namespaces", ":", "[", "]", "string", "{", "defaults", ".", "Namespace", "}", ",", "Rules", ":", "CopyRulesSlice", "(", "DefaultImplicitRules", ")", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// NewImplicitRole is the default implicit role that gets added to all // RoleSets.
[ "NewImplicitRole", "is", "the", "default", "implicit", "role", "that", "gets", "added", "to", "all", "RoleSets", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L115-L133
train
gravitational/teleport
lib/services/role.go
RoleForUser
func RoleForUser(u User) Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: RoleNameForUser(u.GetName()), Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ CertificateFormat: teleport.CertificateFormatStandard, MaxSessionTTL: NewDuration(defaults.MaxCertDuration), PortForwarding: NewBoolOption(true), ForwardAgent: NewBool(true), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, NodeLabels: Labels{Wildcard: []string{Wildcard}}, Rules: CopyRulesSlice(AdminUserRules), }, }, } }
go
func RoleForUser(u User) Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: RoleNameForUser(u.GetName()), Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ CertificateFormat: teleport.CertificateFormatStandard, MaxSessionTTL: NewDuration(defaults.MaxCertDuration), PortForwarding: NewBoolOption(true), ForwardAgent: NewBool(true), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, NodeLabels: Labels{Wildcard: []string{Wildcard}}, Rules: CopyRulesSlice(AdminUserRules), }, }, } }
[ "func", "RoleForUser", "(", "u", "User", ")", "Role", "{", "return", "&", "RoleV3", "{", "Kind", ":", "KindRole", ",", "Version", ":", "V3", ",", "Metadata", ":", "Metadata", "{", "Name", ":", "RoleNameForUser", "(", "u", ".", "GetName", "(", ")", ")", ",", "Namespace", ":", "defaults", ".", "Namespace", ",", "}", ",", "Spec", ":", "RoleSpecV3", "{", "Options", ":", "RoleOptions", "{", "CertificateFormat", ":", "teleport", ".", "CertificateFormatStandard", ",", "MaxSessionTTL", ":", "NewDuration", "(", "defaults", ".", "MaxCertDuration", ")", ",", "PortForwarding", ":", "NewBoolOption", "(", "true", ")", ",", "ForwardAgent", ":", "NewBool", "(", "true", ")", ",", "}", ",", "Allow", ":", "RoleConditions", "{", "Namespaces", ":", "[", "]", "string", "{", "defaults", ".", "Namespace", "}", ",", "NodeLabels", ":", "Labels", "{", "Wildcard", ":", "[", "]", "string", "{", "Wildcard", "}", "}", ",", "Rules", ":", "CopyRulesSlice", "(", "AdminUserRules", ")", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// RoleForUser creates an admin role for a services.User.
[ "RoleForUser", "creates", "an", "admin", "role", "for", "a", "services", ".", "User", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L136-L158
train
gravitational/teleport
lib/services/role.go
RoleForCertAuthority
func RoleForCertAuthority(ca CertAuthority) Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: RoleNameForCertAuthority(ca.GetClusterName()), Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ MaxSessionTTL: NewDuration(defaults.MaxCertDuration), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, NodeLabels: Labels{Wildcard: []string{Wildcard}}, Rules: CopyRulesSlice(DefaultCertAuthorityRules), }, }, } }
go
func RoleForCertAuthority(ca CertAuthority) Role { return &RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: RoleNameForCertAuthority(ca.GetClusterName()), Namespace: defaults.Namespace, }, Spec: RoleSpecV3{ Options: RoleOptions{ MaxSessionTTL: NewDuration(defaults.MaxCertDuration), }, Allow: RoleConditions{ Namespaces: []string{defaults.Namespace}, NodeLabels: Labels{Wildcard: []string{Wildcard}}, Rules: CopyRulesSlice(DefaultCertAuthorityRules), }, }, } }
[ "func", "RoleForCertAuthority", "(", "ca", "CertAuthority", ")", "Role", "{", "return", "&", "RoleV3", "{", "Kind", ":", "KindRole", ",", "Version", ":", "V3", ",", "Metadata", ":", "Metadata", "{", "Name", ":", "RoleNameForCertAuthority", "(", "ca", ".", "GetClusterName", "(", ")", ")", ",", "Namespace", ":", "defaults", ".", "Namespace", ",", "}", ",", "Spec", ":", "RoleSpecV3", "{", "Options", ":", "RoleOptions", "{", "MaxSessionTTL", ":", "NewDuration", "(", "defaults", ".", "MaxCertDuration", ")", ",", "}", ",", "Allow", ":", "RoleConditions", "{", "Namespaces", ":", "[", "]", "string", "{", "defaults", ".", "Namespace", "}", ",", "NodeLabels", ":", "Labels", "{", "Wildcard", ":", "[", "]", "string", "{", "Wildcard", "}", "}", ",", "Rules", ":", "CopyRulesSlice", "(", "DefaultCertAuthorityRules", ")", ",", "}", ",", "}", ",", "}", "\n", "}" ]
// RoleForCertauthority creates role using services.CertAuthority.
[ "RoleForCertauthority", "creates", "role", "using", "services", ".", "CertAuthority", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L161-L180
train
gravitational/teleport
lib/services/role.go
ConvertV1CertAuthority
func ConvertV1CertAuthority(v1 *CertAuthorityV1) (CertAuthority, Role) { ca := v1.V2() role := RoleForCertAuthority(ca) role.SetLogins(Allow, v1.AllowedLogins) ca.AddRole(role.GetName()) return ca, role }
go
func ConvertV1CertAuthority(v1 *CertAuthorityV1) (CertAuthority, Role) { ca := v1.V2() role := RoleForCertAuthority(ca) role.SetLogins(Allow, v1.AllowedLogins) ca.AddRole(role.GetName()) return ca, role }
[ "func", "ConvertV1CertAuthority", "(", "v1", "*", "CertAuthorityV1", ")", "(", "CertAuthority", ",", "Role", ")", "{", "ca", ":=", "v1", ".", "V2", "(", ")", "\n", "role", ":=", "RoleForCertAuthority", "(", "ca", ")", "\n", "role", ".", "SetLogins", "(", "Allow", ",", "v1", ".", "AllowedLogins", ")", "\n", "ca", ".", "AddRole", "(", "role", ".", "GetName", "(", ")", ")", "\n", "return", "ca", ",", "role", "\n", "}" ]
// ConvertV1CertAuthority converts V1 cert authority for new CA and Role
[ "ConvertV1CertAuthority", "converts", "V1", "cert", "authority", "for", "new", "CA", "and", "Role" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L183-L189
train
gravitational/teleport
lib/services/role.go
applyValueTraits
func applyValueTraits(val string, traits map[string][]string) ([]string, error) { // Extract the variablePrefix and variableName from the role variable. variablePrefix, variableName, err := parse.IsRoleVariable(val) if err != nil { if !trace.IsNotFound(err) { return nil, trace.Wrap(err) } return []string{val}, nil } // For internal traits, only internal.logins and internal.kubernetes_groups is supported at the moment. if variablePrefix == teleport.TraitInternalPrefix { if variableName != teleport.TraitLogins && variableName != teleport.TraitKubeGroups { return nil, trace.BadParameter("unsupported variable %q", variableName) } } // If the variable is not found in the traits, skip it. variableValues, ok := traits[variableName] if !ok || len(variableValues) == 0 { return nil, trace.NotFound("variable %q not found in traits", variableName) } return append([]string{}, variableValues...), nil }
go
func applyValueTraits(val string, traits map[string][]string) ([]string, error) { // Extract the variablePrefix and variableName from the role variable. variablePrefix, variableName, err := parse.IsRoleVariable(val) if err != nil { if !trace.IsNotFound(err) { return nil, trace.Wrap(err) } return []string{val}, nil } // For internal traits, only internal.logins and internal.kubernetes_groups is supported at the moment. if variablePrefix == teleport.TraitInternalPrefix { if variableName != teleport.TraitLogins && variableName != teleport.TraitKubeGroups { return nil, trace.BadParameter("unsupported variable %q", variableName) } } // If the variable is not found in the traits, skip it. variableValues, ok := traits[variableName] if !ok || len(variableValues) == 0 { return nil, trace.NotFound("variable %q not found in traits", variableName) } return append([]string{}, variableValues...), nil }
[ "func", "applyValueTraits", "(", "val", "string", ",", "traits", "map", "[", "string", "]", "[", "]", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "variablePrefix", ",", "variableName", ",", "err", ":=", "parse", ".", "IsRoleVariable", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "trace", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "[", "]", "string", "{", "val", "}", ",", "nil", "\n", "}", "\n", "if", "variablePrefix", "==", "teleport", ".", "TraitInternalPrefix", "{", "if", "variableName", "!=", "teleport", ".", "TraitLogins", "&&", "variableName", "!=", "teleport", ".", "TraitKubeGroups", "{", "return", "nil", ",", "trace", ".", "BadParameter", "(", "\"unsupported variable %q\"", ",", "variableName", ")", "\n", "}", "\n", "}", "\n", "variableValues", ",", "ok", ":=", "traits", "[", "variableName", "]", "\n", "if", "!", "ok", "||", "len", "(", "variableValues", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "NotFound", "(", "\"variable %q not found in traits\"", ",", "variableName", ")", "\n", "}", "\n", "return", "append", "(", "[", "]", "string", "{", "}", ",", "variableValues", "...", ")", ",", "nil", "\n", "}" ]
// applyValueTraits applies the passed in traits to the variable, // returns BadParameter in case if referenced variable is unsupported, // returns NotFound in case if referenced trait is missing, // mapped list of values otherwise, the function guarantees to return // at least one value in case if return value is nil
[ "applyValueTraits", "applies", "the", "passed", "in", "traits", "to", "the", "variable", "returns", "BadParameter", "in", "case", "if", "referenced", "variable", "is", "unsupported", "returns", "NotFound", "in", "case", "if", "referenced", "trait", "is", "missing", "mapped", "list", "of", "values", "otherwise", "the", "function", "guarantees", "to", "return", "at", "least", "one", "value", "in", "case", "if", "return", "value", "is", "nil" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L349-L374
train
gravitational/teleport
lib/services/role.go
Equals
func (r *RoleV3) Equals(other Role) bool { if !r.GetOptions().Equals(other.GetOptions()) { return false } for _, condition := range []RoleConditionType{Allow, Deny} { if !utils.StringSlicesEqual(r.GetLogins(condition), other.GetLogins(condition)) { return false } if !utils.StringSlicesEqual(r.GetNamespaces(condition), other.GetNamespaces(condition)) { return false } if !r.GetNodeLabels(condition).Equals(other.GetNodeLabels(condition)) { return false } if !RuleSlicesEqual(r.GetRules(condition), other.GetRules(condition)) { return false } } return true }
go
func (r *RoleV3) Equals(other Role) bool { if !r.GetOptions().Equals(other.GetOptions()) { return false } for _, condition := range []RoleConditionType{Allow, Deny} { if !utils.StringSlicesEqual(r.GetLogins(condition), other.GetLogins(condition)) { return false } if !utils.StringSlicesEqual(r.GetNamespaces(condition), other.GetNamespaces(condition)) { return false } if !r.GetNodeLabels(condition).Equals(other.GetNodeLabels(condition)) { return false } if !RuleSlicesEqual(r.GetRules(condition), other.GetRules(condition)) { return false } } return true }
[ "func", "(", "r", "*", "RoleV3", ")", "Equals", "(", "other", "Role", ")", "bool", "{", "if", "!", "r", ".", "GetOptions", "(", ")", ".", "Equals", "(", "other", ".", "GetOptions", "(", ")", ")", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "condition", ":=", "range", "[", "]", "RoleConditionType", "{", "Allow", ",", "Deny", "}", "{", "if", "!", "utils", ".", "StringSlicesEqual", "(", "r", ".", "GetLogins", "(", "condition", ")", ",", "other", ".", "GetLogins", "(", "condition", ")", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "utils", ".", "StringSlicesEqual", "(", "r", ".", "GetNamespaces", "(", "condition", ")", ",", "other", ".", "GetNamespaces", "(", "condition", ")", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "r", ".", "GetNodeLabels", "(", "condition", ")", ".", "Equals", "(", "other", ".", "GetNodeLabels", "(", "condition", ")", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "RuleSlicesEqual", "(", "r", ".", "GetRules", "(", "condition", ")", ",", "other", ".", "GetRules", "(", "condition", ")", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equals returns true if the roles are equal. Roles are equal if options, // namespaces, logins, labels, and conditions match.
[ "Equals", "returns", "true", "if", "the", "roles", "are", "equal", ".", "Roles", "are", "equal", "if", "options", "namespaces", "logins", "labels", "and", "conditions", "match", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L408-L429
train
gravitational/teleport
lib/services/role.go
GetLogins
func (r *RoleV3) GetLogins(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.Logins } return r.Spec.Deny.Logins }
go
func (r *RoleV3) GetLogins(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.Logins } return r.Spec.Deny.Logins }
[ "func", "(", "r", "*", "RoleV3", ")", "GetLogins", "(", "rct", "RoleConditionType", ")", "[", "]", "string", "{", "if", "rct", "==", "Allow", "{", "return", "r", ".", "Spec", ".", "Allow", ".", "Logins", "\n", "}", "\n", "return", "r", ".", "Spec", ".", "Deny", ".", "Logins", "\n", "}" ]
// GetLogins gets system logins for allow or deny condition.
[ "GetLogins", "gets", "system", "logins", "for", "allow", "or", "deny", "condition", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L478-L483
train
gravitational/teleport
lib/services/role.go
SetLogins
func (r *RoleV3) SetLogins(rct RoleConditionType, logins []string) { lcopy := utils.CopyStrings(logins) if rct == Allow { r.Spec.Allow.Logins = lcopy } else { r.Spec.Deny.Logins = lcopy } }
go
func (r *RoleV3) SetLogins(rct RoleConditionType, logins []string) { lcopy := utils.CopyStrings(logins) if rct == Allow { r.Spec.Allow.Logins = lcopy } else { r.Spec.Deny.Logins = lcopy } }
[ "func", "(", "r", "*", "RoleV3", ")", "SetLogins", "(", "rct", "RoleConditionType", ",", "logins", "[", "]", "string", ")", "{", "lcopy", ":=", "utils", ".", "CopyStrings", "(", "logins", ")", "\n", "if", "rct", "==", "Allow", "{", "r", ".", "Spec", ".", "Allow", ".", "Logins", "=", "lcopy", "\n", "}", "else", "{", "r", ".", "Spec", ".", "Deny", ".", "Logins", "=", "lcopy", "\n", "}", "\n", "}" ]
// SetLogins sets system logins for allow or deny condition.
[ "SetLogins", "sets", "system", "logins", "for", "allow", "or", "deny", "condition", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L486-L494
train
gravitational/teleport
lib/services/role.go
GetKubeGroups
func (r *RoleV3) GetKubeGroups(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.KubeGroups } return r.Spec.Deny.KubeGroups }
go
func (r *RoleV3) GetKubeGroups(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.KubeGroups } return r.Spec.Deny.KubeGroups }
[ "func", "(", "r", "*", "RoleV3", ")", "GetKubeGroups", "(", "rct", "RoleConditionType", ")", "[", "]", "string", "{", "if", "rct", "==", "Allow", "{", "return", "r", ".", "Spec", ".", "Allow", ".", "KubeGroups", "\n", "}", "\n", "return", "r", ".", "Spec", ".", "Deny", ".", "KubeGroups", "\n", "}" ]
// GetKubeGroups returns kubernetes groups
[ "GetKubeGroups", "returns", "kubernetes", "groups" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L497-L502
train
gravitational/teleport
lib/services/role.go
SetKubeGroups
func (r *RoleV3) SetKubeGroups(rct RoleConditionType, groups []string) { lcopy := utils.CopyStrings(groups) if rct == Allow { r.Spec.Allow.KubeGroups = lcopy } else { r.Spec.Deny.KubeGroups = lcopy } }
go
func (r *RoleV3) SetKubeGroups(rct RoleConditionType, groups []string) { lcopy := utils.CopyStrings(groups) if rct == Allow { r.Spec.Allow.KubeGroups = lcopy } else { r.Spec.Deny.KubeGroups = lcopy } }
[ "func", "(", "r", "*", "RoleV3", ")", "SetKubeGroups", "(", "rct", "RoleConditionType", ",", "groups", "[", "]", "string", ")", "{", "lcopy", ":=", "utils", ".", "CopyStrings", "(", "groups", ")", "\n", "if", "rct", "==", "Allow", "{", "r", ".", "Spec", ".", "Allow", ".", "KubeGroups", "=", "lcopy", "\n", "}", "else", "{", "r", ".", "Spec", ".", "Deny", ".", "KubeGroups", "=", "lcopy", "\n", "}", "\n", "}" ]
// SetKubeGroups sets kubernetes groups for allow or deny condition.
[ "SetKubeGroups", "sets", "kubernetes", "groups", "for", "allow", "or", "deny", "condition", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L505-L513
train
gravitational/teleport
lib/services/role.go
GetNamespaces
func (r *RoleV3) GetNamespaces(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.Namespaces } return r.Spec.Deny.Namespaces }
go
func (r *RoleV3) GetNamespaces(rct RoleConditionType) []string { if rct == Allow { return r.Spec.Allow.Namespaces } return r.Spec.Deny.Namespaces }
[ "func", "(", "r", "*", "RoleV3", ")", "GetNamespaces", "(", "rct", "RoleConditionType", ")", "[", "]", "string", "{", "if", "rct", "==", "Allow", "{", "return", "r", ".", "Spec", ".", "Allow", ".", "Namespaces", "\n", "}", "\n", "return", "r", ".", "Spec", ".", "Deny", ".", "Namespaces", "\n", "}" ]
// GetNamespaces gets a list of namespaces this role is allowed or denied access to.
[ "GetNamespaces", "gets", "a", "list", "of", "namespaces", "this", "role", "is", "allowed", "or", "denied", "access", "to", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L516-L521
train
gravitational/teleport
lib/services/role.go
SetNamespaces
func (r *RoleV3) SetNamespaces(rct RoleConditionType, namespaces []string) { ncopy := utils.CopyStrings(namespaces) if rct == Allow { r.Spec.Allow.Namespaces = ncopy } else { r.Spec.Deny.Namespaces = ncopy } }
go
func (r *RoleV3) SetNamespaces(rct RoleConditionType, namespaces []string) { ncopy := utils.CopyStrings(namespaces) if rct == Allow { r.Spec.Allow.Namespaces = ncopy } else { r.Spec.Deny.Namespaces = ncopy } }
[ "func", "(", "r", "*", "RoleV3", ")", "SetNamespaces", "(", "rct", "RoleConditionType", ",", "namespaces", "[", "]", "string", ")", "{", "ncopy", ":=", "utils", ".", "CopyStrings", "(", "namespaces", ")", "\n", "if", "rct", "==", "Allow", "{", "r", ".", "Spec", ".", "Allow", ".", "Namespaces", "=", "ncopy", "\n", "}", "else", "{", "r", ".", "Spec", ".", "Deny", ".", "Namespaces", "=", "ncopy", "\n", "}", "\n", "}" ]
// GetNamespaces sets a list of namespaces this role is allowed or denied access to.
[ "GetNamespaces", "sets", "a", "list", "of", "namespaces", "this", "role", "is", "allowed", "or", "denied", "access", "to", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L524-L532
train
gravitational/teleport
lib/services/role.go
GetNodeLabels
func (r *RoleV3) GetNodeLabels(rct RoleConditionType) Labels { if rct == Allow { return r.Spec.Allow.NodeLabels } return r.Spec.Deny.NodeLabels }
go
func (r *RoleV3) GetNodeLabels(rct RoleConditionType) Labels { if rct == Allow { return r.Spec.Allow.NodeLabels } return r.Spec.Deny.NodeLabels }
[ "func", "(", "r", "*", "RoleV3", ")", "GetNodeLabels", "(", "rct", "RoleConditionType", ")", "Labels", "{", "if", "rct", "==", "Allow", "{", "return", "r", ".", "Spec", ".", "Allow", ".", "NodeLabels", "\n", "}", "\n", "return", "r", ".", "Spec", ".", "Deny", ".", "NodeLabels", "\n", "}" ]
// GetNodeLabels gets the map of node labels this role is allowed or denied access to.
[ "GetNodeLabels", "gets", "the", "map", "of", "node", "labels", "this", "role", "is", "allowed", "or", "denied", "access", "to", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L535-L540
train
gravitational/teleport
lib/services/role.go
SetNodeLabels
func (r *RoleV3) SetNodeLabels(rct RoleConditionType, labels Labels) { if rct == Allow { r.Spec.Allow.NodeLabels = labels.Clone() } else { r.Spec.Deny.NodeLabels = labels.Clone() } }
go
func (r *RoleV3) SetNodeLabels(rct RoleConditionType, labels Labels) { if rct == Allow { r.Spec.Allow.NodeLabels = labels.Clone() } else { r.Spec.Deny.NodeLabels = labels.Clone() } }
[ "func", "(", "r", "*", "RoleV3", ")", "SetNodeLabels", "(", "rct", "RoleConditionType", ",", "labels", "Labels", ")", "{", "if", "rct", "==", "Allow", "{", "r", ".", "Spec", ".", "Allow", ".", "NodeLabels", "=", "labels", ".", "Clone", "(", ")", "\n", "}", "else", "{", "r", ".", "Spec", ".", "Deny", ".", "NodeLabels", "=", "labels", ".", "Clone", "(", ")", "\n", "}", "\n", "}" ]
// SetNodeLabels sets the map of node labels this role is allowed or denied access to.
[ "SetNodeLabels", "sets", "the", "map", "of", "node", "labels", "this", "role", "is", "allowed", "or", "denied", "access", "to", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L543-L549
train
gravitational/teleport
lib/services/role.go
GetRules
func (r *RoleV3) GetRules(rct RoleConditionType) []Rule { if rct == Allow { return r.Spec.Allow.Rules } return r.Spec.Deny.Rules }
go
func (r *RoleV3) GetRules(rct RoleConditionType) []Rule { if rct == Allow { return r.Spec.Allow.Rules } return r.Spec.Deny.Rules }
[ "func", "(", "r", "*", "RoleV3", ")", "GetRules", "(", "rct", "RoleConditionType", ")", "[", "]", "Rule", "{", "if", "rct", "==", "Allow", "{", "return", "r", ".", "Spec", ".", "Allow", ".", "Rules", "\n", "}", "\n", "return", "r", ".", "Spec", ".", "Deny", ".", "Rules", "\n", "}" ]
// GetRules gets all allow or deny rules.
[ "GetRules", "gets", "all", "allow", "or", "deny", "rules", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L552-L557
train
gravitational/teleport
lib/services/role.go
SetRules
func (r *RoleV3) SetRules(rct RoleConditionType, in []Rule) { rcopy := CopyRulesSlice(in) if rct == Allow { r.Spec.Allow.Rules = rcopy } else { r.Spec.Deny.Rules = rcopy } }
go
func (r *RoleV3) SetRules(rct RoleConditionType, in []Rule) { rcopy := CopyRulesSlice(in) if rct == Allow { r.Spec.Allow.Rules = rcopy } else { r.Spec.Deny.Rules = rcopy } }
[ "func", "(", "r", "*", "RoleV3", ")", "SetRules", "(", "rct", "RoleConditionType", ",", "in", "[", "]", "Rule", ")", "{", "rcopy", ":=", "CopyRulesSlice", "(", "in", ")", "\n", "if", "rct", "==", "Allow", "{", "r", ".", "Spec", ".", "Allow", ".", "Rules", "=", "rcopy", "\n", "}", "else", "{", "r", ".", "Spec", ".", "Deny", ".", "Rules", "=", "rcopy", "\n", "}", "\n", "}" ]
// SetRules sets an allow or deny rule.
[ "SetRules", "sets", "an", "allow", "or", "deny", "rule", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L560-L568
train
gravitational/teleport
lib/services/role.go
String
func (r *RoleV3) String() string { return fmt.Sprintf("Role(Name=%v,Options=%v,Allow=%+v,Deny=%+v)", r.GetName(), r.Spec.Options, r.Spec.Allow, r.Spec.Deny) }
go
func (r *RoleV3) String() string { return fmt.Sprintf("Role(Name=%v,Options=%v,Allow=%+v,Deny=%+v)", r.GetName(), r.Spec.Options, r.Spec.Allow, r.Spec.Deny) }
[ "func", "(", "r", "*", "RoleV3", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"Role(Name=%v,Options=%v,Allow=%+v,Deny=%+v)\"", ",", "r", ".", "GetName", "(", ")", ",", "r", ".", "Spec", ".", "Options", ",", "r", ".", "Spec", ".", "Allow", ",", "r", ".", "Spec", ".", "Deny", ")", "\n", "}" ]
// String returns the human readable representation of a role.
[ "String", "returns", "the", "human", "readable", "representation", "of", "a", "role", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L641-L644
train
gravitational/teleport
lib/services/role.go
NewRule
func NewRule(resource string, verbs []string) Rule { return Rule{ Resources: []string{resource}, Verbs: verbs, } }
go
func NewRule(resource string, verbs []string) Rule { return Rule{ Resources: []string{resource}, Verbs: verbs, } }
[ "func", "NewRule", "(", "resource", "string", ",", "verbs", "[", "]", "string", ")", "Rule", "{", "return", "Rule", "{", "Resources", ":", "[", "]", "string", "{", "resource", "}", ",", "Verbs", ":", "verbs", ",", "}", "\n", "}" ]
// NewRule creates a rule based on a resource name and a list of verbs
[ "NewRule", "creates", "a", "rule", "based", "on", "a", "resource", "name", "and", "a", "list", "of", "verbs" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L680-L685
train
gravitational/teleport
lib/services/role.go
CheckAndSetDefaults
func (r *Rule) CheckAndSetDefaults() error { if len(r.Resources) == 0 { return trace.BadParameter("missing resources to match") } if len(r.Verbs) == 0 { return trace.BadParameter("missing verbs") } if len(r.Where) != 0 { parser, err := GetWhereParserFn()(&Context{}) if err != nil { return trace.Wrap(err) } _, err = parser.Parse(r.Where) if err != nil { return trace.BadParameter("could not parse 'where' rule: %q, error: %v", r.Where, err) } } if len(r.Actions) != 0 { parser, err := GetActionsParserFn()(&Context{}) if err != nil { return trace.Wrap(err) } for i, action := range r.Actions { _, err = parser.Parse(action) if err != nil { return trace.BadParameter("could not parse action %v %q, error: %v", i, action, err) } } } return nil }
go
func (r *Rule) CheckAndSetDefaults() error { if len(r.Resources) == 0 { return trace.BadParameter("missing resources to match") } if len(r.Verbs) == 0 { return trace.BadParameter("missing verbs") } if len(r.Where) != 0 { parser, err := GetWhereParserFn()(&Context{}) if err != nil { return trace.Wrap(err) } _, err = parser.Parse(r.Where) if err != nil { return trace.BadParameter("could not parse 'where' rule: %q, error: %v", r.Where, err) } } if len(r.Actions) != 0 { parser, err := GetActionsParserFn()(&Context{}) if err != nil { return trace.Wrap(err) } for i, action := range r.Actions { _, err = parser.Parse(action) if err != nil { return trace.BadParameter("could not parse action %v %q, error: %v", i, action, err) } } } return nil }
[ "func", "(", "r", "*", "Rule", ")", "CheckAndSetDefaults", "(", ")", "error", "{", "if", "len", "(", "r", ".", "Resources", ")", "==", "0", "{", "return", "trace", ".", "BadParameter", "(", "\"missing resources to match\"", ")", "\n", "}", "\n", "if", "len", "(", "r", ".", "Verbs", ")", "==", "0", "{", "return", "trace", ".", "BadParameter", "(", "\"missing verbs\"", ")", "\n", "}", "\n", "if", "len", "(", "r", ".", "Where", ")", "!=", "0", "{", "parser", ",", "err", ":=", "GetWhereParserFn", "(", ")", "(", "&", "Context", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "parser", ".", "Parse", "(", "r", ".", "Where", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "BadParameter", "(", "\"could not parse 'where' rule: %q, error: %v\"", ",", "r", ".", "Where", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "r", ".", "Actions", ")", "!=", "0", "{", "parser", ",", "err", ":=", "GetActionsParserFn", "(", ")", "(", "&", "Context", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "for", "i", ",", "action", ":=", "range", "r", ".", "Actions", "{", "_", ",", "err", "=", "parser", ".", "Parse", "(", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "BadParameter", "(", "\"could not parse action %v %q, error: %v\"", ",", "i", ",", "action", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CheckAndSetDefaults checks and sets defaults for this rule
[ "CheckAndSetDefaults", "checks", "and", "sets", "defaults", "for", "this", "rule" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L688-L718
train
gravitational/teleport
lib/services/role.go
score
func (r *Rule) score() int { score := 0 // wilcard rules are less specific if utils.SliceContainsStr(r.Resources, Wildcard) { score -= 4 } else if len(r.Resources) == 1 { // rules that match specific resource are more specific than // fields that match several resources score += 2 } // rules that have wilcard verbs are less specific if utils.SliceContainsStr(r.Verbs, Wildcard) { score -= 2 } // rules that supply 'where' or 'actions' are more specific // having 'where' or 'actions' is more important than // whether the rules are wildcard or not, so here we have +8 vs // -4 and -2 score penalty for wildcards in resources and verbs if len(r.Where) > 0 { score += 8 } // rules featuring actions are more specific if len(r.Actions) > 0 { score += 8 } return score }
go
func (r *Rule) score() int { score := 0 // wilcard rules are less specific if utils.SliceContainsStr(r.Resources, Wildcard) { score -= 4 } else if len(r.Resources) == 1 { // rules that match specific resource are more specific than // fields that match several resources score += 2 } // rules that have wilcard verbs are less specific if utils.SliceContainsStr(r.Verbs, Wildcard) { score -= 2 } // rules that supply 'where' or 'actions' are more specific // having 'where' or 'actions' is more important than // whether the rules are wildcard or not, so here we have +8 vs // -4 and -2 score penalty for wildcards in resources and verbs if len(r.Where) > 0 { score += 8 } // rules featuring actions are more specific if len(r.Actions) > 0 { score += 8 } return score }
[ "func", "(", "r", "*", "Rule", ")", "score", "(", ")", "int", "{", "score", ":=", "0", "\n", "if", "utils", ".", "SliceContainsStr", "(", "r", ".", "Resources", ",", "Wildcard", ")", "{", "score", "-=", "4", "\n", "}", "else", "if", "len", "(", "r", ".", "Resources", ")", "==", "1", "{", "score", "+=", "2", "\n", "}", "\n", "if", "utils", ".", "SliceContainsStr", "(", "r", ".", "Verbs", ",", "Wildcard", ")", "{", "score", "-=", "2", "\n", "}", "\n", "if", "len", "(", "r", ".", "Where", ")", ">", "0", "{", "score", "+=", "8", "\n", "}", "\n", "if", "len", "(", "r", ".", "Actions", ")", ">", "0", "{", "score", "+=", "8", "\n", "}", "\n", "return", "score", "\n", "}" ]
// score is a sorting score of the rule, the more the score, the more // specific the rule is
[ "score", "is", "a", "sorting", "score", "of", "the", "rule", "the", "more", "the", "score", "the", "more", "specific", "the", "rule", "is" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L722-L748
train
gravitational/teleport
lib/services/role.go
MatchesWhere
func (r *Rule) MatchesWhere(parser predicate.Parser) (bool, error) { if r.Where == "" { return true, nil } ifn, err := parser.Parse(r.Where) if err != nil { return false, trace.Wrap(err) } fn, ok := ifn.(predicate.BoolPredicate) if !ok { return false, trace.BadParameter("unsupported type: %T", ifn) } return fn(), nil }
go
func (r *Rule) MatchesWhere(parser predicate.Parser) (bool, error) { if r.Where == "" { return true, nil } ifn, err := parser.Parse(r.Where) if err != nil { return false, trace.Wrap(err) } fn, ok := ifn.(predicate.BoolPredicate) if !ok { return false, trace.BadParameter("unsupported type: %T", ifn) } return fn(), nil }
[ "func", "(", "r", "*", "Rule", ")", "MatchesWhere", "(", "parser", "predicate", ".", "Parser", ")", "(", "bool", ",", "error", ")", "{", "if", "r", ".", "Where", "==", "\"\"", "{", "return", "true", ",", "nil", "\n", "}", "\n", "ifn", ",", "err", ":=", "parser", ".", "Parse", "(", "r", ".", "Where", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "fn", ",", "ok", ":=", "ifn", ".", "(", "predicate", ".", "BoolPredicate", ")", "\n", "if", "!", "ok", "{", "return", "false", ",", "trace", ".", "BadParameter", "(", "\"unsupported type: %T\"", ",", "ifn", ")", "\n", "}", "\n", "return", "fn", "(", ")", ",", "nil", "\n", "}" ]
// MatchesWhere returns true if Where rule matches // Empty Where block always matches
[ "MatchesWhere", "returns", "true", "if", "Where", "rule", "matches", "Empty", "Where", "block", "always", "matches" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L766-L779
train
gravitational/teleport
lib/services/role.go
ProcessActions
func (r *Rule) ProcessActions(parser predicate.Parser) error { for _, action := range r.Actions { ifn, err := parser.Parse(action) if err != nil { return trace.Wrap(err) } fn, ok := ifn.(predicate.BoolPredicate) if !ok { return trace.BadParameter("unsupported type: %T", ifn) } fn() } return nil }
go
func (r *Rule) ProcessActions(parser predicate.Parser) error { for _, action := range r.Actions { ifn, err := parser.Parse(action) if err != nil { return trace.Wrap(err) } fn, ok := ifn.(predicate.BoolPredicate) if !ok { return trace.BadParameter("unsupported type: %T", ifn) } fn() } return nil }
[ "func", "(", "r", "*", "Rule", ")", "ProcessActions", "(", "parser", "predicate", ".", "Parser", ")", "error", "{", "for", "_", ",", "action", ":=", "range", "r", ".", "Actions", "{", "ifn", ",", "err", ":=", "parser", ".", "Parse", "(", "action", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "fn", ",", "ok", ":=", "ifn", ".", "(", "predicate", ".", "BoolPredicate", ")", "\n", "if", "!", "ok", "{", "return", "trace", ".", "BadParameter", "(", "\"unsupported type: %T\"", ",", "ifn", ")", "\n", "}", "\n", "fn", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ProcessActions processes actions specified for this rule
[ "ProcessActions", "processes", "actions", "specified", "for", "this", "rule" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L782-L795
train
gravitational/teleport
lib/services/role.go
HasResource
func (r *Rule) HasResource(resource string) bool { for _, r := range r.Resources { if r == resource { return true } } return false }
go
func (r *Rule) HasResource(resource string) bool { for _, r := range r.Resources { if r == resource { return true } } return false }
[ "func", "(", "r", "*", "Rule", ")", "HasResource", "(", "resource", "string", ")", "bool", "{", "for", "_", ",", "r", ":=", "range", "r", ".", "Resources", "{", "if", "r", "==", "resource", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasResource returns true if the rule has the specified resource.
[ "HasResource", "returns", "true", "if", "the", "rule", "has", "the", "specified", "resource", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L798-L805
train
gravitational/teleport
lib/services/role.go
HasVerb
func (r *Rule) HasVerb(verb string) bool { for _, v := range r.Verbs { // readnosecrets can be satisfied by having readnosecrets or read if verb == VerbReadNoSecrets { if v == VerbReadNoSecrets || v == VerbRead { return true } continue } if v == verb { return true } } return false }
go
func (r *Rule) HasVerb(verb string) bool { for _, v := range r.Verbs { // readnosecrets can be satisfied by having readnosecrets or read if verb == VerbReadNoSecrets { if v == VerbReadNoSecrets || v == VerbRead { return true } continue } if v == verb { return true } } return false }
[ "func", "(", "r", "*", "Rule", ")", "HasVerb", "(", "verb", "string", ")", "bool", "{", "for", "_", ",", "v", ":=", "range", "r", ".", "Verbs", "{", "if", "verb", "==", "VerbReadNoSecrets", "{", "if", "v", "==", "VerbReadNoSecrets", "||", "v", "==", "VerbRead", "{", "return", "true", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "v", "==", "verb", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasVerb returns true if the rule has verb, // this method also matches wildcard
[ "HasVerb", "returns", "true", "if", "the", "rule", "has", "verb", "this", "method", "also", "matches", "wildcard" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L809-L823
train
gravitational/teleport
lib/services/role.go
Equals
func (r *Rule) Equals(other Rule) bool { if !utils.StringSlicesEqual(r.Resources, other.Resources) { return false } if !utils.StringSlicesEqual(r.Verbs, other.Verbs) { return false } if !utils.StringSlicesEqual(r.Actions, other.Actions) { return false } if r.Where != other.Where { return false } return true }
go
func (r *Rule) Equals(other Rule) bool { if !utils.StringSlicesEqual(r.Resources, other.Resources) { return false } if !utils.StringSlicesEqual(r.Verbs, other.Verbs) { return false } if !utils.StringSlicesEqual(r.Actions, other.Actions) { return false } if r.Where != other.Where { return false } return true }
[ "func", "(", "r", "*", "Rule", ")", "Equals", "(", "other", "Rule", ")", "bool", "{", "if", "!", "utils", ".", "StringSlicesEqual", "(", "r", ".", "Resources", ",", "other", ".", "Resources", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "utils", ".", "StringSlicesEqual", "(", "r", ".", "Verbs", ",", "other", ".", "Verbs", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "utils", ".", "StringSlicesEqual", "(", "r", ".", "Actions", ",", "other", ".", "Actions", ")", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "Where", "!=", "other", ".", "Where", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equals returns true if the rule equals to another
[ "Equals", "returns", "true", "if", "the", "rule", "equals", "to", "another" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L826-L840
train
gravitational/teleport
lib/services/role.go
Slice
func (set RuleSet) Slice() []Rule { var out []Rule for _, rules := range set { out = append(out, rules...) } return out }
go
func (set RuleSet) Slice() []Rule { var out []Rule for _, rules := range set { out = append(out, rules...) } return out }
[ "func", "(", "set", "RuleSet", ")", "Slice", "(", ")", "[", "]", "Rule", "{", "var", "out", "[", "]", "Rule", "\n", "for", "_", ",", "rules", ":=", "range", "set", "{", "out", "=", "append", "(", "out", ",", "rules", "...", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Slice returns slice from a set
[ "Slice", "returns", "slice", "from", "a", "set" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L893-L899
train
gravitational/teleport
lib/services/role.go
MakeRuleSet
func MakeRuleSet(rules []Rule) RuleSet { set := make(RuleSet) for _, rule := range rules { for _, resource := range rule.Resources { rules, ok := set[resource] if !ok { set[resource] = []Rule{rule} } else { rules = append(rules, rule) set[resource] = rules } } } for resource := range set { rules := set[resource] // sort rules by most specific rule, the rule that has actions // is more specific than the one that has no actions sort.Slice(rules, func(i, j int) bool { return rules[i].IsMoreSpecificThan(rules[j]) }) set[resource] = rules } return set }
go
func MakeRuleSet(rules []Rule) RuleSet { set := make(RuleSet) for _, rule := range rules { for _, resource := range rule.Resources { rules, ok := set[resource] if !ok { set[resource] = []Rule{rule} } else { rules = append(rules, rule) set[resource] = rules } } } for resource := range set { rules := set[resource] // sort rules by most specific rule, the rule that has actions // is more specific than the one that has no actions sort.Slice(rules, func(i, j int) bool { return rules[i].IsMoreSpecificThan(rules[j]) }) set[resource] = rules } return set }
[ "func", "MakeRuleSet", "(", "rules", "[", "]", "Rule", ")", "RuleSet", "{", "set", ":=", "make", "(", "RuleSet", ")", "\n", "for", "_", ",", "rule", ":=", "range", "rules", "{", "for", "_", ",", "resource", ":=", "range", "rule", ".", "Resources", "{", "rules", ",", "ok", ":=", "set", "[", "resource", "]", "\n", "if", "!", "ok", "{", "set", "[", "resource", "]", "=", "[", "]", "Rule", "{", "rule", "}", "\n", "}", "else", "{", "rules", "=", "append", "(", "rules", ",", "rule", ")", "\n", "set", "[", "resource", "]", "=", "rules", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "resource", ":=", "range", "set", "{", "rules", ":=", "set", "[", "resource", "]", "\n", "sort", ".", "Slice", "(", "rules", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "rules", "[", "i", "]", ".", "IsMoreSpecificThan", "(", "rules", "[", "j", "]", ")", "\n", "}", ")", "\n", "set", "[", "resource", "]", "=", "rules", "\n", "}", "\n", "return", "set", "\n", "}" ]
// MakeRuleSet converts slice of rules to the set of rules
[ "MakeRuleSet", "converts", "slice", "of", "rules", "to", "the", "set", "of", "rules" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L902-L925
train
gravitational/teleport
lib/services/role.go
CopyRulesSlice
func CopyRulesSlice(in []Rule) []Rule { out := make([]Rule, len(in)) copy(out, in) return out }
go
func CopyRulesSlice(in []Rule) []Rule { out := make([]Rule, len(in)) copy(out, in) return out }
[ "func", "CopyRulesSlice", "(", "in", "[", "]", "Rule", ")", "[", "]", "Rule", "{", "out", ":=", "make", "(", "[", "]", "Rule", ",", "len", "(", "in", ")", ")", "\n", "copy", "(", "out", ",", "in", ")", "\n", "return", "out", "\n", "}" ]
// CopyRulesSlice copies input slice of Rules and returns the copy
[ "CopyRulesSlice", "copies", "input", "slice", "of", "Rules", "and", "returns", "the", "copy" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L928-L932
train
gravitational/teleport
lib/services/role.go
RuleSlicesEqual
func RuleSlicesEqual(a, b []Rule) bool { if len(a) != len(b) { return false } for i := range a { if !a[i].Equals(b[i]) { return false } } return true }
go
func RuleSlicesEqual(a, b []Rule) bool { if len(a) != len(b) { return false } for i := range a { if !a[i].Equals(b[i]) { return false } } return true }
[ "func", "RuleSlicesEqual", "(", "a", ",", "b", "[", "]", "Rule", ")", "bool", "{", "if", "len", "(", "a", ")", "!=", "len", "(", "b", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "a", "{", "if", "!", "a", "[", "i", "]", ".", "Equals", "(", "b", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// RuleSlicesEqual returns true if two rule slices are equal
[ "RuleSlicesEqual", "returns", "true", "if", "two", "rule", "slices", "are", "equal" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L935-L945
train
gravitational/teleport
lib/services/role.go
Equals
func (r *RoleV2) Equals(other Role) bool { return r.V3().Equals(other) }
go
func (r *RoleV2) Equals(other Role) bool { return r.V3().Equals(other) }
[ "func", "(", "r", "*", "RoleV2", ")", "Equals", "(", "other", "Role", ")", "bool", "{", "return", "r", ".", "V3", "(", ")", ".", "Equals", "(", "other", ")", "\n", "}" ]
// Equals test roles for equality. Roles are considered equal if all resources, // logins, namespaces, labels, and options match.
[ "Equals", "test", "roles", "for", "equality", ".", "Roles", "are", "considered", "equal", "if", "all", "resources", "logins", "namespaces", "labels", "and", "options", "match", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L993-L995
train
gravitational/teleport
lib/services/role.go
SetResource
func (r *RoleV2) SetResource(kind string, actions []string) { if r.Spec.Resources == nil { r.Spec.Resources = make(map[string][]string) } r.Spec.Resources[kind] = actions }
go
func (r *RoleV2) SetResource(kind string, actions []string) { if r.Spec.Resources == nil { r.Spec.Resources = make(map[string][]string) } r.Spec.Resources[kind] = actions }
[ "func", "(", "r", "*", "RoleV2", ")", "SetResource", "(", "kind", "string", ",", "actions", "[", "]", "string", ")", "{", "if", "r", ".", "Spec", ".", "Resources", "==", "nil", "{", "r", ".", "Spec", ".", "Resources", "=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "}", "\n", "r", ".", "Spec", ".", "Resources", "[", "kind", "]", "=", "actions", "\n", "}" ]
// SetResource sets resource rule
[ "SetResource", "sets", "resource", "rule" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L998-L1003
train
gravitational/teleport
lib/services/role.go
RemoveResource
func (r *RoleV2) RemoveResource(kind string) { delete(r.Spec.Resources, kind) }
go
func (r *RoleV2) RemoveResource(kind string) { delete(r.Spec.Resources, kind) }
[ "func", "(", "r", "*", "RoleV2", ")", "RemoveResource", "(", "kind", "string", ")", "{", "delete", "(", "r", ".", "Spec", ".", "Resources", ",", "kind", ")", "\n", "}" ]
// RemoveResource deletes resource entry
[ "RemoveResource", "deletes", "resource", "entry" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1006-L1008
train
gravitational/teleport
lib/services/role.go
SetNodeLabels
func (r *RoleV2) SetNodeLabels(labels map[string]string) { r.Spec.NodeLabels = labels }
go
func (r *RoleV2) SetNodeLabels(labels map[string]string) { r.Spec.NodeLabels = labels }
[ "func", "(", "r", "*", "RoleV2", ")", "SetNodeLabels", "(", "labels", "map", "[", "string", "]", "string", ")", "{", "r", ".", "Spec", ".", "NodeLabels", "=", "labels", "\n", "}" ]
// SetNodeLabels sets node labels for role
[ "SetNodeLabels", "sets", "node", "labels", "for", "role" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1016-L1018
train
gravitational/teleport
lib/services/role.go
SetMaxSessionTTL
func (r *RoleV2) SetMaxSessionTTL(duration time.Duration) { r.Spec.MaxSessionTTL = Duration(duration) }
go
func (r *RoleV2) SetMaxSessionTTL(duration time.Duration) { r.Spec.MaxSessionTTL = Duration(duration) }
[ "func", "(", "r", "*", "RoleV2", ")", "SetMaxSessionTTL", "(", "duration", "time", ".", "Duration", ")", "{", "r", ".", "Spec", ".", "MaxSessionTTL", "=", "Duration", "(", "duration", ")", "\n", "}" ]
// SetMaxSessionTTL sets a maximum TTL for SSH or Web session
[ "SetMaxSessionTTL", "sets", "a", "maximum", "TTL", "for", "SSH", "or", "Web", "session" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1021-L1023
train
gravitational/teleport
lib/services/role.go
FromSpec
func FromSpec(name string, spec RoleSpecV3) (RoleSet, error) { role, err := NewRole(name, spec) if err != nil { return nil, trace.Wrap(err) } return NewRoleSet(role), nil }
go
func FromSpec(name string, spec RoleSpecV3) (RoleSet, error) { role, err := NewRole(name, spec) if err != nil { return nil, trace.Wrap(err) } return NewRoleSet(role), nil }
[ "func", "FromSpec", "(", "name", "string", ",", "spec", "RoleSpecV3", ")", "(", "RoleSet", ",", "error", ")", "{", "role", ",", "err", ":=", "NewRole", "(", "name", ",", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "NewRoleSet", "(", "role", ")", ",", "nil", "\n", "}" ]
// FromSpec returns new RoleSet created from spec
[ "FromSpec", "returns", "new", "RoleSet", "created", "from", "spec" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1271-L1278
train
gravitational/teleport
lib/services/role.go
NewRole
func NewRole(name string, spec RoleSpecV3) (Role, error) { role := RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: name, Namespace: defaults.Namespace, }, Spec: spec, } if err := role.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } return &role, nil }
go
func NewRole(name string, spec RoleSpecV3) (Role, error) { role := RoleV3{ Kind: KindRole, Version: V3, Metadata: Metadata{ Name: name, Namespace: defaults.Namespace, }, Spec: spec, } if err := role.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } return &role, nil }
[ "func", "NewRole", "(", "name", "string", ",", "spec", "RoleSpecV3", ")", "(", "Role", ",", "error", ")", "{", "role", ":=", "RoleV3", "{", "Kind", ":", "KindRole", ",", "Version", ":", "V3", ",", "Metadata", ":", "Metadata", "{", "Name", ":", "name", ",", "Namespace", ":", "defaults", ".", "Namespace", ",", "}", ",", "Spec", ":", "spec", ",", "}", "\n", "if", "err", ":=", "role", ".", "CheckAndSetDefaults", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "return", "&", "role", ",", "nil", "\n", "}" ]
// NewRole constructs new standard role
[ "NewRole", "constructs", "new", "standard", "role" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1297-L1312
train
gravitational/teleport
lib/services/role.go
FetchRoles
func FetchRoles(roleNames []string, access RoleGetter, traits map[string][]string) (RoleSet, error) { var roles []Role for _, roleName := range roleNames { role, err := access.GetRole(roleName) if err != nil { return nil, trace.Wrap(err) } roles = append(roles, role.ApplyTraits(traits)) } return NewRoleSet(roles...), nil }
go
func FetchRoles(roleNames []string, access RoleGetter, traits map[string][]string) (RoleSet, error) { var roles []Role for _, roleName := range roleNames { role, err := access.GetRole(roleName) if err != nil { return nil, trace.Wrap(err) } roles = append(roles, role.ApplyTraits(traits)) } return NewRoleSet(roles...), nil }
[ "func", "FetchRoles", "(", "roleNames", "[", "]", "string", ",", "access", "RoleGetter", ",", "traits", "map", "[", "string", "]", "[", "]", "string", ")", "(", "RoleSet", ",", "error", ")", "{", "var", "roles", "[", "]", "Role", "\n", "for", "_", ",", "roleName", ":=", "range", "roleNames", "{", "role", ",", "err", ":=", "access", ".", "GetRole", "(", "roleName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "\n", "roles", "=", "append", "(", "roles", ",", "role", ".", "ApplyTraits", "(", "traits", ")", ")", "\n", "}", "\n", "return", "NewRoleSet", "(", "roles", "...", ")", ",", "nil", "\n", "}" ]
// FetchRoles fetches roles by their names, applies the traits to role // variables, and returns the RoleSet.
[ "FetchRoles", "fetches", "roles", "by", "their", "names", "applies", "the", "traits", "to", "role", "variables", "and", "returns", "the", "RoleSet", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1322-L1334
train
gravitational/teleport
lib/services/role.go
NewRoleSet
func NewRoleSet(roles ...Role) RoleSet { // unauthenticated Nop role should not have any privileges // by default, otherwise it is too permissive if len(roles) == 1 && roles[0].GetName() == string(teleport.RoleNop) { return roles } return append(roles, NewImplicitRole()) }
go
func NewRoleSet(roles ...Role) RoleSet { // unauthenticated Nop role should not have any privileges // by default, otherwise it is too permissive if len(roles) == 1 && roles[0].GetName() == string(teleport.RoleNop) { return roles } return append(roles, NewImplicitRole()) }
[ "func", "NewRoleSet", "(", "roles", "...", "Role", ")", "RoleSet", "{", "if", "len", "(", "roles", ")", "==", "1", "&&", "roles", "[", "0", "]", ".", "GetName", "(", ")", "==", "string", "(", "teleport", ".", "RoleNop", ")", "{", "return", "roles", "\n", "}", "\n", "return", "append", "(", "roles", ",", "NewImplicitRole", "(", ")", ")", "\n", "}" ]
// NewRoleSet returns new RoleSet based on the roles
[ "NewRoleSet", "returns", "new", "RoleSet", "based", "on", "the", "roles" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1337-L1344
train
gravitational/teleport
lib/services/role.go
MatchNamespace
func MatchNamespace(selectors []string, namespace string) (bool, string) { for _, n := range selectors { if n == namespace || n == Wildcard { return true, "matched" } } return false, fmt.Sprintf("no match, role selectors %v, server namespace: %v", selectors, namespace) }
go
func MatchNamespace(selectors []string, namespace string) (bool, string) { for _, n := range selectors { if n == namespace || n == Wildcard { return true, "matched" } } return false, fmt.Sprintf("no match, role selectors %v, server namespace: %v", selectors, namespace) }
[ "func", "MatchNamespace", "(", "selectors", "[", "]", "string", ",", "namespace", "string", ")", "(", "bool", ",", "string", ")", "{", "for", "_", ",", "n", ":=", "range", "selectors", "{", "if", "n", "==", "namespace", "||", "n", "==", "Wildcard", "{", "return", "true", ",", "\"matched\"", "\n", "}", "\n", "}", "\n", "return", "false", ",", "fmt", ".", "Sprintf", "(", "\"no match, role selectors %v, server namespace: %v\"", ",", "selectors", ",", "namespace", ")", "\n", "}" ]
// MatchNamespace returns true if given list of namespace matches // target namespace, wildcard matches everything.
[ "MatchNamespace", "returns", "true", "if", "given", "list", "of", "namespace", "matches", "target", "namespace", "wildcard", "matches", "everything", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1351-L1358
train
gravitational/teleport
lib/services/role.go
MatchLogin
func MatchLogin(selectors []string, login string) (bool, string) { for _, l := range selectors { if l == login { return true, "matched" } } return false, fmt.Sprintf("no match, role selectors %v, login: %v", selectors, login) }
go
func MatchLogin(selectors []string, login string) (bool, string) { for _, l := range selectors { if l == login { return true, "matched" } } return false, fmt.Sprintf("no match, role selectors %v, login: %v", selectors, login) }
[ "func", "MatchLogin", "(", "selectors", "[", "]", "string", ",", "login", "string", ")", "(", "bool", ",", "string", ")", "{", "for", "_", ",", "l", ":=", "range", "selectors", "{", "if", "l", "==", "login", "{", "return", "true", ",", "\"matched\"", "\n", "}", "\n", "}", "\n", "return", "false", ",", "fmt", ".", "Sprintf", "(", "\"no match, role selectors %v, login: %v\"", ",", "selectors", ",", "login", ")", "\n", "}" ]
// MatchLogin returns true if attempted login matches any of the logins.
[ "MatchLogin", "returns", "true", "if", "attempted", "login", "matches", "any", "of", "the", "logins", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1361-L1368
train
gravitational/teleport
lib/services/role.go
MatchLabels
func MatchLabels(selector Labels, target map[string]string) (bool, string, error) { // Empty selector matches nothing. if len(selector) == 0 { return false, "no match, empty selector", nil } // *: * matches everything even empty target set. selectorValues := selector[Wildcard] if len(selectorValues) == 1 && selectorValues[0] == Wildcard { return true, "matched", nil } // Perform full match. for key, selectorValues := range selector { targetVal, hasKey := target[key] if !hasKey { return false, fmt.Sprintf("no key match: '%v'", key), nil } if !utils.SliceContainsStr(selectorValues, Wildcard) { result, err := utils.SliceMatchesRegex(targetVal, selectorValues) if err != nil { return false, "", trace.Wrap(err) } else if !result { return false, fmt.Sprintf("no value match: got '%v' want: '%v'", targetVal, selectorValues), nil } } } return true, "matched", nil }
go
func MatchLabels(selector Labels, target map[string]string) (bool, string, error) { // Empty selector matches nothing. if len(selector) == 0 { return false, "no match, empty selector", nil } // *: * matches everything even empty target set. selectorValues := selector[Wildcard] if len(selectorValues) == 1 && selectorValues[0] == Wildcard { return true, "matched", nil } // Perform full match. for key, selectorValues := range selector { targetVal, hasKey := target[key] if !hasKey { return false, fmt.Sprintf("no key match: '%v'", key), nil } if !utils.SliceContainsStr(selectorValues, Wildcard) { result, err := utils.SliceMatchesRegex(targetVal, selectorValues) if err != nil { return false, "", trace.Wrap(err) } else if !result { return false, fmt.Sprintf("no value match: got '%v' want: '%v'", targetVal, selectorValues), nil } } } return true, "matched", nil }
[ "func", "MatchLabels", "(", "selector", "Labels", ",", "target", "map", "[", "string", "]", "string", ")", "(", "bool", ",", "string", ",", "error", ")", "{", "if", "len", "(", "selector", ")", "==", "0", "{", "return", "false", ",", "\"no match, empty selector\"", ",", "nil", "\n", "}", "\n", "selectorValues", ":=", "selector", "[", "Wildcard", "]", "\n", "if", "len", "(", "selectorValues", ")", "==", "1", "&&", "selectorValues", "[", "0", "]", "==", "Wildcard", "{", "return", "true", ",", "\"matched\"", ",", "nil", "\n", "}", "\n", "for", "key", ",", "selectorValues", ":=", "range", "selector", "{", "targetVal", ",", "hasKey", ":=", "target", "[", "key", "]", "\n", "if", "!", "hasKey", "{", "return", "false", ",", "fmt", ".", "Sprintf", "(", "\"no key match: '%v'\"", ",", "key", ")", ",", "nil", "\n", "}", "\n", "if", "!", "utils", ".", "SliceContainsStr", "(", "selectorValues", ",", "Wildcard", ")", "{", "result", ",", "err", ":=", "utils", ".", "SliceMatchesRegex", "(", "targetVal", ",", "selectorValues", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "\"\"", ",", "trace", ".", "Wrap", "(", "err", ")", "\n", "}", "else", "if", "!", "result", "{", "return", "false", ",", "fmt", ".", "Sprintf", "(", "\"no value match: got '%v' want: '%v'\"", ",", "targetVal", ",", "selectorValues", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "true", ",", "\"matched\"", ",", "nil", "\n", "}" ]
// MatchLabels matches selector against target. Empty selector matches // nothing, wildcard matches everything.
[ "MatchLabels", "matches", "selector", "against", "target", ".", "Empty", "selector", "matches", "nothing", "wildcard", "matches", "everything", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1372-L1403
train
gravitational/teleport
lib/services/role.go
RoleNames
func (set RoleSet) RoleNames() []string { out := make([]string, len(set)) for i, r := range set { out[i] = r.GetName() } return out }
go
func (set RoleSet) RoleNames() []string { out := make([]string, len(set)) for i, r := range set { out[i] = r.GetName() } return out }
[ "func", "(", "set", "RoleSet", ")", "RoleNames", "(", ")", "[", "]", "string", "{", "out", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "set", ")", ")", "\n", "for", "i", ",", "r", ":=", "range", "set", "{", "out", "[", "i", "]", "=", "r", ".", "GetName", "(", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
// RoleNames returns a slice with role names
[ "RoleNames", "returns", "a", "slice", "with", "role", "names" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1406-L1412
train
gravitational/teleport
lib/services/role.go
HasRole
func (set RoleSet) HasRole(role string) bool { for _, r := range set { if r.GetName() == role { return true } } return false }
go
func (set RoleSet) HasRole(role string) bool { for _, r := range set { if r.GetName() == role { return true } } return false }
[ "func", "(", "set", "RoleSet", ")", "HasRole", "(", "role", "string", ")", "bool", "{", "for", "_", ",", "r", ":=", "range", "set", "{", "if", "r", ".", "GetName", "(", ")", "==", "role", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasRole checks if the role set has the role
[ "HasRole", "checks", "if", "the", "role", "set", "has", "the", "role" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1415-L1422
train
gravitational/teleport
lib/services/role.go
AdjustSessionTTL
func (set RoleSet) AdjustSessionTTL(ttl time.Duration) time.Duration { for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if maxSessionTTL != 0 && ttl > maxSessionTTL { ttl = maxSessionTTL } } return ttl }
go
func (set RoleSet) AdjustSessionTTL(ttl time.Duration) time.Duration { for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if maxSessionTTL != 0 && ttl > maxSessionTTL { ttl = maxSessionTTL } } return ttl }
[ "func", "(", "set", "RoleSet", ")", "AdjustSessionTTL", "(", "ttl", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "for", "_", ",", "role", ":=", "range", "set", "{", "maxSessionTTL", ":=", "role", ".", "GetOptions", "(", ")", ".", "MaxSessionTTL", ".", "Value", "(", ")", "\n", "if", "maxSessionTTL", "!=", "0", "&&", "ttl", ">", "maxSessionTTL", "{", "ttl", "=", "maxSessionTTL", "\n", "}", "\n", "}", "\n", "return", "ttl", "\n", "}" ]
// AdjustSessionTTL will reduce the requested ttl to lowest max allowed TTL // for this role set, otherwise it returns ttl unchanged
[ "AdjustSessionTTL", "will", "reduce", "the", "requested", "ttl", "to", "lowest", "max", "allowed", "TTL", "for", "this", "role", "set", "otherwise", "it", "returns", "ttl", "unchanged" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1426-L1434
train
gravitational/teleport
lib/services/role.go
AdjustClientIdleTimeout
func (set RoleSet) AdjustClientIdleTimeout(timeout time.Duration) time.Duration { if timeout < 0 { timeout = 0 } for _, role := range set { roleTimeout := role.GetOptions().ClientIdleTimeout // 0 means not set, so it can't be most restrictive, disregard it too if roleTimeout.Duration() <= 0 { continue } switch { // in case if timeout is 0, means that incoming value // does not restrict the idle timeout, pick any other value // set by the role case timeout == 0: timeout = roleTimeout.Duration() case roleTimeout.Duration() < timeout: timeout = roleTimeout.Duration() } } return timeout }
go
func (set RoleSet) AdjustClientIdleTimeout(timeout time.Duration) time.Duration { if timeout < 0 { timeout = 0 } for _, role := range set { roleTimeout := role.GetOptions().ClientIdleTimeout // 0 means not set, so it can't be most restrictive, disregard it too if roleTimeout.Duration() <= 0 { continue } switch { // in case if timeout is 0, means that incoming value // does not restrict the idle timeout, pick any other value // set by the role case timeout == 0: timeout = roleTimeout.Duration() case roleTimeout.Duration() < timeout: timeout = roleTimeout.Duration() } } return timeout }
[ "func", "(", "set", "RoleSet", ")", "AdjustClientIdleTimeout", "(", "timeout", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "if", "timeout", "<", "0", "{", "timeout", "=", "0", "\n", "}", "\n", "for", "_", ",", "role", ":=", "range", "set", "{", "roleTimeout", ":=", "role", ".", "GetOptions", "(", ")", ".", "ClientIdleTimeout", "\n", "if", "roleTimeout", ".", "Duration", "(", ")", "<=", "0", "{", "continue", "\n", "}", "\n", "switch", "{", "case", "timeout", "==", "0", ":", "timeout", "=", "roleTimeout", ".", "Duration", "(", ")", "\n", "case", "roleTimeout", ".", "Duration", "(", ")", "<", "timeout", ":", "timeout", "=", "roleTimeout", ".", "Duration", "(", ")", "\n", "}", "\n", "}", "\n", "return", "timeout", "\n", "}" ]
// AdjustClientIdleTimeout adjusts requested idle timeout // to the lowest max allowed timeout, the most restrictive // option will be picked, negative values will be assumed as 0
[ "AdjustClientIdleTimeout", "adjusts", "requested", "idle", "timeout", "to", "the", "lowest", "max", "allowed", "timeout", "the", "most", "restrictive", "option", "will", "be", "picked", "negative", "values", "will", "be", "assumed", "as", "0" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1439-L1460
train
gravitational/teleport
lib/services/role.go
AdjustDisconnectExpiredCert
func (set RoleSet) AdjustDisconnectExpiredCert(disconnect bool) bool { for _, role := range set { if role.GetOptions().DisconnectExpiredCert.Value() { disconnect = true } } return disconnect }
go
func (set RoleSet) AdjustDisconnectExpiredCert(disconnect bool) bool { for _, role := range set { if role.GetOptions().DisconnectExpiredCert.Value() { disconnect = true } } return disconnect }
[ "func", "(", "set", "RoleSet", ")", "AdjustDisconnectExpiredCert", "(", "disconnect", "bool", ")", "bool", "{", "for", "_", ",", "role", ":=", "range", "set", "{", "if", "role", ".", "GetOptions", "(", ")", ".", "DisconnectExpiredCert", ".", "Value", "(", ")", "{", "disconnect", "=", "true", "\n", "}", "\n", "}", "\n", "return", "disconnect", "\n", "}" ]
// AdjustDisconnectExpiredCert adjusts the value based on the role set // the most restrictive option will be picked
[ "AdjustDisconnectExpiredCert", "adjusts", "the", "value", "based", "on", "the", "role", "set", "the", "most", "restrictive", "option", "will", "be", "picked" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1464-L1471
train
gravitational/teleport
lib/services/role.go
CheckKubeGroups
func (set RoleSet) CheckKubeGroups(ttl time.Duration) ([]string, error) { groups := make(map[string]bool) var matchedTTL bool for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if ttl <= maxSessionTTL && maxSessionTTL != 0 { matchedTTL = true for _, group := range role.GetKubeGroups(Allow) { groups[group] = true } } } if !matchedTTL { return nil, trace.AccessDenied("this user cannot request kubernetes access for %v", ttl) } if len(groups) == 0 { return nil, trace.AccessDenied("this user cannot request kubernetes access, has no assigned groups") } out := make([]string, 0, len(groups)) for group := range groups { out = append(out, group) } return out, nil }
go
func (set RoleSet) CheckKubeGroups(ttl time.Duration) ([]string, error) { groups := make(map[string]bool) var matchedTTL bool for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if ttl <= maxSessionTTL && maxSessionTTL != 0 { matchedTTL = true for _, group := range role.GetKubeGroups(Allow) { groups[group] = true } } } if !matchedTTL { return nil, trace.AccessDenied("this user cannot request kubernetes access for %v", ttl) } if len(groups) == 0 { return nil, trace.AccessDenied("this user cannot request kubernetes access, has no assigned groups") } out := make([]string, 0, len(groups)) for group := range groups { out = append(out, group) } return out, nil }
[ "func", "(", "set", "RoleSet", ")", "CheckKubeGroups", "(", "ttl", "time", ".", "Duration", ")", "(", "[", "]", "string", ",", "error", ")", "{", "groups", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "var", "matchedTTL", "bool", "\n", "for", "_", ",", "role", ":=", "range", "set", "{", "maxSessionTTL", ":=", "role", ".", "GetOptions", "(", ")", ".", "MaxSessionTTL", ".", "Value", "(", ")", "\n", "if", "ttl", "<=", "maxSessionTTL", "&&", "maxSessionTTL", "!=", "0", "{", "matchedTTL", "=", "true", "\n", "for", "_", ",", "group", ":=", "range", "role", ".", "GetKubeGroups", "(", "Allow", ")", "{", "groups", "[", "group", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "!", "matchedTTL", "{", "return", "nil", ",", "trace", ".", "AccessDenied", "(", "\"this user cannot request kubernetes access for %v\"", ",", "ttl", ")", "\n", "}", "\n", "if", "len", "(", "groups", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "AccessDenied", "(", "\"this user cannot request kubernetes access, has no assigned groups\"", ")", "\n", "}", "\n", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "groups", ")", ")", "\n", "for", "group", ":=", "range", "groups", "{", "out", "=", "append", "(", "out", ",", "group", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// CheckKubeGroups check if role can login into kubernetes // and returns a combined list of allowed groups
[ "CheckKubeGroups", "check", "if", "role", "can", "login", "into", "kubernetes", "and", "returns", "a", "combined", "list", "of", "allowed", "groups" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1475-L1498
train
gravitational/teleport
lib/services/role.go
CheckLoginDuration
func (set RoleSet) CheckLoginDuration(ttl time.Duration) ([]string, error) { logins := make(map[string]bool) var matchedTTL bool for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if ttl <= maxSessionTTL && maxSessionTTL != 0 { matchedTTL = true for _, login := range role.GetLogins(Allow) { logins[login] = true } } } if !matchedTTL { return nil, trace.AccessDenied("this user cannot request a certificate for %v", ttl) } if len(logins) == 0 { return nil, trace.AccessDenied("this user cannot create SSH sessions, has no allowed logins") } out := make([]string, 0, len(logins)) for login := range logins { out = append(out, login) } return out, nil }
go
func (set RoleSet) CheckLoginDuration(ttl time.Duration) ([]string, error) { logins := make(map[string]bool) var matchedTTL bool for _, role := range set { maxSessionTTL := role.GetOptions().MaxSessionTTL.Value() if ttl <= maxSessionTTL && maxSessionTTL != 0 { matchedTTL = true for _, login := range role.GetLogins(Allow) { logins[login] = true } } } if !matchedTTL { return nil, trace.AccessDenied("this user cannot request a certificate for %v", ttl) } if len(logins) == 0 { return nil, trace.AccessDenied("this user cannot create SSH sessions, has no allowed logins") } out := make([]string, 0, len(logins)) for login := range logins { out = append(out, login) } return out, nil }
[ "func", "(", "set", "RoleSet", ")", "CheckLoginDuration", "(", "ttl", "time", ".", "Duration", ")", "(", "[", "]", "string", ",", "error", ")", "{", "logins", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "var", "matchedTTL", "bool", "\n", "for", "_", ",", "role", ":=", "range", "set", "{", "maxSessionTTL", ":=", "role", ".", "GetOptions", "(", ")", ".", "MaxSessionTTL", ".", "Value", "(", ")", "\n", "if", "ttl", "<=", "maxSessionTTL", "&&", "maxSessionTTL", "!=", "0", "{", "matchedTTL", "=", "true", "\n", "for", "_", ",", "login", ":=", "range", "role", ".", "GetLogins", "(", "Allow", ")", "{", "logins", "[", "login", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "!", "matchedTTL", "{", "return", "nil", ",", "trace", ".", "AccessDenied", "(", "\"this user cannot request a certificate for %v\"", ",", "ttl", ")", "\n", "}", "\n", "if", "len", "(", "logins", ")", "==", "0", "{", "return", "nil", ",", "trace", ".", "AccessDenied", "(", "\"this user cannot create SSH sessions, has no allowed logins\"", ")", "\n", "}", "\n", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "logins", ")", ")", "\n", "for", "login", ":=", "range", "logins", "{", "out", "=", "append", "(", "out", ",", "login", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// CheckLoginDuration checks if role set can login up to given duration and // returns a combined list of allowed logins.
[ "CheckLoginDuration", "checks", "if", "role", "set", "can", "login", "up", "to", "given", "duration", "and", "returns", "a", "combined", "list", "of", "allowed", "logins", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1502-L1526
train
gravitational/teleport
lib/services/role.go
CanForwardAgents
func (set RoleSet) CanForwardAgents() bool { for _, role := range set { if role.GetOptions().ForwardAgent.Value() { return true } } return false }
go
func (set RoleSet) CanForwardAgents() bool { for _, role := range set { if role.GetOptions().ForwardAgent.Value() { return true } } return false }
[ "func", "(", "set", "RoleSet", ")", "CanForwardAgents", "(", ")", "bool", "{", "for", "_", ",", "role", ":=", "range", "set", "{", "if", "role", ".", "GetOptions", "(", ")", ".", "ForwardAgent", ".", "Value", "(", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// CanForwardAgents returns true if role set allows forwarding agents.
[ "CanForwardAgents", "returns", "true", "if", "role", "set", "allows", "forwarding", "agents", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1586-L1593
train
gravitational/teleport
lib/services/role.go
CanPortForward
func (set RoleSet) CanPortForward() bool { for _, role := range set { if BoolDefaultTrue(role.GetOptions().PortForwarding) { return true } } return false }
go
func (set RoleSet) CanPortForward() bool { for _, role := range set { if BoolDefaultTrue(role.GetOptions().PortForwarding) { return true } } return false }
[ "func", "(", "set", "RoleSet", ")", "CanPortForward", "(", ")", "bool", "{", "for", "_", ",", "role", ":=", "range", "set", "{", "if", "BoolDefaultTrue", "(", "role", ".", "GetOptions", "(", ")", ".", "PortForwarding", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// CanPortForward returns true if a role in the RoleSet allows port forwarding.
[ "CanPortForward", "returns", "true", "if", "a", "role", "in", "the", "RoleSet", "allows", "port", "forwarding", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1596-L1603
train
gravitational/teleport
lib/services/role.go
CertificateFormat
func (set RoleSet) CertificateFormat() string { var formats []string for _, role := range set { // get the certificate format for each individual role. if a role does not // have a certificate format (like implicit roles) skip over it certificateFormat := role.GetOptions().CertificateFormat if certificateFormat == "" { continue } formats = append(formats, certificateFormat) } // if no formats were found, return standard if len(formats) == 0 { return teleport.CertificateFormatStandard } // sort the slice so the most permissive is the first element sort.Slice(formats, func(i, j int) bool { return certificatePriority(formats[i]) < certificatePriority(formats[j]) }) return formats[0] }
go
func (set RoleSet) CertificateFormat() string { var formats []string for _, role := range set { // get the certificate format for each individual role. if a role does not // have a certificate format (like implicit roles) skip over it certificateFormat := role.GetOptions().CertificateFormat if certificateFormat == "" { continue } formats = append(formats, certificateFormat) } // if no formats were found, return standard if len(formats) == 0 { return teleport.CertificateFormatStandard } // sort the slice so the most permissive is the first element sort.Slice(formats, func(i, j int) bool { return certificatePriority(formats[i]) < certificatePriority(formats[j]) }) return formats[0] }
[ "func", "(", "set", "RoleSet", ")", "CertificateFormat", "(", ")", "string", "{", "var", "formats", "[", "]", "string", "\n", "for", "_", ",", "role", ":=", "range", "set", "{", "certificateFormat", ":=", "role", ".", "GetOptions", "(", ")", ".", "CertificateFormat", "\n", "if", "certificateFormat", "==", "\"\"", "{", "continue", "\n", "}", "\n", "formats", "=", "append", "(", "formats", ",", "certificateFormat", ")", "\n", "}", "\n", "if", "len", "(", "formats", ")", "==", "0", "{", "return", "teleport", ".", "CertificateFormatStandard", "\n", "}", "\n", "sort", ".", "Slice", "(", "formats", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "certificatePriority", "(", "formats", "[", "i", "]", ")", "<", "certificatePriority", "(", "formats", "[", "j", "]", ")", "\n", "}", ")", "\n", "return", "formats", "[", "0", "]", "\n", "}" ]
// CertificateFormat returns the most permissive certificate format in a // RoleSet.
[ "CertificateFormat", "returns", "the", "most", "permissive", "certificate", "format", "in", "a", "RoleSet", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1607-L1632
train
gravitational/teleport
lib/services/role.go
CheckAgentForward
func (set RoleSet) CheckAgentForward(login string) error { // check if we have permission to login and forward agent. we don't check // for deny rules because if you can't forward an agent if you can't login // in the first place. for _, role := range set { for _, l := range role.GetLogins(Allow) { if role.GetOptions().ForwardAgent.Value() && l == login { return nil } } } return trace.AccessDenied("%v can not forward agent for %v", set, login) }
go
func (set RoleSet) CheckAgentForward(login string) error { // check if we have permission to login and forward agent. we don't check // for deny rules because if you can't forward an agent if you can't login // in the first place. for _, role := range set { for _, l := range role.GetLogins(Allow) { if role.GetOptions().ForwardAgent.Value() && l == login { return nil } } } return trace.AccessDenied("%v can not forward agent for %v", set, login) }
[ "func", "(", "set", "RoleSet", ")", "CheckAgentForward", "(", "login", "string", ")", "error", "{", "for", "_", ",", "role", ":=", "range", "set", "{", "for", "_", ",", "l", ":=", "range", "role", ".", "GetLogins", "(", "Allow", ")", "{", "if", "role", ".", "GetOptions", "(", ")", ".", "ForwardAgent", ".", "Value", "(", ")", "&&", "l", "==", "login", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "trace", ".", "AccessDenied", "(", "\"%v can not forward agent for %v\"", ",", "set", ",", "login", ")", "\n", "}" ]
// CheckAgentForward checks if the role can request to forward the SSH agent // for this user.
[ "CheckAgentForward", "checks", "if", "the", "role", "can", "request", "to", "forward", "the", "SSH", "agent", "for", "this", "user", "." ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1649-L1661
train
gravitational/teleport
lib/services/role.go
Clone
func (l Labels) Clone() Labels { if l == nil { return nil } out := make(Labels, len(l)) for key, vals := range l { cvals := make([]string, len(vals)) copy(cvals, vals) out[key] = cvals } return out }
go
func (l Labels) Clone() Labels { if l == nil { return nil } out := make(Labels, len(l)) for key, vals := range l { cvals := make([]string, len(vals)) copy(cvals, vals) out[key] = cvals } return out }
[ "func", "(", "l", "Labels", ")", "Clone", "(", ")", "Labels", "{", "if", "l", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "make", "(", "Labels", ",", "len", "(", "l", ")", ")", "\n", "for", "key", ",", "vals", ":=", "range", "l", "{", "cvals", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "vals", ")", ")", "\n", "copy", "(", "cvals", ",", "vals", ")", "\n", "out", "[", "key", "]", "=", "cvals", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Clone returns non-shallow copy of the labels set
[ "Clone", "returns", "non", "-", "shallow", "copy", "of", "the", "labels", "set" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1816-L1827
train
gravitational/teleport
lib/services/role.go
Equals
func (l Labels) Equals(o Labels) bool { if len(l) != len(o) { return false } for key := range l { if !utils.StringSlicesEqual(l[key], o[key]) { return false } } return true }
go
func (l Labels) Equals(o Labels) bool { if len(l) != len(o) { return false } for key := range l { if !utils.StringSlicesEqual(l[key], o[key]) { return false } } return true }
[ "func", "(", "l", "Labels", ")", "Equals", "(", "o", "Labels", ")", "bool", "{", "if", "len", "(", "l", ")", "!=", "len", "(", "o", ")", "{", "return", "false", "\n", "}", "\n", "for", "key", ":=", "range", "l", "{", "if", "!", "utils", ".", "StringSlicesEqual", "(", "l", "[", "key", "]", ",", "o", "[", "key", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Equals returns true if two label sets are equal
[ "Equals", "returns", "true", "if", "two", "label", "sets", "are", "equal" ]
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/role.go#L1830-L1840
train