mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ea089519 | ||
|
|
e655ce9057 | ||
|
|
d51dd99845 | ||
|
|
3e4306da55 |
No files matched your search
@@ -849,13 +849,14 @@ func staticOIDCProviderRecords(stsConfig *sts.STSConfig) map[string]*OIDCProvide
|
||||
continue
|
||||
}
|
||||
out[arn] = &OIDCProviderRecord{
|
||||
AccountID: stsConfig.AccountId,
|
||||
ARN: arn,
|
||||
URL: issuer,
|
||||
ClientIDs: extractClientIDs(pc.Config),
|
||||
Thumbprints: extractStringList(pc.Config, "thumbprints"),
|
||||
AllowedPrincipalTagKeys: extractStringList(pc.Config, "allowedPrincipalTagKeys"),
|
||||
PolicyClaim: extractString(pc.Config, "policyClaim"),
|
||||
AccountID: stsConfig.AccountId,
|
||||
ARN: arn,
|
||||
URL: issuer,
|
||||
ClientIDs: extractClientIDs(pc.Config),
|
||||
Thumbprints: extractStringList(pc.Config, "thumbprints"),
|
||||
AllowedPrincipalTagKeys: extractStringList(pc.Config, "allowedPrincipalTagKeys"),
|
||||
PolicyClaim: extractString(pc.Config, "policyClaim"),
|
||||
JTIReplayProtectionEnabled: extractBool(pc.Config, sts.ConfigFieldJTIReplayProtectionEnabled),
|
||||
// No CreatedAt: a config-file provider has no creation time the
|
||||
// server could report consistently across restarts.
|
||||
}
|
||||
@@ -1055,14 +1056,15 @@ func (m *IAMManager) oidcProviderStillReferenced(provider *oidc.OIDCProvider) bo
|
||||
// from, so a refresh rebuilds the provider only when that content changed.
|
||||
func oidcProviderFingerprint(rec *OIDCProviderRecord) string {
|
||||
key, _ := json.Marshal(struct {
|
||||
ARN string
|
||||
AccountID string
|
||||
URL string
|
||||
ClientIDs []string
|
||||
Thumbprints []string
|
||||
AllowedPrincipalTagKeys []string
|
||||
PolicyClaim string
|
||||
}{rec.ARN, rec.AccountID, rec.URL, rec.ClientIDs, rec.Thumbprints, rec.AllowedPrincipalTagKeys, rec.PolicyClaim})
|
||||
ARN string
|
||||
AccountID string
|
||||
URL string
|
||||
ClientIDs []string
|
||||
Thumbprints []string
|
||||
AllowedPrincipalTagKeys []string
|
||||
PolicyClaim string
|
||||
JTIReplayProtectionEnabled *bool
|
||||
}{rec.ARN, rec.AccountID, rec.URL, rec.ClientIDs, rec.Thumbprints, rec.AllowedPrincipalTagKeys, rec.PolicyClaim, rec.JTIReplayProtectionEnabled})
|
||||
sum := sha256.Sum256(key)
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
@@ -1072,11 +1074,12 @@ func oidcProviderFingerprint(rec *OIDCProviderRecord) string {
|
||||
// record's name — so records that differ only in identity reuse one provider.
|
||||
func oidcProviderConfigFingerprint(rec *OIDCProviderRecord) string {
|
||||
key, _ := json.Marshal(&oidc.OIDCConfig{
|
||||
Issuer: rec.URL,
|
||||
ClientIDs: rec.ClientIDs,
|
||||
Thumbprints: rec.Thumbprints,
|
||||
AllowedPrincipalTagKeys: rec.AllowedPrincipalTagKeys,
|
||||
PolicyClaim: rec.PolicyClaim,
|
||||
Issuer: rec.URL,
|
||||
ClientIDs: rec.ClientIDs,
|
||||
Thumbprints: rec.Thumbprints,
|
||||
AllowedPrincipalTagKeys: rec.AllowedPrincipalTagKeys,
|
||||
PolicyClaim: rec.PolicyClaim,
|
||||
JTIReplayProtectionEnabled: rec.JTIReplayProtectionEnabled,
|
||||
})
|
||||
sum := sha256.Sum256(key)
|
||||
return hex.EncodeToString(sum[:])
|
||||
@@ -1096,6 +1099,10 @@ func buildOIDCProviderFromRecord(rec *OIDCProviderRecord) (*oidc.OIDCProvider, e
|
||||
AllowedPrincipalTagKeys: append([]string(nil), rec.AllowedPrincipalTagKeys...),
|
||||
PolicyClaim: rec.PolicyClaim,
|
||||
}
|
||||
if rec.JTIReplayProtectionEnabled != nil {
|
||||
enabled := *rec.JTIReplayProtectionEnabled
|
||||
cfg.JTIReplayProtectionEnabled = &enabled
|
||||
}
|
||||
provider := oidc.NewOIDCProvider(rec.ARN)
|
||||
if err := provider.Initialize(cfg); err != nil {
|
||||
return nil, err
|
||||
@@ -1171,6 +1178,18 @@ func extractString(cfg map[string]interface{}, key string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// extractBool reads a single bool field from the provider's static config
|
||||
// map; missing or non-bool values produce nil.
|
||||
func extractBool(cfg map[string]interface{}, key string) *bool {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
if b, ok := cfg[key].(bool); ok {
|
||||
return &b
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getFilerAddress returns the current filer address using the provider function
|
||||
func (m *IAMManager) getFilerAddress() string {
|
||||
if m.filerAddressProvider != nil {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -74,6 +74,10 @@ type OIDCProviderRecord struct {
|
||||
// derive their effective policies from this JWT claim.
|
||||
PolicyClaim string `json:"policyClaim,omitempty"`
|
||||
|
||||
// JTIReplayProtectionEnabled overrides the server default for this
|
||||
// provider; nil means replay protection is on.
|
||||
JTIReplayProtectionEnabled *bool `json:"jtiReplayProtectionEnabled,omitempty"`
|
||||
|
||||
// Tags is the AWS-style tag set attached to the IAM resource itself
|
||||
// (audit/inventory metadata, not propagated into sessions).
|
||||
Tags map[string]string `json:"tags,omitempty"`
|
||||
@@ -639,6 +643,10 @@ func copyOIDCProviderRecord(rec *OIDCProviderRecord) *OIDCProviderRecord {
|
||||
if rec.AllowedPrincipalTagKeys != nil {
|
||||
cp.AllowedPrincipalTagKeys = append([]string(nil), rec.AllowedPrincipalTagKeys...)
|
||||
}
|
||||
if rec.JTIReplayProtectionEnabled != nil {
|
||||
enabled := *rec.JTIReplayProtectionEnabled
|
||||
cp.JTIReplayProtectionEnabled = &enabled
|
||||
}
|
||||
if rec.Tags != nil {
|
||||
cp.Tags = make(map[string]string, len(rec.Tags))
|
||||
for k, v := range rec.Tags {
|
||||
|
||||
@@ -331,6 +331,8 @@ message OIDCProvider {
|
||||
// from it and the issuer URL.
|
||||
string account_id = 4;
|
||||
string arn = 5; // output only
|
||||
// unset means the server default (replay protection on)
|
||||
optional bool jti_replay_protection_enabled = 6;
|
||||
}
|
||||
|
||||
// PutOIDCProviderRequest creates the provider, or replaces the client IDs and
|
||||
@@ -340,6 +342,8 @@ message PutOIDCProviderRequest {
|
||||
repeated string client_ids = 2;
|
||||
repeated string thumbprints = 3;
|
||||
string account_id = 4;
|
||||
// unset keeps the stored value, or the server default on create
|
||||
optional bool jti_replay_protection_enabled = 5;
|
||||
}
|
||||
|
||||
message PutOIDCProviderResponse {
|
||||
|
||||
+39
-15
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v6.33.4
|
||||
// protoc v3.21.12
|
||||
// source: iam.proto
|
||||
|
||||
package iam_pb
|
||||
@@ -2687,10 +2687,12 @@ type OIDCProvider struct {
|
||||
Thumbprints []string `protobuf:"bytes,3,rep,name=thumbprints,proto3" json:"thumbprints,omitempty"`
|
||||
// account_id scopes the provider; empty means global. The ARN is derived
|
||||
// from it and the issuer URL.
|
||||
AccountId string `protobuf:"bytes,4,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"`
|
||||
Arn string `protobuf:"bytes,5,opt,name=arn,proto3" json:"arn,omitempty"` // output only
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
AccountId string `protobuf:"bytes,4,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"`
|
||||
Arn string `protobuf:"bytes,5,opt,name=arn,proto3" json:"arn,omitempty"` // output only
|
||||
// unset means the server default (replay protection on)
|
||||
JtiReplayProtectionEnabled *bool `protobuf:"varint,6,opt,name=jti_replay_protection_enabled,json=jtiReplayProtectionEnabled,proto3,oneof" json:"jti_replay_protection_enabled,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *OIDCProvider) Reset() {
|
||||
@@ -2758,16 +2760,25 @@ func (x *OIDCProvider) GetArn() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *OIDCProvider) GetJtiReplayProtectionEnabled() bool {
|
||||
if x != nil && x.JtiReplayProtectionEnabled != nil {
|
||||
return *x.JtiReplayProtectionEnabled
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// PutOIDCProviderRequest creates the provider, or replaces the client IDs and
|
||||
// thumbprints of an existing one.
|
||||
type PutOIDCProviderRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
IssuerUrl string `protobuf:"bytes,1,opt,name=issuer_url,json=issuerUrl,proto3" json:"issuer_url,omitempty"`
|
||||
ClientIds []string `protobuf:"bytes,2,rep,name=client_ids,json=clientIds,proto3" json:"client_ids,omitempty"`
|
||||
Thumbprints []string `protobuf:"bytes,3,rep,name=thumbprints,proto3" json:"thumbprints,omitempty"`
|
||||
AccountId string `protobuf:"bytes,4,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
IssuerUrl string `protobuf:"bytes,1,opt,name=issuer_url,json=issuerUrl,proto3" json:"issuer_url,omitempty"`
|
||||
ClientIds []string `protobuf:"bytes,2,rep,name=client_ids,json=clientIds,proto3" json:"client_ids,omitempty"`
|
||||
Thumbprints []string `protobuf:"bytes,3,rep,name=thumbprints,proto3" json:"thumbprints,omitempty"`
|
||||
AccountId string `protobuf:"bytes,4,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"`
|
||||
// unset keeps the stored value, or the server default on create
|
||||
JtiReplayProtectionEnabled *bool `protobuf:"varint,5,opt,name=jti_replay_protection_enabled,json=jtiReplayProtectionEnabled,proto3,oneof" json:"jti_replay_protection_enabled,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *PutOIDCProviderRequest) Reset() {
|
||||
@@ -2828,6 +2839,13 @@ func (x *PutOIDCProviderRequest) GetAccountId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PutOIDCProviderRequest) GetJtiReplayProtectionEnabled() bool {
|
||||
if x != nil && x.JtiReplayProtectionEnabled != nil {
|
||||
return *x.JtiReplayProtectionEnabled
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type PutOIDCProviderResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Arn string `protobuf:"bytes,1,opt,name=arn,proto3" json:"arn,omitempty"`
|
||||
@@ -4039,7 +4057,7 @@ const file_iam_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"access_key\x18\x01 \x01(\tR\taccessKey\"g\n" +
|
||||
"$GetServiceAccountByAccessKeyResponse\x12?\n" +
|
||||
"\x0fservice_account\x18\x01 \x01(\v2\x16.iam_pb.ServiceAccountR\x0eserviceAccount\"\x9f\x01\n" +
|
||||
"\x0fservice_account\x18\x01 \x01(\v2\x16.iam_pb.ServiceAccountR\x0eserviceAccount\"\x89\x02\n" +
|
||||
"\fOIDCProvider\x12\x1d\n" +
|
||||
"\n" +
|
||||
"issuer_url\x18\x01 \x01(\tR\tissuerUrl\x12\x1d\n" +
|
||||
@@ -4048,7 +4066,9 @@ const file_iam_proto_rawDesc = "" +
|
||||
"\vthumbprints\x18\x03 \x03(\tR\vthumbprints\x12\x1d\n" +
|
||||
"\n" +
|
||||
"account_id\x18\x04 \x01(\tR\taccountId\x12\x10\n" +
|
||||
"\x03arn\x18\x05 \x01(\tR\x03arn\"\x97\x01\n" +
|
||||
"\x03arn\x18\x05 \x01(\tR\x03arn\x12F\n" +
|
||||
"\x1djti_replay_protection_enabled\x18\x06 \x01(\bH\x00R\x1ajtiReplayProtectionEnabled\x88\x01\x01B \n" +
|
||||
"\x1e_jti_replay_protection_enabled\"\x81\x02\n" +
|
||||
"\x16PutOIDCProviderRequest\x12\x1d\n" +
|
||||
"\n" +
|
||||
"issuer_url\x18\x01 \x01(\tR\tissuerUrl\x12\x1d\n" +
|
||||
@@ -4056,7 +4076,9 @@ const file_iam_proto_rawDesc = "" +
|
||||
"client_ids\x18\x02 \x03(\tR\tclientIds\x12 \n" +
|
||||
"\vthumbprints\x18\x03 \x03(\tR\vthumbprints\x12\x1d\n" +
|
||||
"\n" +
|
||||
"account_id\x18\x04 \x01(\tR\taccountId\"+\n" +
|
||||
"account_id\x18\x04 \x01(\tR\taccountId\x12F\n" +
|
||||
"\x1djti_replay_protection_enabled\x18\x05 \x01(\bH\x00R\x1ajtiReplayProtectionEnabled\x88\x01\x01B \n" +
|
||||
"\x1e_jti_replay_protection_enabled\"+\n" +
|
||||
"\x17PutOIDCProviderResponse\x12\x10\n" +
|
||||
"\x03arn\x18\x01 \x01(\tR\x03arn\"V\n" +
|
||||
"\x16GetOIDCProviderRequest\x12\x1d\n" +
|
||||
@@ -4340,6 +4362,8 @@ func file_iam_proto_init() {
|
||||
if File_iam_proto != nil {
|
||||
return
|
||||
}
|
||||
file_iam_proto_msgTypes[56].OneofWrappers = []any{}
|
||||
file_iam_proto_msgTypes[57].OneofWrappers = []any{}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
|
||||
@@ -59,11 +59,12 @@ func (s *IamGrpcServer) requireRoleStore() (integration.RoleStore, error) {
|
||||
|
||||
func toPbOIDCProvider(rec *integration.OIDCProviderRecord) *iam_pb.OIDCProvider {
|
||||
return &iam_pb.OIDCProvider{
|
||||
IssuerUrl: rec.URL,
|
||||
ClientIds: rec.ClientIDs,
|
||||
Thumbprints: rec.Thumbprints,
|
||||
AccountId: rec.AccountID,
|
||||
Arn: rec.ARN,
|
||||
IssuerUrl: rec.URL,
|
||||
ClientIds: rec.ClientIDs,
|
||||
Thumbprints: rec.Thumbprints,
|
||||
AccountId: rec.AccountID,
|
||||
Arn: rec.ARN,
|
||||
JtiReplayProtectionEnabled: rec.JTIReplayProtectionEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +96,7 @@ func (s *IamGrpcServer) PutOIDCProvider(ctx context.Context, req *iam_pb.PutOIDC
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
rec.JTIReplayProtectionEnabled = req.JtiReplayProtectionEnabled
|
||||
// Put replaces what the request carries and keeps what it cannot. The
|
||||
// store's atomic update decides which against the record as it is when
|
||||
// written, so a delete racing the put is not merged back from a stale read.
|
||||
@@ -109,6 +111,9 @@ func (s *IamGrpcServer) PutOIDCProvider(ctx context.Context, req *iam_pb.PutOIDC
|
||||
next.Tags = existing.Tags
|
||||
next.AllowedPrincipalTagKeys = existing.AllowedPrincipalTagKeys
|
||||
next.PolicyClaim = existing.PolicyClaim
|
||||
if next.JTIReplayProtectionEnabled == nil {
|
||||
next.JTIReplayProtectionEnabled = existing.JTIReplayProtectionEnabled
|
||||
}
|
||||
}
|
||||
return &next, nil
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in new issue
Block a user