mirror of
https://github.com/versity/versitygw.git
synced 2026-09-24 08:54:47 +00:00
feat: add IAM OIDC provider tagging actions
Adds `TagOpenIDConnectProvider`, `UntagOpenIDConnectProvider` and `ListOpenIDConnectProviderTags` to the standalone IAM service, backed by both the internal and Vault storers. They follow the user and role tagging actions in most respects — the tag action merges into the provider's existing tags and rejects a repeated key, untag removal is idempotent, and the tag listing is sorted by key and paginated, with the per-request member count and the per-provider tag total enforced as separate quotas so replacing a tag on a provider already at the 50-tag cap still succeeds — but differ in the one respect IAM itself draws: OIDC provider tag keys are compared exactly, not case-insensitively. On a provider `env` and `ENV` are two independent tags, both may be supplied in a single request, only a byte-identical repeat is a duplicate (reported without the "Tag keys are case insensitive" note the user and role actions carry), and untagging `env` leaves `ENV` in place. That distinction is now carried by `iamutil.TagKeyCase`, which `ParseTags` uses for duplicate detection and which `mergeTags`, `removeTags` and the tag listing's marker lookup use for key matching. `CreateOpenIDConnectProvider` moves onto the exact comparison too, so a provider created with case-differing tag keys keeps both. All three actions are authorized against the target provider's ARN, so `aws:ResourceTag/<key>` reads the provider's own tags, and the tag and untag actions populate `aws:RequestTag/<key>` and `aws:TagKeys` respectively, so a tag-scoped policy Condition governs which tags a caller may set or remove. All three report a missing provider with the wording `DeleteOpenIDConnectProvider` uses rather than the one `GetOpenIDConnectProvider` uses, which is why the Vault provider read now takes the not-found error its calling action reports. The WebGUI gains a Tags section in the OIDC provider manage view, replacing the read-only tag row, and the shared tag editor gains a case-sensitive mode that changes its duplicate-key check, its diffing of an edited set into an untag and tag pair, and the wording of its guidance.
This commit is contained in:
+24
-17
@@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/versity/versitygw/iamapi/iamerr"
|
||||
"github.com/versity/versitygw/iamapi/internal/iamutil"
|
||||
"github.com/versity/versitygw/iamapi/types"
|
||||
)
|
||||
|
||||
@@ -28,8 +29,8 @@ import (
|
||||
// user may hold at once, matching the AWS IAM quota.
|
||||
const MaxAccessKeysPerUser = 2
|
||||
|
||||
// MaxTagsPerResource is the maximum number of tags a single IAM user or
|
||||
// role may carry at once, matching the AWS IAM quota.
|
||||
// MaxTagsPerResource is the maximum number of tags a single IAM user, role
|
||||
// or OIDC provider may carry at once, matching the AWS IAM quota.
|
||||
const MaxTagsPerResource = 50
|
||||
|
||||
// MaxInlinePolicyBytesPerUser is the maximum aggregate size, in bytes, of
|
||||
@@ -200,16 +201,22 @@ type ListOIDCProvidersOutput struct {
|
||||
Providers []types.OpenIDConnectProviderListEntry
|
||||
}
|
||||
|
||||
type ListOIDCProviderTagsInput struct {
|
||||
Arn string
|
||||
Marker string
|
||||
MaxItems int32
|
||||
}
|
||||
|
||||
// mergeTags applies the tag actions' merge semantics to existing: an
|
||||
// incoming tag replaces the existing tag whose key matches
|
||||
// case-insensitively — taking over its position and its key's casing — and
|
||||
// any remaining incoming tag is appended in the order supplied. AWS caps
|
||||
// the merged total, not the request, so replacing a tag on a resource
|
||||
// already at the cap is allowed.
|
||||
func mergeTags(existing, incoming []types.Tag) ([]types.Tag, error) {
|
||||
// incoming tag replaces the existing tag whose key matches under keyCase —
|
||||
// taking over its position and its key's casing — and any remaining
|
||||
// incoming tag is appended in the order supplied. AWS caps the merged
|
||||
// total, not the request, so replacing a tag on a resource already at the
|
||||
// cap is allowed.
|
||||
func mergeTags(existing, incoming []types.Tag, keyCase iamutil.TagKeyCase) ([]types.Tag, error) {
|
||||
merged := slices.Clone(existing)
|
||||
for _, tag := range incoming {
|
||||
if idx := indexOfTagKey(merged, tag.Key); idx >= 0 {
|
||||
if idx := indexOfTagKey(merged, tag.Key, keyCase); idx >= 0 {
|
||||
merged[idx] = tag
|
||||
continue
|
||||
}
|
||||
@@ -222,19 +229,19 @@ func mergeTags(existing, incoming []types.Tag) ([]types.Tag, error) {
|
||||
}
|
||||
|
||||
// removeTags applies the untag actions' removal semantics to existing:
|
||||
// every tag whose key case-insensitively matches one of tagKeys is dropped,
|
||||
// and a key naming no existing tag is ignored rather than reported.
|
||||
func removeTags(existing []types.Tag, tagKeys []string) []types.Tag {
|
||||
// every tag whose key matches one of tagKeys under keyCase is dropped, and
|
||||
// a key naming no existing tag is ignored rather than reported.
|
||||
func removeTags(existing []types.Tag, tagKeys []string, keyCase iamutil.TagKeyCase) []types.Tag {
|
||||
return slices.DeleteFunc(slices.Clone(existing), func(tag types.Tag) bool {
|
||||
return slices.ContainsFunc(tagKeys, func(key string) bool {
|
||||
return strings.EqualFold(key, tag.Key)
|
||||
return keyCase.Equal(key, tag.Key)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func indexOfTagKey(tags []types.Tag, key string) int {
|
||||
func indexOfTagKey(tags []types.Tag, key string, keyCase iamutil.TagKeyCase) int {
|
||||
return slices.IndexFunc(tags, func(tag types.Tag) bool {
|
||||
return strings.EqualFold(tag.Key, key)
|
||||
return keyCase.Equal(tag.Key, key)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -243,7 +250,7 @@ func indexOfTagKey(tags []types.Tag, key string) int {
|
||||
// claim sorted by key; live responses are not), so this sorts by key: a
|
||||
// stable order is what makes a Marker meaningful, and it's the order the
|
||||
// documentation promises.
|
||||
func paginateTags(tags []types.Tag, marker string, maxItems int32) *ListTagsOutput {
|
||||
func paginateTags(tags []types.Tag, marker string, maxItems int32, keyCase iamutil.TagKeyCase) *ListTagsOutput {
|
||||
sorted := slices.Clone(tags)
|
||||
slices.SortFunc(sorted, func(a, b types.Tag) int {
|
||||
return strings.Compare(a.Key, b.Key)
|
||||
@@ -251,7 +258,7 @@ func paginateTags(tags []types.Tag, marker string, maxItems int32) *ListTagsOutp
|
||||
|
||||
if marker != "" {
|
||||
start := len(sorted)
|
||||
if idx := indexOfTagKey(sorted, marker); idx >= 0 {
|
||||
if idx := indexOfTagKey(sorted, marker, keyCase); idx >= 0 {
|
||||
start = idx + 1
|
||||
}
|
||||
sorted = sorted[start:]
|
||||
|
||||
Reference in New Issue
Block a user