You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/08/07 17:29:19 UTC
(opendal-reqsign) 01/01: test(aws): add real credential provider coverage
This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch xuanwo/aws-live-provider-tests
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
commit df4bd9a5bcec4b03e5ff502262e76237d432901d
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Sat Aug 8 01:29:05 2026 +0800
test(aws): add real credential provider coverage
---
.github/aws-live-tests/Dockerfile | 34 ++
.github/aws-live-tests/Dockerfile.dockerignore | 20 +
.github/aws-live-tests/cloudformation.yml | 518 +++++++++++++++++++++
.github/workflows/aws_v4_live.yml | 493 ++++++++++++++++++++
.../aws-core/src/provide_credential/cognito.rs | 37 +-
services/aws-core/src/provide_credential/ecs.rs | 21 +-
.../tests/credential_providers/assume_role.rs | 6 +-
.../assume_role_with_web_identity.rs | 3 +-
.../aws-v4/tests/credential_providers/cognito.rs | 3 +-
.../credential_providers/{imds.rs => default.rs} | 30 +-
services/aws-v4/tests/credential_providers/ecs.rs | 8 +-
services/aws-v4/tests/credential_providers/env.rs | 3 +-
services/aws-v4/tests/credential_providers/imds.rs | 3 +-
services/aws-v4/tests/credential_providers/mod.rs | 54 ++-
.../aws-v4/tests/credential_providers/process.rs | 3 +-
.../aws-v4/tests/credential_providers/profile.rs | 3 +-
.../tests/credential_providers/s3_access_grants.rs | 74 +++
.../credential_providers/{cognito.rs => static.rs} | 38 +-
.../tests/mocks/credential_process_helper.py | 50 +-
19 files changed, 1314 insertions(+), 87 deletions(-)
diff --git a/.github/aws-live-tests/Dockerfile b/.github/aws-live-tests/Dockerfile
new file mode 100644
index 0000000..7d0e4b1
--- /dev/null
+++ b/.github/aws-live-tests/Dockerfile
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM public.ecr.aws/docker/library/rust:1.88-bookworm AS builder
+
+WORKDIR /workspace
+COPY . .
+RUN cargo test -p reqsign-aws-v4 --test main --release --no-run && \
+ test_binary="$(find target/release/deps -maxdepth 1 -type f -perm -111 -name 'main-*' | head -n 1)" && \
+ test -n "${test_binary}" && \
+ cp "${test_binary}" /tmp/reqsign-aws-live-test
+
+FROM public.ecr.aws/docker/library/debian:bookworm-slim
+
+RUN apt-get update && \
+ apt-get install --yes --no-install-recommends ca-certificates libssl3 && \
+ rm -rf /var/lib/apt/lists/*
+COPY --from=builder /tmp/reqsign-aws-live-test /usr/local/bin/reqsign-aws-live-test
+
+ENTRYPOINT ["/usr/local/bin/reqsign-aws-live-test"]
diff --git a/.github/aws-live-tests/Dockerfile.dockerignore b/.github/aws-live-tests/Dockerfile.dockerignore
new file mode 100644
index 0000000..6891919
--- /dev/null
+++ b/.github/aws-live-tests/Dockerfile.dockerignore
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+.git
+target
+**/target
diff --git a/.github/aws-live-tests/cloudformation.yml b/.github/aws-live-tests/cloudformation.yml
new file mode 100644
index 0000000..a405816
--- /dev/null
+++ b/.github/aws-live-tests/cloudformation.yml
@@ -0,0 +1,518 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+AWSTemplateFormatVersion: "2010-09-09"
+Description: Persistent control plane for reqsign AWS live credential-provider tests
+
+Parameters:
+ GitHubOrganization:
+ Type: String
+ Default: apache
+ GitHubRepository:
+ Type: String
+ Default: opendal-reqsign
+ TestBucketName:
+ Type: String
+ Default: reqsign-aws-v4-test
+ VpcId:
+ Type: AWS::EC2::VPC::Id
+ PublicSubnetId:
+ Type: AWS::EC2::Subnet::Id
+
+Resources:
+ EcrRepository:
+ Type: AWS::ECR::Repository
+ Properties:
+ RepositoryName: reqsign-live-test
+ ImageScanningConfiguration:
+ ScanOnPush: true
+ ImageTagMutability: IMMUTABLE
+ LifecyclePolicy:
+ LifecyclePolicyText: |
+ {
+ "rules": [
+ {
+ "rulePriority": 1,
+ "description": "Keep the ten newest live-test images",
+ "selection": {
+ "tagStatus": "any",
+ "countType": "imageCountMoreThan",
+ "countNumber": 10
+ },
+ "action": {"type": "expire"}
+ }
+ ]
+ }
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ EcsCluster:
+ Type: AWS::ECS::Cluster
+ Properties:
+ ClusterName: reqsign-live-test
+ ClusterSettings:
+ - Name: containerInsights
+ Value: disabled
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ EcsLogGroup:
+ Type: AWS::Logs::LogGroup
+ Properties:
+ LogGroupName: /reqsign/live-tests/ecs
+ RetentionInDays: 7
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ LiveTestSecurityGroup:
+ Type: AWS::EC2::SecurityGroup
+ Properties:
+ GroupDescription: Outbound-only networking for reqsign live tests
+ GroupName: reqsign-live-test
+ VpcId: !Ref VpcId
+ SecurityGroupEgress:
+ - IpProtocol: "-1"
+ CidrIp: 0.0.0.0/0
+ Description: AWS public service endpoints
+ Tags:
+ - Key: Name
+ Value: reqsign-live-test
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ EcsTaskExecutionRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-ecs-execution
+ Description: Pulls the reqsign test image and publishes task logs
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Service: ecs-tasks.amazonaws.com
+ Action: sts:AssumeRole
+ Policies:
+ - PolicyName: reqsign-live-test-ecs-execution
+ PolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Action:
+ - ecr:GetAuthorizationToken
+ Resource: "*"
+ - Effect: Allow
+ Action:
+ - ecr:BatchCheckLayerAvailability
+ - ecr:BatchGetImage
+ - ecr:GetDownloadUrlForLayer
+ Resource: !GetAtt EcrRepository.Arn
+ - Effect: Allow
+ Action:
+ - logs:CreateLogStream
+ - logs:PutLogEvents
+ Resource: !Sub ${EcsLogGroup.Arn}:*
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ EcsTaskRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-ecs-task
+ Description: Credential source exercised by ECSCredentialProvider
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Service: ecs-tasks.amazonaws.com
+ Action: sts:AssumeRole
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ Ec2InstanceRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-ec2-instance
+ Description: Credential source exercised by IMDSv2CredentialProvider
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Service: ec2.amazonaws.com
+ Action: sts:AssumeRole
+ Policies:
+ - PolicyName: reqsign-live-test-ec2-bootstrap
+ PolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Action:
+ - ecr:GetAuthorizationToken
+ Resource: "*"
+ - Effect: Allow
+ Action:
+ - ecr:BatchCheckLayerAvailability
+ - ecr:BatchGetImage
+ - ecr:GetDownloadUrlForLayer
+ Resource: !GetAtt EcrRepository.Arn
+ - Effect: Allow
+ Action: s3:PutObject
+ Resource: !Sub arn:${AWS::Partition}:s3:::${TestBucketName}/live-tests/results/*
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ Ec2InstanceProfile:
+ Type: AWS::IAM::InstanceProfile
+ Properties:
+ InstanceProfileName: reqsign-live-test-ec2-instance
+ Roles:
+ - !Ref Ec2InstanceRole
+
+ CognitoIdentityPool:
+ Type: AWS::Cognito::IdentityPool
+ Properties:
+ IdentityPoolName: reqsign_live_test
+ AllowUnauthenticatedIdentities: true
+
+ CognitoUnauthenticatedRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-cognito-unauthenticated
+ Description: Credential source exercised by CognitoIdentityCredentialProvider
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Federated: cognito-identity.amazonaws.com
+ Action: sts:AssumeRoleWithWebIdentity
+ Condition:
+ StringEquals:
+ cognito-identity.amazonaws.com:aud: !Ref CognitoIdentityPool
+ ForAnyValue:StringLike:
+ cognito-identity.amazonaws.com:amr: unauthenticated
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ CognitoIdentityPoolRoleAttachment:
+ Type: AWS::Cognito::IdentityPoolRoleAttachment
+ Properties:
+ IdentityPoolId: !Ref CognitoIdentityPool
+ Roles:
+ unauthenticated: !GetAtt CognitoUnauthenticatedRole.Arn
+
+ S3AccessGrantsInstance:
+ Type: AWS::S3::AccessGrantsInstance
+ Properties:
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ S3AccessGrantsLocationRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-s3-access-grants-location
+ Description: Vends scoped S3 credentials through S3 Access Grants
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Service: access-grants.s3.amazonaws.com
+ Action:
+ - sts:AssumeRole
+ - sts:SetSourceIdentity
+ Condition:
+ StringEquals:
+ aws:SourceAccount: !Ref AWS::AccountId
+ aws:SourceArn: !Sub arn:${AWS::Partition}:s3:${AWS::Region}:${AWS::AccountId}:access-grants/default
+ Policies:
+ - PolicyName: reqsign-live-test-s3-access-grants-location
+ PolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Action: s3:ListBucket
+ Resource: !Sub arn:${AWS::Partition}:s3:::${TestBucketName}
+ Condition:
+ StringLike:
+ s3:prefix:
+ - access-grants/*
+ - Effect: Allow
+ Action:
+ - s3:GetObject
+ - s3:PutObject
+ - s3:DeleteObject
+ Resource: !Sub arn:${AWS::Partition}:s3:::${TestBucketName}/access-grants/*
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ S3AccessGrantsLocation:
+ Type: AWS::S3::AccessGrantsLocation
+ DependsOn: S3AccessGrantsInstance
+ Properties:
+ IamRoleArn: !GetAtt S3AccessGrantsLocationRole.Arn
+ LocationScope: !Sub s3://${TestBucketName}/access-grants/*
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ GitHubActionsRole:
+ Type: AWS::IAM::Role
+ Properties:
+ RoleName: reqsign-live-test-github
+ Description: GitHub OIDC role for reqsign AWS live tests
+ MaxSessionDuration: 3600
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ Federated: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com
+ Action: sts:AssumeRoleWithWebIdentity
+ Condition:
+ StringEquals:
+ token.actions.githubusercontent.com:aud: sts.amazonaws.com
+ StringLike:
+ token.actions.githubusercontent.com:sub:
+ - !Sub repo:${GitHubOrganization}/${GitHubRepository}:ref:refs/heads/main
+ - !Sub repo:${GitHubOrganization}/${GitHubRepository}:pull_request
+ Policies:
+ - PolicyName: reqsign-live-test-runtime
+ PolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Sid: AssumeRoleProvider
+ Effect: Allow
+ Action: sts:AssumeRole
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/reqsign-live-test-assume-role
+ - Sid: GeneralPurposeS3TestBucket
+ Effect: Allow
+ Action: s3:ListBucket
+ Resource: !Sub arn:${AWS::Partition}:s3:::${TestBucketName}
+ - Sid: GeneralPurposeS3TestObjects
+ Effect: Allow
+ Action:
+ - s3:GetObject
+ - s3:PutObject
+ - s3:DeleteObject
+ Resource: !Sub arn:${AWS::Partition}:s3:::${TestBucketName}/*
+ - Sid: S3AccessGrants
+ Effect: Allow
+ Action: s3:GetDataAccess
+ Resource: !GetAtt S3AccessGrantsInstance.AccessGrantsInstanceArn
+ - Sid: S3ExpressSessions
+ Effect: Allow
+ Action: s3express:CreateSession
+ Resource: !Sub arn:${AWS::Partition}:s3express:*:${AWS::AccountId}:bucket/*
+ - Sid: PushLiveTestImageAuthorization
+ Effect: Allow
+ Action: ecr:GetAuthorizationToken
+ Resource: "*"
+ - Sid: PushLiveTestImage
+ Effect: Allow
+ Action:
+ - ecr:BatchCheckLayerAvailability
+ - ecr:BatchGetImage
+ - ecr:CompleteLayerUpload
+ - ecr:GetDownloadUrlForLayer
+ - ecr:InitiateLayerUpload
+ - ecr:PutImage
+ - ecr:DescribeImages
+ - ecr:UploadLayerPart
+ Resource: !GetAtt EcrRepository.Arn
+ - Sid: RegisterTaskDefinition
+ Effect: Allow
+ Action: ecs:RegisterTaskDefinition
+ Resource: "*"
+ - Sid: RunTask
+ Effect: Allow
+ Action: ecs:RunTask
+ Resource: !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:task-definition/reqsign-live-test:*
+ Condition:
+ ArnEquals:
+ ecs:cluster: !GetAtt EcsCluster.Arn
+ - Sid: CleanUpTaskDefinition
+ Effect: Allow
+ Action: ecs:DeregisterTaskDefinition
+ Resource: !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:task-definition/reqsign-live-test:*
+ - Sid: ObserveAndStopTask
+ Effect: Allow
+ Action:
+ - ecs:DescribeTasks
+ - ecs:StopTask
+ - ecs:TagResource
+ Resource: !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:task/${EcsCluster}/*
+ - Sid: ReadTaskLogs
+ Effect: Allow
+ Action:
+ - logs:DescribeLogStreams
+ - logs:GetLogEvents
+ Resource: !Sub ${EcsLogGroup.Arn}:*
+ - Sid: PassLiveTestRoles
+ Effect: Allow
+ Action: iam:PassRole
+ Resource:
+ - !GetAtt EcsTaskExecutionRole.Arn
+ - !GetAtt EcsTaskRole.Arn
+ - !GetAtt Ec2InstanceRole.Arn
+ Condition:
+ StringEquals:
+ iam:PassedToService:
+ - ecs-tasks.amazonaws.com
+ - ec2.amazonaws.com
+ - Sid: ResolveAmazonLinuxAmi
+ Effect: Allow
+ Action: ssm:GetParameter
+ Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}::parameter/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
+ - Sid: LaunchEphemeralImdsInstance
+ Effect: Allow
+ Action: ec2:RunInstances
+ Resource:
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}::image/*
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:network-interface/*
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:security-group/${LiveTestSecurityGroup.GroupId}
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:subnet/${PublicSubnetId}
+ - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:volume/*
+ Condition:
+ StringEquals:
+ aws:RequestedRegion: !Ref AWS::Region
+ ec2:InstanceType: t3.nano
+ ec2:MetadataHttpTokens: required
+ aws:RequestTag/Project: reqsign
+ aws:RequestTag/Purpose: live-test
+ - Sid: TagEphemeralImdsInstance
+ Effect: Allow
+ Action: ec2:CreateTags
+ Resource: !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
+ Condition:
+ StringEquals:
+ ec2:CreateAction: RunInstances
+ - Sid: TerminateEphemeralImdsInstance
+ Effect: Allow
+ Action: ec2:TerminateInstances
+ Resource: !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
+ Condition:
+ StringEquals:
+ aws:ResourceTag/Project: reqsign
+ aws:ResourceTag/Purpose: live-test
+ - Sid: ObserveEphemeralImdsInstance
+ Effect: Allow
+ Action:
+ - ec2:DescribeInstances
+ - ec2:DescribeInstanceStatus
+ - ec2:GetConsoleOutput
+ Resource: "*"
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ AssumeRoleTargetRole:
+ Type: AWS::IAM::Role
+ DependsOn: GitHubActionsRole
+ Properties:
+ RoleName: reqsign-live-test-assume-role
+ Description: Target exercised by AssumeRoleCredentialProvider
+ AssumeRolePolicyDocument:
+ Version: "2012-10-17"
+ Statement:
+ - Effect: Allow
+ Principal:
+ AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/reqsign-live-test-github
+ Action: sts:AssumeRole
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+ S3AccessGrant:
+ Type: AWS::S3::AccessGrant
+ Properties:
+ AccessGrantsLocationId: !GetAtt S3AccessGrantsLocation.AccessGrantsLocationId
+ Grantee:
+ GranteeType: IAM
+ GranteeIdentifier: !GetAtt GitHubActionsRole.Arn
+ Permission: READWRITE
+ Tags:
+ - Key: Project
+ Value: reqsign
+ - Key: Purpose
+ Value: live-test
+
+Outputs:
+ GitHubActionsRoleArn:
+ Value: !GetAtt GitHubActionsRole.Arn
+ AssumeRoleTargetArn:
+ Value: !GetAtt AssumeRoleTargetRole.Arn
+ CognitoIdentityPoolId:
+ Value: !Ref CognitoIdentityPool
+ EcrRepositoryUri:
+ Value: !GetAtt EcrRepository.RepositoryUri
+ EcsClusterName:
+ Value: !Ref EcsCluster
+ EcsTaskExecutionRoleArn:
+ Value: !GetAtt EcsTaskExecutionRole.Arn
+ EcsTaskRoleArn:
+ Value: !GetAtt EcsTaskRole.Arn
+ EcsLogGroupName:
+ Value: !Ref EcsLogGroup
+ PublicSubnetId:
+ Value: !Ref PublicSubnetId
+ SecurityGroupId:
+ Value: !GetAtt LiveTestSecurityGroup.GroupId
+ Ec2InstanceProfileName:
+ Value: !Ref Ec2InstanceProfile
+ TestBucketName:
+ Value: !Ref TestBucketName
+ S3AccessGrantsPrefix:
+ Value: access-grants/
diff --git a/.github/workflows/aws_v4_live.yml b/.github/workflows/aws_v4_live.yml
new file mode 100644
index 0000000..eb5a51c
--- /dev/null
+++ b/.github/workflows/aws_v4_live.yml
@@ -0,0 +1,493 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: AWS V4 Live Test
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ branches:
+ - main
+ workflow_dispatch:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
+ cancel-in-progress: true
+
+env:
+ RUST_LOG: DEBUG
+ RUST_BACKTRACE: full
+
+permissions: {}
+
+jobs:
+ check_live_test:
+ runs-on: ubuntu-latest
+ outputs:
+ enabled: ${{ steps.check.outputs.enabled }}
+ steps:
+ - name: Check whether AWS live tests are trusted
+ id: check
+ shell: bash
+ run: |
+ if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "workflow_dispatch" || ( "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.fork }}" == "false" && "${{ github.actor }}" != "dependabot[bot]" ) ]]; then
+ echo "enabled=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "enabled=false" >> "$GITHUB_OUTPUT"
+ fi
+
+ test_hosted_providers:
+ needs: check_live_test
+ if: needs.check_live_test.outputs.enabled == 'true'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - name: Assume the reqsign live-test role
+ uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1
+ with:
+ aws-region: ${{ vars.REQSIGN_AWS_LIVE_REGION }}
+ role-to-assume: ${{ vars.REQSIGN_AWS_LIVE_ROLE_ARN }}
+ role-session-name: reqsign-hosted-${{ github.run_id }}
+ - name: Test StaticCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_STATIC: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ run: cargo test test_static_credential_provider_live --no-fail-fast -- --nocapture
+ - name: Test EnvCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_ENV: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ run: cargo test test_env_credential_provider --no-fail-fast -- --nocapture
+ - name: Test DefaultCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_DEFAULT: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ run: cargo test test_default_credential_provider_live --no-fail-fast -- --nocapture
+ - name: Create an ephemeral shared profile
+ shell: bash
+ run: |
+ test_home="$(mktemp -d)"
+ credentials_file="$test_home/credentials"
+ config_file="$test_home/config"
+ {
+ printf '[reqsign-live]\n'
+ printf 'aws_access_key_id = %s\n' "$AWS_ACCESS_KEY_ID"
+ printf 'aws_secret_access_key = %s\n' "$AWS_SECRET_ACCESS_KEY"
+ printf 'aws_session_token = %s\n' "$AWS_SESSION_TOKEN"
+ } > "$credentials_file"
+ {
+ printf '[profile reqsign-live]\n'
+ printf 'region = %s\n' "$AWS_REGION"
+ } > "$config_file"
+ chmod 600 "$credentials_file" "$config_file"
+ {
+ echo "REQSIGN_PROFILE_TEST_HOME=$test_home"
+ echo "REQSIGN_PROFILE_CREDENTIALS=$credentials_file"
+ echo "REQSIGN_PROFILE_CONFIG=$config_file"
+ } >> "$GITHUB_ENV"
+ - name: Test ProfileCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_PROFILE: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ run: |
+ export AWS_PROFILE=reqsign-live
+ export AWS_SHARED_CREDENTIALS_FILE="$REQSIGN_PROFILE_CREDENTIALS"
+ export AWS_CONFIG_FILE="$REQSIGN_PROFILE_CONFIG"
+ cargo test test_profile_credential_provider --no-fail-fast -- --nocapture
+ - name: Create an ephemeral credential_process profile
+ shell: bash
+ run: |
+ process_home="$(mktemp -d)"
+ process_helper="$process_home/credential-process.py"
+ process_config="$process_home/config"
+ cp services/aws-v4/tests/mocks/credential_process_helper.py "$process_helper"
+ chmod 700 "$process_helper"
+ {
+ printf '[profile reqsign-live-process]\n'
+ printf 'credential_process = python3 %s\n' "$process_helper"
+ printf 'region = %s\n' "$AWS_REGION"
+ } > "$process_config"
+ chmod 600 "$process_config"
+ echo "REQSIGN_PROCESS_TEST_HOME=$process_home" >> "$GITHUB_ENV"
+ echo "REQSIGN_PROCESS_CONFIG=$process_config" >> "$GITHUB_ENV"
+ - name: Test ProcessCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_PROCESS: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ run: |
+ export REQSIGN_AWS_PROCESS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"
+ export REQSIGN_AWS_PROCESS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"
+ export REQSIGN_AWS_PROCESS_SESSION_TOKEN="$AWS_SESSION_TOKEN"
+ export AWS_PROFILE=reqsign-live-process
+ export AWS_CONFIG_FILE="$REQSIGN_PROCESS_CONFIG"
+ cargo test test_process_credential_provider --no-fail-fast -- --nocapture
+ - name: Test AssumeRoleCredentialProvider and granter
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_ASSUME_ROLE: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ REQSIGN_AWS_V4_ASSUME_ROLE_ARN: ${{ vars.REQSIGN_AWS_LIVE_ASSUME_ROLE_ARN }}
+ run: cargo test test_assume_role --no-fail-fast -- --nocapture
+ - name: Get a fresh GitHub OIDC token
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ const token = await core.getIDToken('sts.amazonaws.com');
+ core.setSecret(token);
+ require('fs').writeFileSync('/tmp/reqsign-web-identity-token', token, { mode: 0o600 });
+ - name: Test AssumeRoleWithWebIdentityCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_WEB_IDENTITY: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ AWS_ROLE_ARN: ${{ vars.REQSIGN_AWS_LIVE_ROLE_ARN }}
+ AWS_ROLE_SESSION_NAME: reqsign-web-${{ github.run_id }}
+ AWS_WEB_IDENTITY_TOKEN_FILE: /tmp/reqsign-web-identity-token
+ run: cargo test test_assume_role_with_web_identity_credential_provider --no-fail-fast -- --nocapture
+ - name: Test CognitoIdentityCredentialProvider
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_COGNITO: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ AWS_COGNITO_IDENTITY_POOL_ID: ${{ vars.REQSIGN_AWS_LIVE_COGNITO_POOL_ID }}
+ run: cargo test test_cognito_identity_credential_provider --no-fail-fast -- --nocapture
+ - name: Test S3AccessGrantsGranter
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_S3_ACCESS_GRANTS: on
+ REQSIGN_AWS_V4_VALIDATE_CREDENTIALS: on
+ REQSIGN_AWS_V4_ACCOUNT_ID: ${{ vars.REQSIGN_AWS_LIVE_ACCOUNT_ID }}
+ REQSIGN_AWS_V4_S3_ACCESS_GRANTS_BUCKET: ${{ vars.REQSIGN_AWS_LIVE_TEST_BUCKET }}
+ REQSIGN_AWS_V4_S3_ACCESS_GRANTS_PREFIX: access-grants/
+ run: cargo test test_s3_access_grants_granter_live --no-fail-fast -- --nocapture
+ - name: Test S3ExpressSessionProvider and granter
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST_S3_EXPRESS: on
+ REQSIGN_AWS_V4_S3_EXPRESS_BUCKET: ${{ vars.REQSIGN_AWS_LIVE_S3_EXPRESS_BUCKET }}
+ AWS_REGION: ${{ vars.REQSIGN_AWS_LIVE_S3_EXPRESS_REGION }}
+ run: cargo test test_s3_express --no-fail-fast -- --nocapture
+ - name: Test request signing against S3
+ working-directory: services/aws-v4
+ env:
+ REQSIGN_AWS_V4_TEST: on
+ REQSIGN_AWS_V4_REGION: ${{ vars.REQSIGN_AWS_LIVE_REGION }}
+ REQSIGN_AWS_V4_SERVICE: s3
+ REQSIGN_AWS_V4_URL: https://${{ vars.REQSIGN_AWS_LIVE_TEST_BUCKET }}.s3.${{ vars.REQSIGN_AWS_LIVE_REGION }}.amazonaws.com
+ run: |
+ export REQSIGN_AWS_V4_ACCESS_KEY="$AWS_ACCESS_KEY_ID"
+ export REQSIGN_AWS_V4_SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
+ export REQSIGN_AWS_V4_SESSION_TOKEN="$AWS_SESSION_TOKEN"
+ cargo test signing:: --no-fail-fast -- --nocapture
+ - name: Remove signing test objects
+ if: always()
+ env:
+ TEST_BUCKET: ${{ vars.REQSIGN_AWS_LIVE_TEST_BUCKET }}
+ run: aws s3api delete-object --bucket "$TEST_BUCKET" --key put_object_test >/dev/null 2>&1 || true
+ - name: Remove ephemeral credential files
+ if: always()
+ shell: bash
+ run: |
+ if [[ -n "${REQSIGN_PROFILE_TEST_HOME:-}" ]]; then
+ rm -rf -- "$REQSIGN_PROFILE_TEST_HOME"
+ fi
+ if [[ -n "${REQSIGN_PROCESS_TEST_HOME:-}" ]]; then
+ rm -rf -- "$REQSIGN_PROCESS_TEST_HOME"
+ fi
+ rm -f -- /tmp/reqsign-web-identity-token
+
+ build_live_image:
+ needs: check_live_test
+ if: needs.check_live_test.outputs.enabled == 'true'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ outputs:
+ image: ${{ steps.image.outputs.image }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - name: Assume the reqsign live-test role
+ uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1
+ with:
+ aws-region: ${{ vars.REQSIGN_AWS_LIVE_REGION }}
+ role-to-assume: ${{ vars.REQSIGN_AWS_LIVE_ROLE_ARN }}
+ role-session-name: reqsign-image-${{ github.run_id }}
+ - name: Build and push the live-test image
+ id: image
+ env:
+ ECR_REPOSITORY_URI: ${{ vars.REQSIGN_AWS_LIVE_ECR_REPOSITORY }}
+ IMAGE_TAG: sha-${{ github.sha }}
+ shell: bash
+ run: |
+ repository_name="${ECR_REPOSITORY_URI#*/}"
+ if ! aws ecr describe-images --repository-name "$repository_name" --image-ids "imageTag=$IMAGE_TAG" >/dev/null 2>&1; then
+ aws ecr get-login-password | docker login --username AWS --password-stdin "${ECR_REPOSITORY_URI%/*}"
+ docker build --platform linux/amd64 --file .github/aws-live-tests/Dockerfile --tag "$ECR_REPOSITORY_URI:$IMAGE_TAG" .
+ docker push "$ECR_REPOSITORY_URI:$IMAGE_TAG"
+ fi
+ echo "image=$ECR_REPOSITORY_URI:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
+
+ test_ecs_provider:
+ needs:
+ - check_live_test
+ - build_live_image
+ if: needs.check_live_test.outputs.enabled == 'true'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - name: Assume the reqsign live-test role
+ uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1
+ with:
+ aws-region: ${{ vars.REQSIGN_AWS_LIVE_REGION }}
+ role-to-assume: ${{ vars.REQSIGN_AWS_LIVE_ROLE_ARN }}
+ role-session-name: reqsign-ecs-${{ github.run_id }}
+ - name: Register and run the Fargate task
+ env:
+ IMAGE_URI: ${{ needs.build_live_image.outputs.image }}
+ CLUSTER: ${{ vars.REQSIGN_AWS_LIVE_ECS_CLUSTER }}
+ EXECUTION_ROLE_ARN: ${{ vars.REQSIGN_AWS_LIVE_ECS_EXECUTION_ROLE_ARN }}
+ TASK_ROLE_ARN: ${{ vars.REQSIGN_AWS_LIVE_ECS_TASK_ROLE_ARN }}
+ LOG_GROUP: ${{ vars.REQSIGN_AWS_LIVE_ECS_LOG_GROUP }}
+ SUBNET_ID: ${{ vars.REQSIGN_AWS_LIVE_SUBNET_ID }}
+ SECURITY_GROUP_ID: ${{ vars.REQSIGN_AWS_LIVE_SECURITY_GROUP_ID }}
+ shell: bash
+ run: |
+ container_definitions="$(jq -n \
+ --arg image "$IMAGE_URI" \
+ --arg region "$AWS_REGION" \
+ --arg log_group "$LOG_GROUP" \
+ '[{
+ name: "reqsign-live-test",
+ image: $image,
+ essential: true,
+ command: ["test_ecs_credential_provider", "--nocapture"],
+ environment: [
+ {name: "AWS_REGION", value: $region},
+ {name: "REQSIGN_AWS_V4_TEST_ECS", value: "on"},
+ {name: "REQSIGN_AWS_V4_VALIDATE_CREDENTIALS", value: "on"},
+ {name: "RUST_LOG", value: "info"}
+ ],
+ logConfiguration: {
+ logDriver: "awslogs",
+ options: {
+ "awslogs-group": $log_group,
+ "awslogs-region": $region,
+ "awslogs-stream-prefix": "ecs"
+ }
+ }
+ }]')"
+ task_definition_arn="$(aws ecs register-task-definition \
+ --family reqsign-live-test \
+ --requires-compatibilities FARGATE \
+ --network-mode awsvpc \
+ --runtime-platform cpuArchitecture=X86_64,operatingSystemFamily=LINUX \
+ --cpu 256 \
+ --memory 512 \
+ --execution-role-arn "$EXECUTION_ROLE_ARN" \
+ --task-role-arn "$TASK_ROLE_ARN" \
+ --container-definitions "$container_definitions" \
+ --query 'taskDefinition.taskDefinitionArn' \
+ --output text)"
+ echo "TASK_DEFINITION_ARN=$task_definition_arn" >> "$GITHUB_ENV"
+
+ task_arn="$(aws ecs run-task \
+ --cluster "$CLUSTER" \
+ --task-definition "$task_definition_arn" \
+ --launch-type FARGATE \
+ --network-configuration "awsvpcConfiguration={subnets=[$SUBNET_ID],securityGroups=[$SECURITY_GROUP_ID],assignPublicIp=ENABLED}" \
+ --started-by "reqsign-${GITHUB_RUN_ID}" \
+ --query 'tasks[0].taskArn' \
+ --output text)"
+ test "$task_arn" != "None"
+ echo "TASK_ARN=$task_arn" >> "$GITHUB_ENV"
+ aws ecs wait tasks-stopped --cluster "$CLUSTER" --tasks "$task_arn"
+
+ task_json="$(aws ecs describe-tasks --cluster "$CLUSTER" --tasks "$task_arn")"
+ printf '%s\n' "$task_json" | jq '{stoppedReason: .tasks[0].stoppedReason, containers: [.tasks[0].containers[] | {name, exitCode, reason}]}'
+ task_id="${task_arn##*/}"
+ log_stream="ecs/reqsign-live-test/$task_id"
+ for _ in {1..12}; do
+ if aws logs get-log-events --log-group-name "$LOG_GROUP" --log-stream-name "$log_stream" --start-from-head --query 'events[].message' --output text; then
+ break
+ fi
+ sleep 5
+ done
+ test "$(printf '%s\n' "$task_json" | jq -r '.tasks[0].containers[0].exitCode')" = "0"
+ - name: Clean up the Fargate task
+ if: always()
+ env:
+ CLUSTER: ${{ vars.REQSIGN_AWS_LIVE_ECS_CLUSTER }}
+ shell: bash
+ run: |
+ if [[ -n "${TASK_ARN:-}" ]]; then
+ last_status="$(aws ecs describe-tasks --cluster "$CLUSTER" --tasks "$TASK_ARN" --query 'tasks[0].lastStatus' --output text 2>/dev/null || true)"
+ if [[ "$last_status" == "RUNNING" || "$last_status" == "PENDING" || "$last_status" == "PROVISIONING" || "$last_status" == "ACTIVATING" ]]; then
+ aws ecs stop-task --cluster "$CLUSTER" --task "$TASK_ARN" --reason "GitHub Actions cleanup" >/dev/null
+ fi
+ fi
+ if [[ -n "${TASK_DEFINITION_ARN:-}" ]]; then
+ aws ecs deregister-task-definition --task-definition "$TASK_DEFINITION_ARN" >/dev/null
+ fi
+
+ test_imds_provider:
+ needs:
+ - check_live_test
+ - build_live_image
+ if: needs.check_live_test.outputs.enabled == 'true'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - name: Assume the reqsign live-test role
+ uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1
+ with:
+ aws-region: ${{ vars.REQSIGN_AWS_LIVE_REGION }}
+ role-to-assume: ${{ vars.REQSIGN_AWS_LIVE_ROLE_ARN }}
+ role-session-name: reqsign-imds-${{ github.run_id }}
+ - name: Launch the ephemeral IMDSv2 test instance
+ env:
+ IMAGE_URI: ${{ needs.build_live_image.outputs.image }}
+ INSTANCE_PROFILE: ${{ vars.REQSIGN_AWS_LIVE_EC2_INSTANCE_PROFILE }}
+ SUBNET_ID: ${{ vars.REQSIGN_AWS_LIVE_SUBNET_ID }}
+ SECURITY_GROUP_ID: ${{ vars.REQSIGN_AWS_LIVE_SECURITY_GROUP_ID }}
+ RESULT_BUCKET: ${{ vars.REQSIGN_AWS_LIVE_TEST_BUCKET }}
+ shell: bash
+ run: |
+ result_key="live-tests/results/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}/imds.log"
+ echo "IMDS_RESULT_KEY=$result_key" >> "$GITHUB_ENV"
+ cat > "$RUNNER_TEMP/reqsign-imds-user-data.sh" <<EOF
+ #!/bin/bash
+ log_file=/var/log/reqsign-live-test.log
+ (
+ set -euo pipefail
+ dnf install --assumeyes docker
+ systemctl enable --now docker
+ aws ecr get-login-password --region '${AWS_REGION}' | docker login --username AWS --password-stdin '${IMAGE_URI%/*}'
+ docker run --rm --network host \
+ --env AWS_REGION='${AWS_REGION}' \
+ --env REQSIGN_AWS_V4_TEST_IMDS=on \
+ --env REQSIGN_AWS_V4_VALIDATE_CREDENTIALS=on \
+ --env RUST_LOG=info \
+ '${IMAGE_URI}' test_imds_v2_credential_provider --nocapture
+ ) > "\$log_file" 2>&1
+ test_status=\$?
+ printf '\nREQSIGN_TEST_EXIT_CODE=%s\n' "\$test_status" >> "\$log_file"
+ aws s3 cp "\$log_file" 's3://${RESULT_BUCKET}/${result_key}' --region '${AWS_REGION}'
+ shutdown -h now
+ EOF
+ chmod 700 "$RUNNER_TEMP/reqsign-imds-user-data.sh"
+
+ ami_id="$(aws ssm get-parameter \
+ --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
+ --query 'Parameter.Value' \
+ --output text)"
+ expires_at="$(date -u -d '+2 hours' '+%Y-%m-%dT%H:%M:%SZ')"
+ instance_id="$(aws ec2 run-instances \
+ --image-id "$ami_id" \
+ --instance-type t3.nano \
+ --count 1 \
+ --iam-instance-profile "Name=$INSTANCE_PROFILE" \
+ --subnet-id "$SUBNET_ID" \
+ --security-group-ids "$SECURITY_GROUP_ID" \
+ --associate-public-ip-address \
+ --metadata-options 'HttpEndpoint=enabled,HttpTokens=required,HttpPutResponseHopLimit=2,InstanceMetadataTags=disabled' \
+ --instance-initiated-shutdown-behavior terminate \
+ --user-data "file://$RUNNER_TEMP/reqsign-imds-user-data.sh" \
+ --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=reqsign-live-test-imds},{Key=Project,Value=reqsign},{Key=Purpose,Value=live-test},{Key=GitHubRunId,Value=${GITHUB_RUN_ID}},{Key=ExpiresAt,Value=$expires_at}]" \
+ --query 'Instances[0].InstanceId' \
+ --output text)"
+ echo "INSTANCE_ID=$instance_id" >> "$GITHUB_ENV"
+
+ result_found=false
+ for _ in {1..120}; do
+ if aws s3api head-object --bucket "$RESULT_BUCKET" --key "$result_key" >/dev/null 2>&1; then
+ result_found=true
+ break
+ fi
+ sleep 10
+ done
+ test "$result_found" = "true"
+ aws s3 cp "s3://$RESULT_BUCKET/$result_key" "$RUNNER_TEMP/reqsign-imds-result.log"
+ sed -E 's/(AccessKeyId|SecretAccessKey|Token).*/\1: [REDACTED]/I' "$RUNNER_TEMP/reqsign-imds-result.log"
+ grep -qx 'REQSIGN_TEST_EXIT_CODE=0' "$RUNNER_TEMP/reqsign-imds-result.log"
+ - name: Clean up the IMDSv2 test instance
+ if: always()
+ env:
+ RESULT_BUCKET: ${{ vars.REQSIGN_AWS_LIVE_TEST_BUCKET }}
+ shell: bash
+ run: |
+ if [[ -n "${INSTANCE_ID:-}" ]]; then
+ aws ec2 terminate-instances --instance-ids "$INSTANCE_ID" >/dev/null 2>&1 || true
+ fi
+ if [[ -n "${IMDS_RESULT_KEY:-}" ]]; then
+ aws s3api delete-object --bucket "$RESULT_BUCKET" --key "$IMDS_RESULT_KEY" >/dev/null 2>&1 || true
+ fi
+
+ summary:
+ if: always()
+ needs:
+ - check_live_test
+ - test_hosted_providers
+ - build_live_image
+ - test_ecs_provider
+ - test_imds_provider
+ runs-on: ubuntu-latest
+ steps:
+ - name: Write live-test summary
+ env:
+ ENABLED: ${{ needs.check_live_test.outputs.enabled }}
+ HOSTED_RESULT: ${{ needs.test_hosted_providers.result }}
+ IMAGE_RESULT: ${{ needs.build_live_image.result }}
+ ECS_RESULT: ${{ needs.test_ecs_provider.result }}
+ IMDS_RESULT: ${{ needs.test_imds_provider.result }}
+ shell: bash
+ run: |
+ {
+ echo "## AWS V4 live credential-provider tests"
+ echo
+ echo "| Coverage | Result |"
+ echo "|---|---|"
+ echo "| Static, Env, Profile, Process, Default | $HOSTED_RESULT |"
+ echo "| AssumeRole, WebIdentity, Cognito, S3 Access Grants, S3 Express, S3 signing | $HOSTED_RESULT |"
+ echo "| Live-test image | $IMAGE_RESULT |"
+ echo "| ECS task credentials on Fargate | $ECS_RESULT |"
+ echo "| IMDSv2 credentials on ephemeral EC2 | $IMDS_RESULT |"
+ echo
+ echo "SSOCredentialProvider remains mock-only because the current provider requires a pre-authorized legacy SSO cache and has no unattended token refresh flow."
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ if [[ "$ENABLED" == "true" && ( "$HOSTED_RESULT" != "success" || "$IMAGE_RESULT" != "success" || "$ECS_RESULT" != "success" || "$IMDS_RESULT" != "success" ) ]]; then
+ exit 1
+ fi
diff --git a/services/aws-core/src/provide_credential/cognito.rs b/services/aws-core/src/provide_credential/cognito.rs
index 318ec71..0805f6b 100644
--- a/services/aws-core/src/provide_credential/cognito.rs
+++ b/services/aws-core/src/provide_credential/cognito.rs
@@ -223,7 +223,8 @@ impl CognitoIdentityCredentialProvider {
.map_err(|e| Error::unexpected(format!("failed to parse credentials response: {e}")))?;
let creds = result.credentials;
- let expires_in = Timestamp::from_second(creds.expiration)
+ let expiration = parse_expiration(&creds.expiration)?;
+ let expires_in = Timestamp::from_second(expiration)
.map_err(|e| Error::unexpected(format!("invalid expiration date: {e}")))?;
Ok(Credential {
@@ -255,7 +256,27 @@ struct CognitoCredentials {
access_key_id: String,
secret_key: String,
session_token: String,
- expiration: i64,
+ expiration: serde_json::Number,
+}
+
+fn parse_expiration(expiration: &serde_json::Number) -> Result<i64> {
+ if let Some(expiration) = expiration.as_i64() {
+ return Ok(expiration);
+ }
+
+ let expiration = expiration
+ .as_f64()
+ .ok_or_else(|| Error::unexpected("Cognito credential expiration is not a JSON number"))?;
+ if !expiration.is_finite()
+ || expiration.fract() != 0.0
+ || expiration < i64::MIN as f64
+ || expiration >= -(i64::MIN as f64)
+ {
+ return Err(Error::unexpected(
+ "Cognito credential expiration must be a whole number of Unix seconds",
+ ));
+ }
+ Ok(expiration as i64)
}
impl ProvideCredential for CognitoIdentityCredentialProvider {
type Credential = Credential;
@@ -309,4 +330,16 @@ mod tests {
);
assert_eq!(provider.region, Some("us-east-1".to_string()));
}
+
+ #[test]
+ fn test_parse_cognito_expiration() {
+ let integer = serde_json::from_str("1786124131").unwrap();
+ assert_eq!(parse_expiration(&integer).unwrap(), 1_786_124_131);
+
+ let whole_float = serde_json::from_str("1786124131.0").unwrap();
+ assert_eq!(parse_expiration(&whole_float).unwrap(), 1_786_124_131);
+
+ let fractional = serde_json::from_str("1786124131.5").unwrap();
+ assert!(parse_expiration(&fractional).is_err());
+ }
}
diff --git a/services/aws-core/src/provide_credential/ecs.rs b/services/aws-core/src/provide_credential/ecs.rs
index c46c7c3..5cb41ea 100644
--- a/services/aws-core/src/provide_credential/ecs.rs
+++ b/services/aws-core/src/provide_credential/ecs.rs
@@ -26,7 +26,6 @@ const AWS_CONTAINER_CREDENTIALS_FULL_URI: &str = "AWS_CONTAINER_CREDENTIALS_FULL
const AWS_CONTAINER_AUTHORIZATION_TOKEN: &str = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
const AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE: &str = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
const ECS_METADATA_ENDPOINT: &str = "http://169.254.170.2";
-const ECS_CONTAINER_METADATA_URI: &str = "ECS_CONTAINER_METADATA_URI";
/// ECS Task Role Credentials Provider
///
@@ -56,7 +55,6 @@ const ECS_CONTAINER_METADATA_URI: &str = "ECS_CONTAINER_METADATA_URI";
/// - `AWS_CONTAINER_CREDENTIALS_FULL_URI`: Full URI to fetch credentials (Fargate)
/// - `AWS_CONTAINER_AUTHORIZATION_TOKEN`: Authorization token for the request
/// - `AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE`: File containing the authorization token
-/// - `ECS_CONTAINER_METADATA_URI`: Override the default base endpoint (for testing)
///
/// # Examples
///
@@ -189,13 +187,10 @@ impl ECSCredentialProvider {
// Try relative URI from environment (ECS)
if let Some(relative_uri) = ctx.env_var(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
- // Allow override of metadata endpoint for testing
- let base_endpoint = match &self.metadata_uri_override {
- Some(override_uri) => override_uri.clone(),
- None => ctx
- .env_var(ECS_CONTAINER_METADATA_URI)
- .unwrap_or_else(|| ECS_METADATA_ENDPOINT.to_string()),
- };
+ let base_endpoint = self
+ .metadata_uri_override
+ .as_deref()
+ .unwrap_or(ECS_METADATA_ENDPOINT);
return Ok(format!("{base_endpoint}{relative_uri}"));
}
@@ -348,7 +343,7 @@ mod tests {
}
#[tokio::test]
- async fn test_get_endpoint_relative_uri_with_custom_base() {
+ async fn test_fargate_metadata_uri_does_not_override_credentials_endpoint() {
let ctx = Context::new()
.with_file_read(TokioFileRead)
.with_http_send(ReqwestHttpSend::default());
@@ -360,15 +355,15 @@ mod tests {
"/creds".to_string(),
),
(
- ECS_CONTAINER_METADATA_URI.to_string(),
- "http://localhost:51679".to_string(),
+ "ECS_CONTAINER_METADATA_URI".to_string(),
+ "http://169.254.170.2/v3/task-id".to_string(),
),
]),
});
let provider = ECSCredentialProvider::new();
let endpoint = provider.get_endpoint(&ctx).unwrap();
- assert_eq!(endpoint, "http://localhost:51679/creds");
+ assert_eq!(endpoint, "http://169.254.170.2/creds");
}
#[tokio::test]
diff --git a/services/aws-v4/tests/credential_providers/assume_role.rs b/services/aws-v4/tests/credential_providers/assume_role.rs
index 0187017..8820f6d 100644
--- a/services/aws-v4/tests/credential_providers/assume_role.rs
+++ b/services/aws-v4/tests/credential_providers/assume_role.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context;
+use super::{assert_credentials_work, create_test_context};
use log::info;
use reqsign_aws_v4::{
AssumeRoleCredentialProvider, AssumeRoleGrant, AssumeRoleGranter, DefaultCredentialProvider,
@@ -63,6 +63,7 @@ async fn test_assume_role_credential_provider() {
cred.session_token.is_some(),
"AssumeRole should return session token"
);
+ assert_credentials_work(&ctx, &cred).await;
}
#[tokio::test]
@@ -78,7 +79,7 @@ async fn test_assume_role_granter() {
let context = create_test_context();
let grant = AssumeRoleGrant::new(role_arn, "reqsign-granter");
let granter = Granter::new(
- context,
+ context.clone(),
DefaultCredentialProvider::new(),
AssumeRoleGranter::new(region, grant),
);
@@ -97,4 +98,5 @@ async fn test_assume_role_granter() {
credential.expires_in.is_some(),
"AssumeRole grant should preserve expiration"
);
+ assert_credentials_work(&context, &credential).await;
}
diff --git a/services/aws-v4/tests/credential_providers/assume_role_with_web_identity.rs b/services/aws-v4/tests/credential_providers/assume_role_with_web_identity.rs
index f7bf7d4..5c50fac 100644
--- a/services/aws-v4/tests/credential_providers/assume_role_with_web_identity.rs
+++ b/services/aws-v4/tests/credential_providers/assume_role_with_web_identity.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context_with_env;
+use super::{assert_credentials_work, create_test_context_with_env};
use log::info;
use reqsign_aws_v4::AssumeRoleWithWebIdentityCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -69,4 +69,5 @@ async fn test_assume_role_with_web_identity_credential_provider() {
cred.session_token.is_some(),
"Web identity should return session token"
);
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/cognito.rs b/services/aws-v4/tests/credential_providers/cognito.rs
index 0804370..b8bb840 100644
--- a/services/aws-v4/tests/credential_providers/cognito.rs
+++ b/services/aws-v4/tests/credential_providers/cognito.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context;
+use super::{assert_credentials_work, create_test_context};
use log::info;
use reqsign_aws_v4::CognitoIdentityCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -48,4 +48,5 @@ async fn test_cognito_identity_credential_provider() {
cred.session_token.is_some(),
"Cognito should return session token"
);
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/imds.rs b/services/aws-v4/tests/credential_providers/default.rs
similarity index 57%
copy from services/aws-v4/tests/credential_providers/imds.rs
copy to services/aws-v4/tests/credential_providers/default.rs
index 3c2d904..1bbace4 100644
--- a/services/aws-v4/tests/credential_providers/imds.rs
+++ b/services/aws-v4/tests/credential_providers/default.rs
@@ -15,36 +15,24 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context;
+use super::{assert_credentials_work, create_test_context};
use log::info;
-use reqsign_aws_v4::IMDSv2CredentialProvider;
+use reqsign_aws_v4::DefaultCredentialProvider;
use reqsign_core::ProvideCredential;
use std::env;
#[tokio::test]
-async fn test_imds_v2_credential_provider() {
- if env::var("REQSIGN_AWS_V4_TEST_IMDS").unwrap_or_default() != "on" {
- info!("REQSIGN_AWS_V4_TEST_IMDS not set, skipping");
+async fn test_default_credential_provider_live() {
+ if env::var("REQSIGN_AWS_V4_TEST_DEFAULT").unwrap_or_default() != "on" {
+ info!("REQSIGN_AWS_V4_TEST_DEFAULT not set, skipping");
return;
}
let ctx = create_test_context();
- let provider = IMDSv2CredentialProvider::new();
-
- let cred = provider
+ let credential = DefaultCredentialProvider::new()
.provide_credential(&ctx)
.await
- .expect("IMDSv2CredentialProvider should succeed on EC2");
-
- assert!(
- cred.is_some(),
- "Should load credentials from EC2 instance metadata"
- );
- let cred = cred.unwrap();
- assert!(!cred.access_key_id.is_empty());
- assert!(!cred.secret_access_key.is_empty());
- assert!(
- cred.session_token.is_some(),
- "IMDS should return session token"
- );
+ .expect("DefaultCredentialProvider should succeed")
+ .expect("DefaultCredentialProvider should return credentials");
+ assert_credentials_work(&ctx, &credential).await;
}
diff --git a/services/aws-v4/tests/credential_providers/ecs.rs b/services/aws-v4/tests/credential_providers/ecs.rs
index 6b555d8..c8551d4 100644
--- a/services/aws-v4/tests/credential_providers/ecs.rs
+++ b/services/aws-v4/tests/credential_providers/ecs.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context_with_env;
+use super::{assert_credentials_work, create_test_context_with_env};
use log::info;
use reqsign_aws_v4::ECSCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -31,11 +31,6 @@ async fn test_ecs_credential_provider() {
let mut envs = HashMap::new();
- // Add custom metadata endpoint if set (for testing)
- if let Ok(metadata_uri) = env::var("ECS_CONTAINER_METADATA_URI") {
- envs.insert("ECS_CONTAINER_METADATA_URI".to_string(), metadata_uri);
- }
-
// ECS can use either relative or full URI
if let Ok(relative_uri) = env::var("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI") {
envs.insert(
@@ -66,4 +61,5 @@ async fn test_ecs_credential_provider() {
let cred = cred.unwrap();
assert!(!cred.access_key_id.is_empty());
assert!(!cred.secret_access_key.is_empty());
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/env.rs b/services/aws-v4/tests/credential_providers/env.rs
index 6394ae3..5df8a5d 100644
--- a/services/aws-v4/tests/credential_providers/env.rs
+++ b/services/aws-v4/tests/credential_providers/env.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context_with_env;
+use super::{assert_credentials_work, create_test_context_with_env};
use log::info;
use reqsign_aws_v4::EnvCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -61,4 +61,5 @@ async fn test_env_credential_provider() {
let cred = cred.unwrap();
assert!(!cred.access_key_id.is_empty());
assert!(!cred.secret_access_key.is_empty());
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/imds.rs b/services/aws-v4/tests/credential_providers/imds.rs
index 3c2d904..590ab2a 100644
--- a/services/aws-v4/tests/credential_providers/imds.rs
+++ b/services/aws-v4/tests/credential_providers/imds.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context;
+use super::{assert_credentials_work, create_test_context};
use log::info;
use reqsign_aws_v4::IMDSv2CredentialProvider;
use reqsign_core::ProvideCredential;
@@ -47,4 +47,5 @@ async fn test_imds_v2_credential_provider() {
cred.session_token.is_some(),
"IMDS should return session token"
);
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/mod.rs b/services/aws-v4/tests/credential_providers/mod.rs
index 447c8b2..a1358ea 100644
--- a/services/aws-v4/tests/credential_providers/mod.rs
+++ b/services/aws-v4/tests/credential_providers/mod.rs
@@ -18,19 +18,25 @@
mod assume_role;
mod assume_role_with_web_identity;
mod cognito;
+mod default;
mod ecs;
mod env;
mod imds;
#[cfg(not(target_arch = "wasm32"))]
mod process;
mod profile;
+mod s3_access_grants;
mod s3_express;
#[cfg(not(target_arch = "wasm32"))]
mod sso;
+mod r#static;
+use bytes::Bytes;
+use http::{Method, Request, StatusCode};
+use reqsign_aws_v4::{Credential, EMPTY_STRING_SHA256, RequestSigner};
#[cfg(not(target_arch = "wasm32"))]
use reqsign_command_execute_tokio::TokioCommandExecute;
-use reqsign_core::{Context, OsEnv, StaticEnv};
+use reqsign_core::{Context, OsEnv, SignRequest, StaticEnv};
use reqsign_file_read_tokio::TokioFileRead;
use reqsign_http_send_reqwest::ReqwestHttpSend;
use std::collections::HashMap;
@@ -72,3 +78,49 @@ pub fn create_test_context_with_env(envs: HashMap<String, String>) -> Context {
// StaticEnv overrides specific environment variables on top of OsEnv
ctx.with_env(StaticEnv { home_dir, envs })
}
+
+pub async fn assert_credentials_work(ctx: &Context, credential: &Credential) {
+ if std::env::var("REQSIGN_AWS_V4_VALIDATE_CREDENTIALS").unwrap_or_default() != "on" {
+ return;
+ }
+
+ let region = std::env::var("AWS_REGION")
+ .or_else(|_| std::env::var("AWS_DEFAULT_REGION"))
+ .unwrap_or_else(|_| "us-west-1".to_string());
+ let endpoint =
+ format!("https://sts.{region}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15");
+ let request = Request::builder()
+ .method(Method::GET)
+ .uri(endpoint)
+ .header(
+ http::header::CONTENT_TYPE,
+ "application/x-www-form-urlencoded",
+ )
+ .header("x-amz-content-sha256", EMPTY_STRING_SHA256)
+ .body(Bytes::new())
+ .expect("GetCallerIdentity request should be valid");
+ let (mut parts, body) = request.into_parts();
+
+ RequestSigner::new("sts", ®ion)
+ .sign_request(ctx, &mut parts, Some(credential), None)
+ .await
+ .expect("GetCallerIdentity request should be signed");
+
+ let response = ctx
+ .http_send(Request::from_parts(parts, body))
+ .await
+ .expect("GetCallerIdentity should reach AWS STS");
+ assert_eq!(
+ response.status(),
+ StatusCode::OK,
+ "GetCallerIdentity failed: {}",
+ String::from_utf8_lossy(response.body())
+ );
+ assert!(
+ response
+ .body()
+ .windows(b"<GetCallerIdentityResult".len())
+ .any(|window| window == b"<GetCallerIdentityResult"),
+ "GetCallerIdentity returned an unexpected response"
+ );
+}
diff --git a/services/aws-v4/tests/credential_providers/process.rs b/services/aws-v4/tests/credential_providers/process.rs
index 91abf99..56270fb 100644
--- a/services/aws-v4/tests/credential_providers/process.rs
+++ b/services/aws-v4/tests/credential_providers/process.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context_with_env;
+use super::{assert_credentials_work, create_test_context_with_env};
use log::info;
use reqsign_aws_v4::ProcessCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -55,4 +55,5 @@ async fn test_process_credential_provider() {
let cred = cred.unwrap();
assert!(!cred.access_key_id.is_empty());
assert!(!cred.secret_access_key.is_empty());
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/profile.rs b/services/aws-v4/tests/credential_providers/profile.rs
index 55f8092..d293834 100644
--- a/services/aws-v4/tests/credential_providers/profile.rs
+++ b/services/aws-v4/tests/credential_providers/profile.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context_with_env;
+use super::{assert_credentials_work, create_test_context_with_env};
use log::info;
use reqsign_aws_v4::ProfileCredentialProvider;
use reqsign_core::ProvideCredential;
@@ -60,4 +60,5 @@ async fn test_profile_credential_provider() {
let cred = cred.unwrap();
assert!(!cred.access_key_id.is_empty());
assert!(!cred.secret_access_key.is_empty());
+ assert_credentials_work(&ctx, &cred).await;
}
diff --git a/services/aws-v4/tests/credential_providers/s3_access_grants.rs b/services/aws-v4/tests/credential_providers/s3_access_grants.rs
new file mode 100644
index 0000000..b7b8d2b
--- /dev/null
+++ b/services/aws-v4/tests/credential_providers/s3_access_grants.rs
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::{assert_credentials_work, create_test_context};
+use log::info;
+use reqsign_aws_v4::{
+ DefaultCredentialProvider, S3AccessGrantsConfig, S3AccessGrantsGrant, S3AccessGrantsGranter,
+ S3AccessGrantsPermission, S3AccessGrantsPrivilege, S3AccessGrantsTarget,
+};
+use reqsign_core::{Granter, ProvideCredential};
+use std::env;
+use std::time::Duration;
+
+#[tokio::test]
+async fn test_s3_access_grants_granter_live() {
+ if env::var("REQSIGN_AWS_V4_TEST_S3_ACCESS_GRANTS").unwrap_or_default() != "on" {
+ info!("REQSIGN_AWS_V4_TEST_S3_ACCESS_GRANTS not set, skipping");
+ return;
+ }
+
+ let account_id =
+ env::var("REQSIGN_AWS_V4_ACCOUNT_ID").expect("REQSIGN_AWS_V4_ACCOUNT_ID must be set");
+ let region = env::var("AWS_REGION").expect("AWS_REGION must be set");
+ let bucket = env::var("REQSIGN_AWS_V4_S3_ACCESS_GRANTS_BUCKET")
+ .expect("REQSIGN_AWS_V4_S3_ACCESS_GRANTS_BUCKET must be set");
+ let prefix = env::var("REQSIGN_AWS_V4_S3_ACCESS_GRANTS_PREFIX")
+ .expect("REQSIGN_AWS_V4_S3_ACCESS_GRANTS_PREFIX must be set");
+
+ let context = create_test_context();
+ let source = DefaultCredentialProvider::new()
+ .provide_credential(&context)
+ .await
+ .expect("source credential provider should succeed")
+ .expect("source credential provider should return credentials");
+ let operation = S3AccessGrantsGranter::new(
+ S3AccessGrantsConfig::new(account_id, region),
+ S3AccessGrantsGrant::new(
+ S3AccessGrantsTarget::for_prefix(bucket, prefix),
+ S3AccessGrantsPermission::ReadWrite,
+ S3AccessGrantsPrivilege::Minimal,
+ )
+ .with_audit_context("reqsign-live-test"),
+ );
+ let mut source_provider = reqsign_aws_v4::StaticCredentialProvider::new(
+ &source.access_key_id,
+ &source.secret_access_key,
+ );
+ if let Some(session_token) = source.session_token.as_deref() {
+ source_provider = source_provider.with_session_token(session_token);
+ }
+ let granter = Granter::new(context.clone(), source_provider, operation);
+
+ let credential = granter
+ .grant(Some(Duration::from_secs(900)))
+ .await
+ .expect("S3 Access Grants GetDataAccess should succeed");
+ assert!(credential.session_token.is_some());
+ assert!(credential.expires_in.is_some());
+ assert_credentials_work(&context, &credential).await;
+}
diff --git a/services/aws-v4/tests/credential_providers/cognito.rs b/services/aws-v4/tests/credential_providers/static.rs
similarity index 52%
copy from services/aws-v4/tests/credential_providers/cognito.rs
copy to services/aws-v4/tests/credential_providers/static.rs
index 0804370..50f35ad 100644
--- a/services/aws-v4/tests/credential_providers/cognito.rs
+++ b/services/aws-v4/tests/credential_providers/static.rs
@@ -15,37 +15,31 @@
// specific language governing permissions and limitations
// under the License.
-use super::create_test_context;
+use super::{assert_credentials_work, create_test_context};
use log::info;
-use reqsign_aws_v4::CognitoIdentityCredentialProvider;
+use reqsign_aws_v4::StaticCredentialProvider;
use reqsign_core::ProvideCredential;
use std::env;
#[tokio::test]
-async fn test_cognito_identity_credential_provider() {
- if env::var("REQSIGN_AWS_V4_TEST_COGNITO").unwrap_or_default() != "on" {
- info!("REQSIGN_AWS_V4_TEST_COGNITO not set, skipping");
+async fn test_static_credential_provider_live() {
+ if env::var("REQSIGN_AWS_V4_TEST_STATIC").unwrap_or_default() != "on" {
+ info!("REQSIGN_AWS_V4_TEST_STATIC not set, skipping");
return;
}
- // Provider will read configuration from environment variables:
- // - AWS_COGNITO_IDENTITY_POOL_ID
- // - AWS_REGION or AWS_DEFAULT_REGION
- // - AWS_COGNITO_ENDPOINT (for mock server)
- let ctx = create_test_context();
- let provider = CognitoIdentityCredentialProvider::new();
+ let access_key = env::var("AWS_ACCESS_KEY_ID").expect("AWS_ACCESS_KEY_ID must be set");
+ let secret_key = env::var("AWS_SECRET_ACCESS_KEY").expect("AWS_SECRET_ACCESS_KEY must be set");
+ let mut provider = StaticCredentialProvider::new(&access_key, &secret_key);
+ if let Ok(session_token) = env::var("AWS_SESSION_TOKEN") {
+ provider = provider.with_session_token(&session_token);
+ }
- let cred = provider
+ let ctx = create_test_context();
+ let credential = provider
.provide_credential(&ctx)
.await
- .expect("CognitoIdentity should succeed");
-
- assert!(cred.is_some(), "Should load credentials from Cognito");
- let cred = cred.unwrap();
- assert!(!cred.access_key_id.is_empty());
- assert!(!cred.secret_access_key.is_empty());
- assert!(
- cred.session_token.is_some(),
- "Cognito should return session token"
- );
+ .expect("StaticCredentialProvider should succeed")
+ .expect("StaticCredentialProvider should return credentials");
+ assert_credentials_work(&ctx, &credential).await;
}
diff --git a/services/aws-v4/tests/mocks/credential_process_helper.py b/services/aws-v4/tests/mocks/credential_process_helper.py
index f6ecd72..bc8cbbe 100755
--- a/services/aws-v4/tests/mocks/credential_process_helper.py
+++ b/services/aws-v4/tests/mocks/credential_process_helper.py
@@ -8,49 +8,71 @@ It can be used in ~/.aws/config as:
"""
import json
+import os
import sys
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
def generate_credentials(profile=None):
"""Generate mock AWS credentials in the credential_process format"""
-
+
# Calculate expiration time (1 hour from now)
- expiration = (datetime.utcnow() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ')
-
- # Different credentials based on profile (for testing multiple profiles)
- if profile == "test":
+ expiration = (datetime.now(timezone.utc) + timedelta(hours=1)).strftime(
+ "%Y-%m-%dT%H:%M:%SZ"
+ )
+
+ live_values = {
+ "access_key": os.environ.get("REQSIGN_AWS_PROCESS_ACCESS_KEY_ID"),
+ "secret_key": os.environ.get("REQSIGN_AWS_PROCESS_SECRET_ACCESS_KEY"),
+ "session_token": os.environ.get("REQSIGN_AWS_PROCESS_SESSION_TOKEN"),
+ }
+ if any(live_values.values()) and not (
+ live_values["access_key"] and live_values["secret_key"]
+ ):
+ raise RuntimeError(
+ "REQSIGN_AWS_PROCESS_ACCESS_KEY_ID and "
+ "REQSIGN_AWS_PROCESS_SECRET_ACCESS_KEY must be set together"
+ )
+
+ if live_values["access_key"] and live_values["secret_key"]:
+ access_key = live_values["access_key"]
+ secret_key = live_values["secret_key"]
+ session_token = live_values["session_token"]
+ elif profile == "test":
access_key = "ASIAPROCESSTEST"
secret_key = "process/test/secret/key/EXAMPLE"
+ session_token = "FwoGZXIvYXdzEPROCESS//////////wEaDEXAMPLETOKEN"
else:
access_key = "ASIAPROCESSEXAMPLE"
secret_key = "process/secret/key/EXAMPLE"
-
+ session_token = "FwoGZXIvYXdzEPROCESS//////////wEaDEXAMPLETOKEN"
+
credentials = {
"Version": 1,
"AccessKeyId": access_key,
"SecretAccessKey": secret_key,
- "SessionToken": "FwoGZXIvYXdzEPROCESS//////////wEaDEXAMPLETOKEN",
- "Expiration": expiration
+ "Expiration": expiration,
}
-
+ if session_token:
+ credentials["SessionToken"] = session_token
+
return credentials
def main():
"""Main entry point for the credential process helper"""
-
+
# Check if a profile argument was provided
profile = None
if len(sys.argv) > 2 and sys.argv[1] == "--profile":
profile = sys.argv[2]
-
+
# Generate and output credentials
credentials = generate_credentials(profile)
print(json.dumps(credentials, indent=2))
-
+
return 0
if __name__ == "__main__":
- sys.exit(main())
\ No newline at end of file
+ sys.exit(main())