-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (154 loc) · 6.36 KB
/
main.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Test and deploy to AWS
on:
push:
branches: [ main ]
paths-ignore:
- '.github/workflows/codeql.yml'
- '.github/dependabot.yml'
- 'build/**'
- 'examples/**'
- '**.md'
workflow_dispatch:
permissions:
id-token: write # This is required for requesting the JWT for AWS authentication
contents: read # This is required for actions/checkout
jobs:
test-and-deploy:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
fail-fast: true
matrix:
include:
- environment: nonprod-aws
SERVICE_DOMAIN: sso.nonprod-service.security.gov.uk
TF_WORKSPACE: nonprod
AWS_REGION: eu-west-2
- environment: prod-aws
SERVICE_DOMAIN: sso.service.security.gov.uk
TF_WORKSPACE: prod
AWS_REGION: eu-west-2
environment:
name: ${{ matrix.environment }}
steps:
- name: Checkout this repo
uses: actions/checkout@v3
with:
ref: main
path: main
- name: Read .terraform-version file
run: |
TV=$(cat main/terraform/.terraform-version | tr -d [:space:])
echo "terraform_version=${TV}"
echo "terraform_version=${TV}" >> $GITHUB_OUTPUT
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.terraform_version }}
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Show me files
run: ls -lah
- name: Build and test viewer-request
env:
AWS_CLOUDFRONT_KEY: ${{ secrets.AWS_CLOUDFRONT_KEY }}
run: |
cd main/
chmod +x build/*.sh
bash build/test_viewer-request.sh
- name: Build and test viewer-response
run: |
cd main/
chmod +x build/*.sh
bash build/test_viewer-response.sh
- name: Build and test Flask app
env:
AWS_CLOUDFRONT_KEY: ${{ secrets.AWS_CLOUDFRONT_KEY }}
run: |
cd main/
chmod +x build/*.sh
python -V
bash build/build_lambda.sh
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ matrix.AWS_REGION }}
- name: Test IAM credentials
run: aws sts get-caller-identity
- name: Apply Terraform
env:
AWS_CLOUDFRONT_KEY: ${{ secrets.AWS_CLOUDFRONT_KEY }}
AWS_REGION: ${{ matrix.AWS_REGION }}
TF_WORKSPACE: ${{ matrix.TF_WORKSPACE }}
run: |
cd main/
chmod +x build/*.sh
bash build/test_viewer-request.sh
bash build/test_viewer-response.sh
bash build/build_lambda.sh
cd terraform/
terraform workspace show
terraform init
terraform apply -auto-approve
- name: Deploy S3 assets
env:
S3_ASSET_BUCKET: ${{ matrix.SERVICE_DOMAIN }}
AWS_REGION: ${{ matrix.AWS_REGION }}
run: |
cd main/
aws s3 cp assets/ "s3://${S3_ASSET_BUCKET}/assets/" --recursive
- name: Check deployed URLs
env:
SERVICE_DOMAIN: ${{ matrix.SERVICE_DOMAIN }}
TEST_CLIENT_ID: ${{ secrets.TEST_CLIENT_ID }}
run: |
echo "Checking CloudFront status"
curl -v "https://${SERVICE_DOMAIN}/.well-known/status" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .cfstatus.txt
egrep -i '< HTTP/[0123\.]+ 200' .cfstatus.txt
egrep -i "OK" .cfstatus.txt
echo "Checking Lambda status"
curl -v "https://${SERVICE_DOMAIN}/internal/health" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .lstatus.txt
egrep -i '< HTTP/[0123\.]+ 200' .lstatus.txt
egrep -i "IMOK" .lstatus.txt
echo "Checking OIDC status"
curl -v "https://${SERVICE_DOMAIN}/.well-known/openid-configuration" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .oidc.txt
egrep -i '< HTTP/[0123\.]+ 200' .oidc.txt
egrep -i "\"issuer\":\s*\"https://${SERVICE_DOMAIN}\"" .oidc.txt
echo "Checking '/' is public"
curl -v "https://${SERVICE_DOMAIN}/" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .www-status.txt
egrep -i '< HTTP/[0123\.]+ 200' .www-status.txt
egrep -i "<script src=\"https://${SERVICE_DOMAIN}/assets/init.js\">" .www-status.txt
echo "Checking '/dashboard' is private and requires auth"
curl -v "https://${SERVICE_DOMAIN}/dashboard" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .priv-status.txt
egrep -i '< HTTP/[0123\.]+ 30[0-9]' .priv-status.txt
grep '< location: /sign-in' .priv-status.txt
echo "Checking JWKs status"
curl -v "https://${SERVICE_DOMAIN}/.well-known/jwks.json" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .jwks.txt
egrep -i '< HTTP/[0123\.]+ 200' .jwks.txt
egrep -i "\"kid\":\s*\"[a-z]+\-[a-z0-9]+\"" .jwks.txt
echo "Checking /auth/token"
curl -v "https://${SERVICE_DOMAIN}/auth/token" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .authtoken.txt
egrep -i '< HTTP/[0123\.]+ 400' .authtoken.txt
echo "Checking /auth/profile"
curl -v "https://${SERVICE_DOMAIN}/auth/profile" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .authprofile.txt
egrep -i '< HTTP/[0123\.]+ 200' .authprofile.txt
egrep -i "\"sub\":\s*null" .authprofile.txt
echo "Checking /auth/oidc failure"
curl -v "https://${SERVICE_DOMAIN}/auth/oidc" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .authoidc.txt
egrep -i '< HTTP/[0123\.]+ 30[0-9]' .authoidc.txt
grep '< location: /error?type=response_type-not-set' .authoidc.txt
echo "Checking /auth/oidc semi-success"
curl -v "https://${SERVICE_DOMAIN}/auth/oidc?response_type=code&client_id=${TEST_CLIENT_ID}" \
--connect-timeout 10 --max-redirs 0 --silent --stderr - > .authoidc2.txt
egrep -i '< HTTP/[0123\.]+ 30[0-9]' .authoidc2.txt
grep "< location: /sign-in?to_app=${TEST_CLIENT_ID}" .authoidc2.txt