diff --git a/weed/iam/integration/oidc_provider_persist_test.go b/weed/iam/integration/oidc_provider_persist_test.go index 26a6f81250..1b9dc0968c 100644 --- a/weed/iam/integration/oidc_provider_persist_test.go +++ b/weed/iam/integration/oidc_provider_persist_test.go @@ -649,3 +649,62 @@ func TestSameIssuerRecordsShareOneProvider(t *testing.T) { "a changed record kept the shared provider") assert.True(t, stsKnowsIssuerForAccount(t, mgr, persistTestAPIIssuer, "222222222222")) } + +// The replay flag is part of what a provider is built from: two records that +// differ only in it must not share a provider, and flipping it on a record +// must rebuild. +func TestOIDCProviderFingerprintsSeparateReplayFlag(t *testing.T) { + disabled := false + base := &OIDCProviderRecord{ + ARN: "arn:aws:iam::111111111111:oidc-provider/issuer.example", URL: "https://issuer.example", + ClientIDs: []string{"aud"}, + } + off := *base + off.JTIReplayProtectionEnabled = &disabled + + assert.NotEqual(t, oidcProviderConfigFingerprint(base), oidcProviderConfigFingerprint(&off), + "records differing only in the replay flag share a config fingerprint") + assert.NotEqual(t, oidcProviderFingerprint(base), oidcProviderFingerprint(&off), + "a flipped replay flag does not rebuild the provider") +} + +// A config-file provider's jtiReplayProtectionEnabled rides the record into +// the runtime build path, so a mirrored static provider keeps the flag the +// provider factory would have applied. +func TestStaticOIDCProviderRecordsCarryJTIReplayFlag(t *testing.T) { + records := staticOIDCProviderRecords(&sts.STSConfig{ + AccountId: "111111111111", + Providers: []*sts.ProviderConfig{ + { + Name: "k8s", Type: sts.ProviderTypeOIDC, Enabled: true, + Config: map[string]interface{}{ + "issuer": "https://k8s.example", + "clientId": "sts.amazonaws.com", + "jtiReplayProtectionEnabled": false, + }, + }, + { + Name: "plain", Type: sts.ProviderTypeOIDC, Enabled: true, + Config: map[string]interface{}{ + "issuer": "https://issuer.example", + "clientId": "sts.amazonaws.com", + }, + }, + }, + }) + require.Len(t, records, 2) + + var flagged, plain *OIDCProviderRecord + for _, rec := range records { + if rec.URL == "https://k8s.example" { + flagged = rec + } else { + plain = rec + } + } + require.NotNil(t, flagged) + require.NotNil(t, flagged.JTIReplayProtectionEnabled) + assert.False(t, *flagged.JTIReplayProtectionEnabled) + require.NotNil(t, plain) + assert.Nil(t, plain.JTIReplayProtectionEnabled) +} diff --git a/weed/server/filer_server_handlers_iam_grpc_sts_test.go b/weed/server/filer_server_handlers_iam_grpc_sts_test.go index c45865be71..720958b131 100644 --- a/weed/server/filer_server_handlers_iam_grpc_sts_test.go +++ b/weed/server/filer_server_handlers_iam_grpc_sts_test.go @@ -497,3 +497,40 @@ func TestIamGrpc_DeleteOIDCProviderDoesNotDeleteAProviderReplacedMeanwhile(t *te require.NoError(t, err, "the replacement record was deleted") assert.Equal(t, []string{"new"}, rec.ClientIDs) } + +// The flag rides PutOIDCProvider into the record, is reported back by Get, and +// a Put that does not carry it keeps the stored value. +func TestIamGrpc_PutOIDCProviderJTIReplayProtectionFlag(t *testing.T) { + s, ctx, providers, _ := newSTSTestServer(t) + disabled, enabled := false, true + + put, err := s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{ + IssuerUrl: "https://oidc.example", ClientIds: []string{"aud"}, + JtiReplayProtectionEnabled: &disabled, + }) + require.NoError(t, err) + + got, err := s.GetOIDCProvider(ctx, &iam_pb.GetOIDCProviderRequest{IssuerUrl: "https://oidc.example"}) + require.NoError(t, err) + require.NotNil(t, got.Provider.JtiReplayProtectionEnabled) + assert.False(t, *got.Provider.JtiReplayProtectionEnabled) + + _, err = s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{ + IssuerUrl: "https://oidc.example", ClientIds: []string{"aud2"}, + }) + require.NoError(t, err) + rec, err := providers.GetProviderByARN(context.Background(), "", put.Arn) + require.NoError(t, err) + require.NotNil(t, rec.JTIReplayProtectionEnabled) + assert.False(t, *rec.JTIReplayProtectionEnabled) + + _, err = s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{ + IssuerUrl: "https://oidc.example", ClientIds: []string{"aud"}, + JtiReplayProtectionEnabled: &enabled, + }) + require.NoError(t, err) + rec, err = providers.GetProviderByARN(context.Background(), "", put.Arn) + require.NoError(t, err) + require.NotNil(t, rec.JTIReplayProtectionEnabled) + assert.True(t, *rec.JTIReplayProtectionEnabled) +}