Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/sts_session_token/tasks/main.yml

raw
1 ---
2 # tasks file for sts_assume_role
3 - module_defaults:
4 group/aws:
5 region: "{{ aws_region }}"
6 access_key: "{{ aws_access_key }}"
7 secret_key: "{{ aws_secret_key }}"
8 session_token: "{{ security_token | default(omit) }}"
9 collections:
10 - amazon.aws
11 block:
12 # Get some information about who we are before starting our tests
13 # we'll need this as soon as we start working on the policies
14 - name: get ARN of calling user
15 aws_caller_info:
16 register: original_aws_caller_info
17
18 # ============================================================
19
20 - name: Get a session token
21 sts_session_token:
22 register: token_details
23 no_log: True
24
25 - assert:
26 that:
27 - '"sts_creds" in token_details'
28 - '"access_key" in token_details.sts_creds'
29 - '"expiration" in token_details.sts_creds'
30 - '"secret_key" in token_details.sts_creds'
31 - '"session_token" in token_details.sts_creds'
32
33 - name: Get a session token
34 sts_session_token:
35 duration_seconds: 1000
36 register: token_details
37 no_log: True
38
39 - debug:
40 var: ansible_date_time
41
42 - assert:
43 that:
44 - '"sts_creds" in token_details'
45 - '"access_key" in token_details.sts_creds'
46 - '"expiration" in token_details.sts_creds'
47 - '"secret_key" in token_details.sts_creds'
48 - '"session_token" in token_details.sts_creds'
49 # Expiry within a minute of given duration
50 - (((expiry | int) - (ansible_date_time.epoch | int)) - 1000 | abs) < 60
51 vars:
52 # 2022-06-21T03:26:13+00:00
53 expiry: "{{ (token_details.sts_creds.expiration | to_datetime('%Y-%m-%dT%H:%M:%S%z')).strftime('%s') }}"
54
55 - name: Get ARN of user when running with generated token
56 aws_caller_info:
57 access_key: "{{ token_details.sts_creds.access_key }}"
58 secret_key: "{{ token_details.sts_creds.secret_key }}"
59 session_token: "{{ token_details.sts_creds.session_token }}"
60 register: token_aws_caller_info
61
62 - assert:
63 that:
64 - token_aws_caller_info.account == original_aws_caller_info.account
65 - token_aws_caller_info.arn == original_aws_caller_info.arn
66
67 # ============================================================
68 always: []