Skip to content

Commit 1eb27ee

Browse files
committed
add instructions on generating IAP tokens
1 parent 97b587c commit 1eb27ee

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/webapp/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ Go to `<env>-sst.datakind.org/api/v1/docs`: e.g. https://dev-sst.datakind.org/ap
66

77
Note that dev and staging links are all behind a GCP Identity-Aware Proxy.
88

9+
If you need to access endpoints from a non-browser environment (i.e. curl), you can generate authentication tokens
10+
to access endpoints behind IAP.
11+
12+
```
13+
# https://console.cloud.google.com/iam-admin/serviceaccounts
14+
iap_sa_email=<IAP impersonation service account email>
15+
# https://console.cloud.google.com/apis/credentials
16+
client_id=<OAuth 2 Client ID for the service>
17+
iap_token=$(gcloud auth print-identity-token --impersonate-service-account=$iap_sa_email --audiences=$client_id --include-email)
18+
api_key=<Webapp API key>
19+
curl
20+
-H "Proxy-Authorization: Bearer $iap_token" \
21+
-H "Authorization: Bearer $api_key" \
22+
'https://subdomain.datakind.org/api/v1/endpoint'
23+
```
24+
925
## Authentication
1026

1127
Authentication of the API is primarily via JWTs in the Authorization header of the HTTP calls. These JWTs are short-term tokens that expire and are signed by the API. They are slightly more secure than using API keys directly to authenticate every call as API keys are long-term/non-expiring authentication tokens which are more powerful if stolen. So the mechanism used here is that API keys are exchanged for JWTs, which are then used to authenticate each call and can store additional information such as "enduser" identity.

src/worker/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ Go to `<env>-sst.datakind.org/worker/api/v1/docs`: e.g. https://dev-sst.datakind
88

99
Note that dev and staging links are all behind a GCP Identity-Aware Proxy.
1010

11+
If you need to access endpoints from a non-browser environment (i.e. curl), you can generate authentication tokens
12+
to access endpoints behind IAP.
13+
14+
```
15+
# https://console.cloud.google.com/iam-admin/serviceaccounts
16+
iap_sa_email=<IAP impersonation service account email>
17+
# https://console.cloud.google.com/apis/credentials
18+
client_id=<OAuth 2 Client ID for the service>
19+
iap_token=$(gcloud auth print-identity-token --impersonate-service-account=$iap_sa_email --audiences=$client_id --include-email)
20+
api_key=<Webapp API key>
21+
curl
22+
-H "Proxy-Authorization: Bearer $iap_token" \
23+
-H "Authorization: Bearer $api_key" \
24+
'https://subdomain.datakind.org/api/v1/endpoint'
25+
```
26+
1127
## Authentication
1228

1329
Authentication of this program is via Username/Password. There is a single username/password combination that will authenticate to this program and its set in the env var file as the variables `USERNAME` and `PASSWORD`. There's no user table or api key situation as this is a worker job with limited functionality. And it is supposed to have a limited set of users (a subset of Datakinders -- probably only one or two people).

0 commit comments

Comments
 (0)