mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-16 16:56:04 +01:00
feat(iam): OIDC provider mutations + multi-client + TLS thumbprints (Phase 2b) (#9320)
* feat(iam): OIDC provider mutations + multi-client + TLS thumbprints - Mutating IAM actions: CreateOpenIDConnectProvider, DeleteOpenIDConnectProvider, AddClientIDToOpenIDConnectProvider, RemoveClientIDFromOpenIDConnectProvider, UpdateOpenIDConnectProviderThumbprint, TagOpenIDConnectProvider, UntagOpenIDConnectProvider. Each enforces AWS-shape input bounds and the read-only mode rejects all mutations. - Multiple client_ids per provider in OIDCConfig (clientIds list, plural) with full backward compatibility — singular clientId still works and is merged into the audience allowlist. Provider factory accepts both. - AWS-compatible TLS thumbprint pinning: when OIDCConfig.Thumbprints is non-empty, JWKS fetches enforce that the negotiated TLS chain contains a certificate whose SHA-1 hex matches the allowlist. Empty list keeps the existing system-trust path. * fix(iam): factor Tags.member.N parser into a helper CreateOpenIDConnectProvider and TagOpenIDConnectProvider were both walking the AWS Tags.member.N.Key / Tags.member.N.Value query-string convention with copy-pasted loops. Factor into extractTags so the parsing rules and the "no tags present" semantics live in one place. Addresses gemini medium review on PR #9320. * fix(iam): sentinel errors for OIDC provider not-found / already-exists The s3api dispatcher was using strings.Contains(err.Error(), "not found") and "already exists" to map IAM-manager errors back to AWS error codes. Substring matching on a formatted message couples the API error code to the exact wording of the upstream message — touching the message silently changes the IAM API contract. Define ErrOIDCProviderNotFound and ErrOIDCProviderAlreadyExists in the integration package, fmt.Errorf("%w: ...") them at the four return sites in iam_manager.go and oidc_provider_store.go, and use errors.Is at the s3api call sites. Same control flow, no string-match fragility. Addresses gemini medium review on PR #9320. * fix(iam): surface non-NotFound errors from CreateOIDCProvider lookup Previously CreateOIDCProvider only treated GetProviderByARN's success path as "exists" and silently fell through on any error, including transient backend failures. That hid real problems and still attempted a write. Distinguish ErrOIDCProviderNotFound (the only "safe to create" case) from other errors so we don't mask filer outages or partition issues. * fix(iam): enforce 100-client-ID cap on AddClientIDToOIDCProvider CreateOIDCProvider and the implicit update path through validateOIDC- ProviderRecord both reject lists with more than 100 client IDs, but AddClientIDToOIDCProvider could grow the list past that bound one ID at a time. Refuse the add when the list is already at the cap so the invariant holds across every mutation entry point. * feat(iam): IAM-managed OIDC provider live view in STS service Add a separate, mutex-guarded map of admin-managed OIDC providers on the STS service. The map can be atomically replaced via SetIAMManagedOIDCProvidersByIssuer; AssumeRoleWithWebIdentity lookups consult it first and fall back to the existing static-config map, so records persisted through the IAM API can shadow bootstrap entries without a restart. This is the runtime hook the IAM API and the metadata-subscribe path will both call when the OIDCProviderStore changes (next two commits). * feat(iam): refresh STS service runtime view after OIDC mutations Add IAMManager.RefreshOIDCProvidersFromStore: lists every persisted OIDCProviderRecord, builds a runtime OIDCProvider for each, and atomically publishes the issuer-keyed map into the STS service. Each mutating IAM API call (Create / Delete / AddClientID / RemoveClientID / UpdateThumbprints) now triggers this refresh inline so the local instance picks up the change without waiting for a metadata-subscribe round trip. Tag mutations skip the refresh because tags do not affect token validation. Refresh failures only log; the persisted write has already succeeded by that point, so a transient list error must not surface to the API caller. The peer-instance update path (filer metadata subscription) is added in a follow-up commit. * feat(iam): subscribe to OIDC provider changes on the filer Watch /etc/iam/oidc-providers under the existing s3 metadata-subscribe loop and call RefreshOIDCProvidersFromStore on any create / update / delete / rename. This is the cross-instance update path: S3 server A writes via the IAM API, the filer fans out the metadata change, and S3 servers B..N pick up the new runtime view without a restart. Mirrors the existing onIamConfigChange / onCircuitBreakerConfigChange pattern. The handler short-circuits when the path is unrelated, and when no IAMManager is wired in (static-only configurations).
This commit is contained in:
1 parent
6141222ab0
commit
f8973b3ed6
12 files changed
+1196
-24
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package s3api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -12,6 +13,8 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
)
|
||||
|
||||
const oidcProvidersDir = filer.IamConfigDirectory + "/oidc-providers"
|
||||
|
||||
func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, lastTsNs int64, prefix string, directoriesToWatch []string) {
|
||||
|
||||
processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
|
||||
@@ -30,12 +33,14 @@ func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, lastTsNs int64, p
|
||||
// These handlers check for nil entries internally
|
||||
_ = s3a.onBucketMetadataChange(dir, message.OldEntry, message.NewEntry)
|
||||
_ = s3a.onIamConfigChange(dir, message.OldEntry, message.NewEntry)
|
||||
_ = s3a.onOIDCProviderChange(dir, message.OldEntry, message.NewEntry)
|
||||
_ = s3a.onCircuitBreakerConfigChange(dir, message.OldEntry, message.NewEntry)
|
||||
|
||||
// For moves across directories, replay a delete event for the source directory
|
||||
if message.NewParentPath != "" && resp.Directory != message.NewParentPath {
|
||||
_ = s3a.onBucketMetadataChange(resp.Directory, message.OldEntry, nil)
|
||||
_ = s3a.onIamConfigChange(resp.Directory, message.OldEntry, nil)
|
||||
_ = s3a.onOIDCProviderChange(resp.Directory, message.OldEntry, nil)
|
||||
_ = s3a.onCircuitBreakerConfigChange(resp.Directory, message.OldEntry, nil)
|
||||
}
|
||||
|
||||
@@ -123,6 +128,33 @@ func (s3a *S3ApiServer) onIamConfigChange(dir string, oldEntry *filer_pb.Entry,
|
||||
return nil
|
||||
}
|
||||
|
||||
// onOIDCProviderChange refreshes the IAM-managed OIDC provider runtime view
|
||||
// whenever the persisted store under /etc/iam/oidc-providers changes — both
|
||||
// for mutations originated on this S3 server (the local IAM API also calls
|
||||
// RefreshOIDCProvidersFromStore inline, but the subscribe path costs nothing
|
||||
// extra) and for mutations originated on peer S3 servers, which this is the
|
||||
// only mechanism to learn about. A single refresh covers create, update,
|
||||
// delete, and rename because the store is small and a full reload is the
|
||||
// safest way to reach a consistent view.
|
||||
func (s3a *S3ApiServer) onOIDCProviderChange(dir string, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) error {
|
||||
if dir != oidcProvidersDir && !strings.HasPrefix(dir, oidcProvidersDir+"/") {
|
||||
return nil
|
||||
}
|
||||
if s3a.iam == nil || s3a.iam.iamIntegration == nil {
|
||||
return nil
|
||||
}
|
||||
s3iam, ok := s3a.iam.iamIntegration.(*S3IAMIntegration)
|
||||
if !ok || s3iam.iamManager == nil {
|
||||
return nil
|
||||
}
|
||||
if err := s3iam.iamManager.RefreshOIDCProvidersFromStore(context.Background()); err != nil {
|
||||
glog.Warningf("OIDC provider refresh after %s change failed: %v", dir, err)
|
||||
return err
|
||||
}
|
||||
glog.V(2).Infof("Refreshed IAM-managed OIDC providers after %s change", dir)
|
||||
return nil
|
||||
}
|
||||
|
||||
// onCircuitBreakerConfigChange handles circuit breaker config file changes (create, update, delete)
|
||||
func (s3a *S3ApiServer) onCircuitBreakerConfigChange(dir string, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) error {
|
||||
if dir != s3_constants.CircuitBreakerConfigDir {
|
||||
|
||||
@@ -12,12 +12,17 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam/integration"
|
||||
)
|
||||
|
||||
// OIDC provider IAM actions handled by this file. Mutating actions are
|
||||
// reserved for Phase 2b; the read-only set lands now so existing static-config
|
||||
// providers become discoverable through the AWS IAM API.
|
||||
// OIDC provider IAM actions handled by this file.
|
||||
const (
|
||||
actionGetOpenIDConnectProvider = "GetOpenIDConnectProvider"
|
||||
actionListOpenIDConnectProviders = "ListOpenIDConnectProviders"
|
||||
actionGetOpenIDConnectProvider = "GetOpenIDConnectProvider"
|
||||
actionListOpenIDConnectProviders = "ListOpenIDConnectProviders"
|
||||
actionCreateOpenIDConnectProvider = "CreateOpenIDConnectProvider"
|
||||
actionDeleteOpenIDConnectProvider = "DeleteOpenIDConnectProvider"
|
||||
actionAddClientIDToOpenIDConnectProvider = "AddClientIDToOpenIDConnectProvider"
|
||||
actionRemoveClientIDFromOpenIDConnectProvider = "RemoveClientIDFromOpenIDConnectProvider"
|
||||
actionUpdateOpenIDConnectProviderThumbprint = "UpdateOpenIDConnectProviderThumbprint"
|
||||
actionTagOpenIDConnectProvider = "TagOpenIDConnectProvider"
|
||||
actionUntagOpenIDConnectProvider = "UntagOpenIDConnectProvider"
|
||||
)
|
||||
|
||||
// isOIDCProviderAction reports whether an action belongs to the OIDC provider
|
||||
@@ -26,7 +31,14 @@ const (
|
||||
func isOIDCProviderAction(action string) bool {
|
||||
switch action {
|
||||
case actionGetOpenIDConnectProvider,
|
||||
actionListOpenIDConnectProviders:
|
||||
actionListOpenIDConnectProviders,
|
||||
actionCreateOpenIDConnectProvider,
|
||||
actionDeleteOpenIDConnectProvider,
|
||||
actionAddClientIDToOpenIDConnectProvider,
|
||||
actionRemoveClientIDFromOpenIDConnectProvider,
|
||||
actionUpdateOpenIDConnectProviderThumbprint,
|
||||
actionTagOpenIDConnectProvider,
|
||||
actionUntagOpenIDConnectProvider:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -56,10 +68,221 @@ func (e *EmbeddedIamApi) dispatchOIDCProviderAction(ctx context.Context, values
|
||||
case actionGetOpenIDConnectProvider:
|
||||
resp, err := e.getOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionCreateOpenIDConnectProvider:
|
||||
resp, err := e.createOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionDeleteOpenIDConnectProvider:
|
||||
resp, err := e.deleteOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionAddClientIDToOpenIDConnectProvider:
|
||||
resp, err := e.addClientIDToOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionRemoveClientIDFromOpenIDConnectProvider:
|
||||
resp, err := e.removeClientIDFromOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionUpdateOpenIDConnectProviderThumbprint:
|
||||
resp, err := e.updateOpenIDConnectProviderThumbprint(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionTagOpenIDConnectProvider:
|
||||
resp, err := e.tagOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
case actionUntagOpenIDConnectProvider:
|
||||
resp, err := e.untagOpenIDConnectProvider(ctx, mgr, values)
|
||||
return resp, err, true
|
||||
}
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
// extractMemberList collects all values from `Foo.member.<n>=...` form
|
||||
// parameters in order of N. AWS query-string conventions encode list inputs
|
||||
// this way, so List/Add/Update/Tag actions all share this helper.
|
||||
func extractMemberList(values url.Values, prefix string) []string {
|
||||
out := []string{}
|
||||
// Members are indexed from 1; iterate until a missing index breaks the run.
|
||||
for i := 1; ; i++ {
|
||||
key := fmt.Sprintf("%s.member.%d", prefix, i)
|
||||
v := values.Get(key)
|
||||
if v == "" {
|
||||
break
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) createOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.CreateOpenIDConnectProviderResponse, *iamError) {
|
||||
urlStr := strings.TrimSpace(values.Get("Url"))
|
||||
if urlStr == "" {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("Url is required")}
|
||||
}
|
||||
clientIDs := extractMemberList(values, "ClientIDList")
|
||||
if len(clientIDs) == 0 {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("ClientIDList must contain at least one entry")}
|
||||
}
|
||||
thumbprints := extractMemberList(values, "ThumbprintList")
|
||||
tags := extractTags(values)
|
||||
|
||||
accountID := mgr.GetSTSService().Config.AccountId
|
||||
arn, err := integration.DeriveOIDCProviderARN(accountID, urlStr)
|
||||
if err != nil {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: err}
|
||||
}
|
||||
|
||||
rec := &integration.OIDCProviderRecord{
|
||||
AccountID: accountID,
|
||||
ARN: arn,
|
||||
URL: urlStr,
|
||||
ClientIDs: clientIDs,
|
||||
Thumbprints: thumbprints,
|
||||
Tags: tags,
|
||||
}
|
||||
if err := mgr.CreateOIDCProvider(ctx, rec); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderAlreadyExists) {
|
||||
return nil, &iamError{Code: iam.ErrCodeEntityAlreadyExistsException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: err}
|
||||
}
|
||||
|
||||
resp := &iamlib.CreateOpenIDConnectProviderResponse{}
|
||||
resp.CreateOpenIDConnectProviderResult.OpenIDConnectProviderArn = rec.ARN
|
||||
if len(rec.Tags) > 0 {
|
||||
out := make([]*iamlib.IAMTag, 0, len(rec.Tags))
|
||||
for k, v := range rec.Tags {
|
||||
out = append(out, &iamlib.IAMTag{Key: k, Value: v})
|
||||
}
|
||||
resp.CreateOpenIDConnectProviderResult.Tags = out
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) deleteOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.DeleteOpenIDConnectProviderResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
if err := mgr.DeleteOIDCProvider(ctx, arn); err != nil {
|
||||
return nil, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
}
|
||||
return &iamlib.DeleteOpenIDConnectProviderResponse{}, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) addClientIDToOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.AddClientIDToOpenIDConnectProviderResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
clientID := strings.TrimSpace(values.Get("ClientID"))
|
||||
if clientID == "" {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("ClientID is required")}
|
||||
}
|
||||
if err := mgr.AddClientIDToOIDCProvider(ctx, arn, clientID); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderNotFound) {
|
||||
return nil, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
}
|
||||
return &iamlib.AddClientIDToOpenIDConnectProviderResponse{}, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) removeClientIDFromOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.RemoveClientIDFromOpenIDConnectProviderResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
clientID := strings.TrimSpace(values.Get("ClientID"))
|
||||
if clientID == "" {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("ClientID is required")}
|
||||
}
|
||||
if err := mgr.RemoveClientIDFromOIDCProvider(ctx, arn, clientID); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderNotFound) {
|
||||
return nil, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
}
|
||||
return &iamlib.RemoveClientIDFromOpenIDConnectProviderResponse{}, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) updateOpenIDConnectProviderThumbprint(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.UpdateOpenIDConnectProviderThumbprintResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
thumbprints := extractMemberList(values, "ThumbprintList")
|
||||
if len(thumbprints) == 0 {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("ThumbprintList must contain at least one entry")}
|
||||
}
|
||||
if err := mgr.UpdateOIDCProviderThumbprints(ctx, arn, thumbprints); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderNotFound) {
|
||||
return nil, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: err}
|
||||
}
|
||||
return &iamlib.UpdateOpenIDConnectProviderThumbprintResponse{}, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) tagOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.TagOpenIDConnectProviderResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
tags := extractTags(values)
|
||||
if len(tags) == 0 {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("Tags must contain at least one Key/Value pair")}
|
||||
}
|
||||
if err := mgr.TagOIDCProvider(ctx, arn, tags); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderNotFound) {
|
||||
return nil, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
}
|
||||
return &iamlib.TagOpenIDConnectProviderResponse{}, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) untagOpenIDConnectProvider(ctx context.Context, mgr *integration.IAMManager, values url.Values) (*iamlib.UntagOpenIDConnectProviderResponse, *iamError) {
|
||||
arn, iamErr := requireProviderArn(values)
|
||||
if iamErr != nil {
|
||||
return nil, iamErr
|
||||
}
|
||||
keys := extractMemberList(values, "TagKeys")
|
||||
if len(keys) == 0 {
|
||||
return nil, &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("TagKeys must contain at least one entry")}
|
||||
}
|
||||
if err := mgr.UntagOIDCProvider(ctx, arn, keys); err != nil {
|
||||
if errors.Is(err, integration.ErrOIDCProviderNotFound) {
|
||||
return nil, &iamError{Code: iam.ErrCodeNoSuchEntityException, Error: err}
|
||||
}
|
||||
return nil, &iamError{Code: iam.ErrCodeServiceFailureException, Error: err}
|
||||
}
|
||||
return &iamlib.UntagOpenIDConnectProviderResponse{}, nil
|
||||
}
|
||||
|
||||
// extractTags walks the AWS IAM "Tags.member.N.Key / Tags.member.N.Value"
|
||||
// query-string convention and returns the parsed map. Returns nil (not an
|
||||
// empty map) when no tags are present so the caller can distinguish
|
||||
// "untouched" from "empty".
|
||||
func extractTags(values url.Values) map[string]string {
|
||||
var out map[string]string
|
||||
for i := 1; ; i++ {
|
||||
k := values.Get(fmt.Sprintf("Tags.member.%d.Key", i))
|
||||
if k == "" {
|
||||
break
|
||||
}
|
||||
if out == nil {
|
||||
out = make(map[string]string)
|
||||
}
|
||||
out[k] = values.Get(fmt.Sprintf("Tags.member.%d.Value", i))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func requireProviderArn(values url.Values) (string, *iamError) {
|
||||
arn := strings.TrimSpace(values.Get("OpenIDConnectProviderArn"))
|
||||
if arn == "" {
|
||||
return "", &iamError{Code: iam.ErrCodeInvalidInputException, Error: errors.New("OpenIDConnectProviderArn is required")}
|
||||
}
|
||||
return arn, nil
|
||||
}
|
||||
|
||||
func (e *EmbeddedIamApi) oidcIAMManager() *integration.IAMManager {
|
||||
if e.iam == nil || e.iam.iamIntegration == nil {
|
||||
return nil
|
||||
|
||||
@@ -149,3 +149,248 @@ func TestReadOnlyAllowsOIDCList(t *testing.T) {
|
||||
t.Fatalf("read-only mode should allow ListOpenIDConnectProviders: %v", iamErr.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadOnlyDeniesOIDCMutations(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
api.readOnly = true
|
||||
mutations := []string{
|
||||
actionCreateOpenIDConnectProvider,
|
||||
actionDeleteOpenIDConnectProvider,
|
||||
actionAddClientIDToOpenIDConnectProvider,
|
||||
actionRemoveClientIDFromOpenIDConnectProvider,
|
||||
actionUpdateOpenIDConnectProviderThumbprint,
|
||||
actionTagOpenIDConnectProvider,
|
||||
actionUntagOpenIDConnectProvider,
|
||||
}
|
||||
for _, action := range mutations {
|
||||
t.Run(action, func(t *testing.T) {
|
||||
values := url.Values{}
|
||||
values.Set("Action", action)
|
||||
_, iamErr := api.ExecuteAction(context.Background(), values, true, "ro-deny")
|
||||
if iamErr == nil {
|
||||
t.Fatalf("expected denial for %s in read-only mode", action)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOpenIDConnectProvider(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionCreateOpenIDConnectProvider)
|
||||
values.Set("Url", "https://auth.example.com")
|
||||
values.Set("ClientIDList.member.1", "alpha")
|
||||
values.Set("ClientIDList.member.2", "beta")
|
||||
values.Set("ThumbprintList.member.1", "9e99a48a9960b14926bb7f3b02e22da2b0ab7280")
|
||||
values.Set("Tags.member.1.Key", "team")
|
||||
values.Set("Tags.member.1.Value", "infra")
|
||||
|
||||
resp, iamErr := api.ExecuteAction(context.Background(), values, true, "create-1")
|
||||
if iamErr != nil {
|
||||
t.Fatalf("ExecuteAction: %v", iamErr.Error)
|
||||
}
|
||||
createResp, ok := resp.(*iamlib.CreateOpenIDConnectProviderResponse)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected response type %T", resp)
|
||||
}
|
||||
wantArn := "arn:aws:iam::111122223333:oidc-provider/auth.example.com"
|
||||
if createResp.CreateOpenIDConnectProviderResult.OpenIDConnectProviderArn != wantArn {
|
||||
t.Fatalf("ARN mismatch: got=%s want=%s",
|
||||
createResp.CreateOpenIDConnectProviderResult.OpenIDConnectProviderArn, wantArn)
|
||||
}
|
||||
|
||||
// Get the new provider back to confirm persistence and clientId list.
|
||||
getValues := url.Values{}
|
||||
getValues.Set("Action", actionGetOpenIDConnectProvider)
|
||||
getValues.Set("OpenIDConnectProviderArn", wantArn)
|
||||
getResp, iamErr := api.ExecuteAction(context.Background(), getValues, true, "get-after-create")
|
||||
if iamErr != nil {
|
||||
t.Fatalf("Get after create: %v", iamErr.Error)
|
||||
}
|
||||
gr := getResp.(*iamlib.GetOpenIDConnectProviderResponse).GetOpenIDConnectProviderResult
|
||||
if len(gr.ClientIDList) != 2 || gr.ClientIDList[0] != "alpha" || gr.ClientIDList[1] != "beta" {
|
||||
t.Fatalf("ClientIDList persisted incorrectly: %v", gr.ClientIDList)
|
||||
}
|
||||
if len(gr.ThumbprintList) != 1 || gr.ThumbprintList[0] != "9e99a48a9960b14926bb7f3b02e22da2b0ab7280" {
|
||||
t.Fatalf("ThumbprintList persisted incorrectly: %v", gr.ThumbprintList)
|
||||
}
|
||||
if len(gr.Tags) != 1 || gr.Tags[0].Key != "team" || gr.Tags[0].Value != "infra" {
|
||||
t.Fatalf("Tags persisted incorrectly: %v", gr.Tags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOpenIDConnectProviderRejectsBadInput(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
|
||||
t.Run("missing Url", func(t *testing.T) {
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionCreateOpenIDConnectProvider)
|
||||
values.Set("ClientIDList.member.1", "x")
|
||||
_, iamErr := api.ExecuteAction(context.Background(), values, true, "")
|
||||
if iamErr == nil || iamErr.Code != "InvalidInput" {
|
||||
t.Fatalf("expected InvalidInput, got %v", iamErr)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing ClientIDList", func(t *testing.T) {
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionCreateOpenIDConnectProvider)
|
||||
values.Set("Url", "https://auth.example.com")
|
||||
_, iamErr := api.ExecuteAction(context.Background(), values, true, "")
|
||||
if iamErr == nil || iamErr.Code != "InvalidInput" {
|
||||
t.Fatalf("expected InvalidInput, got %v", iamErr)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("invalid thumbprint", func(t *testing.T) {
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionCreateOpenIDConnectProvider)
|
||||
values.Set("Url", "https://auth.example.com")
|
||||
values.Set("ClientIDList.member.1", "x")
|
||||
values.Set("ThumbprintList.member.1", "not-a-sha1")
|
||||
_, iamErr := api.ExecuteAction(context.Background(), values, true, "")
|
||||
if iamErr == nil || iamErr.Code != "InvalidInput" {
|
||||
t.Fatalf("expected InvalidInput, got %v", iamErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateOpenIDConnectProviderConflict(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionCreateOpenIDConnectProvider)
|
||||
values.Set("Url", "https://accounts.google.com") // already mirrored from static config
|
||||
values.Set("ClientIDList.member.1", "x")
|
||||
|
||||
_, iamErr := api.ExecuteAction(context.Background(), values, true, "")
|
||||
if iamErr == nil {
|
||||
t.Fatal("expected conflict for duplicate provider")
|
||||
}
|
||||
if iamErr.Code != "EntityAlreadyExists" {
|
||||
t.Fatalf("expected EntityAlreadyExists, got %s", iamErr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteOpenIDConnectProvider(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
arn := "arn:aws:iam::111122223333:oidc-provider/accounts.google.com"
|
||||
|
||||
values := url.Values{}
|
||||
values.Set("Action", actionDeleteOpenIDConnectProvider)
|
||||
values.Set("OpenIDConnectProviderArn", arn)
|
||||
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), values, true, ""); iamErr != nil {
|
||||
t.Fatalf("delete: %v", iamErr.Error)
|
||||
}
|
||||
// Verify gone.
|
||||
getValues := url.Values{}
|
||||
getValues.Set("Action", actionGetOpenIDConnectProvider)
|
||||
getValues.Set("OpenIDConnectProviderArn", arn)
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), getValues, true, ""); iamErr == nil {
|
||||
t.Fatal("expected not-found after delete")
|
||||
}
|
||||
// Idempotent.
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), values, true, ""); iamErr != nil {
|
||||
t.Fatalf("idempotent delete failed: %v", iamErr.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddRemoveClientID(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
arn := "arn:aws:iam::111122223333:oidc-provider/accounts.google.com"
|
||||
|
||||
add := url.Values{}
|
||||
add.Set("Action", actionAddClientIDToOpenIDConnectProvider)
|
||||
add.Set("OpenIDConnectProviderArn", arn)
|
||||
add.Set("ClientID", "extra-client")
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), add, true, ""); iamErr != nil {
|
||||
t.Fatalf("add: %v", iamErr.Error)
|
||||
}
|
||||
|
||||
getValues := url.Values{}
|
||||
getValues.Set("Action", actionGetOpenIDConnectProvider)
|
||||
getValues.Set("OpenIDConnectProviderArn", arn)
|
||||
resp, iamErr := api.ExecuteAction(context.Background(), getValues, true, "")
|
||||
if iamErr != nil {
|
||||
t.Fatalf("get: %v", iamErr.Error)
|
||||
}
|
||||
got := resp.(*iamlib.GetOpenIDConnectProviderResponse).GetOpenIDConnectProviderResult.ClientIDList
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("expected 2 clients after add, got %v", got)
|
||||
}
|
||||
|
||||
// Idempotent add.
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), add, true, ""); iamErr != nil {
|
||||
t.Fatalf("idempotent add: %v", iamErr.Error)
|
||||
}
|
||||
|
||||
// Remove.
|
||||
rm := url.Values{}
|
||||
rm.Set("Action", actionRemoveClientIDFromOpenIDConnectProvider)
|
||||
rm.Set("OpenIDConnectProviderArn", arn)
|
||||
rm.Set("ClientID", "extra-client")
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), rm, true, ""); iamErr != nil {
|
||||
t.Fatalf("remove: %v", iamErr.Error)
|
||||
}
|
||||
resp, _ = api.ExecuteAction(context.Background(), getValues, true, "")
|
||||
got = resp.(*iamlib.GetOpenIDConnectProviderResponse).GetOpenIDConnectProviderResult.ClientIDList
|
||||
if len(got) != 1 || got[0] != "client-google" {
|
||||
t.Fatalf("unexpected clients after remove: %v", got)
|
||||
}
|
||||
|
||||
// Removing a missing client is a no-op.
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), rm, true, ""); iamErr != nil {
|
||||
t.Fatalf("idempotent remove: %v", iamErr.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateThumbprintAndTags(t *testing.T) {
|
||||
api, _ := newOIDCTestAPI(t)
|
||||
arn := "arn:aws:iam::111122223333:oidc-provider/accounts.google.com"
|
||||
|
||||
upd := url.Values{}
|
||||
upd.Set("Action", actionUpdateOpenIDConnectProviderThumbprint)
|
||||
upd.Set("OpenIDConnectProviderArn", arn)
|
||||
upd.Set("ThumbprintList.member.1", "0000000000000000000000000000000000000000")
|
||||
upd.Set("ThumbprintList.member.2", "1111111111111111111111111111111111111111")
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), upd, true, ""); iamErr != nil {
|
||||
t.Fatalf("update thumbprints: %v", iamErr.Error)
|
||||
}
|
||||
|
||||
tag := url.Values{}
|
||||
tag.Set("Action", actionTagOpenIDConnectProvider)
|
||||
tag.Set("OpenIDConnectProviderArn", arn)
|
||||
tag.Set("Tags.member.1.Key", "owner")
|
||||
tag.Set("Tags.member.1.Value", "platform")
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), tag, true, ""); iamErr != nil {
|
||||
t.Fatalf("tag: %v", iamErr.Error)
|
||||
}
|
||||
|
||||
get := url.Values{}
|
||||
get.Set("Action", actionGetOpenIDConnectProvider)
|
||||
get.Set("OpenIDConnectProviderArn", arn)
|
||||
resp, iamErr := api.ExecuteAction(context.Background(), get, true, "")
|
||||
if iamErr != nil {
|
||||
t.Fatalf("get: %v", iamErr.Error)
|
||||
}
|
||||
gr := resp.(*iamlib.GetOpenIDConnectProviderResponse).GetOpenIDConnectProviderResult
|
||||
if len(gr.ThumbprintList) != 2 {
|
||||
t.Fatalf("ThumbprintList persisted incorrectly: %v", gr.ThumbprintList)
|
||||
}
|
||||
if len(gr.Tags) != 1 || gr.Tags[0].Key != "owner" {
|
||||
t.Fatalf("Tags persisted incorrectly: %v", gr.Tags)
|
||||
}
|
||||
|
||||
untag := url.Values{}
|
||||
untag.Set("Action", actionUntagOpenIDConnectProvider)
|
||||
untag.Set("OpenIDConnectProviderArn", arn)
|
||||
untag.Set("TagKeys.member.1", "owner")
|
||||
if _, iamErr := api.ExecuteAction(context.Background(), untag, true, ""); iamErr != nil {
|
||||
t.Fatalf("untag: %v", iamErr.Error)
|
||||
}
|
||||
resp, _ = api.ExecuteAction(context.Background(), get, true, "")
|
||||
gr = resp.(*iamlib.GetOpenIDConnectProviderResponse).GetOpenIDConnectProviderResult
|
||||
if len(gr.Tags) != 0 {
|
||||
t.Fatalf("Tags should be empty after untag, got: %v", gr.Tags)
|
||||
}
|
||||
}
|
||||
@@ -373,6 +373,7 @@ func NewS3ApiServerWithStore(router *mux.Router, option *S3ApiServerOption, expl
|
||||
filer.IamConfigDirectory + "/policies",
|
||||
filer.IamConfigDirectory + "/service_accounts",
|
||||
filer.IamConfigDirectory + "/groups",
|
||||
filer.IamConfigDirectory + "/oidc-providers",
|
||||
})
|
||||
|
||||
// Start bucket size metrics collection in background
|
||||
|
||||
Reference in new issue
Block a user