forked from usnistgov/blossom-oscal
-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (96 loc) · 4.48 KB
/
account_request_approve.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Account Request Approved
on:
issues:
types:
- labeled
jobs:
# When ACCOUNT_APPROVED label is added to account management request
request-approved:
if: github.event.label.name == 'ACCOUNT_APPROVED'
runs-on: ubuntu-20.04
permissions:
issues: write
steps:
- name: Notify Blossom Sysdevs about Approved Account
run: gh issue comment "$NUMBER" --body "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
BODY: >
Account management request APPROVED by Blossom Management.
@usnistgov/blossom-sysdevs please ensure the ACL and/or Cognito are updated and the SSP is in sync with the update.
When implemented, add the ACCOUNT_IMPLEMENTED label and
link this account request issue to the PR with the implementation.
parse-issue:
needs: request-approved
runs-on: ubuntu-20.04
outputs:
account-modification: ${{ steps.issue-parser.outputs.issueparser_account-modification }}
user-first-name: ${{ steps.issue-parser.outputs.issueparser_user-first-name }}
user-last-name: ${{ steps.issue-parser.outputs.issueparser_user-last-name }}
user-username: ${{ steps.issue-parser.outputs.issueparser_user-username }}
user-email: ${{ steps.issue-parser.outputs.issueparser_user-email }}
account-type: ${{ steps.issue-parser.outputs.issueparser_account-type }}
ssp-file-path: ${{ steps.issue-parser.outputs.issueparser_ssp-file-path }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
sparse-checkout: |
.github/ISSUE_TEMPLATE/account_management_request_form.yaml
sparse-checkout-cone-mode: false
- name: Parse issue body
uses: stefanbuck/github-issue-parser@2d2ff50d4aae06ab58d26bf59468d98086605f11 # v3.2.1
id: issue-parser
with:
template-path: ".github/ISSUE_TEMPLATE/account_management_request_form.yaml"
create-user:
needs: parse-issue
if: ${{ needs.parse-issue.outputs.account-modification == 'Create' }}
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Ensure directory exists for created users
run: |
mkdir -p ato/oscal-artifacts/created_users/
- name: Ensure directory exists for created users references
run: |
mkdir -p ato/oscal-artifacts/reference_created_users/
- name: Create yaml file for automated user creation
env:
USER_NAME: "${{ needs.parse-issue.outputs.user-first-name }} ${{ needs.parse-issue.outputs.user-last-name }}"
USER_USERNAME: ${{ needs.parse-issue.outputs.user-username }}
USER_EMAIL: ${{ needs.parse-issue.outputs.user-email }}
USER_ROLE: ${{ needs.parse-issue.outputs.account-type }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
SSP_FILE_PATH: ${{ needs.parse-issue.outputs.ssp-file-path }}
run: |
python ato/secops/create_user.py --user-name "$USER_NAME" --user-username "$USER_USERNAME" --user-email "$USER_EMAIL" --user-role "$USER_ROLE" --issue-number "$ISSUE_NUMBER" --ssp-path "$SSP_FILE_PATH"
- name: Store user yaml in repo
run: |
git config user.name "create-user-action[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config pull.rebase false
git fetch --all
git checkout "$BRANCH_NAME" || git checkout -b "$BRANCH_NAME"
git pull origin "$BRANCH_NAME"
git add "ato/oscal-artifacts/created_users/*"
git add "ato/oscal-artifacts/reference_created_users/*"
git commit -m "Create user request #$ISSUE_NUMBER"
git push origin "$BRANCH_NAME"
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
BRANCH_NAME: "account-request"
- name: Configure AWS CLI
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 # v4
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
- name: Copy reference yaml to bucket
run: |
aws s3 cp --recursive ato/oscal-artifacts/reference_created_users/ s3://"$AWS_BUCKET"
env:
AWS_BUCKET: ${{ secrets.AWS_BUCKET }}