fix(s3): sync IAM policies to advanced IAM Manager policy engine (#9577)

* fix(s3): sync IAM policies to advanced IAM Manager policy engine

* test(s3): add unit tests for PutPolicy/DeletePolicy IAM Manager sync

* fix(s3): flush loaded policies in SetIAMIntegration, drop extra reload

Sync the policies already loaded from the credential store into the IAM
Manager's engine from SetIAMIntegration itself, instead of re-running a
full LoadS3ApiConfigurationFromCredentialManager after setup. This covers
both startup orderings without a second filer round-trip or racing the
async loader goroutine: if the load won, the policies are in memory to
push; if SetIAMIntegration won, the load's own sync runs afterward.

Move the runtime PutPolicy/DeletePolicy sync out of the iam.m write lock
so the per-request auth RLock path isn't blocked by the policy recompile.

* fix(s3): serialize IAM manager policy resync to avoid stale snapshots

SyncRuntimePolicies replaces the manager's full policy set, so applying a
policy view captured before a later mutation can resurrect a deleted
policy or drop a new one. Funnel every path (PutPolicy, DeletePolicy,
SetIAMIntegration, and the credential-manager load) through a single
resyncIAMManagerPolicies that serializes on a dedicated mutex and reads
iam.policies fresh at apply time, so the live map always wins regardless
of interleaving. The load now installs the config into iam.policies
before resyncing, closing the window where the manager held policies the
map didn't yet have.

---------

Co-authored-by: Chris Lu <chris.lu@gmail.com>
This commit is contained in:
Mmx233andChris Lu authored and GitHub committed 2026-05-21 00:39:42 -07:00
1 parent 7e4691f2dc
commit 9b9fdb5b76
3 files changed
+223 -7

No files matched your search

+7
View File
@@ -323,6 +323,13 @@ func NewS3ApiServerWithStore(router *mux.Router, option *S3ApiServerOption, expl
// IAM config file. Without one, EnableIam is the implicit mini default
// and we must keep the "no credentials = allow all" startup behavior so
// `docker run seaweedfs` works out of the box (fixes #9557).
//
// SetIAMIntegration also flushes the policies already loaded from the
// credential store into this manager's engine. The earlier config
// loads (the synchronous one in NewIdentityAccessManagementWithStore
// and the async goroutine) may have run before iamIntegration was set,
// in which case their syncRuntimePoliciesToIAMManager call was a no-op
// and identities relying on policy_names would get AccessDenied.
iam.SetIAMIntegration(s3iam)
if option.IamConfig != "" {
iam.EnableAuthEnforcement()