A developer is building a secure enterprise document management portal. User authentication is managed by a third-party Identity Provider (IdP). The client applications send a JSON Web Token (JWT) issued by the IdP in the `Authorization` header of every request to an Amazon API Gateway REST API. The developer must secure the `/documents/delete` resource so that only users who have a custom claim `user_role` set to `Administrator` in the JWT are permitted to invoke the backend service. This validation must be enforced at the API Gateway boundary to prevent unauthorized requests from invoking the backend integration. Which solution should the developer implement to meet these requirements with the least operational overhead?
- Create an API Gateway Lambda Request Authorizer. In the Lambda function, verify the signature of the incoming JWT using the Identity Provider's JSON Web Key Set (JWKS), extract the custom `user_role` claim, and return an IAM policy that allows the `execute-api:Invoke` action on the target resource if the claim value is `Administrator`.Cevap
- BSet up an Amazon Cognito User Pool federated with the third-party IdP, and configure an API Gateway Cognito User Pools Authorizer. In the method request settings for the `/documents/delete` resource, add custom OAuth Scopes to validate that the custom `user_role` attribute in the user's identity token matches `Administrator`.
- CSet up an Amazon Cognito Identity Pool to exchange the third-party JWT for temporary AWS credentials. Enable IAM authorization on the `/documents/delete` resource, and write a custom API Gateway Resource Policy that denies requests if the `$context.authorizer.claims.user_role` context variable does not match `Administrator`.
- DSet up a Lambda Proxy Integration for the `/documents/delete` resource. In the backend Lambda function, extract the custom `user_role` claim from the request payload, and return an API Gateway Resource Policy dynamically to deny the request if the claim value is not `Administrator`.
Cevap
Create an API Gateway Lambda Request Authorizer to decode and validate the token, extract the custom claim, and generate an IAM policy that grants access if the claim matches the required role.
Implementing an API Gateway Lambda Request Authorizer allows the developer to run custom code at the API Gateway boundary. The Lambda function can fetch the IdP's JSON Web Key Set (JWKS), verify the JWT signature, read the custom `user_role` claim, and generate an IAM policy that allows or denies access using the `execute-api:Invoke` action.
Adım Adım Çözüm
Anahtar Kavram
API Gateway custom Lambda Authorizers allow developers to perform custom JWT verification and inspect arbitrary token claims at the API Gateway boundary to return an IAM policy.
Tahmini Süre:3m 0s