Skip to content

AWS hook should automatically refresh credentials when using temporary credentials #16770

Closed

Description

@baolsen

Apache Airflow version: 1.10.8 (Patched with latest AWS Hook)

Environment:

  • Cloud provider or hardware configuration: 4 VCPU 8GB RAM VM
  • OS (e.g. from /etc/os-release): RHEL 7.7
  • Kernel (e.g. uname -a): Linux 3.10.0-957.el7.x86_64
  • Install tools:
  • Others:
    The AWS Hook functionality for AssumeRoleWithSAML is not available in this version, we manually added it via patching the hook file.

What happened:
We've been using this hook for a while now with this issue, basically sts.assume_role and sts.assume_role_with_saml will return temporary credentials that are only valid for eg 1 hour by default. Eventually with long running operators / hooks / sensors some of them fail because the credentials have expired.

Example error messages
An error occurred (ExpiredTokenException) when calling the AssumeRole operation: Response has expired
An error occurred (ExpiredTokenException) when calling the AssumeRoleWithSAML operation: Response has expired
botocore.exceptions.ClientError: An error occurred (ExpiredTokenException) when calling the operation: The security token included in the request is expired

What you expected to happen:

AWS hook should be updated to use boto3 RefreshableCredentials when temporary credentials are in use.

How to reproduce it:

Use any of the assume role methods with the AWS Hook, create a session, wait 1 hour (or whatever expiry period applies to your role), and try and use the hook again.

Anything else we need to know:

I have a solution, please self-assign this.

Activity

  1. baolsen commented on Oct 15, 2021

    @baolsen
    ContributorAuthor
  2. mik-laj commented on Oct 19, 2021

    @mik-laj
    Member

    This is not tied to the Airflow release but to Amazon provider package release. See: http://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/index.html
    This change has been releasesd in apache-airflow-providers-amazon v2.1.0

  3. mik-laj commented on Oct 19, 2021

    @mik-laj
    Member

    Docker images for Airflow 2.1.0 has been shipped with apache-airflow-providers-amazon==2.0.0,
    https://github.com/apache/airflow/blob/constraints-2.1.2/constraints-3.9.txt#L49
    so if you are using this image then you need to update the package.
    For details, see: http://airflow.apache.org/docs/docker-stack/build.html#example-of-upgrading-airflow-provider-packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions