mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-05-31 05:56:21 +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.
69 lines
1.5 KiB
Go
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()
|
|
})
|
|
}
|