Files
seaweedfs/weed/shell/command_s3_accesskey_list.go
Chris Lu 37e6263efe fix(shell): attach admin JWT for filer IAM gRPC calls (#9536)
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.
2026-05-18 13:42:32 -07:00

69 lines
1.5 KiB
Go

package shell
import (
"context"
"flag"
"fmt"
"io"
"text/tabwriter"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
)
func init() {
Commands = append(Commands, &commandS3AccessKeyList{})
}
type commandS3AccessKeyList struct {
}
func (c *commandS3AccessKeyList) Name() string {
return "s3.accesskey.list"
}
func (c *commandS3AccessKeyList) Help() string {
return `list access keys for an S3 IAM user
s3.accesskey.list -user <username>
`
}
func (c *commandS3AccessKeyList) HasTag(CommandTag) bool {
return false
}
func (c *commandS3AccessKeyList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
f := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
user := f.String("user", "", "user name")
if err := f.Parse(args); err != nil {
return err
}
if *user == "" {
return fmt.Errorf("-user is required")
}
return commandEnv.withIamClient(func(ctx context.Context, client iam_pb.SeaweedIdentityAccessManagementClient) error {
resp, err := client.GetUser(ctx, &iam_pb.GetUserRequest{Username: *user})
if err != nil {
return err
}
if len(resp.Identity.Credentials) == 0 {
fmt.Fprintf(writer, "No access keys for user %q.\n", *user)
return nil
}
tw := tabwriter.NewWriter(writer, 0, 4, 2, ' ', 0)
fmt.Fprintln(tw, "ACCESS KEY\tSTATUS")
for _, cred := range resp.Identity.Credentials {
st := cred.Status
if st == "" {
st = "Active"
}
fmt.Fprintf(tw, "%s\t%s\n", cred.AccessKey, st)
}
return tw.Flush()
})
}