mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-18 13:17:08 +00:00
When jwt.filer_signing.key is set, the filer's IamGrpcServer requires a Bearer token on every IAM RPC. The shell's s3.* IAM commands dialed without that header and failed with Unauthenticated. Route them through a small helper that mints a token from the same key viper-loaded from security.toml and appends it as outgoing metadata, matching the credential grpc_store pattern.
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"text/tabwriter"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandS3ServiceAccountList{})
|
|
}
|
|
|
|
type commandS3ServiceAccountList struct {
|
|
}
|
|
|
|
func (c *commandS3ServiceAccountList) Name() string {
|
|
return "s3.serviceaccount.list"
|
|
}
|
|
|
|
func (c *commandS3ServiceAccountList) Help() string {
|
|
return `list service accounts
|
|
|
|
s3.serviceaccount.list
|
|
s3.serviceaccount.list -user <parent_user>
|
|
|
|
Lists all service accounts, optionally filtered by parent user.
|
|
`
|
|
}
|
|
|
|
func (c *commandS3ServiceAccountList) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandS3ServiceAccountList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
|
|
f := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
user := f.String("user", "", "filter by parent user (optional)")
|
|
if err := f.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
return commandEnv.withIamClient(func(ctx context.Context, client iam_pb.SeaweedIdentityAccessManagementClient) error {
|
|
resp, err := client.ListServiceAccounts(ctx, &iam_pb.ListServiceAccountsRequest{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var filtered []*iam_pb.ServiceAccount
|
|
for _, sa := range resp.ServiceAccounts {
|
|
if *user == "" || sa.ParentUser == *user {
|
|
filtered = append(filtered, sa)
|
|
}
|
|
}
|
|
|
|
if len(filtered) == 0 {
|
|
fmt.Fprintln(writer, "No service accounts found.")
|
|
return nil
|
|
}
|
|
|
|
tw := tabwriter.NewWriter(writer, 0, 4, 2, ' ', 0)
|
|
fmt.Fprintln(tw, "ID\tPARENT\tSTATUS\tDESCRIPTION")
|
|
for _, sa := range filtered {
|
|
st := "enabled"
|
|
if sa.Disabled {
|
|
st = "disabled"
|
|
}
|
|
desc := sa.Description
|
|
if len(desc) > 40 {
|
|
desc = desc[:37] + "..."
|
|
}
|
|
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", sa.Id, sa.ParentUser, st, desc)
|
|
}
|
|
return tw.Flush()
|
|
})
|
|
}
|