mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-28 02:08:13 +08:00
Brought back configure/cstrings
This commit is contained in:
Generated
+4
@@ -5,6 +5,10 @@
|
||||
"./..."
|
||||
],
|
||||
"Deps": [
|
||||
{
|
||||
"ImportPath": "github.com/gravitational/configure/cstrings",
|
||||
"Rev": "be52937128b38f1d99787bb476c789e2af1147f1"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/Sirupsen/logrus",
|
||||
"Comment": "v0.9.0",
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/configure/cstrings"
|
||||
"github.com/gravitational/teleport"
|
||||
"github.com/gravitational/teleport/lib/backend/encryptedbk"
|
||||
"github.com/gravitational/teleport/lib/backend/encryptedbk/encryptor"
|
||||
@@ -152,7 +153,7 @@ func (s *AuthServer) SignIn(user string, password []byte) (string, error) {
|
||||
}
|
||||
|
||||
func (s *AuthServer) GenerateToken(nodeName string, role teleport.Role, ttl time.Duration) (string, error) {
|
||||
if !utils.IsValidDomainName(nodeName) {
|
||||
if !cstrings.IsValidDomainName(nodeName) {
|
||||
return "", trace.Wrap(teleport.BadParameter("nodeName",
|
||||
fmt.Sprintf("'%v' is not a valid dns name", nodeName)))
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/configure/cstrings"
|
||||
"github.com/gravitational/teleport"
|
||||
"github.com/gravitational/teleport/lib/services"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/gokyle/hotp"
|
||||
@@ -49,12 +49,12 @@ var TokenTTLAfterUse = time.Second * 10
|
||||
//
|
||||
// allowedLogins are linux user logins allowed for the new user to use
|
||||
func (s *AuthServer) CreateSignupToken(user string, allowedLogins []string) (string, error) {
|
||||
if !utils.IsValidUnixUser(user) {
|
||||
if !cstrings.IsValidUnixUser(user) {
|
||||
return "", trace.Wrap(
|
||||
teleport.BadParameter("user", fmt.Sprintf("'%v' is not a valid user name", user)))
|
||||
}
|
||||
for _, login := range allowedLogins {
|
||||
if !utils.IsValidUnixUser(login) {
|
||||
if !cstrings.IsValidUnixUser(login) {
|
||||
return "", trace.Wrap(teleport.BadParameter(
|
||||
"allowedLogins", fmt.Sprintf("'%v' is not a valid user name", login)))
|
||||
}
|
||||
|
||||
@@ -234,7 +234,6 @@ func (s *HangoutsSuite) TestHangout(c *C) {
|
||||
osUser := u.Username
|
||||
nodeListeningAddress := "localhost:41003"
|
||||
authListeningAddress := "localhost:41004"
|
||||
DefaultSSHShell = "/bin/sh"
|
||||
|
||||
// Initializing tsh share
|
||||
hangoutServer, err := New(s.reverseTunnelAddress, nodeListeningAddress,
|
||||
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/configure/cstrings"
|
||||
|
||||
"github.com/gravitational/teleport"
|
||||
"github.com/gravitational/teleport/lib/auth"
|
||||
"github.com/gravitational/teleport/lib/limiter"
|
||||
@@ -343,7 +345,7 @@ func (s *server) keyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permiss
|
||||
|
||||
func (s *server) upsertRegularSite(conn net.Conn, sshConn *ssh.ServerConn) (*tunnelSite, error) {
|
||||
domainName := sshConn.Permissions.Extensions[extAuthority]
|
||||
if !utils.IsValidDomainName(domainName) {
|
||||
if !cstrings.IsValidDomainName(domainName) {
|
||||
return nil, trace.Wrap(teleport.BadParameter(
|
||||
"authDomain", fmt.Sprintf("'%v' is a bad domain name", domainName)))
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,9 +24,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/configure/cstrings"
|
||||
"github.com/gravitational/teleport"
|
||||
"github.com/gravitational/teleport/lib/backend"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
|
||||
"github.com/gravitational/trace"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -68,7 +68,7 @@ func (c *CertAuthID) Check() error {
|
||||
if err := c.Type.Check(); err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if !utils.IsValidDomainName(c.DomainName) {
|
||||
if !cstrings.IsValidDomainName(c.DomainName) {
|
||||
return trace.Wrap(&teleport.BadParameterError{
|
||||
Param: "DomainName",
|
||||
Err: fmt.Sprintf("'%v' is a bad domain name", c.DomainName),
|
||||
|
||||
+3
-3
@@ -27,9 +27,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gravitational/configure/cstrings"
|
||||
"github.com/gravitational/teleport"
|
||||
"github.com/gravitational/teleport/lib/backend"
|
||||
"github.com/gravitational/teleport/lib/utils"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/gokyle/hotp"
|
||||
@@ -90,7 +90,7 @@ func (s *WebService) GetUsers() ([]User, error) {
|
||||
|
||||
// UpsertUser updates parameters about user
|
||||
func (s *WebService) UpsertUser(user User) error {
|
||||
if !utils.IsValidUnixUser(user.Name) {
|
||||
if !cstrings.IsValidUnixUser(user.Name) {
|
||||
return trace.Wrap(
|
||||
teleport.BadParameter("user.Name", fmt.Sprintf("'%v is not a valid unix username'", user.Name)))
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (s *WebService) UpsertUser(user User) error {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
for _, l := range user.AllowedLogins {
|
||||
if !utils.IsValidUnixUser(l) {
|
||||
if !cstrings.IsValidUnixUser(l) {
|
||||
return trace.Wrap(
|
||||
teleport.BadParameter("login", fmt.Sprintf("'%v is not a valid unix username'", l)))
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Gravitational, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func TestValidators(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
type ValidatorsSuite struct {
|
||||
}
|
||||
|
||||
var _ = check.Suite(&ValidatorsSuite{})
|
||||
|
||||
func (s *ValidatorsSuite) TestUnixUsers(c *check.C) {
|
||||
// good users
|
||||
c.Assert(IsValidUnixUser("user"), check.Equals, true)
|
||||
|
||||
// bad users:
|
||||
c.Assert(IsValidUnixUser("User"), check.Equals, false)
|
||||
c.Assert(IsValidUnixUser(""), check.Equals, false)
|
||||
c.Assert(IsValidUnixUser("*()"), check.Equals, false)
|
||||
longName := strings.Repeat("a", 33)
|
||||
c.Assert(IsValidUnixUser(longName), check.Equals, false)
|
||||
|
||||
}
|
||||
|
||||
func (s *ValidatorsSuite) TestDomains(c *check.C) {
|
||||
badDomains := []string{
|
||||
"",
|
||||
strings.Repeat("a", 256),
|
||||
"((*23*",
|
||||
"one..two",
|
||||
}
|
||||
for _, d := range badDomains {
|
||||
c.Assert(IsValidDomainName(d), check.Equals, false)
|
||||
}
|
||||
goodDomains := []string{
|
||||
"one",
|
||||
"one.two.three",
|
||||
strings.Repeat("a", 60) + ".com",
|
||||
}
|
||||
for _, d := range goodDomains {
|
||||
c.Assert(IsValidDomainName(d), check.Equals, true)
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+1
-30
@@ -1,33 +1,4 @@
|
||||
/*
|
||||
Copyright 2015 Gravitational, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var usersRe = regexp.MustCompile("^[a-z_][a-z0-9_-]*$")
|
||||
|
||||
// IsValidUnixUser returns true if passed string appears to
|
||||
func IsValidUnixUser(u string) bool {
|
||||
if len(u) > 32 {
|
||||
return false
|
||||
}
|
||||
return usersRe.MatchString(u)
|
||||
}
|
||||
package cstrings
|
||||
|
||||
// IsValidDomainName is a primitive domain name checker
|
||||
// taken from go standard library
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package cstrings
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var usersRe = regexp.MustCompile("^[a-z_][a-z0-9_-]*$")
|
||||
|
||||
// IsValidUnixUser returns true if passed string appears to
|
||||
func IsValidUnixUser(u string) bool {
|
||||
if len(u) > 32 {
|
||||
return false
|
||||
}
|
||||
return usersRe.MatchString(u)
|
||||
}
|
||||
Reference in New Issue
Block a user