forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46369ef
commit 0c425d3
Showing
53 changed files
with
4,533 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
flymake* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
ETCD_NODE1 := http://127.0.0.1:4001 | ||
ETCD_NODE2 := http://127.0.0.1:4002 | ||
ETCD_NODE3 := http://127.0.0.1:4003 | ||
ETCD_NODES := ${ETCD_NODE1},${ETCD_NODE2},${ETCD_NODE3} | ||
ETCD_FLAGS := TELEPORT_TEST_ETCD_NODES=${ETCD_NODES} | ||
|
||
test: clean | ||
go test -v ./... -cover | ||
|
||
test-with-etcd: clean | ||
${ETCD_FLAGS} go test -v ./... -cover | ||
|
||
clean: | ||
find . -name flymake_* -delete | ||
|
||
test-package: clean | ||
go test -v ./$(p) | ||
|
||
test-package-with-etcd: clean | ||
${ETCD_FLAGS} go test -v ./$(p) | ||
|
||
update: | ||
rm -rf Godeps/ | ||
find . -iregex .*go | xargs sed -i 's:".*Godeps/_workspace/src/:":g' | ||
godep save -r ./... | ||
|
||
test-grep-package: clean | ||
go test -v ./$(p) -check.f=$(e) | ||
|
||
cover-package: clean | ||
go test -v ./$(p) -coverprofile=/tmp/coverage.out | ||
go tool cover -html=/tmp/coverage.out | ||
|
||
cover-package-with-etcd: clean | ||
${ETCD_FLAGS} go test -v ./$(p) -coverprofile=/tmp/coverage.out | ||
go tool cover -html=/tmp/coverage.out | ||
|
||
install: clean | ||
go install github.com/gravitational/teleport/teleport | ||
|
||
run: install | ||
teleport -addr=localhost:2022\ | ||
-log=console\ | ||
-logSeverity=INFO\ | ||
-shell=/bin/bash\ | ||
-hostCert=./fixtures/keys/hosts/node.gravitational.io-cert.pub\ | ||
-hostPrivateKey=./fixtures/keys/hosts/node.gravitational.io\ | ||
-authSrv\ | ||
-backend=etcd\ | ||
-backendConfig='{"nodes": ["${ETCD_NODE1}","${ETCD_NODE2}","${ETCD_NODE3}"], "key": "/teleport"}'\ | ||
|
||
profile: | ||
go tool pprof http://localhost:6060/debug/pprof/profile | ||
|
||
sloccount: | ||
find . -path ./Godeps -prune -o -name "*.go" -print0 | xargs -0 wc -l | ||
|
||
# sets development etcd keys | ||
set-etcd: | ||
bash ./scripts/etcd.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// package auth implements certificate signing authority and access control server | ||
// Authority server is composed of several parts: | ||
// | ||
// * Authority server itself that implements signing and acl logic | ||
// * HTTP server wrapper for authority server | ||
// * HTTP client wrapper | ||
// | ||
package auth | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gravitational/teleport/backend" | ||
) | ||
|
||
// Authority implements minimal key-management facility for generating OpenSSH | ||
//compatible public/private key pairs and OpenSSH certificates | ||
type Authority interface { | ||
GenerateKeyPair(passphrase string) ([]byte, []byte, error) | ||
|
||
// GenerateHostCert generates host certificate, it takes pkey as a signing private key (host certificate authority) | ||
GenerateHostCert(pkey, key []byte, id, hostname string, ttl time.Duration) ([]byte, error) | ||
|
||
// GenerateHostCert generates user certificate, it takes pkey as a signing private key (user certificate authority) | ||
GenerateUserCert(pkey, key []byte, id, username string, ttl time.Duration) ([]byte, error) | ||
} | ||
|
||
func NewAuthServer(b backend.Backend, a Authority) *AuthServer { | ||
return &AuthServer{ | ||
b: b, | ||
a: a, | ||
} | ||
} | ||
|
||
// AuthServer implements key signing, generation and ACL functionality used by teleport | ||
type AuthServer struct { | ||
b backend.Backend | ||
a Authority | ||
} | ||
|
||
// UpsertUserKey takes user's public key, generates certificate for it | ||
// and adds it to the authorized keys database. It returns certificate signed by user CA in case of success, | ||
// error otherwise. The certificate will be valid for the duration of the ttl passed in. | ||
func (s *AuthServer) UpsertUserKey(user string, key backend.AuthorizedKey, ttl time.Duration) ([]byte, error) { | ||
cert, err := s.GenerateUserCert(key.Value, key.ID, user, ttl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
key.Value = cert | ||
if err := s.b.UpsertUserKey(user, key, ttl); err != nil { | ||
return nil, err | ||
} | ||
return cert, nil | ||
} | ||
|
||
func (s *AuthServer) GetUsers() ([]string, error) { | ||
return s.b.GetUsers() | ||
} | ||
|
||
func (s *AuthServer) DeleteUser(user string) error { | ||
return s.b.DeleteUser(user) | ||
} | ||
|
||
func (s *AuthServer) GetUserKeys(user string) ([]backend.AuthorizedKey, error) { | ||
return s.b.GetUserKeys(user) | ||
} | ||
|
||
// DeleteUserKey deletes user key by given ID | ||
func (s *AuthServer) DeleteUserKey(user, key string) error { | ||
return s.b.DeleteUserKey(user, key) | ||
} | ||
|
||
// GenerateKeyPair generates private and public key pair of OpenSSH style certificates | ||
func (s *AuthServer) GenerateKeyPair(pass string) ([]byte, []byte, error) { | ||
return s.a.GenerateKeyPair(pass) | ||
} | ||
|
||
// ResetHostCA generates host certificate authority and updates the backend | ||
func (s *AuthServer) ResetHostCA(pass string) error { | ||
priv, pub, err := s.a.GenerateKeyPair(pass) | ||
if err != nil { | ||
return err | ||
} | ||
return s.b.UpsertHostCA(backend.CA{Pub: pub, Priv: priv}) | ||
} | ||
|
||
// ResetHostCA generates user certificate authority and updates the backend | ||
func (s *AuthServer) ResetUserCA(pass string) error { | ||
priv, pub, err := s.a.GenerateKeyPair(pass) | ||
if err != nil { | ||
return err | ||
} | ||
return s.b.UpsertUserCA(backend.CA{Pub: pub, Priv: priv}) | ||
} | ||
|
||
// GetHostCAPub returns a public key for host key signing authority | ||
func (s *AuthServer) GetHostCAPub() ([]byte, error) { | ||
return s.b.GetHostCAPub() | ||
} | ||
|
||
// GetHostCAPub returns a public key for user key signing authority | ||
func (s *AuthServer) GetUserCAPub() ([]byte, error) { | ||
return s.b.GetUserCAPub() | ||
} | ||
|
||
// GenerateHostCert generates host certificate, it takes pkey as a signing private key (host certificate authority) | ||
func (s *AuthServer) GenerateHostCert(key []byte, id, hostname string, ttl time.Duration) ([]byte, error) { | ||
hk, err := s.b.GetHostCA() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.a.GenerateHostCert(hk.Priv, key, id, hostname, ttl) | ||
} | ||
|
||
// GenerateHostCert generates user certificate, it takes pkey as a signing private key (user certificate authority) | ||
func (s *AuthServer) GenerateUserCert(key []byte, id, username string, ttl time.Duration) ([]byte, error) { | ||
hk, err := s.b.GetUserCA() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.a.GenerateUserCert(hk.Priv, key, id, username, ttl) | ||
} | ||
|
||
const Week = time.Hour * 24 * 7 |
Oops, something went wrong.