Skip to content

Commit 20556d1

Browse files
committed
Adjusted the README
1 parent 1d71382 commit 20556d1

File tree

3 files changed

+75
-33
lines changed

3 files changed

+75
-33
lines changed

auth-oidc/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.env
1+
.env
2+
oidc-env.properties
3+
oidc.properties

auth-oidc/README.md

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,93 @@
1-
# OAuth 2.0 / OIDC
1+
# OIDC sample
22

3-
A pretty simple golang application that, in its most basic form, will
4-
return "Hello World" back to the caller.
3+
This example demonstrates how to OIDC authentication can be added to protect an IBM Cloud Code Engine app.
54

6-
Check the source code for all of the things you can make it do either via
7-
environment variables or query parameters. This is good for testing the
8-
system to see how it reacts - for example, when the app crashes.
5+
![](ce-oidc.simple.png)
96

10-
Note: we added some extra logic to this so I can also be used as a batch job
11-
but you can ignore that if all you care about is the App side of things.
7+
## Setting up an OIDC SSO configuration
128

9+
In order to be able to authenticate using OIDC SSO, you'll need to choose and configure a suitable OIDC provider. For this sample we demonstrate how this can be achieved by either using GitHub, or an IBM-internal provider. While many other OIDC providers will also work out-of-the-box, some may require few adjustments in the implementation of the auth app that we provide in this sample.
1310

11+
### Github.com OIDC SSO
12+
13+
GitHub.com provides a publicly available OIDC provider, that can be used to point to Code Engine applications, which you deployed in your IBM Cloud account. Use the following steps to configure an SSO app:
14+
15+
* Create Github OIDC app through https://github.com/settings/developers
16+
```
17+
name: oidc-sample
18+
homepage: https://oidc-sample.<CE_SUBDOMAIN>.<REGION>.codeengine.appdomain.cloud
19+
callback URL: https://oidc-sample.<CE_SUBDOMAIN>.<REGION>.codeengine.appdomain.cloud/auth/callback
20+
```
21+
* Store the client id and the secret in local file called `oidc.properties`
22+
```
23+
echo "OIDC_CLIENT_ID=<CLIENT_ID>" > oidc.properties
24+
echo "OIDC_CLIENT_SECRET=<CLIENT_SECRET>" >> oidc.properties
25+
```
26+
* Generate a random cookie secret that is used to encrypt the auth cookie value and add it to the `oidc.properties` file
27+
```
28+
echo "COOKIE_ENCRYPTION_KEY=$(openssl rand -base64 32)" >> oidc.properties
29+
```
30+
* From your OIDC provider obtain the following values and add them to the `oidc.properties` file
31+
```
32+
echo "OIDC_PROVIDER_AUTHORIZATION_ENDPOINT=https://github.com/login/oauth/authorize" >> oidc.properties
33+
echo "OIDC_PROVIDER_TOKEN_ENDPOINT=https://github.com/login/oauth/access_token" >> oidc.properties
34+
echo "OIDC_PROVIDER_USERINFO_ENDPOINT=https://api.github.com/user" >> oidc.properties
35+
```
36+
37+
### IBMers-only: w3Id OIDC SSO
38+
39+
To protect IBM's workforce, the SSO Provisioner provides the ability to configure an w3Id SSO. Note: This SSO provider can only be used by IBMers
40+
41+
* Create w3Id OIDC configuration through https://w3.ibm.com/security/sso-provisioner
42+
```
43+
name: oidc-sample
44+
homepage: https://oidc-sample.<CE_SUBDOMAIN>.<REGION>.codeengine.appdomain.cloud
45+
callback URL: https://oidc-sample.<CE_SUBDOMAIN>.<REGION>.codeengine.appdomain.cloud/auth/callback
46+
```
47+
* Store the client id and the secret in local file called `oidc.properties`
48+
```
49+
echo "OIDC_CLIENT_ID=<CLIENT_ID>" > oidc.properties
50+
echo "OIDC_CLIENT_SECRET=<CLIENT_SECRET>" >> oidc.properties
51+
```
52+
* Generate a random cookie secret that is used to encrypt the auth cookie value and add it to the `oidc.properties` file
53+
```
54+
echo "COOKIE_ENCRYPTION_KEY=$(openssl rand -base64 32)" >> oidc.properties
55+
```
56+
* From your OIDC provider obtain the following values and add them to the `oidc.properties` file
57+
```
58+
echo "OIDC_PROVIDER_AUTHORIZATION_ENDPOINT=" >> oidc.properties
59+
echo "OIDC_PROVIDER_TOKEN_ENDPOINT=" >> oidc.properties
60+
echo "OIDC_PROVIDER_USERINFO_ENDPOINT=" >> oidc.properties
61+
```
62+
63+
## Setup and Configuration
64+
65+
Make sure the file `oidc.properties` contains the following properties are defined and contain meaningful values
1466
```
15-
OIDC_CLIENT_ID= > .env
16-
OIDC_CLIENT_SECRET= >> .env
17-
OIDC_PROVIDER_AUTHORIZATION_ENDPOINT= >> .env
18-
OIDC_PROVIDER_TOKEN_ENDPOINT= >> .env
19-
OIDC_PROVIDER_USERINFO_ENDPOINT= >> .env
67+
OIDC_CLIENT_ID
68+
OIDC_CLIENT_SECRET
69+
COOKIE_ENCRYPTION_KEY
70+
OIDC_PROVIDER_AUTHORIZATION_ENDPOINT
71+
OIDC_PROVIDER_TOKEN_ENDPOINT
72+
OIDC_PROVIDER_USERINFO_ENDPOINT
2073
```
2174
2275
* Create the secret
2376
```
24-
ibmcloud ce secret create --name oidc-credentials --from-env-file .env
77+
ibmcloud ce secret create --name oidc-credentials --from-env-file oidc.properties
2578
```
2679
2780
* Create the application
2881
```
2982
ENCRYPTION_KEY=$(openssl rand -base64 32)
30-
LANGUAGE=go
31-
ibmcloud ce app create --name oidc-sample-$LANGUAGE \
83+
LANGUAGE=node
84+
CE_SUBDOMAIN=$(ibmcloud ce proj current -o json |jq -r '.kube_config_context')
85+
REGION=$(ibmcloud ce proj current -o json |jq -r '.region_id')
86+
ibmcloud ce app create --name oidc-sample \
3287
--src "." \
3388
--build-context-dir "$LANGUAGE" \
3489
--cpu 0.125 \
3590
--memory 0.25G \
3691
--env-from-secret oidc-credentials \
37-
--env COOKIE_ENCRYPTION_KEY=$ENCRYPTION_KEY \
38-
--env OIDC_REDIRECT_URL=https://oidc-sample-$LANGUAGE.1ryejitws058.eu-es.codeengine.appdomain.cloud/auth/callback
39-
40-
OIDC_REDIRECT_URL=$(ibmcloud ce app get -n oidc-sample-$LANGUAGE --output url)
41-
ibmcloud ce app update --name oidc-sample-$LANGUAGE --env OIDC_REDIRECT_URL=$OIDC_REDIRECT_URL/auth/callback
42-
cd ..
92+
--env OIDC_REDIRECT_URL=https://oidc-sample.$CE_SUBDOMAIN.$REGION.codeengine.appdomain.cloud/auth/callback
4393
```
44-
45-
- - -
46-
47-
As noted in [the main README](../README.md), this sample has two pieces:
48-
49-
- a `build` script which will build the container image(s) used
50-
- a `run` script which deploys resources that use those images
51-
52-
The main purpose of this example is the `run` script, but the `build`
53-
script is included for complete educational (and reuse) purposes.

auth-oidc/ce-oidc.simple.png

62.4 KB
Loading

0 commit comments

Comments
 (0)