Skip to content

Commit

Permalink
Fix TELEPORT_ALLOW_NO_SECOND_FACTOR
Browse files Browse the repository at this point in the history
Some parts of Teleport required this env var to be set to "true"
while other parts required a value of "yes" - this made it
impossible to pass all of the checks.

Use ParseBool instead to be more generous in what values are allowed.
  • Loading branch information
zmb3 authored and github-actions committed Jan 31, 2025
1 parent 5c2ef5d commit 226fa54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/auth/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"log/slog"
"os"
"slices"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -791,7 +792,7 @@ func initializeAuthPreference(ctx context.Context, asrv *Server, newAuthPref typ
}

if !shouldReplace {
if os.Getenv(teleport.EnvVarAllowNoSecondFactor) != "true" {
if allowNoSecondFactor, _ := strconv.ParseBool(os.Getenv(teleport.EnvVarAllowNoSecondFactor)); allowNoSecondFactor {
err := modules.ValidateResource(storedAuthPref)
if errors.Is(err, modules.ErrCannotDisableSecondFactor) {
return trace.Wrap(err, secondFactorUpgradeInstructions)
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -334,9 +335,9 @@ var ErrCannotDisableSecondFactor = errors.New("cannot disable multi-factor authe
// ValidateResource performs additional resource checks.
func ValidateResource(res types.Resource) error {
// todo(tross): DELETE WHEN ABLE TO [remove env var, leave insecure test mode]
allowNoSecondFactor, _ := strconv.ParseBool(os.Getenv(teleport.EnvVarAllowNoSecondFactor))
if GetModules().Features().Cloud ||
(os.Getenv(teleport.EnvVarAllowNoSecondFactor) != "yes" && !IsInsecureTestMode()) {

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

0 comments on commit 226fa54

Please sign in to comment.