Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access bucket (HTTP 403) when using IAM Roles attached to Service Accounts on EKS #430

Open
2 of 3 tasks
NicholasFiorentini opened this issue Apr 17, 2023 · 3 comments

Comments

@NicholasFiorentini
Copy link

NicholasFiorentini commented Apr 17, 2023

Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request

I'm running my code from rshiny server. The session token is provided using https://docs.aws.amazon.com/eks/latest/userguide/pod-configuration.html.

## Install package
install.packages(c(
    "aws.ec2metadata",
    "aws.signature", 
    "aws.s3",
  ),
  repos=c(cloudyr = "http://cloudyr.github.io/drat", getOption("repos"))
)

# tried this:
# install.packages("aws.s3", repos="https://rforge.net")
# but the packages is not loaded

## load package
library(aws.ec2metadata)
library(aws.signature)
library(aws.s3)

## Minimal example
credentials <- aws.signature::locate_credentials()
    
bucket_exist <- aws.s3::bucket_exists("name_of_my_bucket")
cat(file=stderr(), paste0("AWS_DEFAULT_REGION: ", Sys.getenv("AWS_DEFAULT_REGION"), "\n"))
cat(file=stderr(), paste0("Bucket exists: ", bucket_exist, "\n"))

The bucket_exists call fails with the error:

Client error: (403) Forbidden
 Warning: Error in : Bucket name_of_my_bucket does not exist.
] Error : Bucket name_of_my_bucket does not exist.

Further details

The output of credentials shows the correct key id, secret, toke, and region.

The attached token is valid: running awscli from the same pod I can access the bucket without error.

Output of sessionInfo()

platform = "x86_64-pc-linux-gnu"
arch = "x86_64"
os = "linux-gnu"
system = "x86_64, linux-gnu"
status = ""
major = "4"
minor = "2.3"
`svn rev` = "83980"
language = "R"
version.string = "R version 4.2.3 (2023-03-15)"
nickname = "Shortstop Beagle"
LC_CTYPE=en_US.UTF-8;
LC_NUMERIC=C;
LC_TIME=en_US.UTF-8;
LC_COLLATE=en_US.UTF-8;
LC_MONETARY=en_US.UTF-8;
LC_MESSAGES=en_US.UTF-8;
LC_PAPER=en_US.UTF-8;
LC_NAME=C;
LC_ADDRESS=C;
LC_TELEPHONE=C;
LC_MEASUREMENT=en_US.UTF-8;
LC_IDENTIFICATION=C
Package = "aws.s3", Type = "Package", Title = "'AWS S3' Client Package", Version = "0.3.22"
Package = "aws.signature", Type = "Package", Title = "Amazon Web Services Request Signatures", Version = "0.6.0",
Package = "aws.ec2metadata", Type = "Package", Title = "Get EC2 Instance Metadata", Version = "0.2.0"
@NicholasFiorentini
Copy link
Author

NicholasFiorentini commented Apr 17, 2023

Just to double-check, I tried this:

cat(file=stderr(), paste0("Key: ", aws_credentials$key, "\n"))
cat(file=stderr(), paste0("Secret: ", aws_credentials$secret, "\n"))
cat(file=stderr(), paste0("Token: ", aws_credentials$session_token, "\n"))
cat(file=stderr(), paste0("Region: ", aws_credentials$region, "\n"))

bucket_access <- aws.s3::bucket_exists(
        "my_bucket",
        key=aws_credentials$key,
        secret=aws_credentials$secret,
        session_token=aws_credentials$session_token,
        region=aws_credentials$region)

Output:

Key: ***
Secret: ***
Token: ***
Region: us-west-2

Client error: (403) Forbidden

Does aws.s3 support STS tokens?

@andrewhharmon
Copy link

I'm facing the same issue. Any workarounds?

@NicholasFiorentini
Copy link
Author

Ultimately, I moved to a different library to overcome this limitation.

The workaround would be using an AWS API key, but I would avoid it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants