Skip to content

Commit 9d67dca

Browse files
authored
Merge pull request canonical#89 from SimoneDutto/update-tutorial-to-use-local-identity-provider
feat(tutorial): update tutorial to use the identity provider in the identity bundle
2 parents 1df1379 + 7a0fd37 commit 9d67dca

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed

.wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ hostnames
2828
IAM
2929
installable
3030
Integrations
31+
IP
32+
IPs
3133
JSON
3234
Juju
3335
Kubeflow
@@ -38,6 +40,7 @@ LTS
3840
Makefile
3941
Matrix
4042
Mattermost
43+
MetalLB
4144
MyST
4245
namespace
4346
namespaces

tutorial/index.md

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Set up an isolated test environment with Multipass and the `charm-dev` blueprint
1717

1818
On your machine, install Multipass and use it to set up an Ubuntu virtual machine (VM) called `my-juju-vm` from the `charm-dev` blueprint.
1919

20-
> See more: [Set things up (automatically)](https://canonical-juju.readthedocs-hosted.com/en/latest/user/howto/manage-your-deployment/manage-your-deployment-environment/#manage-your-deployment-environment)
20+
> See more: [Set things up (automatically)](https://documentation.ubuntu.com/juju/latest/howto/manage-your-deployment/manage-your-deployment-environment/index.html#manage-your-deployment-environment)
2121
2222
```{note}
2323
This document also contains a manual path, using which you can set things up without the Multipass VM or the `charm-dev` blueprint. However, please note that the manual path may yield slightly different results that may impact your experience of this tutorial.
@@ -35,7 +35,10 @@ Make sure MicroK8s is correctly set up:
3535

3636
```text
3737
# enable necessary add-ons
38-
sudo microk8s dns ingress host-access
38+
sudo microk8s enable dns host-access
39+
# reconfigure metallb
40+
sudo microk8s disable metallb
41+
sudo microk8s enable metallb:10.64.140.43-10.64.140.49
3942
```
4043

4144
Then install some handy tools to query and extract info from json and yaml:
@@ -57,7 +60,7 @@ Now we will create a Juju model for the identity platform and deploy the bundle.
5760

5861
```text
5962
juju add-model iam
60-
juju deploy identity-platform --trust --channel 0.2/edge
63+
juju deploy identity-platform --trust --channel latest/edge
6164
```
6265

6366
Watch the deployment by running:
@@ -79,47 +82,36 @@ juju offer self-signed-certificates:send-ca-cert
7982

8083
Running `juju status` should now two offers that we will use from a different model in the next step.
8184

82-
## Setup External IdP
83-
84-
We recommend using the following [how-to](https://charmhub.io/topics/canonical-identity-platform/how-to/integrate-external-identity-provider)
85-
and choosing your preferred identity provider.
86-
87-
```{note}
88-
You can temporarily skip this step and return to it later, JIMM can still run without integrating the identity bundle to an external identity provider but login to JIMM will not work.
85+
### Create an user.
86+
```text
87+
# disable MFA to avoid unnecessary steps
88+
juju config kratos enforce_mfa=False
89+
# create the user and get the identity-id
90+
juju run kratos/0 create-admin-account [email protected] password=test username=admin
91+
# reset the password to make it active
92+
juju add-secret password-secret password=abc
93+
juju grant-secret password-secret kratos
94+
juju run kratos/0 reset-password identity-id=<identity-id> password-secret-id=<secret:id>
8995
```
9096

91-
Setting up an IdP to point to your local environment can be tricky depending on the provider used. Below are some tips to make this work.
92-
93-
When setting up certain providers, e.g. Google, security restrictions limit what redirect URLs can be used. Some restrictions include,
97+
### Expose the identity bundle to your host machine. (only necessary if running in Multipass)
98+
The reason you need to expose the identity bundle to your host machine is that at the end of this tutorial
99+
you will need to login via a web browser.
94100

95-
- The redirect URL must be `https`.
96-
- The redirect URL must be a top level domain `.com`.
97-
- The redirect URL cannot be an IP address.
98-
99-
The redirect URL is the URL that your browser is returned to after you have signed in at the identity provider. When using Canonical's
100-
identity bundle, the redirect URL after login will be something like `https://<kratos-public-url>/self-service/methods/oidc/callback/<provider-id>`.
101-
as described in the above how-to. Although the URL is `https`, it is an IP address.
102-
This address needs to be registered in your identity provider as an approved redirect URI/URL.
103-
104-
If your preferred identity provider does not accept an IP address, we recommend using a tool like `https://nip.io/`,
105-
a DNS resolver service that can map any IP address to a hostname.
106-
107-
| This service can map hostnames of the form `<anything>[.-]<IP Address>.nip.io` to return simply `<IP Address>`.
108-
| E.g. `magic.127.0.0.1.nip.io` resolves to `127.0.0.1`. This service is very useful when working with an IdP locally for testing.
109-
110-
```{note}
111-
The same effect can be obtained by editing your `/etc/hosts` file but this would require changes on your host system and within various containers.
101+
Locate the IP of your Multipass instance by running `multipass list` on your host machine, if you have multiple IPs pick the first one.
102+
```text
103+
juju config traefik-public external_hostname=<multipass-ip>
104+
sudo microk8s.kubectl port-forward traefik-public-0 443:443 --namespace=iam --address=<multipass_ip> &
112105
```
113106

114-
To utilise `nip.io`, get the address of your `traefik-public` instance and set the `external_hostname` config option as below,
115-
107+
Run the following on your host machine to test that you've successfully exposed the identity bundle:
116108
```text
117-
TRAEFIK_PUBLIC=$(juju status traefik-public --format yaml | yq .applications.traefik-public.address)
118-
juju config traefik-public external_hostname="iam.$TRAEFIK_PUBLIC.nip.io"
109+
curl -k https://<multipass-ip>/iam-hydra/health/ready
110+
```
111+
The response should be:
112+
```
113+
{"status":"ok"}
119114
```
120-
121-
This has now changed the URL that the identity provider shares to related applications like JIMM. JIMM and your browser will still be able
122-
to resolve this hostname and the IP will only be reachable from your local system.
123115

124116
## Deploy JIMM
125117

@@ -145,8 +137,8 @@ juju deploy juju-jimm-k8s --channel=3/edge jimm
145137
juju deploy openfga-k8s --channel=2.0/stable openfga
146138
juju deploy postgresql-k8s --channel=14/stable postgresql
147139
juju deploy vault-k8s --channel=1.15/beta vault
148-
juju deploy nginx-ingress-integrator --channel=latest/stable --trust ingress
149-
juju relate jimm:nginx-route ingress
140+
juju deploy traefik-k8s --channel=latest/stable --trust ingress
141+
juju relate jimm:ingress ingress
150142
juju relate jimm:openfga openfga
151143
juju relate jimm:database postgresql
152144
juju relate jimm:vault vault
@@ -165,7 +157,7 @@ We are doing this step afterwards to avoid issues that occur when performing the
165157

166158
```text
167159
juju deploy self-signed-certificates jimm-cert
168-
juju relate ingress jimm-cert
160+
juju relate ingress:certificates jimm-cert:certificates
169161
```
170162

171163
Now move onto the next step to initialise Vault.
@@ -266,13 +258,27 @@ Run the following commands:
266258
# Changes to the UUID value after deployment will likely result in broken permissions.
267259
# Use a randomly generated UUID.
268260
juju config jimm uuid=3f4d142b-732e-4e99-80e7-5899b7e67e59
269-
# The address to reach JIMM, this will configure ingress and is also used for OAuth flows/redirects.
270-
juju config jimm dns-name=test-jimm.localhost
261+
```
262+
263+
```text
264+
sudo snap install go
271265
# A private and public key for macaroon based authentication with Juju controllers.
266+
go run github.com/go-macaroon-bakery/macaroon-bakery/cmd/bakery-keygen/v3@latest
267+
# extract the public and private keys from the response
272268
juju config jimm public-key="<public-key>"
273269
juju config jimm private-key="<private-key>"
274270
```
275271

272+
Now you need to amend your `/etc/hosts` to create a DNS record for your ingress.
273+
To do so you need to locate the IP MetalLB assigned to your ingress by running `juju status` and locating the IP
274+
in the description of the `ingress` application ("Serving at <IP>").
275+
276+
```
277+
echo "<ip> test-jimm.local" | sudo tee -a /etc/hosts
278+
# The address to reach JIMM, this will configure ingress and is also used for OAuth flows/redirects.
279+
juju config jimm dns-name=test-jimm.local
280+
```
281+
276282
Optionally, if you have deployed Juju Dashboard, you can configure JIMM to enable browser flow for authentication:
277283

278284
```text
@@ -286,32 +292,15 @@ However, in absence of a Juju Dashboard, you can still enable OAuth browser auth
286292
juju config jimm juju-dashboard-location="http://test-jimm.localhost/auth/whoami"
287293
```
288294

289-
Note that the public and private key pairs must be generated by the [go macaroon bakery repository](https://github.com/go-macaroon-bakery/macaroon-bakery).
290-
To do this briefly run the following command, ensuring you have the `go` tool installed:
291-
292-
```text
293-
go run github.com/go-macaroon-bakery/macaroon-bakery/cmd/bakery-keygen/v3@latest
294-
```
295-
296-
This should return a private and public key pair as below which can be used to configure JIMM.
297-
These values are only used internally between JIMM and Juju controllers.
298-
299-
```text
300-
{
301-
"public": "<public-key>",
302-
"private": "<private-key>"
303-
}
304-
```
305-
306295
At this point you can run `juju status` and you should observe JIMM is active.
307296
Navigate to `http://test-jimm.localhost/debug/info` to verify your JIMM deployment.
308297

309298
Finally we will obtain the ca-certificate generated to ensure that we can connect to JIMM with HTTPS.
310299
This is necessary for the Juju CLI to work properly
311300

312301
```text
313-
juju run jimm-cert/0 get-ca-certificate --quiet | yq .ca-certificate | sudo tee /usrlocal/share/ca-certificates/jimm-test.crt
314-
sudo update-ca-certificates
302+
juju run jimm-cert/0 get-ca-certificate --quiet | yq .ca-certificate | sudo tee /usr/local/share/ca-certificates/jimm-test.crt
303+
sudo update-ca-certificates --fresh
315304
```
316305

317306
Verify that you can securely connect to JIMM with the following command:
@@ -325,7 +314,15 @@ You should be presented with a message to login.
325314

326315
```text
327316
juju login test-jimm.localhost:443 -c jimm-k8s
328-
# Please visit https://iam.10.64.140.46.nip.io/iam-hydra/oauth2/device/verify and entercode <code> to log in.
317+
# Please visit https://<multipass-ip>/iam-hydra/oauth2/device/verify and entercode <code> to log in.
318+
```
319+
Visit the link from your browser, fill the credentials you've created before and you should see.
320+
```text
321+
Welcome, [email protected]. You are now logged into "jimm-k8s".
322+
323+
There are no models available. You can add models with
324+
"juju add-model", or you can ask an administrator or owner
325+
of a model to grant access to that model with "juju grant".
329326
```
330327

331328
## Using Your JIMM Deployment

0 commit comments

Comments
 (0)