Skip to content

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

@NicholasFiorentini

Description

@NicholasFiorentini

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions