Files
seaweedfs/weed/shell/command_s3_serviceaccount_show.go
T
Chris LuandGitHub 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

88 lines
2.1 KiB
Go

package shell
import (
"context"
"flag"
"fmt"
"io"
"strings"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
)
func init() {
Commands = append(Commands, &commandS3ServiceAccountShow{})
}
type commandS3ServiceAccountShow struct {
}
func (c *commandS3ServiceAccountShow) Name() string {
return "s3.serviceaccount.show"
}
func (c *commandS3ServiceAccountShow) Help() string {
return `show details of a service account
s3.serviceaccount.show -id <service_account_id>
`
}
func (c *commandS3ServiceAccountShow) HasTag(CommandTag) bool {
return false
}
func (c *commandS3ServiceAccountShow) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
f := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
id := f.String("id", "", "service account ID")
if err := f.Parse(args); err != nil {
return err
}
if *id == "" {
return fmt.Errorf("-id is required")
}
return commandEnv.withIamClient(func(ctx context.Context, client iam_pb.SeaweedIdentityAccessManagementClient) error {
resp, err := client.GetServiceAccount(ctx, &iam_pb.GetServiceAccountRequest{Id: *id})
if err != nil {
return err
}
sa := resp.ServiceAccount
status := "enabled"
if sa.Disabled {
status = "disabled"
}
fmt.Fprintf(writer, "ID: %s\n", sa.Id)
fmt.Fprintf(writer, "Parent: %s\n", sa.ParentUser)
fmt.Fprintf(writer, "Status: %s\n", status)
if sa.Description != "" {
fmt.Fprintf(writer, "Description: %s\n", sa.Description)
}
if sa.Credential != nil {
st := sa.Credential.Status
if st == "" {
st = "Active"
}
fmt.Fprintf(writer, "Access Key: %s (%s)\n", sa.Credential.AccessKey, st)
}
if len(sa.Actions) > 0 {
fmt.Fprintf(writer, "Actions: %s\n", strings.Join(sa.Actions, ", "))
}
if sa.Expiration > 0 {
fmt.Fprintf(writer, "Expires: %s\n", time.Unix(sa.Expiration, 0).Format(time.RFC3339))
}
if sa.CreatedAt > 0 {
fmt.Fprintf(writer, "Created: %s\n", time.Unix(sa.CreatedAt, 0).Format(time.RFC3339))
}
if sa.CreatedBy != "" {
fmt.Fprintf(writer, "Created By: %s\n", sa.CreatedBy)
}
return nil
})
}