Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

1005 B
Raw Blame
package credential

import (
	"fmt"
	"regexp"
)

var (
	PolicyNamePattern = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
	// ServiceAccountIdPattern matches sa:<parent-user>:<uuid>. The parent-user
	// segment accepts every character allowed in an AWS IAM username
	// (`[\w+=,.@-]+` per
	// https://docs.aws.amazon.com/IAM/latest/APIReference/API_User.html)
	// so service accounts created for users with e.g. `[email protected]`
	// don't fail validation at the persistence layer.
	ServiceAccountIdPattern = regexp.MustCompile(`^sa:[A-Za-z0-9_+=,.@-]+:[a-z0-9-]+$`)
)

func ValidatePolicyName(name string) error {
	if !PolicyNamePattern.MatchString(name) {
		return fmt.Errorf("invalid policy name: %s", name)
	}
	return nil
}

func ValidateServiceAccountId(id string) error {
	if id == "" {
		return fmt.Errorf("service account ID cannot be empty")
	}
	if !ServiceAccountIdPattern.MatchString(id) {
		return fmt.Errorf("invalid service account ID: %s (expected format sa:<user>:<uuid>)", id)
	}
	return nil
}