@@ -26,12 +26,15 @@ import (
26
26
"io"
27
27
"io/ioutil"
28
28
"net/http"
29
+ "strconv"
29
30
"strings"
31
+ "time"
30
32
31
33
xhttp "github.com/minio/minio/cmd/http"
32
34
xjwt "github.com/minio/minio/cmd/jwt"
33
35
"github.com/minio/minio/cmd/logger"
34
36
"github.com/minio/minio/pkg/auth"
37
+ objectlock "github.com/minio/minio/pkg/bucket/object/lock"
35
38
"github.com/minio/minio/pkg/bucket/policy"
36
39
"github.com/minio/minio/pkg/hash"
37
40
iampolicy "github.com/minio/minio/pkg/iam/policy"
@@ -464,6 +467,106 @@ func (a authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
464
467
writeErrorResponse (r .Context (), w , errorCodes .ToAPIErr (ErrSignatureVersionNotSupported ), r .URL , guessIsBrowserReq (r ))
465
468
}
466
469
470
+ func validateSignature (atype authType , r * http.Request ) (auth.Credentials , bool , map [string ]interface {}, APIErrorCode ) {
471
+ var cred auth.Credentials
472
+ var owner bool
473
+ var s3Err APIErrorCode
474
+ switch atype {
475
+ case authTypeUnknown , authTypeStreamingSigned :
476
+ return cred , owner , nil , ErrSignatureVersionNotSupported
477
+ case authTypeSignedV2 , authTypePresignedV2 :
478
+ if s3Err = isReqAuthenticatedV2 (r ); s3Err != ErrNone {
479
+ return cred , owner , nil , s3Err
480
+ }
481
+ cred , owner , s3Err = getReqAccessKeyV2 (r )
482
+ case authTypePresigned , authTypeSigned :
483
+ region := globalServerRegion
484
+ if s3Err = isReqAuthenticated (GlobalContext , r , region , serviceS3 ); s3Err != ErrNone {
485
+ return cred , owner , nil , s3Err
486
+ }
487
+ cred , owner , s3Err = getReqAccessKeyV4 (r , region , serviceS3 )
488
+ }
489
+ if s3Err != ErrNone {
490
+ return cred , owner , nil , s3Err
491
+ }
492
+
493
+ claims , s3Err := checkClaimsFromToken (r , cred )
494
+ if s3Err != ErrNone {
495
+ return cred , owner , nil , s3Err
496
+ }
497
+
498
+ return cred , owner , claims , ErrNone
499
+ }
500
+
501
+ func isPutRetentionAllowed (bucketName , objectName string , retDays int , retDate time.Time , retMode objectlock.RetMode , byPassSet bool , r * http.Request , cred auth.Credentials , owner bool , claims map [string ]interface {}) (s3Err APIErrorCode ) {
502
+ var retSet bool
503
+ if cred .AccessKey == "" {
504
+ conditions := getConditionValues (r , "" , "" , nil )
505
+ conditions ["object-lock-mode" ] = []string {string (retMode )}
506
+ conditions ["object-lock-retain-until-date" ] = []string {retDate .Format (time .RFC3339 )}
507
+ if retDays > 0 {
508
+ conditions ["object-lock-remaining-retention-days" ] = []string {strconv .Itoa (retDays )}
509
+ }
510
+ if retMode == objectlock .RetGovernance && byPassSet {
511
+ byPassSet = globalPolicySys .IsAllowed (policy.Args {
512
+ AccountName : cred .AccessKey ,
513
+ Action : policy .Action (policy .BypassGovernanceRetentionAction ),
514
+ BucketName : bucketName ,
515
+ ConditionValues : conditions ,
516
+ IsOwner : false ,
517
+ ObjectName : objectName ,
518
+ })
519
+ }
520
+ if globalPolicySys .IsAllowed (policy.Args {
521
+ AccountName : cred .AccessKey ,
522
+ Action : policy .Action (policy .PutObjectRetentionAction ),
523
+ BucketName : bucketName ,
524
+ ConditionValues : conditions ,
525
+ IsOwner : false ,
526
+ ObjectName : objectName ,
527
+ }) {
528
+ retSet = true
529
+ }
530
+ if byPassSet || retSet {
531
+ return ErrNone
532
+ }
533
+ return ErrAccessDenied
534
+ }
535
+
536
+ conditions := getConditionValues (r , "" , cred .AccessKey , claims )
537
+ conditions ["object-lock-mode" ] = []string {string (retMode )}
538
+ conditions ["object-lock-retain-until-date" ] = []string {retDate .Format (time .RFC3339 )}
539
+ if retDays > 0 {
540
+ conditions ["object-lock-remaining-retention-days" ] = []string {strconv .Itoa (retDays )}
541
+ }
542
+ if retMode == objectlock .RetGovernance && byPassSet {
543
+ byPassSet = globalIAMSys .IsAllowed (iampolicy.Args {
544
+ AccountName : cred .AccessKey ,
545
+ Action : policy .BypassGovernanceRetentionAction ,
546
+ BucketName : bucketName ,
547
+ ObjectName : objectName ,
548
+ ConditionValues : conditions ,
549
+ IsOwner : owner ,
550
+ Claims : claims ,
551
+ })
552
+ }
553
+ if globalIAMSys .IsAllowed (iampolicy.Args {
554
+ AccountName : cred .AccessKey ,
555
+ Action : policy .PutObjectRetentionAction ,
556
+ BucketName : bucketName ,
557
+ ConditionValues : conditions ,
558
+ ObjectName : objectName ,
559
+ IsOwner : owner ,
560
+ Claims : claims ,
561
+ }) {
562
+ retSet = true
563
+ }
564
+ if byPassSet || retSet {
565
+ return ErrNone
566
+ }
567
+ return ErrAccessDenied
568
+ }
569
+
467
570
// isPutActionAllowed - check if PUT operation is allowed on the resource, this
468
571
// call verifies bucket policies and IAM policies, supports multi user
469
572
// checks etc.
0 commit comments