mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-12 09:30:46 +02:00
* shell: add s3.accesskey.*, s3.anonymous.*, s3.serviceaccount.* commands Add credential, anonymous access, and service account management commands: Access key commands: - s3.accesskey.create: add credentials to an existing user - s3.accesskey.list: list access keys for a user (key ID + status) - s3.accesskey.delete: remove a specific access key - s3.accesskey.rotate: atomic create-new + delete-old key rotation Anonymous access commands: - s3.anonymous.set: set/remove public access on a bucket - s3.anonymous.get: show anonymous access for a bucket - s3.anonymous.list: list all buckets with anonymous access Service account commands: - s3.serviceaccount.create: create with optional action subset and expiry - s3.serviceaccount.list: tabular listing, optionally filtered by parent - s3.serviceaccount.show: detailed view of a service account - s3.serviceaccount.delete: remove a service account These replace the credential and anonymous portions of the monolithic s3.configure and s3.bucket.access commands. * shell: address review feedback for s3.accesskey.*, s3.anonymous.*, s3.serviceaccount.* - Return flag parse errors instead of swallowing them (all commands) - Add action validation in s3.anonymous.set (Read, Write, List, Tagging, Admin) - Fix s3.serviceaccount.create output: note to use list for server-assigned ID since CreateServiceAccountResponse does not return the ID * shell: fix bucket matching and action validation in s3.anonymous.* - Use SplitN instead of HasSuffix for bucket name matching to avoid false positives when one bucket name is a suffix of another - Make action validation case-insensitive with canonical normalization * shell: fix nil panics, dedup actions, validate service account actions - Fix nil-pointer panic in getOrCreateAnonymousUser when GetUser returns err==nil with nil Identity (status.FromError(nil) returns nil status) - Add nil Identity guards in s3.anonymous.get and s3.anonymous.list - Deduplicate action values in s3.anonymous.set (e.g. -access Read,Read) - Add action validation in s3.serviceaccount.create with case normalization * shell: dedup actions and reject negative expiry in s3.serviceaccount.create - Deduplicate -actions values (e.g. Read,read,Read produces one entry) - Reject negative -expiry values instead of silently treating as no expiration
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"text/tabwriter"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
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 pb.WithGrpcClient(false, 0, func(conn *grpc.ClientConn) error {
|
|
client := iam_pb.NewSeaweedIdentityAccessManagementClient(conn)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
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()
|
|
}, commandEnv.option.FilerAddress.ToGrpcAddress(), false, commandEnv.option.GrpcDialOption)
|
|
}
|