(ctx context.Context, r *http.Request, action policy.Action)
| 320 | } |
| 321 | |
| 322 | func authenticateRequest(ctx context.Context, r *http.Request, action policy.Action) (s3Err APIErrorCode) { |
| 323 | if logger.GetReqInfo(ctx) == nil { |
| 324 | logger.LogIf(ctx, errors.New("unexpected context.Context does not have a logger.ReqInfo"), logger.Minio) |
| 325 | return ErrAccessDenied |
| 326 | } |
| 327 | |
| 328 | var cred auth.Credentials |
| 329 | var owner bool |
| 330 | switch getRequestAuthType(r) { |
| 331 | case authTypeUnknown, authTypeStreamingSigned: |
| 332 | return ErrSignatureVersionNotSupported |
| 333 | case authTypePresignedV2, authTypeSignedV2: |
| 334 | if s3Err = isReqAuthenticatedV2(r); s3Err != ErrNone { |
| 335 | return s3Err |
| 336 | } |
| 337 | cred, owner, s3Err = getReqAccessKeyV2(r) |
| 338 | case authTypeSigned, authTypePresigned: |
| 339 | region := globalSite.Region |
| 340 | switch action { |
| 341 | case policy.GetBucketLocationAction, policy.ListAllMyBucketsAction: |
| 342 | region = "" |
| 343 | } |
| 344 | if s3Err = isReqAuthenticated(ctx, r, region, serviceS3); s3Err != ErrNone { |
| 345 | return s3Err |
| 346 | } |
| 347 | cred, owner, s3Err = getReqAccessKeyV4(r, region, serviceS3) |
| 348 | } |
| 349 | if s3Err != ErrNone { |
| 350 | return s3Err |
| 351 | } |
| 352 | |
| 353 | logger.GetReqInfo(ctx).Cred = cred |
| 354 | logger.GetReqInfo(ctx).Owner = owner |
| 355 | logger.GetReqInfo(ctx).Region = globalSite.Region |
| 356 | |
| 357 | // region is valid only for CreateBucketAction. |
| 358 | var region string |
| 359 | if action == policy.CreateBucketAction { |
| 360 | // To extract region from XML in request body, get copy of request body. |
| 361 | payload, err := io.ReadAll(io.LimitReader(r.Body, maxLocationConstraintSize)) |
| 362 | if err != nil { |
| 363 | logger.LogIf(ctx, err, logger.Application) |
| 364 | return ErrMalformedXML |
| 365 | } |
| 366 | |
| 367 | // Populate payload to extract location constraint. |
| 368 | r.Body = io.NopCloser(bytes.NewReader(payload)) |
| 369 | region, s3Err = parseLocationConstraint(r) |
| 370 | if s3Err != ErrNone { |
| 371 | return s3Err |
| 372 | } |
| 373 | |
| 374 | // Populate payload again to handle it in HTTP handler. |
| 375 | r.Body = io.NopCloser(bytes.NewReader(payload)) |
| 376 | } |
| 377 | |
| 378 | logger.GetReqInfo(ctx).Region = region |
| 379 |
no test coverage detected