Skip to content

Commit

Permalink
Minor fixes for assume_role (#643)
Browse files Browse the repository at this point in the history
* Increase duration testset drift to 5 seconds

* More reliable way of determining current user

* Enable MinIO tests only when supported

* Set project version to 1.89.1
  • Loading branch information
omus authored Jun 27, 2023
1 parent bd39b39 commit 4de6422
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ jobs:
- os: ubuntu-latest
version: "1.6"
arch: x64
env:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio123
MINIO_REGION_NAME: aregion
steps:
- uses: actions/checkout@v2
- name: Assume AWS role
Expand All @@ -45,6 +41,12 @@ jobs:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/AWS.jl
aws-region: us-east-1
- name: MinIO server setup
if: runner.os != 'Windows'
env:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio123
MINIO_REGION_NAME: aregion
shell: bash
run: |
case "$RUNNER_OS" in
Linux)
Expand All @@ -58,10 +60,11 @@ jobs:
exit 1
;;
esac
curl -LO "https://dl.minio.io/server/minio/release/${host_os}/minio"
curl -sSLO "https://dl.minio.io/server/minio/release/${host_os}/minio"
mkdir data
chmod +x ./minio
./minio server --compat --quiet data 2>&1 > minio.log &
env | grep ^MINIO_ | tee -a "$GITHUB_ENV"
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AWS"
uuid = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
license = "MIT"
version = "1.89.0"
version = "1.89.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
14 changes: 13 additions & 1 deletion src/utilities/role.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function assume_role_creds(
else
params["RoleSessionName"] = _role_session_name(
"AWS.jl-",
ENV["USER"],
_whoami(),
"-" * Dates.format(now(UTC), dateformat"yyyymmdd\THHMMSS\Z"),
)
end
Expand Down Expand Up @@ -128,3 +128,15 @@ function assume_role_creds(
renew,
)
end

"""
_whoami() -> AbstractString
The identity of the current user (i.e. effective user name). May differ from the
logged in user if the current user has been assumed, perhaps by means of `su`.
Note that the environmental variables `USER` or `USERNAME` are
[not Bash built-in variables](https://tldp.org/LDP/abs/html/internalvariables.html#AMIROOT)
and by default are not present in containers.
"""
_whoami() = readchomp(`id -un`) # The `whoami` utility is marked as obsolete
18 changes: 13 additions & 5 deletions test/role.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ end

get_assumed_role(creds::AWSCredentials) = get_assumed_role(AWSConfig(; creds))

@testset "_whoami" begin
user = AWS._whoami()
@test user isa AbstractString
@test !isempty(user)
end

@testset "assume_role / assume_role_creds" begin
# In order to mitigate the effects of using `assume_role` in order to test itself we'll
# use the lowest-level call with as many defaults as possible.
Expand Down Expand Up @@ -54,21 +60,23 @@ get_assumed_role(creds::AWSCredentials) = get_assumed_role(AWSConfig(; creds))
end

@testset "duration" begin
drift = Second(1)
# Have seen up to 3 seconds of drift on CI jobs
drift = Second(5)

creds = assume_role_creds(config, role_a; duration=nothing)
t = floor(now(UTC), Second)
@test t <= creds.expiry <= t + Second(3600) + drift

creds = assume_role_creds(config, role_a; duration=900)
duration = 900 # Minimum allowed duration
creds = assume_role_creds(config, role_a; duration)
t = floor(now(UTC), Second)
@test t <= creds.expiry <= t + Second(900) + drift
@test t <= creds.expiry <= t + Second(duration) + drift
end

@testset "session_name" begin
session_prefix = "AWS.jl-" * ENV["USER"]
session_prefix = "AWS.jl-"
creds = assume_role_creds(config, role_a; session_name=nothing)
regex = r":assumed-role/" * (role_a * '/' * session_prefix) * r"-\d{8}T\d{6}Z$"
regex = r":assumed-role/" * (role_a * '/' * session_prefix) * r".*-\d{8}T\d{6}Z$"
@test contains(creds.user_arn, regex)
@test get_assumed_role(creds) == role_a

Expand Down

2 comments on commit 4de6422

@omus
Copy link
Member Author

@omus omus commented on 4de6422 Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/86391

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.89.1 -m "<description of version>" 4de642247e323a434354eadf2809473d87fc77a7
git push origin v1.89.1

Please sign in to comment.