Skip to content

Commit

Permalink
Cache per-cluster SSH certificates under ~/.tsh
Browse files Browse the repository at this point in the history
```diff
 ~/.tsh/
 └── keys
    ├── one.example.com            --> Proxy hostname
    │   ├── certs.pem              --> TLS CA certs for the Teleport CA
    │   ├── foo                    --> RSA Private Key for user "foo"
    │   ├── foo.pub                --> Public Key
-   │   ├── foo-cert.pub           --> SSH certificate for proxies and nodes
    │   ├── foo-x509.pem           --> TLS client certificate for Auth Server
+   │   ├── foo-ssh                --> SSH certs for user "foo"
+   │   │   ├── root-cert.pub      --> SSH cert for Teleport cluster "root"
+   │   │   └── leaf-cert.pub      --> SSH cert for Teleport cluster "leaf"
```

When `-J` is provided, this also loads/reissues the SSH cert for the
cluster associated with the jumphost's certificate.
  • Loading branch information
andrejtokarcik authored and awly committed Mar 30, 2021
1 parent 3dd1afc commit f3af7a5
Show file tree
Hide file tree
Showing 18 changed files with 1,167 additions and 1,157 deletions.
2 changes: 1 addition & 1 deletion api/client/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func FullProfilePath(dir string) string {
// defaultProfilePath retrieves the default path of the TSH profile.
func defaultProfilePath() string {
home := os.TempDir()
if u, err := user.Current(); err == nil {
if u, err := user.Current(); err == nil && u.HomeDir != "" {
home = u.HomeDir
}
return filepath.Join(home, profileDir)
Expand Down
4 changes: 2 additions & 2 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ type UserCreds struct {

// SetupUserCreds sets up user credentials for client
func SetupUserCreds(tc *client.TeleportClient, proxyHost string, creds UserCreds) error {
_, err := tc.AddKey(proxyHost, &creds.Key)
_, err := tc.AddKey(&creds.Key)
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -1209,7 +1209,7 @@ func (i *TeleInstance) NewClient(cfg ClientConfig) (*client.TeleportClient, erro
if user.Key == nil {
return nil, trace.BadParameter("user %q has no key", cfg.Login)
}
_, err = tc.AddKey(cfg.Host, user.Key)
_, err = tc.AddKey(user.Key)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
24 changes: 14 additions & 10 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3430,9 +3430,10 @@ func (s *IntSuite) TestRotateSuccess(c *check.C) {
defer svc.Shutdown(context.TODO())

cfg := ClientConfig{
Login: s.me.Username,
Host: Loopback,
Port: t.GetPortSSHInt(),
Login: s.me.Username,
Cluster: Site,
Host: Loopback,
Port: t.GetPortSSHInt(),
}
clt, err := t.NewClientWithCreds(cfg, *initialCreds)
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -3577,9 +3578,10 @@ func (s *IntSuite) TestRotateRollback(c *check.C) {
c.Assert(err, check.IsNil)

cfg := ClientConfig{
Login: s.me.Username,
Host: Loopback,
Port: t.GetPortSSHInt(),
Login: s.me.Username,
Cluster: Site,
Host: Loopback,
Port: t.GetPortSSHInt(),
}
clt, err := t.NewClientWithCreds(cfg, *initialCreds)
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -4353,8 +4355,9 @@ func (s *IntSuite) TestList(c *check.C) {

// Create a Teleport client.
cfg := ClientConfig{
Login: tt.inLogin,
Port: t.GetPortSSHInt(),
Login: tt.inLogin,
Cluster: Site,
Port: t.GetPortSSHInt(),
}
userClt, err := t.NewClientWithCreds(cfg, *initialCreds)
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -4452,8 +4455,9 @@ func (s *IntSuite) TestCmdLabels(c *check.C) {

for _, tt := range tts {
cfg := ClientConfig{
Login: s.me.Username,
Labels: tt.labels,
Login: s.me.Username,
Cluster: Site,
Labels: tt.labels,
}

output, err := runCommand(t, tt.command, cfg, 1)
Expand Down
Loading

0 comments on commit f3af7a5

Please sign in to comment.