Skip to content

Commit cf57405

Browse files
committed
Revert "Tenant support (#1400)"
This reverts commit f39a138.
1 parent 98ae13d commit cf57405

File tree

6 files changed

+2
-340
lines changed

6 files changed

+2
-340
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ The Defang CLI recognizes the following environment variables:
148148
- `DEFANG_PULUMI_BACKEND` - The Pulumi backend URL or `"pulumi-cloud"`; defaults to a self-hosted backend
149149
- `DEFANG_PULUMI_DIR` - Run Pulumi from this folder, instead of spawning a cloud task; requires `--debug` (BYOC only)
150150
- `DEFANG_PULUMI_VERSION` - Override the version of the Pulumi image to use (`aws` provider only)
151-
- `DEFANG_TENANT` - The name of the tenant to use.
152151
- `NO_COLOR` - If set to any value, disables color output; by default, color output is enabled depending on the terminal
153152
- `PULUMI_ACCESS_TOKEN` - The Pulumi access token to use for authentication to Pulumi Cloud; see `DEFANG_PULUMI_BACKEND`
154153
- `PULUMI_CONFIG_PASSPHRASE` - Passphrase used to generate a unique key for your stack, and configuration and encrypted state values

pkgs/npm/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The Defang CLI recognizes the following environment variables:
4343
- `DEFANG_PULUMI_BACKEND` - The Pulumi backend URL or `"pulumi-cloud"`; defaults to a self-hosted backend
4444
- `DEFANG_PULUMI_DIR` - Run Pulumi from this folder, instead of spawning a cloud task; requires `--debug` (BYOC only)
4545
- `DEFANG_PULUMI_VERSION` - Override the version of the Pulumi image to use (`aws` provider only)
46-
- `DEFANG_TENANT` - The name of the tenant to use.
4746
- `NO_COLOR` - If set to any value, disables color output; by default, color output is enabled depending on the terminal
4847
- `PULUMI_ACCESS_TOKEN` - The Pulumi access token to use for authentication to Pulumi Cloud; see `DEFANG_PULUMI_BACKEND`
4948
- `PULUMI_CONFIG_PASSPHRASE` - Passphrase used to generate a unique key for your stack, and configuration and encrypted state values

src/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The Defang CLI recognizes the following environment variables:
4343
- `DEFANG_PULUMI_BACKEND` - The Pulumi backend URL or `"pulumi-cloud"`; defaults to a self-hosted backend
4444
- `DEFANG_PULUMI_DIR` - Run Pulumi from this folder, instead of spawning a cloud task; requires `--debug` (BYOC only)
4545
- `DEFANG_PULUMI_VERSION` - Override the version of the Pulumi image to use (`aws` provider only)
46-
- `DEFANG_TENANT` - The name of the tenant to use.
4746
- `NO_COLOR` - If set to any value, disables color output; by default, color output is enabled depending on the terminal
4847
- `PULUMI_ACCESS_TOKEN` - The Pulumi access token to use for authentication to Pulumi Cloud; see `DEFANG_PULUMI_BACKEND`
4948
- `PULUMI_CONFIG_PASSPHRASE` - Passphrase used to generate a unique key for your stack, and configuration and encrypted state values

src/cmd/cli/command/commands.go

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import (
99
"os/exec"
1010
"path/filepath"
1111
"regexp"
12-
"sort"
1312
"strings"
1413
"time"
1514

1615
"github.com/AlecAivazis/survey/v2"
1716
_ "github.com/DefangLabs/defang/src/cmd/cli/autoload"
1817
"github.com/DefangLabs/defang/src/pkg"
19-
"github.com/DefangLabs/defang/src/pkg/auth"
2018
"github.com/DefangLabs/defang/src/pkg/cli"
2119
cliClient "github.com/DefangLabs/defang/src/pkg/cli/client"
2220
"github.com/DefangLabs/defang/src/pkg/cli/client/byoc"
@@ -59,7 +57,6 @@ var (
5957
modelId = os.Getenv("DEFANG_MODEL_ID") // for Pro users only
6058
nonInteractive = !hasTty
6159
org string
62-
tenantFlag string
6360
providerID = cliClient.ProviderID(pkg.Getenv("DEFANG_PROVIDER", "auto"))
6461
verbose = false
6562
)
@@ -166,7 +163,6 @@ func SetupCommands(ctx context.Context, version string) {
166163
RootCmd.PersistentFlags().StringVarP(&cluster, "cluster", "s", pcluster.DefangFabric, "Defang cluster to connect to")
167164
RootCmd.PersistentFlags().MarkHidden("cluster")
168165
RootCmd.PersistentFlags().StringVar(&org, "org", os.Getenv("DEFANG_ORG"), "override GitHub organization name (tenant)")
169-
RootCmd.PersistentFlags().StringVar(&tenantFlag, "tenant", "", "select tenant by name")
170166
RootCmd.PersistentFlags().VarP(&providerID, "provider", "P", fmt.Sprintf(`bring-your-own-cloud provider; one of %v`, cliClient.AllProviders()))
171167
// RootCmd.Flag("provider").NoOptDefVal = "auto" NO this will break the "--provider aws"
172168
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose logging") // backwards compat: only used by tail
@@ -219,9 +215,6 @@ func SetupCommands(ctx context.Context, version string) {
219215
// Whoami Command
220216
RootCmd.AddCommand(whoamiCmd)
221217

222-
// Tenants Command
223-
RootCmd.AddCommand(tenantsCmd)
224-
225218
// Logout Command
226219
RootCmd.AddCommand(logoutCmd)
227220

@@ -372,18 +365,6 @@ var RootCmd = &cobra.Command{
372365
}
373366
}
374367

375-
// Configure tenant selection based on --tenant flag
376-
if f := cmd.Root().Flag("tenant"); f != nil && f.Changed {
377-
// Highest precedence: explicit --tenant flag
378-
auth.SetSelectedTenantName(tenantFlag)
379-
} else if envTenant := os.Getenv("DEFANG_TENANT"); strings.TrimSpace(envTenant) != "" {
380-
// Next precedence: DEFANG_TENANT environment variable
381-
auth.SetSelectedTenantName(envTenant)
382-
} else {
383-
// Default behavior: auto-select tenant by JWT subject if no explicit name is provided
384-
auth.SetAutoSelectBySub(true)
385-
}
386-
387368
client, err = cli.Connect(ctx, getCluster())
388369

389370
if v, err := client.GetVersions(ctx); err == nil {
@@ -395,8 +376,6 @@ var RootCmd = &cobra.Command{
395376
}
396377
}
397378

398-
// (deliberately skip tenant resolution here to avoid blocking non-auth commands)
399-
400379
// Check if we are correctly logged in, but only if the command needs authorization
401380
if _, ok := cmd.Annotations[authNeeded]; !ok {
402381
return nil
@@ -408,80 +387,7 @@ var RootCmd = &cobra.Command{
408387
err = login.InteractiveRequireLoginAndToS(ctx, client, getCluster())
409388
}
410389

411-
if err != nil {
412-
return err
413-
}
414-
415-
// Ensure tenant is resolved post-login as we now have a token
416-
if tok := pcluster.GetExistingToken(getCluster()); tok != "" {
417-
if err2 := auth.ResolveAndSetTenantFromToken(ctx, tok); err2 != nil {
418-
return err2
419-
}
420-
// log the tenant name and id
421-
term.Debug("Selected tenant:", auth.GetSelectedTenantName(), "(", auth.GetSelectedTenantID(), ")")
422-
}
423-
424-
return nil
425-
},
426-
}
427-
428-
var tenantsCmd = &cobra.Command{
429-
Use: "tenants",
430-
Args: cobra.NoArgs,
431-
Annotations: authNeededAnnotation,
432-
Short: "List tenants available to the logged-in user",
433-
RunE: func(cmd *cobra.Command, args []string) error {
434-
ctx := cmd.Context()
435-
tok := pcluster.GetExistingToken(getCluster())
436-
if strings.TrimSpace(tok) == "" {
437-
return errors.New("not logged in; run 'defang login'")
438-
}
439-
440-
tenants, err := auth.ListTenantsFromToken(ctx, tok)
441-
if err != nil {
442-
return err
443-
}
444-
445-
// Sort by name for stable output
446-
sort.Slice(tenants, func(i, j int) bool { return strings.ToLower(tenants[i].Name) < strings.ToLower(tenants[j].Name) })
447-
448-
if len(tenants) == 0 {
449-
term.Info("No tenants found")
450-
return nil
451-
}
452-
453-
currentID := auth.GetSelectedTenantID()
454-
currentName := auth.GetSelectedTenantName()
455-
456-
// Compute longest name for aligned output
457-
maxNameLen := 0
458-
for _, t := range tenants {
459-
if l := len(t.Name); l > maxNameLen {
460-
maxNameLen = l
461-
}
462-
}
463-
464-
for _, t := range tenants {
465-
selected := t.ID == currentID || (currentID == "" && t.Name == currentName && strings.TrimSpace(currentName) != "")
466-
marker := "-"
467-
if selected {
468-
marker = "*" // highlight selected
469-
}
470-
471-
var line string
472-
if verbose {
473-
line = fmt.Sprintf("%s %-*s (%s)\n", marker, maxNameLen, t.Name, t.ID)
474-
} else {
475-
line = fmt.Sprintf("%s %s\n", marker, t.Name)
476-
}
477-
478-
if selected {
479-
term.Printc(term.BrightCyan, line)
480-
} else {
481-
term.Printc(term.InfoColor, line)
482-
}
483-
}
484-
return nil
390+
return err
485391
},
486392
}
487393

src/pkg/auth/interceptor.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import (
77
"github.com/bufbuild/connect-go"
88
)
99

10-
const (
11-
XDefangOrgID = "X-Defang-Orgid"
12-
XDefangTenantID = "X-Defang-Tenant-Id"
13-
)
10+
const XDefangOrgID = "X-Defang-Orgid"
1411

1512
type authInterceptor struct {
1613
authorization string
@@ -26,9 +23,6 @@ func (a *authInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
2623
req.Header().Set("Authorization", a.authorization)
2724
req.Header().Set("Content-Type", "application/grpc") // same as the gRPC client
2825
req.Header().Set(XDefangOrgID, a.orgID)
29-
if tid := GetSelectedTenantID(); tid != "" {
30-
req.Header().Set(XDefangTenantID, tid)
31-
}
3226
return next(ctx, req)
3327
}
3428
}
@@ -39,9 +33,6 @@ func (a *authInterceptor) WrapStreamingClient(next connect.StreamingClientFunc)
3933
conn.RequestHeader().Set("Authorization", a.authorization)
4034
conn.RequestHeader().Set("Content-Type", "application/grpc") // same as the gRPC client
4135
conn.RequestHeader().Set(XDefangOrgID, a.orgID)
42-
if tid := GetSelectedTenantID(); tid != "" {
43-
conn.RequestHeader().Set(XDefangTenantID, tid)
44-
}
4536
return conn
4637
}
4738
}

0 commit comments

Comments
 (0)