Skip to content

Commit a0336cf

Browse files
authored
Merge pull request #5 from marcohutzsch1234/master
Rename GITHUB_TOKEN env var to PERSONAL_ACCESS_TOKEN
2 parents 50f0cac + 86037ae commit a0336cf

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
- Description: Session Token for the current AWS session. Only required if you assume a role first.
1515

1616
#### IAM_USERNAME
17-
- Required: ***True***
18-
- Description: Name of IAM user being rotated
17+
- Required: ***False***
18+
- Description: Name of IAM user being rotated, if not set the username which is used in the AWS credentials is used
1919

20-
#### GITHUB_TOKEN
20+
#### PERSONAL_ACCESS_TOKEN
2121
- Required: ***True***
22-
- Description: Github Token with **Repo Admin** access of the target repo. As of 4/16/2020 `${{github.token}}` does not have permission to query the Secrets API.
22+
- Description: Github Token with **Repo Admin** access of the target repo. As of 4/16/2020 `${{github.token}}` does not have permission to query the Secrets API. The existing env var GITHUB_TOKEN which is added automatically to all runs does not have the access secrets.
2323

2424
#### OWNER_REPOSITORY
2525
- Required: ***True***
@@ -55,7 +55,7 @@ jobs:
5555
AWS_ACCESS_KEY_ID: ${{ secrets.access_key_name }}
5656
AWS_SECRET_ACCESS_KEY: ${{ secrets.secret_key_name }}
5757
IAM_USERNAME: 'iam-user-name'
58-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
58+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
5959
OWNER_REPOSITORY: ${{ github.repository }}
6060
```
6161

@@ -78,7 +78,7 @@ jobs:
7878
AWS_ACCESS_KEY_ID: ${{ secrets.access_key_name }}
7979
AWS_SECRET_ACCESS_KEY: ${{ secrets.secret_key_name }}
8080
IAM_USERNAME: 'iam-user-name'
81-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
81+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
8282
OWNER_REPOSITORY: ${{ github.repository }}
8383
8484
- name: Send Slack Status

rotate_keys.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
)
2323

2424
def main_function():
25-
iam_username = os.environ['IAM_USERNAME']
26-
github_token = os.environ['GITHUB_TOKEN']
25+
iam_username = os.environ['IAM_USERNAME'] if 'IAM_USERNAME' in os.environ else who_am_i()
26+
github_token = os.environ['PERSONAL_ACCESS_TOKEN']
2727
owner_repository = os.environ['OWNER_REPOSITORY']
2828

2929
list_ret = iam.list_access_keys(UserName=iam_username)
@@ -59,6 +59,19 @@ def main_function():
5959

6060
sys.exit(0)
6161

62+
def who_am_i():
63+
# ask the aws backend for myself with a boto3 sts client
64+
sts = boto3.client(
65+
'sts',
66+
aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID'],
67+
aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY'],
68+
aws_session_token = os.environ['AWS_SESSION_TOKEN'] if 'AWS_SESSION_TOKEN' in os.environ else None
69+
)
70+
71+
user = sts.get_caller_identity()
72+
# return last element of splitted list to get username
73+
return user['Arn'].split("/")[-1]
74+
6275
def create_new_keys(iam_username):
6376
# create the keys
6477
create_ret = iam.create_access_key(

0 commit comments

Comments
 (0)