Skip to content

Commit

Permalink
[buddy] Error if TTL in tctl auth sign is too long (#19563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Enes authored Dec 22, 2022
1 parent 2d89c20 commit 693b164
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tool/tctl/common/auth_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,17 @@ func (a *AuthCommand) generateUserKeys(ctx context.Context, clusterAPI auth.Clie
kubeTLSServerName = client.GetKubeTLSServerName(a.config.Proxy.WebAddr.Host())
}

expires, err := key.TeleportTLSCertValidBefore()
if err != nil {
log.WithError(err).Warn("Failed to check TTL validity")
// err swallowed on purpose
} else if reqExpiry.Sub(expires) > time.Minute {
maxAllowedTTL := time.Until(expires).Round(time.Second)
return trace.BadParameter(`The credential was not issued because the requested TTL of %s exceeded the maximum allowed value of %s. To successfully request a credential, please reduce the requested TTL.`,
a.genTTL,
maxAllowedTTL)
}

// write the cert+private key to the output:
filesWritten, err := identityfile.Write(identityfile.WriteConfig{
OutputPath: a.output,
Expand All @@ -686,19 +697,6 @@ func (a *AuthCommand) generateUserKeys(ctx context.Context, clusterAPI auth.Clie
}
fmt.Printf("\nThe credentials have been written to %s\n", strings.Join(filesWritten, ", "))

expires, err := key.TeleportTLSCertValidBefore()
if err != nil {
log.WithError(err).Warn("Failed to check TTL validity")
// err swallowed on purpose
return nil
}
if reqExpiry.Sub(expires) > time.Minute {
log.Warnf("Requested TTL of %s was not granted. User may have a role with a shorter max session TTL"+
" or an existing session ending before the requested TTL. Proceeding with %s",
a.genTTL,
time.Until(expires).Round(time.Second))
}

return nil
}

Expand Down

0 comments on commit 693b164

Please sign in to comment.