Skip to content

Commit

Permalink
Revert "Remove 2FA bypass (#47288)"
Browse files Browse the repository at this point in the history
This reverts commit 1952dd8.
  • Loading branch information
rosstimothy committed Dec 3, 2024
1 parent 87320df commit c2bf77a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ const (

// MinimumEtcdVersion is the minimum version of etcd supported by Teleport
MinimumEtcdVersion = "3.3.0"

// EnvVarAllowNoSecondFactor is used to allow disabling second factor auth
// todo(tross): DELETE WHEN ABLE TO
EnvVarAllowNoSecondFactor = "TELEPORT_ALLOW_NO_SECOND_FACTOR"
)

const (
Expand Down
10 changes: 6 additions & 4 deletions lib/auth/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"log/slog"
"os"
"slices"
"strings"
"sync"
Expand Down Expand Up @@ -786,14 +787,15 @@ func initializeAuthPreference(ctx context.Context, asrv *Server, newAuthPref typ
}

if !shouldReplace {
if err := modules.ValidateResource(storedAuthPref); err != nil {
if os.Getenv(teleport.EnvVarAllowNoSecondFactor) != "true" {
err := modules.ValidateResource(storedAuthPref)
if errors.Is(err, modules.ErrCannotDisableSecondFactor) {
return trace.Wrap(err, secondFactorUpgradeInstructions)
}

return trace.Wrap(err)
if err != nil {
return trace.Wrap(err)
}
}

return nil
}

Expand Down
6 changes: 5 additions & 1 deletion lib/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"crypto"
"errors"
"fmt"
"os"
"runtime"
"sync"
"time"
Expand Down Expand Up @@ -332,7 +333,10 @@ var ErrCannotDisableSecondFactor = errors.New("cannot disable multi-factor authe

// ValidateResource performs additional resource checks.
func ValidateResource(res types.Resource) error {
if GetModules().Features().Cloud || !IsInsecureTestMode() {
// todo(tross): DELETE WHEN ABLE TO [remove env var, leave insecure test mode]
if GetModules().Features().Cloud ||
(os.Getenv(teleport.EnvVarAllowNoSecondFactor) != "yes" && !IsInsecureTestMode()) {

switch r := res.(type) {
case types.AuthPreference:
if !r.IsSecondFactorEnforced() {
Expand Down

0 comments on commit c2bf77a

Please sign in to comment.