Skip to content

Commit 4de6422

Browse files
authored
Minor fixes for assume_role (#643)
* 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
1 parent bd39b39 commit 4de6422

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

Diff for: .github/workflows/CI.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ jobs:
3333
- os: ubuntu-latest
3434
version: "1.6"
3535
arch: x64
36-
env:
37-
MINIO_ACCESS_KEY: minio
38-
MINIO_SECRET_KEY: minio123
39-
MINIO_REGION_NAME: aregion
4036
steps:
4137
- uses: actions/checkout@v2
4238
- name: Assume AWS role
@@ -45,6 +41,12 @@ jobs:
4541
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/AWS.jl
4642
aws-region: us-east-1
4743
- name: MinIO server setup
44+
if: runner.os != 'Windows'
45+
env:
46+
MINIO_ACCESS_KEY: minio
47+
MINIO_SECRET_KEY: minio123
48+
MINIO_REGION_NAME: aregion
49+
shell: bash
4850
run: |
4951
case "$RUNNER_OS" in
5052
Linux)
@@ -58,10 +60,11 @@ jobs:
5860
exit 1
5961
;;
6062
esac
61-
curl -LO "https://dl.minio.io/server/minio/release/${host_os}/minio"
63+
curl -sSLO "https://dl.minio.io/server/minio/release/${host_os}/minio"
6264
mkdir data
6365
chmod +x ./minio
6466
./minio server --compat --quiet data 2>&1 > minio.log &
67+
env | grep ^MINIO_ | tee -a "$GITHUB_ENV"
6568
- uses: julia-actions/setup-julia@v1
6669
with:
6770
version: ${{ matrix.version }}

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AWS"
22
uuid = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
33
license = "MIT"
4-
version = "1.89.0"
4+
version = "1.89.1"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

Diff for: src/utilities/role.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function assume_role_creds(
8181
else
8282
params["RoleSessionName"] = _role_session_name(
8383
"AWS.jl-",
84-
ENV["USER"],
84+
_whoami(),
8585
"-" * Dates.format(now(UTC), dateformat"yyyymmdd\THHMMSS\Z"),
8686
)
8787
end
@@ -128,3 +128,15 @@ function assume_role_creds(
128128
renew,
129129
)
130130
end
131+
132+
"""
133+
_whoami() -> AbstractString
134+
135+
The identity of the current user (i.e. effective user name). May differ from the
136+
logged in user if the current user has been assumed, perhaps by means of `su`.
137+
138+
Note that the environmental variables `USER` or `USERNAME` are
139+
[not Bash built-in variables](https://tldp.org/LDP/abs/html/internalvariables.html#AMIROOT)
140+
and by default are not present in containers.
141+
"""
142+
_whoami() = readchomp(`id -un`) # The `whoami` utility is marked as obsolete

Diff for: test/role.jl

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ end
1616

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

19+
@testset "_whoami" begin
20+
user = AWS._whoami()
21+
@test user isa AbstractString
22+
@test !isempty(user)
23+
end
24+
1925
@testset "assume_role / assume_role_creds" begin
2026
# In order to mitigate the effects of using `assume_role` in order to test itself we'll
2127
# use the lowest-level call with as many defaults as possible.
@@ -54,21 +60,23 @@ get_assumed_role(creds::AWSCredentials) = get_assumed_role(AWSConfig(; creds))
5460
end
5561

5662
@testset "duration" begin
57-
drift = Second(1)
63+
# Have seen up to 3 seconds of drift on CI jobs
64+
drift = Second(5)
5865

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

63-
creds = assume_role_creds(config, role_a; duration=900)
70+
duration = 900 # Minimum allowed duration
71+
creds = assume_role_creds(config, role_a; duration)
6472
t = floor(now(UTC), Second)
65-
@test t <= creds.expiry <= t + Second(900) + drift
73+
@test t <= creds.expiry <= t + Second(duration) + drift
6674
end
6775

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

0 commit comments

Comments
 (0)