@@ -40,6 +40,7 @@ const bucket_semaphore = new KeysSemaphore(1);
4040const Quota = require ( '../system_services/objects/quota' ) ;
4141const { STORAGE_CLASS_GLACIER_IR } = require ( '../../endpoint/s3/s3_utils' ) ;
4242const noobaa_s3_client = require ( '../../sdk/noobaa_s3_client/noobaa_s3_client' ) ;
43+ const string_utils = require ( '../../util/string_utils' ) ;
4344
4445const VALID_BUCKET_NAME_REGEXP =
4546 / ^ ( ( [ a - z 0 - 9 ] | [ a - z 0 - 9 ] [ a - z 0 - 9 - ] * [ a - z 0 - 9 ] ) \. ) * ( [ a - z 0 - 9 ] | [ a - z 0 - 9 ] [ a - z 0 - 9 - ] * [ a - z 0 - 9 ] ) $ / ;
@@ -516,26 +517,25 @@ async function get_bucket_policy(req) {
516517/*
517518 validate ARN principle
518519 1. validate basic ARN, like arn prefix `arn:aws:iam::`
519- 2. If principal ARN end with `root sufix its a account and get account with id eg : aws:arn :${account_id}:root
520+ 2. If principal ARN end with `root sufix its a account and get account with id eg : arn: aws:iam: :${account_id}:root
520521 3. if principle ARN contains `user` its a IAM user and get account with username and id
521- eg : aws:arn :${account_id}:user/${iam_path}/${use_name}
522+ eg : arn: aws:iam: :${account_id}:user/${iam_path}/${use_name}
522523 account email = ${iam_user_name}:${account_id}
523524*/
524525async function principal_validation_handler ( principal ) {
525526 const principal_as_string = principal instanceof SensitiveString ? principal . unwrap ( ) : principal ;
526- const arn_prefix = 'arn:aws:iam::' ;
527527 const root_sufix = 'root' ;
528528 const user_sufix = 'user' ;
529529 const arn_parts = principal_as_string . split ( ':' ) ;
530- if ( ! principal_as_string . startsWith ( arn_prefix ) || arn_parts . length < 6 ) {
530+ if ( ! string_utils . AWS_ARN_REGEXP . test ( principal_as_string ) ) {
531531 return ;
532532 }
533533 const account_id = arn_parts [ 4 ] ;
534534 if ( principal_as_string . endsWith ( root_sufix ) ) {
535535 return system_store . data . accounts . find ( account => account . _id . toString ( ) === account_id ) ;
536- } else if ( principal_as_string . includes ( user_sufix ) ) {
536+ } else if ( arn_parts [ 5 ] && arn_parts [ 5 ] . startsWith ( user_sufix ) ) {
537537 const arn_path_parts = principal_as_string . split ( '/' ) ;
538- const iam_user_name = arn_path_parts [ arn_path_parts . length - 1 ] ;
538+ const iam_user_name = arn_path_parts [ arn_path_parts . length - 1 ] . trim ( ) ;
539539 return system_store . get_account_by_email ( new SensitiveString ( `${ iam_user_name } :${ account_id } ` ) ) ;
540540 }
541541}
0 commit comments