Skip to content

Commit

Permalink
Correctly validate JWT CA on bootstrap (#8128)
Browse files Browse the repository at this point in the history
Presently, teleport start --bootstrap state.yaml fails due to incorrect
handling of JWT CAs, even when the data is generated using
tctl get all --with-secrets.

Backport of #8119.
  • Loading branch information
codingllama committed Sep 2, 2021
1 parent a76a82d commit 6eb543d
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 13 deletions.
21 changes: 15 additions & 6 deletions lib/auth/init.go
Expand Up @@ -44,8 +44,8 @@ import (
"github.com/gravitational/teleport/lib/sshutils"
"github.com/gravitational/teleport/lib/tlsca"
"github.com/gravitational/teleport/lib/utils"

"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
Expand Down Expand Up @@ -127,7 +127,6 @@ type InitConfig struct {

// StaticTokens are pre-defined host provisioning tokens supplied via config file for
// environments where paranoid security is not needed
//StaticTokens []services.ProvisionToken
StaticTokens types.StaticTokens

// AuthPreference defines the authentication type (local, oidc) and second
Expand Down Expand Up @@ -822,16 +821,26 @@ func checkResourceConsistency(clusterName string, resources ...types.Resource) e
// check that signing CAs have expected cluster name and that
// all CAs for this cluster do having signing keys.
seemsLocal := r.GetClusterName() == clusterName

var hasKeys bool
_, err := sshSigner(r)
var signerErr error
switch r.GetType() {
case types.HostCA, types.UserCA:
_, signerErr = sshSigner(r)
case types.JWTSigner:
_, signerErr = services.GetJWTSigner(r, clockwork.NewRealClock())
default:
return trace.BadParameter("unexpected cert_authority type %s for cluster %v", r.GetType(), clusterName)
}
switch {
case err == nil:
case signerErr == nil:
hasKeys = true
case trace.IsNotFound(err):
case trace.IsNotFound(signerErr):
hasKeys = false
default:
return trace.Wrap(err)
return trace.Wrap(signerErr)
}

if seemsLocal && !hasKeys {
return trace.BadParameter("ca for local cluster %q missing signing keys", clusterName)
}
Expand Down

0 comments on commit 6eb543d

Please sign in to comment.